require(
"src/app/scenes/Utils"
)--这个是我的一个工具类,这里没有用到,所以,有没有这句话都行
"src/app/data/EnermyConfig"
)
localBulletConfig=require(
"src/app/data/BulletConfig"
)
localBulletSprite=import(
".BulletSprite"
)
localEnermySprite=import(
".EnermySprite"
)
)
localGameScene=
@H_335_ 403@"GameScene"
display.newScene(
)
end)
functionGameScene:ctor()
self.player=display.newSprite(
"hero_1.png"
):addTo(self)
self.player:pos(display.cx,display.cy)
self.player:setLocalZOrder(10)
self.touchPos=cc.p(0,0)
self.bullets={}
self.enermy={}
self.touchLayer=display.newColorLayer(cc.c4b(255,255)):addTo(self)
self.touchLayer:setTouchEnabled(
true
)
self.touchLayer:addNodeEventListener(cc.NODE_TOUCH_EVENT,function(event)
if
event.name==
"began"
then
self.touchPos=cc.p(event.x,event.y)
elseifevent.name==
"moved"
then
localx=event.x-self.touchPos.x;
localy=event.y-self.touchPos.y;
self:onTouch(x,y);
else
end
return
true
end)
scheduler.scheduleGlobal(function()
self:createBullet()--这里将产生子弹和敌人放在了同一个计时器中,实际上不应该是这样的
self:createEnermy()
end
functionGameScene:onTouch(x,y)
--更新飞机的位置,没有对飞机是否会触屏做限制
self.player:pos(self.player:getPositionX()+x,self.player:getPositionY()+y)
end
functionGameScene:createBullet()
localconfig=config_bullets[1]
localbullet=BulletSprite:create(config):addTo(self)
bullet:pos(self.player:getPosition())
self.bullets[bullet]=bullet
end
functionGameScene:createEnermy()
--print(
"createenermyschedule"
)
localconfig=config_enermy[1]
localx=math.random(100,400)
localy=display.height+100
localenermy=EnermySprite:create(config):addTo(self)
enermy:setPosition(cc.p(x,y))
self.enermy[enermy]=enermy
end
functionGameScene:onEnter()
end
functionGameScene:onExit()
end
GameScene
|