Exemple #1
0
def gameInit():
    global stageLayer, gameLayer, ctrlLayer, mapLayer, characterLayer, fps

    # create some layers
    stageLayer = Sprite()
    addChild(stageLayer)

    gameLayer = Sprite()
    stageLayer.addChild(gameLayer)

    mapLayer = Sprite()
    gameLayer.addChild(mapLayer)

    characterLayer = Sprite()
    characterLayer.mouseChildren = False
    gameLayer.addChild(characterLayer)

    ctrlLayer = Sprite()
    stageLayer.addChild(ctrlLayer)

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

    addMap()
    initCtrlLayer()
    addEvents()
Exemple #2
0
def main():
	# save the file paths which need to be loaded
	loadList = [
		{"name" : "map", "path" : "./images/map.jpg"},
		{"name" : "guanyu_mov", "path" : "./images/guanyu_mov.png"},
		{"name" : "guanyu_atk", "path" : "./images/guanyu_atk.png"},
		{"name" : "soldier1_atk", "path" : "./images/soldier1_atk.png"},
		{"name" : "soldier1_mov", "path" : "./images/soldier1_mov.png"},
		{"name" : "soldier2_mov", "path" : "./images/soldier2_mov.png"},
		{"name" : "xiahoudun_atk", "path" : "./images/xiahoudun_atk.png"},
		{"name" : "xiahoudun_mov", "path" : "./images/xiahoudun_mov.png"},
	]

	# create loading page
	loadingPage = LoadingSample2()
	addChild(loadingPage)

	def loadComplete(result):
		global dataList

		loadingPage.remove()

		dataList = result

		gameInit()

	# load files
	LoadManage.load(loadList, loadingPage.setProgress, loadComplete)
Exemple #3
0
def main():
	# save the file paths which need to be loaded
	loadList = [
		{"name" : "player", "path" : "./images/player.png"},
		{"name" : "bg", "path" : "./images/bg.jpg"},
		{"name" : "item0", "path" : "./images/item0.png"},
		{"name" : "item1", "path" : "./images/item1.png"},
		{"name" : "item2", "path" : "./images/item2.png"},
		{"name" : "item3", "path" : "./images/item3.png"},
		{"name" : "item4", "path" : "./images/item4.png"},
		{"name" : "item5", "path" : "./images/item5.png"},
		{"name" : "item6", "path" : "./images/item6.png"},
		{"name" : "item7", "path" : "./images/item7.png"}
	]

	# create loading page
	loadingPage = LoadingSample1()
	addChild(loadingPage)

	def loadComplete(result):
		loadingPage.remove()

		gameInit(result)

	# load files
	LoadManage.load(loadList, loadingPage.setProgress, loadComplete)
Exemple #4
0
def main():
	layer = Sprite()
	layer.x = layer.y = 50
	addChild(layer)

	layer.graphics.beginFill()
	layer.graphics.lineStyle(5, "green", 0.2)
	layer.graphics.drawRect(0, 0, 150, 150)
	layer.graphics.endFill()

	layer.graphics.beginFill()
	layer.graphics.lineStyle(5, "green", 0.8)
	layer.graphics.drawRect(200, 0, 150, 150)
	layer.graphics.endFill()

	layer.graphics.beginFill("lightgreen")
	layer.graphics.lineStyle(5, "green", 0.5)
	layer.graphics.drawRect(400, 0, 150, 150)
	layer.graphics.endFill()


	layer.graphics.beginFill()
	layer.graphics.lineStyle(5, "green", 0.2)
	layer.graphics.drawCircle(75, 275, 75)
	layer.graphics.endFill()

	layer.graphics.beginFill()
	layer.graphics.lineStyle(5, "green", 0.8)
	layer.graphics.drawCircle(275, 275, 75)
	layer.graphics.endFill()

	layer.graphics.beginFill("lightgreen")
	layer.graphics.lineStyle(5, "green", 0.5)
	layer.graphics.drawCircle(475, 275, 75)
	layer.graphics.endFill()


	layer.graphics.beginFill()
	layer.graphics.lineStyle(5, "green", 0.2)
	layer.graphics.moveTo(0, 498)
	layer.graphics.lineTo(75, 400)
	layer.graphics.lineTo(150, 498)
	layer.graphics.lineTo(0, 498)
	layer.graphics.endFill()

	layer.graphics.beginFill()
	layer.graphics.lineStyle(5, "green", 0.8)
	layer.graphics.moveTo(200, 498)
	layer.graphics.lineTo(275, 400)
	layer.graphics.lineTo(350, 498)
	layer.graphics.lineTo(200, 498)
	layer.graphics.endFill()

	layer.graphics.beginFill("lightgreen")
	layer.graphics.lineStyle(5, "green", 0.5)
	layer.graphics.moveTo(400, 498)
	layer.graphics.lineTo(475, 400)
	layer.graphics.lineTo(550, 498)
	layer.graphics.lineTo(400, 498)
	layer.graphics.endFill()
Exemple #5
0
def startGame(e):
	global beginningLayer, gameLayer

	beginningLayer.remove()

	gameLayer = GameLayer(dataList["bg"])
	addChild(gameLayer)
Exemple #6
0
def gameInit():
	global stageLayer, gameLayer, ctrlLayer, mapLayer, characterLayer, fps

	# create some layers
	stageLayer = Sprite()
	addChild(stageLayer)

	gameLayer = Sprite()
	stageLayer.addChild(gameLayer)

	mapLayer = Sprite()
	gameLayer.addChild(mapLayer)

	characterLayer = Sprite()
	characterLayer.mouseChildren = False
	gameLayer.addChild(characterLayer)

	ctrlLayer = Sprite()
	stageLayer.addChild(ctrlLayer)

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

	addMap()
	initCtrlLayer()
	addEvents()
def startGame(e):
	global beginningLayer, gameLayer

	beginningLayer.remove()

	gameLayer = GameLayer(dataList["bg"])
	addChild(gameLayer)
Exemple #8
0
def main():
    layer = Sprite()
    layer.x = layer.y = 50
    addChild(layer)

    layer.graphics.beginFill()
    layer.graphics.lineStyle(5, "green", 0.2)
    layer.graphics.drawRect(0, 0, 150, 150)
    layer.graphics.endFill()

    layer.graphics.beginFill()
    layer.graphics.lineStyle(5, "green", 0.8)
    layer.graphics.drawRect(200, 0, 150, 150)
    layer.graphics.endFill()

    layer.graphics.beginFill("lightgreen")
    layer.graphics.lineStyle(5, "green", 0.5)
    layer.graphics.drawRect(400, 0, 150, 150)
    layer.graphics.endFill()

    layer.graphics.beginFill()
    layer.graphics.lineStyle(5, "green", 0.2)
    layer.graphics.drawCircle(75, 275, 75)
    layer.graphics.endFill()

    layer.graphics.beginFill()
    layer.graphics.lineStyle(5, "green", 0.8)
    layer.graphics.drawCircle(275, 275, 75)
    layer.graphics.endFill()

    layer.graphics.beginFill("lightgreen")
    layer.graphics.lineStyle(5, "green", 0.5)
    layer.graphics.drawCircle(475, 275, 75)
    layer.graphics.endFill()

    layer.graphics.beginFill()
    layer.graphics.lineStyle(5, "green", 0.2)
    layer.graphics.moveTo(0, 498)
    layer.graphics.lineTo(75, 400)
    layer.graphics.lineTo(150, 498)
    layer.graphics.lineTo(0, 498)
    layer.graphics.endFill()

    layer.graphics.beginFill()
    layer.graphics.lineStyle(5, "green", 0.8)
    layer.graphics.moveTo(200, 498)
    layer.graphics.lineTo(275, 400)
    layer.graphics.lineTo(350, 498)
    layer.graphics.lineTo(200, 498)
    layer.graphics.endFill()

    layer.graphics.beginFill("lightgreen")
    layer.graphics.lineStyle(5, "green", 0.5)
    layer.graphics.moveTo(400, 498)
    layer.graphics.lineTo(475, 400)
    layer.graphics.lineTo(550, 498)
    layer.graphics.lineTo(400, 498)
    layer.graphics.endFill()
Exemple #9
0
def main():
    global loadingPage

    # save the file path which needs to be loaded
    loadList = [{"name": "bg", "path": "./images/bg.jpg"}]

    # create loading page
    loadingPage = LoadingSample2()
    addChild(loadingPage)

    # load file
    LoadManage.load(loadList, loadingPage.setProgress, gameInit)
Exemple #10
0
def main():
    # save the file paths which need to be loaded
    loadList = [
        {
            "name": "map",
            "path": "./images/map.jpg"
        },
        {
            "name": "guanyu_mov",
            "path": "./images/guanyu_mov.png"
        },
        {
            "name": "guanyu_atk",
            "path": "./images/guanyu_atk.png"
        },
        {
            "name": "soldier1_atk",
            "path": "./images/soldier1_atk.png"
        },
        {
            "name": "soldier1_mov",
            "path": "./images/soldier1_mov.png"
        },
        {
            "name": "soldier2_mov",
            "path": "./images/soldier2_mov.png"
        },
        {
            "name": "xiahoudun_atk",
            "path": "./images/xiahoudun_atk.png"
        },
        {
            "name": "xiahoudun_mov",
            "path": "./images/xiahoudun_mov.png"
        },
    ]

    # create loading page
    loadingPage = LoadingSample2()
    addChild(loadingPage)

    def loadComplete(result):
        global dataList

        loadingPage.remove()

        dataList = result

        gameInit()

    # load files
    LoadManage.load(loadList, loadingPage.setProgress, loadComplete)
Exemple #11
0
def main():
	global loadingBar

	loadList = [
		{"name" : "1", "path" : "./1.png"},
		{"name" : "2", "path" : "./2.png"},
		{"name" : "3", "path" : "./3.png"}
	]

	loadingBar = LoadingSample2()
	addChild(loadingBar)

	LoadManage.load(loadList, loadingBar.setProgress, demoInit)
Exemple #12
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)
Exemple #13
0
def main():
	global loadingPage

	# save the file path which needs to be loaded
	loadList = [
		{"name" : "bg", "path" : "./images/bg.jpg"}
	]

	# create loading page
	loadingPage = LoadingSample2()
	addChild(loadingPage)

	# load file
	LoadManage.load(loadList, loadingPage.setProgress, gameInit)
Exemple #14
0
def main():
    global loadingBar

    loadList = [{
        "name": "atk",
        "path": "./atk.png"
    }, {
        "name": "mov",
        "path": "./mov.png"
    }]

    loadingBar = LoadingSample2()
    addChild(loadingBar)

    LoadManage.load(loadList, loadingBar.setProgress, demoInit)
Exemple #15
0
def main():
	global loadingBar

	loadList = [
		{"name" : "bgm", "path" : "./bgm.mp3"},
		{"name" : "1", "path" : "./1.jpg"},
		{"name" : "2", "path" : "./2.jpg"},
		{"name" : "3", "path" : "./3.jpg"},
		{"name" : "4", "path" : "./4.jpg"}
	]

	loadingBar = LoadingSample3()
	addChild(loadingBar)

	LoadManage.load(loadList, loadingBar.setProgress, demoInit)
Exemple #16
0
def main():
	global loadingBar

	loadList = [
		{"name" : "bgm", "path" : "./bgm.mp3"},
		{"name" : "1", "path" : "./1.jpg"},
		{"name" : "2", "path" : "./2.jpg"},
		{"name" : "3", "path" : "./3.jpg"},
		{"name" : "4", "path" : "./4.jpg"}
	]

	loadingBar = LoadingSample3()
	addChild(loadingBar)
	
	LoadManage.load(loadList, loadingBar.setProgress, demoInit)
Exemple #17
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)
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 #19
0
def demoInit(result):
	global loadingBar

	loadingBar.remove()

	imageList = [BitmapData(result["1"]), BitmapData(result["2"]), BitmapData(result["3"]), BitmapData(result["4"])]

	for i, bmpd in enumerate(imageList):
		bmp = Bitmap(bmpd)
		bmp.scaleX = bmp.scaleY = 0.3
		bmp.x += i * 140
		bmp.y += i * 150
		addChild(bmp)

	sound = Sound()
	sound.load(result["bgm"])
	sound.play()
Exemple #20
0
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)
Exemple #21
0
def main():
    global loadingBar

    loadList = [{
        "name": "1",
        "path": "./1.png"
    }, {
        "name": "2",
        "path": "./2.png"
    }, {
        "name": "3",
        "path": "./3.png"
    }]

    loadingBar = LoadingSample2()
    addChild(loadingBar)

    LoadManage.load(loadList, loadingBar.setProgress, demoInit)
Exemple #22
0
def demoInit(result):
	global loadingBar

	loadingBar.remove()

	imageList = [BitmapData(result["1"]), BitmapData(result["2"]), BitmapData(result["3"]), BitmapData(result["4"])]

	for i, bmpd in enumerate(imageList):
		bmp = Bitmap(bmpd)
		bmp.scaleX = bmp.scaleY = 0.3
		bmp.x += i * 140
		bmp.y += i * 150
		addChild(bmp)

	sound = Sound()
	sound.loop = True
	sound.load(result["bgm"])
	sound.play()
def main():
    global stageLayer

    stageLayer = Sprite()
    stageLayer.graphics.beginFill()
    stageLayer.graphics.drawRect(0, 0, stage.width, stage.height)
    stageLayer.graphics.endFill()
    addChild(stageLayer)

    # add events
    stageLayer.addEventListener(MouseEvent.MOUSE_MOVE, mouseMove)
    stageLayer.addEventListener(MouseEvent.MOUSE_UP, mouseUp)

    # create a circle
    circle = DraggableShape(Circle(0, 0, 60))
    circle.x = circle.y = 150
    stageLayer.addChild(circle)

    # create a square
    square = DraggableShape(Polygon(getPolygonVertices(4, 70)))
    square.x = square.y = 350
    stageLayer.addChild(square)

    # create a pentagon
    pentagon = DraggableShape(Polygon(getPolygonVertices(5, 80)))
    pentagon.x = 150
    pentagon.y = 350
    stageLayer.addChild(pentagon)

    # create a hexagon
    hexagon = DraggableShape(Polygon(getPolygonVertices(6, 90)))
    hexagon.x = 350
    hexagon.y = 150
    stageLayer.addChild(hexagon)

    # create a dodecagon
    dodecagon = DraggableShape(Polygon(getPolygonVertices(12, 100)))
    dodecagon.x = 580
    dodecagon.y = 250
    stageLayer.addChild(dodecagon)
Exemple #24
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)
Exemple #25
0
def gameInit(result):

    global dataList, stageLayer  # 全局变量dataList和stageLayer

    dataList = result  # 将result的值赋给dataList,又因为dataList是全局变量,所以在其他函数中也可以通过dataList调用加载完成的文件

    # 创建主界面
    stageLayer = Sprite()  # 创建了一个Sprite类的对象stageLayer
    addChild(
        stageLayer)  # addChild是一个用于把显示对象加到自身这个层上的函数,详见utils.py文件中的全局函数addChild

    # 创建背景元素
    bg = Bitmap(BitmapData(dataList["bg"]))
    #dataList保存加载完成的文件,BitmapData类用于存储图像数据,而Bitmap类用于显示图片,类似于TextField
    stageLayer.addChild(bg)
    #此处使用的不是全局函数addChild,而是stageLayer对象调用的addChild,stageLayer作为self参数传入,使得bd添加在了stageLayer上

    # 创建文本元素
    titleTxt = creatTxt("忍住不能吃零食", 70, 155, 100,
                        "black")  #以上代码生成的是第一行文本,即游戏的名字

    # 创建按钮元素
    button0 = creatButton("button0", stage.width - 225, 350,
                          mySettings)  # button0是"开始游戏"按钮,点击按钮进入"设置"界面
    button1 = creatButton("button1", stage.width - 225, 420,
                          introduction)  # button1是"规则介绍"按钮,点击按钮进入"规则介绍"界面

    # 创建音乐播放元素
    music0 = Sound()
    music0.load("http:\\bd.kuwo.cn\yinyue\37552330?from=baidu")
    music0.play()
    #未能正常运行

    # 添加监听器
    stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDown)
    stage.addEventListener(KeyboardEvent.KEY_UP, keyUp)
Exemple #26
0
def demoInit(result):
	global loadingBar

	loadingBar.remove()

	dataList = result

	bmp1 = Bitmap(BitmapData(dataList["1"]))
	bmp1.x = 530
	bmp1.y = 30
	addChild(bmp1)

	bmp2 = Bitmap(BitmapData(dataList["2"]))
	bmp2.x = 530
	bmp2.y = 230
	addChild(bmp2)

	bmp3 = Bitmap(BitmapData(dataList["3"]))
	bmp3.x = 530
	bmp3.y = 460
	addChild(bmp3)

	TweenLite.to(bmp1, 3, {
		"x" : 30,
		"alpha" : 0.5,
		"ease" : Easing.Sine.easeOut
	})

	TweenLite.to(bmp2, 3, {
		"x" : 50,
		"rotation" : 360,
		"ease" : Easing.Back.easeIn
	})

	TweenLite.to(bmp3, 3, {
		"x" : 250,
		"y" : 700,
		"scaleX" : -1,
		"scaleY" : -1,
		"ease" : Easing.Quad.easeIn
	}).to(bmp3, 2, {
		"delay" : 1,
		"scaleY" : 1,
		"y" : 460
	})
Exemple #27
0
def demoInit(result):
    global loadingBar

    loadingBar.remove()

    dataList = result

    bmp1 = Bitmap(BitmapData(dataList["1"]))
    bmp1.x = 530
    bmp1.y = 30
    addChild(bmp1)

    bmp2 = Bitmap(BitmapData(dataList["2"]))
    bmp2.x = 530
    bmp2.y = 230
    addChild(bmp2)

    bmp3 = Bitmap(BitmapData(dataList["3"]))
    bmp3.x = 530
    bmp3.y = 460
    addChild(bmp3)

    TweenLite.to(bmp1, 3, {"x": 30, "alpha": 0.5, "ease": Easing.Sine.easeOut})

    TweenLite.to(bmp2, 3, {
        "x": 50,
        "rotation": 360,
        "ease": Easing.Back.easeIn
    })

    TweenLite.to(bmp3, 3, {
        "x": 250,
        "y": 700,
        "scaleX": -1,
        "scaleY": -1,
        "ease": Easing.Quad.easeIn
    }).to(bmp3, 2, {
        "delay": 1,
        "scaleY": 1,
        "y": 460
    })
Exemple #28
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)
Exemple #29
0
def main():

    # 资源列表,列出了所有需要调用的图片资源及路径

    loadList = [
        {
            "name": "player0",
            "path": "./images/player0.png"
        },  #游戏角色图片0
        {
            "name": "player1",
            "path": "./images/player1.png"
        },  #游戏角色图片1
        {
            "name": "player2",
            "path": "./images/player2.png"
        },  #游戏角色图片2
        {
            "name": "player3",
            "path": "./images/player3.png"
        },  #游戏角色图片3
        {
            "name": "player00",
            "path": "./images/player00.png"
        },  #游戏角色图片00
        {
            "name": "player01",
            "path": "./images/player01.png"
        },  #游戏角色图片01
        {
            "name": "player02",
            "path": "./images/player02.png"
        },  #游戏角色图片02
        {
            "name": "player03",
            "path": "./images/player03.png"
        },  #游戏角色图片03
        {
            "name": "bg",
            "path": "./images/bg.jpg"
        },  #游戏背景图片
        {
            "name": "bg1",
            "path": "./images/bg1.png"
        },  #规则说明背景图片
        {
            "name": "bg2",
            "path": "./images/bg2.png"
        },  #设置界面
        {
            "name": "bg3",
            "path": "./images/bg3.png"
        },  #确认设置界面
        {
            "name": "item0",
            "path": "./images/item0.png"
        },  #加分物体1
        {
            "name": "item1",
            "path": "./images/item1.png"
        },  #加分物体2
        {
            "name": "item2",
            "path": "./images/item2.png"
        },  #加分物体3
        {
            "name": "item3",
            "path": "./images/item3.png"
        },  #加分物体4
        {
            "name": "item4",
            "path": "./images/item4.png"
        },  #减分物体1
        {
            "name": "item5",
            "path": "./images/item5.png"
        },  #减分物体2
        {
            "name": "item6",
            "path": "./images/item6.png"
        },  #减分物体3
        {
            "name": "item7",
            "path": "./images/item7.png"
        },  #减分物体4
        {
            "name": "button0",
            "path": "./images/button0.png"
        },  #开始按钮
        {
            "name": "button1",
            "path": "./images/button1.png"
        },  #规则介绍按钮
        {
            "name": "button2",
            "path": "./images/button2.png"
        },  #返回按钮
        {
            "name": "level0",
            "path": "./images/level0.png"
        },  #简单模式
        {
            "name": "level1",
            "path": "./images/level1.png"
        },  #中等模式
        {
            "name": "level2",
            "path": "./images/level2.png"
        },  #复杂模式
        {
            "name": "choice",
            "path": "./images/choice.png"
        },  #选择框
        {
            "name": "result0",
            "path": "./images/result0.png"
        },  #失败装饰品
        {
            "name": "result1",
            "path": "./images/result1.png"
        }  #胜利装饰品
    ]
    # 加载页
    loadingPage = LoadingSample1()
    #LoadingSample1类在ui.py文件中,是LoadingSample的子类,()中写的是继承的父类,在这里只是标准的类对象生成格式
    addChild(loadingPage)

    #addChild是一个用于把显示对象加到自身这个层上的函数,详见utils.py文件中的全局函数addChild

    def loadComplete(result):
        loadingPage.remove()  #把loading页面删除
        #LoadingSample1类中的父类display.py文件中的DisplayObject类的remove函数,进而使用到了同文件中DisplayObjectContainer类中的removeChild类

        gameInit(result)  #游戏界面初始化
        #本文件中的一个全局函数,用于初始化游戏

    # 加载文件的命令,实现
    LoadManage.load(loadList, loadingPage.setProgress, loadComplete)
Exemple #30
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)
Exemple #31
0
def demoInit(result):
    global loadingBar, animaSet

    loadingBar.remove()

    # move image
    mov = result["mov"]
    # atk image
    atk = result["atk"]

    ###
    # create animation set to contain a sort of animations
    ###
    animaSet = AnimationSet()
    animaSet.x = animaSet.y = 100
    addChild(animaSet)

    ###
    # move animation
    ###
    # get move animation frame list
    frameList = Animation.divideUniformSizeFrames(48, 96, 1, 2)

    # move down
    bmpd = BitmapData(mov, 0, 0, 48, 96)
    anima = Animation(bmpd, frameList)
    animaSet.addAnimation("move_down", anima)
    # move up
    bmpd = BitmapData(mov, 0, 96, 48, 96)
    anima = Animation(bmpd, frameList)
    animaSet.addAnimation("move_up", anima)
    # move left
    bmpd = BitmapData(mov, 0, 192, 48, 96)
    anima = Animation(bmpd, frameList)
    animaSet.addAnimation("move_left", anima)
    # move right
    bmpd = BitmapData(mov, 0, 192, 48, 96)
    anima = Animation(bmpd, frameList)
    anima.mirroring = True
    animaSet.addAnimation("move_right", anima)

    ###
    # attack animation
    ###
    # get atk animation frame list
    frameList = Animation.divideUniformSizeFrames(64, 256, 1, 4)

    # atk down
    bmpd = BitmapData(atk, 0, 0, 64, 256)
    anima = Animation(bmpd, frameList)
    animaSet.addAnimation("atk_down", anima)
    # atk up
    bmpd = BitmapData(atk, 0, 256, 64, 256)
    anima = Animation(bmpd, frameList)
    animaSet.addAnimation("atk_up", anima)
    # atk left
    bmpd = BitmapData(atk, 0, 512, 64, 256)
    anima = Animation(bmpd, frameList)
    animaSet.addAnimation("atk_left", anima)
    # atk right
    bmpd = BitmapData(atk, 0, 512, 64, 256)
    anima = Animation(bmpd, frameList)
    anima.mirroring = True
    animaSet.addAnimation("atk_right", anima)

    for n in animaSet.animationList:
        o = animaSet.animationList[n]

        o.playMode = AnimationPlayMode.VERTICAL
        o.speed = 5

        # if atk animation... (because atk animation is bigger than move animation)
        if n.find("atk") >= 0:
            o.x -= 8
            o.y -= 8

    animaSet.changeAnimation("move_down")

    ###
    # create buttons
    ###
    btnList = [
        "move down", "move up", "move right", "move left", "atk down",
        "atk up", "atk right", "atk left"
    ]

    btnLayer = Sprite()
    btnLayer.x = 200
    btnLayer.y = 50
    addChild(btnLayer)

    for i, n in enumerate(btnList):
        btn = ButtonSample(text=n)
        btn.label = n
        btnLayer.addChild(btn)
        btn.addEventListener(MouseEvent.MOUSE_DOWN, onBtnClick)

        btn.x = (0 if (4 - i) > 0 else 1) * 150
        btn.y = (i % 4) * 50