def demoInit(result): m1 = Shape() m1.graphics.beginFill() m1.graphics.drawRect(50, 50, 100, 100) m1.graphics.drawCircle(25, 25, 25) m1.graphics.moveTo(200, 25) m1.graphics.lineTo(150, 125) m1.graphics.lineTo(250, 150) m1.graphics.closePath() m1.graphics.drawRect(40, 175, 150, 150) m1.graphics.drawCircle(250, 225, 50) img1 = Bitmap(BitmapData(result["avatar"])) img1.mask = m1 addChild(img1) img1_bg = Bitmap(BitmapData(result["avatar"])) img1_bg.alpha = 0.3 addChild(img1_bg) m2 = Shape() m2.graphics.beginFill() m2.graphics.drawRect(100, 100, 200, 200) m2.graphics.drawCircle(200, 200, 50) img2 = Bitmap(BitmapData(result["girl"])) img2.x = 320 img2.mask = m2 addChild(img2) img2_bg = Bitmap(BitmapData(result["girl"])) img2_bg.x = 320 img2_bg.alpha = 0.3 addChild(img2_bg)
def displayImg2(e): bmp2 = Bitmap(BitmapData(e.currentTarget.content)) bmp2.x = 400 bmp2.y = 10 bmp2.rotation = 15 bmp2.alpha = 0.8 addChild(bmp2)
def main(): loader1 = Loader() loader1.load("./1.png") bmp1 = Bitmap(BitmapData(loader1.content)) bmp1.x = bmp1.y = 10 addChild(bmp1) loader2 = Loader() loader2.load("./2.png") bmp2 = Bitmap(BitmapData(loader2.content)) bmp2.x = 400 bmp2.y = 10 bmp2.rotation = 15 bmp2.alpha = 0.8 addChild(bmp2)
def gameOver(overKind, overInfo): if effectsOn: gameOverEffect.play() global gameContinue gameContinue = False playingLayer.removeAllEventListeners() if overInfo["snakeKind"] == "snake1": snake = snake1 else: snake = snake2 # adjust the positions winner = ["P1"] snake1.speed = 1 snake2.speed = 1 snake1.eatenCandies = 0 snake2.eatenCandies = 0 if (overKind == "wall"): if overInfo["snakeKind"] == "snake1": winner[0] = "P2" while True: if (snake.items[0]["row"] <= 0 or snake.items[0]["row"] >= 49) or (snake.items[0]["col"] <= 0 or snake.items[0]["col"] >= 49): break else: snake.move() elif overKind == "head": if snake1.score == snake2.score: winner = [] elif snake1.score < snake2.score: winner[0] = "P2" for s in overInfo["snakeToMove"]: while (s.items[0]["row"], s.items[0]["col"]) != overInfo["point"]: s.move() elif (overKind == "body"): if overInfo["snakeKind"] == "snake1": winner[0] = "P2" for s in overInfo["snakeToMove"]: while (s.items[0]["row"], s.items[0]["col"]) != overInfo["point"]: s.move() elif (overKind == "bodySameDirection"): if overInfo["snakeKind"] == "snake1": winner[0] = "P2" for s in overInfo["snakeToMove"]: while not((s.items[0]["row"], s.items[0]["col"]) in overInfo["s2Position"]): s.move() lastHead = snake.items[0]["item"] lastHead.visible = False newHead = Bitmap(BitmapData(dataList[snake.snakeKind+"Head"+snake.direction])) newHead.x = lastHead.x newHead.y = lastHead.y playingLayer.addChild(newHead) # display the faces p1Face = TextField() playingLayer.addChild(p1Face) if "P1" in winner: p1Face.text = "😂" else: p1Face.text = "ðŸ˜" p1Face.size = 50 p1Face.x = 20 + 50 - p1Face.width/2 p1Face.y = 20 + 50 - p1Face.height/2 p2Face = TextField() playingLayer.addChild(p2Face) if "P2" in winner: p2Face.text = "😂" else: p2Face.text = "ðŸ˜" p2Face.size = 50 p2Face.x = 400 + 50 - p2Face.width/2 p2Face.y = 20 + 50 - p2Face.height/2 # define the state of buttons normal = Bitmap(BitmapData(dataList["normalLeaveBtn"])) over = Bitmap(BitmapData(dataList["actionLeaveBtn"])) down = Bitmap(BitmapData(dataList["actionLeaveBtn"])) normal.alpha = 0.5 over.alpha = 0.75 down.alpha = 0.75 leaveBtn = Button(normal, over, down, None) leaveBtn.x = 135 leaveBtn.y = 130+250-leaveBtn.height/2 playingLayer.addChild(leaveBtn) def next(e): btnEffect.play() exit() leaveBtn.addEventListener(MouseEvent.MOUSE_UP, next) leaveBtn.addEventListener(MouseEvent.MOUSE_DOWN, btnEffectPlay)