Ejemplo n.º 1
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)
Ejemplo n.º 2
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)
Ejemplo n.º 3
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
Ejemplo n.º 4
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
Ejemplo n.º 5
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
	})
Ejemplo n.º 6
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
    })
Ejemplo n.º 7
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
Ejemplo n.º 8
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)
Ejemplo n.º 9
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)
Ejemplo n.º 10
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)
Ejemplo n.º 11
0
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
Ejemplo n.º 12
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)
Ejemplo n.º 13
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)