Exemple #1
0
def creatPict(Name, X, Y):
    global dataList, stageLayer
    picture = Bitmap(BitmapData(dataList[Name]))
    picture.x = X
    picture.y = Y
    stageLayer.addChild(picture)
    return picture
Exemple #2
0
def initCoverPage(result):
    # receive the loaded data
    dataList = result

    # add the cover layer
    coverLayer = Sprite()
    addChild(coverLayer)

    # set the bg image
    coverBg = Bitmap(BitmapData(dataList["coverBg"], 0, 0, 520, 640))
    coverLayer.addChild(coverBg)

    # define the state of buttons
    normal = Bitmap(BitmapData(dataList["normalStartBtn"]))
    over = Bitmap(BitmapData(dataList["actionStartBtn"]))
    down = Bitmap(BitmapData(dataList["actionStartBtn"]))

    startBtn = Button(normal, over, down, None)
    startBtn.x = 135
    startBtn.y = 385
    coverLayer.addChild(startBtn)

    def next(e):
        # remove the contents of cover layer
        coverLayer.remove()

        # init cover layer
        initSettingPage(dataList)

    startBtn.addEventListener(MouseEvent.MOUSE_UP, next)
Exemple #3
0
 def addBody(self, y, x):
     item = Bitmap(BitmapData(dataList[self.snakeKind+"Body"]))
     item.x = x
     item.y = y
     playingLayer.addChild(item)
     self.items.append({"row":int(y/10)-13, "col":int(x/10)-1, "item":item}) # the row and col is wrt the gameBoard
     if (y/10-13 >= 0) and (x/10-1 >= 0):
         gameBoard[int(y/10-13)][int(x/10-1)] = self.snakeKind
Exemple #4
0
def generate(ratio):
    global candies
    while (len(candies)/(2500-len(snake1.items)-len(snake2.items)) < ratio):
        row = random.randint(0, 49)
        col = random.randint(0, 49)

        if (gameBoard[row][col] == None):
            gameBoard[row][col] = "candy"
            candyKind = random.randint(0,3)
            newCandy = Bitmap(BitmapData(dataList["candy%s" % candyKind]))
            newCandy.x = 10 + col*10
            newCandy.y = 130 + row*10
            playingLayer.addChild(newCandy)
            candies[str(row)+"_"+str(col)] = newCandy
Exemple #5
0
def addMap():
	global mapLayer

	for y, row in enumerate(mapImageList):
		for x, v in enumerate(row):
			# get the small image's position in map.jpg
			yIndex = math.floor(v / 10)
			xIndex = v % 10

			# get the small image in map.jpg
			bmpd = BitmapData(dataList["map"], xIndex * 48, yIndex * 48, 48, 48)
			# display the small image
			bmp = Bitmap(bmpd)
			bmp.x = x * 48
			bmp.y = y * 48
			mapLayer.addChild(bmp)
Exemple #6
0
def addMap():
	global mapLayer

	for y, row in enumerate(mapImageList):
		for x, v in enumerate(row):
			# get the small image's position in map.jpg
			yIndex = math.floor(v / 10)
			xIndex = v % 10

			# get the small image in map.jpg
			bmpd = BitmapData(dataList["map"], xIndex * 48, yIndex * 48, 48, 48)
			# display the small image
			bmp = Bitmap(bmpd)
			bmp.x = x * 48
			bmp.y = y * 48
			mapLayer.addChild(bmp)
Exemple #7
0
    def __init__(self, image):
        super(Item, self).__init__()

        bmp = Bitmap(BitmapData(image))
        self.addChild(bmp)

        self.index = 0
        self.y = -bmp.height / 2
    def __init__(self, snakeKind, startX, startY, direction):
        super(snake, self).__init__()
        self.snakeKind = snakeKind
        self.direction = direction
        self.startX = startX
        self.startY = startY
        self.speed = 1
        self.eatenCandies = 0
        self.score = 0
        self.heads = {
            "Up" : Bitmap(BitmapData(dataList[self.snakeKind+"HeadUp"])),
            "Down" : Bitmap(BitmapData(dataList[self.snakeKind+"HeadDown"])),
            "Left" : Bitmap(BitmapData(dataList[self.snakeKind+"HeadLeft"])),
            "Right" : Bitmap(BitmapData(dataList[self.snakeKind+"HeadRight"]))
        }
        for i in self.heads:
            playingLayer.addChild(self.heads[i])
            self.heads[i].visible = False
        self.items = [{"row":int(self.startY/10)-13, "col":int(self.startX/10)-1, "item":self.heads[self.direction]}]
        self.items[0]["item"].x = self.startX
        self.items[0]["item"].y = self.startY
        self.items[0]["item"].visible = True
        playingLayer.addChild(self.items[0]["item"])

        global gameBoard
        if (startX/10-1 >= 0) and (startY/10-13 >= 0):
            gameBoard[int(startY/10-13)][int(startX/10-1)] = "head"

        if self.direction == "Up":
            for i in range(5):
                self.addBody(self.startY+(1+i)*10, self.startX)
        elif  self.direction == "Down":
            for i in range(5):
                self.addBody(self.startY+(-1-i)*10, self.startX)
        elif self.direction == "Left":
            for i in range(5):
                self.addBody(self.startY, self.startX+(1+i)*10)
        elif self.direction == "Right":
            for i in range(5):
                self.addBody(self.startY, self.startX+(-1-i)*10)
        for i in gameBoard:
            for j in i:
                if j == "snake1":
                    boo = True
        print("snake init:", boo)
Exemple #9
0
def creatBg(name):
    global dataList, stageLayer
    stageLayer.removeAllChildren()  # 移除原界面的背景和元素
    stageLayer.removeAllEventListeners()

    # 创建背景元素
    bg = Bitmap(BitmapData(dataList[name]))
    stageLayer.addChild(bg)
    return bg
Exemple #10
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 #11
0
def displayImg2(e):
    bmp2 = Bitmap(BitmapData(e.currentTarget.content))
    bmp2.x = 400
    bmp2.y = 10
    bmp2.rotation = 15
    bmp2.alpha = 0.8
    addChild(bmp2)
def generate(ratio, candyKind):
    global candies, gameBoard

    boo = False 
    for i in gameBoard:
        for j in i:
            if j == "snake1":
                boo = True
    print("directly before really generate:", boo)

    while (len(candies)/(2500-len(snake1.items)-len(snake2.items)) < ratio):
        row = random.randint(0, 49)
        col = random.randint(0, 49)

        if (gameBoard[row][col] == None):
            gameBoard[row][col] = "candy"
            # candyKind = random.randint(0,3)
            newCandy = Bitmap(BitmapData(dataList["candy%s" % candyKind]))
            newCandy.x = 10 + col*10
            newCandy.y = 130 + row*10
            playingLayer.addChild(newCandy)
            candies[str(row)+"_"+str(col)] = newCandy
Exemple #13
0
    def __init__(self, bg):
        super(GameLayer, self).__init__()

        self.blockLayer = None
        self.characters = (("我", "找"), ("王", "玉"), ("籍", "藉"), ("春", "舂"),
                           ("龙", "尤"), ("已", "己"), ("巳", "已"))

        # add background
        bg = Bitmap(BitmapData(bg, 50, 50))
        self.addChild(bg)

        # start game
        self.start()
Exemple #14
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 #15
0
	def selectCharacter(e):
		global selectedCharacter

		name = e.currentTarget.name

		# create selectedCharacter
		selectedCharacter = Sprite()
		selectedCharacter.name = name
		selectedCharacter.mouseShelter = False
		stageLayer.addChild(selectedCharacter)

		bmp = Bitmap(BitmapData(dataList[name + "_mov"], 0, 0, 48, 48))
		selectedCharacter.addChild(bmp)

		# make selectedCharacter move to mouse's position
		selectedCharacter.x = e.offsetX - selectedCharacter.width / 2
		selectedCharacter.y = e.offsetY - selectedCharacter.height / 2
Exemple #16
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 #17
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(result["bgm"])
	sound.loopCount = Sound.LOOP_FOREVER
	sound.play()
Exemple #18
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 #19
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)
Exemple #20
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 #21
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)
Exemple #22
0
def initCtrlLayer():
	global ctrlLayer, selectedCharacter, startBtn, moneyTxt, livesTxt, money, lives

	def selectCharacter(e):
		global selectedCharacter

		name = e.currentTarget.name

		# create selectedCharacter
		selectedCharacter = Sprite()
		selectedCharacter.name = name
		selectedCharacter.mouseShelter = False
		stageLayer.addChild(selectedCharacter)

		bmp = Bitmap(BitmapData(dataList[name + "_mov"], 0, 0, 48, 48))
		selectedCharacter.addChild(bmp)

		# make selectedCharacter move to mouse's position
		selectedCharacter.x = e.offsetX - selectedCharacter.width / 2
		selectedCharacter.y = e.offsetY - selectedCharacter.height / 2

	# draw the background of the ctrlLayer
	ctrlLayer.graphics.beginFill("#333333")
	ctrlLayer.graphics.lineStyle(3, "#222222")
	ctrlLayer.graphics.drawRect(0, 0, 150, stage.height)
	ctrlLayer.graphics.endFill()

	# list of our characters
	ourList = ["guanyu", "xiahoudun", "soldier1"]

	# show selectors of our characters
	selectorsLayer = Sprite()
	ctrlLayer.addChild(selectorsLayer)

	for i, v in enumerate(ourList):
		selector = Sprite()
		selector.name = v
		selectorsLayer.addChild(selector)

		# the appearance of the character
		bmp = Bitmap(BitmapData(dataList[v + "_mov"], 0, 0, 48, 48))
		selector.addChild(bmp)

		# show the cost of the character
		costTxt = TextField()
		costTxt.text = charactersData[v]["cost"]
		costTxt.textColor = "white"
		costTxt.x = (bmp.width - costTxt.width) / 2
		costTxt.y = bmp.height + 10
		selector.addChild(costTxt)

		selector.y = i * 88

		selector.addEventListener(MouseEvent.MOUSE_DOWN, selectCharacter)

	selectorsLayer.x = (ctrlLayer.width - selectorsLayer.width) / 2
	selectorsLayer.y = 40

	# add lives and money text
	livesTxt = TextField()
	livesTxt.text = "Lives: %s" % lives
	livesTxt.x = (ctrlLayer.width - livesTxt.width) / 2
	livesTxt.y = stage.height - 150
	livesTxt.textColor = "white"
	ctrlLayer.addChild(livesTxt)

	moneyTxt = TextField()
	moneyTxt.text = "Money: %s" % money
	moneyTxt.x = (ctrlLayer.width - moneyTxt.width) / 2
	moneyTxt.y = livesTxt.y + 30
	moneyTxt.textColor = "white"
	ctrlLayer.addChild(moneyTxt)

	# add a button to start game
	def clickStartBtn(e):
		global start, enemyNum

		start = True

		enemyNum = 0

		e.currentTarget.state = ButtonState.DISABLED

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

	txt = TextField()
	txt.text = "START"
	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, 100, 60)
	over.graphics.endFill()

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

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

	txt = TextField()
	txt.text = "START"
	txt.textColor = "#333333"
	txt.size = 20
	txt.x = (disabled.width - txt.width) / 2
	txt.y = (disabled.height - txt.height) / 2
	disabled.addChild(txt)

	startBtn = Button(normal, over, None, disabled)
	startBtn.x = (ctrlLayer.width - startBtn.width) / 2
	startBtn.y = stage.height - 80
	ctrlLayer.addChild(startBtn)

	startBtn.addEventListener(MouseEvent.MOUSE_UP, clickStartBtn)

	ctrlLayer.x = stage.width - ctrlLayer.width
Exemple #23
0
def gameOver(overKind, overInfo):
    if effectsOn:
        gameOverEffect.play()
    global gameContinue
    gameContinue = False
    playingLayer.removeAllEventListeners()
    if overInfo["snakeKind"] == "snake1":
        snake = snake1
    else:
        snake = snake2


    # adjust the positions
    winner = ["P1"]
    snake1.speed = 1
    snake2.speed = 1
    snake1.eatenCandies = 0
    snake2.eatenCandies = 0
    if (overKind == "wall"):
        if overInfo["snakeKind"] == "snake1":
            winner[0] = "P2"
        while True:

            if (snake.items[0]["row"] <= 0 or snake.items[0]["row"] >= 49) or (snake.items[0]["col"] <= 0 or snake.items[0]["col"] >= 49):
                break
            else:
                snake.move()
    elif overKind == "head":
        if snake1.score == snake2.score:
            winner = []
        elif snake1.score < snake2.score:
            winner[0] = "P2"

        for s in overInfo["snakeToMove"]:
            while (s.items[0]["row"], s.items[0]["col"]) != overInfo["point"]:
                s.move()
    elif (overKind == "body"):
        if overInfo["snakeKind"] == "snake1":
            winner[0] = "P2"

        for s in overInfo["snakeToMove"]:
            while (s.items[0]["row"], s.items[0]["col"]) != overInfo["point"]:
                s.move()
    elif (overKind == "bodySameDirection"):
        if overInfo["snakeKind"] == "snake1":
            winner[0] = "P2"

        for s in overInfo["snakeToMove"]:
            while not((s.items[0]["row"], s.items[0]["col"]) in overInfo["s2Position"]):
                s.move()

    lastHead = snake.items[0]["item"]
    lastHead.visible = False
    newHead = Bitmap(BitmapData(dataList[snake.snakeKind+"Head"+snake.direction]))
    newHead.x = lastHead.x
    newHead.y = lastHead.y
    playingLayer.addChild(newHead)


    # display the faces
    p1Face = TextField()
    playingLayer.addChild(p1Face)
    if "P1" in winner:
        p1Face.text = "😂"
    else:
        p1Face.text = "😭"
    p1Face.size = 50
    p1Face.x = 20 + 50 - p1Face.width/2
    p1Face.y = 20 + 50 - p1Face.height/2

    p2Face = TextField()
    playingLayer.addChild(p2Face)
    if "P2" in winner:
        p2Face.text = "😂"
    else:
        p2Face.text = "😭"
    p2Face.size = 50
    p2Face.x = 400 + 50 - p2Face.width/2
    p2Face.y = 20 + 50 - p2Face.height/2


    # define the state of buttons
    normal = Bitmap(BitmapData(dataList["normalLeaveBtn"]))
    over = Bitmap(BitmapData(dataList["actionLeaveBtn"]))
    down = Bitmap(BitmapData(dataList["actionLeaveBtn"]))
    normal.alpha = 0.5
    over.alpha = 0.75
    down.alpha = 0.75

    leaveBtn = Button(normal, over, down, None)
    leaveBtn.x = 135
    leaveBtn.y = 130+250-leaveBtn.height/2
    playingLayer.addChild(leaveBtn)

    def next(e):
        btnEffect.play()
        exit()
        
    leaveBtn.addEventListener(MouseEvent.MOUSE_UP, next)
    leaveBtn.addEventListener(MouseEvent.MOUSE_DOWN, btnEffectPlay)
Exemple #24
0
 def move(self):
     # head style
     lastHead = self.items[0]["item"]
     lastHead.visible = False
     self.items[0]["item"] = self.heads[self.direction]
     self.items[0]["item"].x = lastHead.x
     self.items[0]["item"].y = lastHead.y
     self.items[0]["item"].visible = True
     # create new bodies
     newBodies = []
     for i in range(self.eatenCandies):
         new = {"row":0, "col":0, "item":Bitmap(BitmapData(dataList[self.snakeKind+"Body"]))}
         new["item"].x = self.items[-self.speed+i]["item"].x
         new["item"].y = self.items[-self.speed+i]["item"].y
         new["row"] = self.items[-self.speed+i]["row"]
         new["col"] = self.items[-self.speed+i]["col"]
         newBodies.append(new)
         playingLayer.addChild(new["item"])
         gameBoard[new["row"]][new["col"]] = self.snakeKind
     self.eatenCandies = 0
     # move
     for i in range(len(self.items)-1, -1, -1):
         # clear gameBoard
         gameBoard[int(self.items[i]["row"])][int(self.items[i]["col"])] = None
         if (i - self.speed >= 0):
             # update images' position
             self.items[i]["item"].x = self.items[i-self.speed]["item"].x
             self.items[i]["item"].y = self.items[i-self.speed]["item"].y
             # update the dictionary's row and col
             self.items[i]["row"] = self.items[i-self.speed]["row"]
             self.items[i]["col"] = self.items[i-self.speed]["col"]
         else:
             if self.direction == "Up":
                 # update images' position
                 self.items[i]["item"].x = self.items[0]["item"].x
                 self.items[i]["item"].y = self.items[0]["item"].y - (self.speed-i) * 10
                 # update the dictionary's row and col
                 self.items[i]["col"] = self.items[0]["col"]
                 self.items[i]["row"] = self.items[0]["row"] - (self.speed-i)
             elif self.direction == "Down":
                 # update images' position
                 self.items[i]["item"].x = self.items[0]["item"].x
                 self.items[i]["item"].y = self.items[0]["item"].y + (self.speed-i) * 10
                 # update the dictionary's row and col
                 self.items[i]["col"] = self.items[0]["col"]
                 self.items[i]["row"] = self.items[0]["row"] + (self.speed-i)
             elif self.direction == "Left":
                 # update images' position
                 self.items[i]["item"].x = self.items[0]["item"].x - (self.speed-i) * 10
                 self.items[i]["item"].y = self.items[0]["item"].y
                 # update the dictionary's row and col
                 self.items[i]["col"] = self.items[0]["col"] - (self.speed-i)
                 self.items[i]["row"] = self.items[0]["row"]
             elif self.direction == "Right":
                 # update images' position
                 self.items[i]["item"].x = self.items[0]["item"].x + (self.speed-i) * 10
                 self.items[i]["item"].y = self.items[0]["item"].y
                 # update the dictionary's row and col
                 self.items[i]["col"] = self.items[0]["col"] + (self.speed-i)
                 self.items[i]["row"] = self.items[0]["row"]
         # Update the gameBoard
         if (i == 0):
             if (int(self.items[i]["row"]) < 0 or int(self.items[i]["row"]) > 49) or (int(self.items[i]["col"]) < 0 or int(self.items[i]["col"]) > 49):
                 print("speed:", self.speed)
                 print("row and col:", self.items[i]["row"], self.items[i]["col"])
             gameBoard[int(self.items[i]["row"])][int(self.items[i]["col"])] = "head"
             if self.direction == "Up":
                 nextHeadRow = self.items[0]["row"] - 1
                 nextHeadCol = self.items[0]["col"]
             elif self.direction == "Down":
                 nextHeadRow = self.items[0]["row"] + 1
                 nextHeadCol = self.items[0]["col"]
             elif self.direction == "Left":
                 nextHeadRow = self.items[0]["row"]
                 nextHeadCol = self.items[0]["col"] - 1
             elif  self.direction == "Right":
                 nextHeadRow = self.items[0]["row"]
                 nextHeadCol = self.items[0]["col"] + 1
         else:
             gameBoard[int(self.items[i]["row"])][int(self.items[i]["col"])] = self.snakeKind
     
     # add newly grown bodies
     for newbody in newBodies:
         self.items.append(newbody)
     return (nextHeadRow, nextHeadCol)
Exemple #25
0
 def __init__(self, image, X, Y):
     super(Button, self).__init__()
     bmp = Bitmap(BitmapData(image))
     self.addChild(bmp)
     self.x = X
     self.y = Y
Exemple #26
0
def displayImg1(e):
    bmp1 = Bitmap(BitmapData(e.target))
    bmp1.x = bmp1.y = 10
    addChild(bmp1)
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 demoInit(result):
    m1 = Shape()
    m1.graphics.beginFill()
    m1.graphics.drawRect(50, 50, 100, 100)
    m1.graphics.drawCircle(25, 25, 25)
    m1.graphics.moveTo(200, 25)
    m1.graphics.lineTo(150, 125)
    m1.graphics.lineTo(250, 150)
    m1.graphics.closePath()
    m1.graphics.drawRect(40, 175, 150, 150)
    m1.graphics.drawCircle(250, 225, 50)

    img1 = Bitmap(BitmapData(result["avatar"]))
    img1.mask = m1
    addChild(img1)

    img1_bg = Bitmap(BitmapData(result["avatar"]))
    img1_bg.alpha = 0.3
    addChild(img1_bg)

    m2 = Shape()
    m2.graphics.beginFill()
    m2.graphics.drawRect(100, 100, 200, 200)
    m2.graphics.drawCircle(200, 200, 50)

    img2 = Bitmap(BitmapData(result["girl"]))
    img2.x = 320
    img2.mask = m2
    addChild(img2)

    img2_bg = Bitmap(BitmapData(result["girl"]))
    img2_bg.x = 320
    img2_bg.alpha = 0.3
    addChild(img2_bg)