def initScoreTex(self): self.scoreTex = dkl.Texture() self.scoreTex.x = 20 self.scoreTex.y = self.game.windowHeight - 50 self.stageLayer.addChild(self.scoreTex) self.updateScoreText(self.score)
def gameOver(self): self.playing = False self.textTex = dkl.Texture( dkl.TextureData.fromText("Game Over", size=80)) self.textTex.x = (self.game.windowWidth - self.textTex.getWidth()) / 2 self.textTex.y = 340 self.stageLayer.addChild(self.textTex) self.hintTextTex = dkl.Texture( dkl.TextureData.fromText(">>Press 'F5' to restart<<", size=40, color=dkl.Color.GREEN)) self.hintTextTex.x = (self.game.windowWidth - self.hintTextTex.getWidth()) / 2 self.hintTextTex.y = 260 self.stageLayer.addChild(self.hintTextTex)
def gameOver(self): self.playing = False titleTextTex = dkl.Texture( dkl.TextureData.fromText("Game Over", size=70, color=dkl.Color.RED)) titleTextTex.x = (self.game.windowWidth - titleTextTex.getWidth()) / 2 titleTextTex.y = 340 self.stageLayer.addChild(titleTextTex) hintTextTex = dkl.Texture( dkl.TextureData.fromText(">>Press 'ENTER' to restart<<", size=30, color=dkl.Color.ORANGE)) hintTextTex.x = (self.game.windowWidth - hintTextTex.getWidth()) / 2 hintTextTex.y = 240 self.stageLayer.addChild(hintTextTex)
def __init__(self, img, index): super(Item, self).__init__() self.index = index self.tex = dkl.Texture(img) self.tex.x = -32 self.tex.y = -32 self.addChild(self.tex)
def start(self): self.start = False self.startTex = dkl.Texture( dkl.TextureData.fromText(" Please Enter 'SPACE' To Start ", size=40)) self.startTex.x = (self.game.windowWidth - self.startTex.getWidth()) / 2 self.startTex.y = 320 self.stageLayer.addChild(self.startTex)
def create(self): self.stageLayer = dkl.Sprite() self.game.stage.addChild(self.stageLayer) self.game.stage.addEventListener(dkl.KeyboardEvent.KEY_DOWN, self.onKeyDown) self.stageLayer.addEventListener(dkl.LoopEvent.ENTER_FRAME, self.mainLoop) self.scoreTex = dkl.Texture() self.scoreTex.x = self.scoreTex.y = 1 self.stageLayer.addChild(self.scoreTex) self.updateScoreText(self.score)
def __init__(self, img): super(Player, self).__init__() self.direction = 0 self.animaCol = 0 self.animaRow = 3 self.nextFrameIndex = 0 self.nextFrameSpeed = 5 self.tex = dkl.Texture(img) self.tex.x = -32 self.tex.y = -32 self.tex.textureData.y = self.animaRow * 64 self.tex.textureData.width = 64 self.tex.textureData.height = 64 self.addChild(self.tex)
def create(self): ## keyboard event test def onKeyUp(e): if e.data["key"] == dkl.Keyboard.ESC: self.game.exit() self.game.stage.addEventListener(dkl.KeyboardEvent.KEY_UP, onKeyUp) ## draw shapes: rectangle, circle, triangle layer = dkl.Sprite() layer.x = 50 layer.y = 300 layer.graphics.drawRect(0, 0, 150, 150, fillStyle=dkl.Color.fromHex("#00EE00"), strokeStyle=dkl.Color.fromHex("#009900"), lineWidth=5) layer.graphics.drawArc(275, 75, 75, fillStyle=dkl.Color.fromHex("#EE0000"), strokeStyle=dkl.Color.fromHex("#990000"), lineWidth=5) layer.graphics.drawVertices( [dkl.Point2D(400, 0), dkl.Point2D(475, 150), dkl.Point2D(550, 0)], fillStyle=dkl.Color.fromHex("#0000EE"), strokeStyle=dkl.Color.fromHex("#000099"), lineWidth=5) self.game.stage.addChild(layer) def moveShapes(e): e.currentTarget.x += 1 e.currentTarget.rotation += 0.5 def onClick(e): dkl.log("Click at (%s, %s)" % (e.data["selfX"], e.data["selfY"])) layer.addEventListener(dkl.LoopEvent.ENTER_FRAME, moveShapes) layer.addEventListener(dkl.MouseEvent.MOUSE_UP, onClick) ## load and display images loader = dkl.TextureDataLoader() loader.loadList([{ "name": "yaxi_logo", "path": "./yaxi_logo.png" }, { "name": "avatar", "path": "./avatar.png" }]) tex1 = dkl.Texture(loader.get("avatar")) tex1.x = tex1.y = 60 tex1.textureData.x = tex1.textureData.y = 30 tex1.textureData.width = tex1.textureData.height = 100 self.game.stage.addChild(tex1) tex2 = dkl.Texture(loader.get("yaxi_logo")) tex2.x = 360 tex2.y = 30 tex2.rotation = 30 self.game.stage.addChild(tex2) ## display text field textTexData = dkl.TextureData.fromText( "Hello World! 你好世界!こんにちは世界!", color=dkl.Color.fromHex("#FF0000"), antialiasing=False) textTex = dkl.Texture(textTexData) textTex.x = 50 textTex.y = 500 textTex.scaleX = 1.5 textTex.scaleY = 1.6 self.game.stage.addChild(textTex)
def addBg(self): bgTex = dkl.Texture(self.loader.get("bg")) self.stageLayer.addChild(bgTex)
def create_bird(self): self.bird = dkl.Texture(self.load.get('bird')) self.bird.x = 4 self.bird.y = self.game.windowHeight / 2 self.stageLayer.addChild(self.bird)