Esempio n. 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)
Esempio n. 2
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)
Esempio n. 3
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
Esempio n. 4
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
Esempio n. 5
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.name = "xxx"
        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)
Esempio n. 6
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.name = "xxx"
        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)