Exemple #1
0
def gameInit(result):
    global beginningLayer, dataList, loadingPage

    loadingPage.remove()

    # save the data which is loaded
    dataList = result

    # create a Sprite object
    beginningLayer = Sprite()
    # push the Sprite object into display list to show
    addChild(beginningLayer)

    # add background
    bg = Bitmap(BitmapData(dataList["bg"], 330, 300))
    beginningLayer.addChild(bg)

    # add some text fields
    title = TextField()
    title.text = "Find Character"
    title.font = "Microsoft YaHei"
    title.size = 60
    title.weight = TextFormatWeight.BOLD
    title.x = (stage.width - title.width) / 2
    title.y = 150
    beginningLayer.addChild(title)

    hintTxt = TextField()
    hintTxt.text = "Tap to Start The Game"
    hintTxt.font = "Microsoft YaHei"
    hintTxt.size = 30
    hintTxt.x = (stage.width - hintTxt.width) / 2
    hintTxt.y = 300
    beginningLayer.addChild(hintTxt)

    engineTxt = TextField()
    engineTxt.text = "- Powered by Pylash -"
    engineTxt.font = "Microsoft YaHei"
    engineTxt.size = 20
    engineTxt.italic = True
    engineTxt.x = (stage.width - engineTxt.width) / 2
    engineTxt.y = 400
    beginningLayer.addChild(engineTxt)

    # add event that game will start when you click
    beginningLayer.addEventListener(MouseEvent.MOUSE_UP, startGame)
Exemple #2
0
    def addResultLayer(self, *text):
        resultLayer = Sprite()
        self.addChild(resultLayer)

        for i in text:
            txt = TextField()
            txt.font = "Microsoft YaHei"
            txt.text = i
            txt.size = 40
            txt.textAlign = TextFormatAlign.CENTER
            txt.x = stage.width / 2
            txt.y = resultLayer.height + 20
            txt.textColor = "orangered"
            txt.weight = TextFormatWeight.BOLD
            resultLayer.addChild(txt)

        # add a botton used for restart
        restartBtn = Sprite()
        restartBtn.graphics.beginFill("yellow")
        restartBtn.graphics.lineStyle(3, "orangered")
        restartBtn.graphics.drawRect(0, 0, 200, 60)
        restartBtn.graphics.endFill()
        restartBtn.x = (stage.width - restartBtn.width) / 2
        restartBtn.y = resultLayer.height + 50
        resultLayer.addChild(restartBtn)

        restartTxt = TextField()
        restartTxt.font = "Microsoft YaHei"
        restartTxt.text = "Restart"
        restartTxt.textColor = "orangered"
        restartTxt.size = 30
        restartTxt.x = (restartBtn.width - restartTxt.width) / 2
        restartTxt.y = (restartBtn.height - restartTxt.height) / 2
        restartBtn.addChild(restartTxt)

        def restart(e):
            self.start()

            resultLayer.remove()

        restartBtn.addEventListener(MouseEvent.MOUSE_UP, restart)

        # make the result layer locate at vertical center
        resultLayer.y = (stage.height - resultLayer.height) / 2
Exemple #3
0
    def startLevel(self, char):
        # get random position of target
        targetX = random.randint(0, 9)
        targetY = random.randint(0, 9)

        self.blockLayer = Sprite()
        self.blockLayer.x = 50
        self.blockLayer.y = 50
        self.blockLayer.alpha = 0.7
        self.blockLayer.mouseChildren = False
        self.addChild(self.blockLayer)

        shapeLayer = Sprite()
        self.blockLayer.addChild(shapeLayer)

        txtLayer = Sprite()
        self.blockLayer.addChild(txtLayer)

        # create blocks with a character
        for i in range(10):
            for j in range(10):
                block = Shape()
                block.x = j * 50
                block.y = i * 50
                block.graphics.beginFill("#33CCFF")
                block.graphics.lineStyle(5, "#0066FF")
                block.graphics.drawRect(0, 0, 50, 50)
                block.graphics.endFill()
                shapeLayer.addChild(block)

                txt = TextField()
                txt.size = 20
                txt.font = "Microsoft YaHei"

                # when this block is target
                if i == targetY and j == targetX:
                    txt.text = char[1]

                    block.isTarget = True
                # when this block is not target
                else:
                    txt.text = char[0]

                    block.isTarget = False

                txt.x = block.x + (50 - txt.width) / 2
                txt.y = block.y + (50 - txt.height) / 2
                txtLayer.addChild(txt)

        self.blockLayer.addEventListener(MouseEvent.MOUSE_UP, self.check)
Exemple #4
0
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)