Esempio n. 1
0
def main():
	t1 = TextField()
	t1.x = t1.y = 50
	t1.size = 30
	t1.text = "Hello World!"
	addChild(t1)

	t2 = TextField()
	t2.x = 50
	t2.y = 150
	t2.text = "Hello Pylash~"
	t2.rotation = 30
	t2.size = 50
	t2.textColor = "#FF4500"
	t2.weight = TextFormatWeight.BOLD
	addChild(t2)

	t3 = TextField()
	t3.x = 300
	t3.y = 130
	t3.text = "Based on Python3, PyQt4"
	t3.alpha = 0.7
	t3.size = 40
	t3.textColor = "#0000FF"
	t3.italic = True
	addChild(t3)
Esempio n. 2
0
def gameOver(e):
	global player, scoreTxt, stageLayer, keyboardEnabled

	keyboardEnabled = False

	stageLayer.removeAllEventListeners()

	scoreTxt.remove()
	player.animation.stop()

	resultTxt = TextField()
	resultTxt.text = "Final Score: %s" % score
	resultTxt.size = 40
	resultTxt.weight = TextFormatWeight.BOLD
	resultTxt.textColor = "orangered"
	resultTxt.x = (stage.width - resultTxt.width) / 2
	resultTxt.y = 250
	stageLayer.addChild(resultTxt)

	hintTxt = TextField()
	hintTxt.text = "Double Click to Restart"
	hintTxt.size = 35
	hintTxt.textColor = "red"
	hintTxt.x = (stage.width - hintTxt.width) / 2
	hintTxt.y = 320
	stageLayer.addChild(hintTxt)

	# add double click event to restart
	stageLayer.addEventListener(MouseEvent.DOUBLE_CLICK, startGame)
Esempio n. 3
0
def gameInit(result):
	global dataList, stageLayer

	dataList = result

	# create stage layer
	stageLayer = Sprite()
	addChild(stageLayer)

	# add FPS
	fps = FPS()
	addChild(fps)

	# add background
	bg = Bitmap(BitmapData(dataList["bg"]))
	stageLayer.addChild(bg)

	# add some text fields
	titleTxt = TextField()
	titleTxt.text = "Get Furit"
	titleTxt.size = 70
	titleTxt.textColor = "red"
	titleTxt.x = (stage.width - titleTxt.width) / 2
	titleTxt.y = 100
	stageLayer.addChild(titleTxt)

	hintTxt = TextField()
	hintTxt.text = "Tap to Start the Game!~"
	hintTxt.textColor = "red"
	hintTxt.size = 40
	hintTxt.x = (stage.width - hintTxt.width) / 2
	hintTxt.y = 300
	stageLayer.addChild(hintTxt)

	engineTxt = TextField()
	engineTxt.text = "- Powered by Pylash -"
	engineTxt.textColor = "red"
	engineTxt.size = 20
	engineTxt.weight = TextFormatWeight.BOLD
	engineTxt.italic = True
	engineTxt.x = (stage.width - engineTxt.width) / 2
	engineTxt.y = 500
	stageLayer.addChild(engineTxt)

	# add event that the game will start when you click
	stageLayer.addEventListener(MouseEvent.MOUSE_UP, startGame)

	# add keyboard events to control player
	stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDown)
	stage.addEventListener(KeyboardEvent.KEY_UP, keyUp)
Esempio n. 4
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. 5
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. 6
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. 7
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. 8
0
def startGame(e):
	global player, itemLayer, scoreTxt, addItemSpeedIndex, score, keyboardEnabled

	# reset some global variables
	addItemSpeedIndex = 0
	score = 0

	keyboardEnabled = True

	stageLayer.removeAllChildren()
	stageLayer.removeAllEventListeners()

	# add background
	bg = Bitmap(BitmapData(dataList["bg"]))
	stageLayer.addChild(bg)

	# create player
	player = Player(dataList["player"])
	player.x = (stage.width - player.width) / 2
	player.y = 450
	stageLayer.addChild(player)

	# create item layer to contain objects falling from the top
	itemLayer = Sprite()
	stageLayer.addChild(itemLayer)
	# set the hit target to confirm a object which will be checked collision with items
	itemLayer.hitTarget = player

	# add score text field
	scoreTxt = TextField()
	scoreTxt.text = "Score: 0"
	scoreTxt.textColor = "red"
	scoreTxt.size = 30
	scoreTxt.x = scoreTxt.y = 30
	scoreTxt.weight = TextFormatWeight.BOLDER
	stageLayer.addChild(scoreTxt)

	# add events
	stageLayer.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown)
	stageLayer.addEventListener(MouseEvent.MOUSE_UP, onMouseUp)
	stageLayer.addEventListener(Event.ENTER_FRAME, loop)
Esempio n. 9
0
def gameOver():
	global stageLayer, selectedCharacter, start, enemyNum, isMouseDownAtGameLayer

	for o in AttackCharacter.ourList:
		o.animaSet.currentAnimation.removeAllEventListeners()
		o.animaSet.currentAnimation.stop()

	for o in Enemy.enemyList:
		o.animaSet.currentAnimation.removeAllEventListeners()
		o.animaSet.currentAnimation.stop()

	start = False

	stageLayer.mouseEnabled = False
	stageLayer.mouseChildren = False

	if selectedCharacter:
		selectedCharacter.remove()

	selectedCharacter = None

	enemyNum = 0
	isMouseDownAtGameLayer = False

	resultLayer = Sprite()
	addChild(resultLayer)

	# add hint of game over
	hintTxt = TextField()
	hintTxt.textColor = "red"
	hintTxt.text = "Game Over!"
	hintTxt.weight = TextFormatWeight.BOLD
	hintTxt.size = 50
	hintTxt.x = (stage.width - hintTxt.width) / 2
	hintTxt.y = (stage.height - hintTxt.height) / 2 - 40
	resultLayer.addChild(hintTxt)

	# add restart button
	def clickRestartBtn(e):
		global money, lives, loopIndex, stageLayer, fps, terrain

		AttackCharacter.ourList = []
		Enemy.enemyList = []
		
		loopIndex = 0
		money = 200
		lives = 10

		terrain = copy.deepcopy(terrainList)

		stageLayer.remove()
		fps.remove()

		resultLayer.remove()

		gameInit()

	normal = Sprite()
	normal.graphics.beginFill("#666666")
	normal.graphics.lineStyle(3, "#222222")
	normal.graphics.drawRect(0, 0, 130, 60)
	normal.graphics.endFill()

	txt = TextField()
	txt.text = "RESTART"
	txt.textColor = "white"
	txt.size = 20
	txt.x = (normal.width - txt.width) / 2
	txt.y = (normal.height - txt.height) / 2
	normal.addChild(txt)

	over = Sprite()
	over.graphics.beginFill("#888888")
	over.graphics.lineStyle(3, "#222222")
	over.graphics.drawRect(0, 0, 130, 60)
	over.graphics.endFill()

	txt = TextField()
	txt.text = "RESTART"
	txt.textColor = "white"
	txt.size = 20
	txt.x = (over.width - txt.width) / 2
	txt.y = (over.height - txt.height) / 2
	over.addChild(txt)

	restartBtn = Button(normal, over)
	restartBtn.x = (stage.width - restartBtn.width) / 2
	restartBtn.y = stage.height / 2 + 30
	resultLayer.addChild(restartBtn)

	restartBtn.addEventListener(MouseEvent.MOUSE_UP, clickRestartBtn)
Esempio n. 10
0
def gameOver():
    global stageLayer, selectedCharacter, start, enemyNum, isMouseDownAtGameLayer

    for o in AttackCharacter.ourList:
        o.animaSet.currentAnimation.removeAllEventListeners()
        o.animaSet.currentAnimation.stop()

    for o in Enemy.enemyList:
        o.animaSet.currentAnimation.removeAllEventListeners()
        o.animaSet.currentAnimation.stop()

    start = False

    stageLayer.mouseEnabled = False
    stageLayer.mouseChildren = False

    if selectedCharacter:
        selectedCharacter.remove()

    selectedCharacter = None

    enemyNum = 0
    isMouseDownAtGameLayer = False

    resultLayer = Sprite()
    addChild(resultLayer)

    # add hint of game over
    hintTxt = TextField()
    hintTxt.textColor = "red"
    hintTxt.text = "Game Over!"
    hintTxt.weight = TextFormatWeight.BOLD
    hintTxt.size = 50
    hintTxt.x = (stage.width - hintTxt.width) / 2
    hintTxt.y = (stage.height - hintTxt.height) / 2 - 40
    resultLayer.addChild(hintTxt)

    # add restart button
    def clickRestartBtn(e):
        global money, lives, loopIndex, stageLayer, fps, terrain

        AttackCharacter.ourList = []
        Enemy.enemyList = []

        loopIndex = 0
        money = 200
        lives = 10

        terrain = copy.deepcopy(terrainList)

        stageLayer.remove()
        fps.remove()

        resultLayer.remove()

        gameInit()

    normal = Sprite()
    normal.graphics.beginFill("#666666")
    normal.graphics.lineStyle(3, "#222222")
    normal.graphics.drawRect(0, 0, 130, 60)
    normal.graphics.endFill()

    txt = TextField()
    txt.text = "RESTART"
    txt.textColor = "white"
    txt.size = 20
    txt.x = (normal.width - txt.width) / 2
    txt.y = (normal.height - txt.height) / 2
    normal.addChild(txt)

    over = Sprite()
    over.graphics.beginFill("#888888")
    over.graphics.lineStyle(3, "#222222")
    over.graphics.drawRect(0, 0, 130, 60)
    over.graphics.endFill()

    txt = TextField()
    txt.text = "RESTART"
    txt.textColor = "white"
    txt.size = 20
    txt.x = (over.width - txt.width) / 2
    txt.y = (over.height - txt.height) / 2
    over.addChild(txt)

    restartBtn = Button(normal, over)
    restartBtn.x = (stage.width - restartBtn.width) / 2
    restartBtn.y = stage.height / 2 + 30
    resultLayer.addChild(restartBtn)

    restartBtn.addEventListener(MouseEvent.MOUSE_UP, clickRestartBtn)