def gameStart(data, bgmPlay, effectsPlay, p1Profile, p2Profile): global dataList, playingLayer, effectsOn, gameOverEffect, eatCandyEffects, moveEffect, btnEffect effectsOn = effectsPlay # receive the loaded data dataList = data gameOverEffect = Sound(dataList["gameOverEffect"]) eatCandyEffects = [Sound(dataList["eatCandyEffect1"]),Sound(dataList["eatCandyEffect2"]),Sound(dataList["eatCandyEffect3"])] for eatCandyEffect in eatCandyEffects: eatCandyEffect.loopCount = 1 moveEffect = Sound(dataList["moveEffect"]) moveEffect.loopCount = Sound.LOOP_FOREVER btnEffect = Sound(dataList["btnEffect"]) btnEffect.loopCount = 1 # create the playing layer playingLayer = Sprite() addChild(playingLayer) # set the bg image playingBg = Bitmap(BitmapData(dataList["playingBg"], 0, 0, 520, 640)) playingLayer.addChild(playingBg) # add profiles profile1 = Bitmap(BitmapData(dataList["profile%s" % p1Profile])) profile1.x = 20 profile1.y = 20 profile1.width = 100 profile1.height = 100 playingLayer.addChild(profile1) profile2 = Bitmap(BitmapData(dataList["profile%s" % p2Profile])) profile2.x = 400 profile2.y = 20 profile2.width = 100 profile2.height = 100 playingLayer.addChild(profile2) # display the scores colon = TextField() colon.text = ":" colon.size = 50 colon.x = 260 - colon.width/2 colon.y = 70 - colon.height/2 colon.textColor = "#225590" colon.font = "Bradley Hand" playingLayer.addChild(colon) global snake1, snake2 # create game snakes snake1 = snake("snake1", 60, 180, "Right") snake2 = snake("snake2", 450, 570, "Left") global score1Txt, score2Txt score1Txt = TextField() score1Txt.text = "%s" % snake1.score score1Txt.size = 50 score1Txt.x = 260 - 20 - score1Txt.width score1Txt.y = 70 - score1Txt.height/2 score1Txt.textColor = "#225590" score1Txt.font = "Bradley Hand" playingLayer.addChild(score1Txt) score2Txt = TextField() score2Txt.text = "%s" % snake2.score score2Txt.size = 50 score2Txt.x = 260 + 20 score2Txt.y = 70 - score2Txt.height/2 score2Txt.textColor = "#225590" score2Txt.font = "Bradley Hand" playingLayer.addChild(score2Txt) # add sample snakes sampleSnake1 = snake("snake1", 130, 40, "Up") sampleSnake2 = snake("snake2", 380, 40, "Up") stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDown) stage.addEventListener(KeyboardEvent.KEY_UP, keyUp) playingLayer.addEventListener(LoopEvent.ENTER_FRAME, loop) generate(0.05)