コード例 #1
0
def run():
    # MENU
    if keyboard.key_pressed("esc"):
        store.dispatch("state", value=0)
        window.delay(150)

    # POWER UP
    if keyboard.key_pressed("p"):
        store.dispatch("state", value=2)
        window.delay(150)

    # GAME OVER
    if store.get("player").life <= 0:
        store.dispatch("state", value=3)
        window.delay(150)

    # CHANGE LEVEL
    if keyboard.key_pressed("y"):
        store.dispatch("enemy_mtx", value=[])

    # DIE
    if keyboard.key_pressed("u"):
        store.get("player").life = -1

    # SCORE
    if keyboard.key_pressed("t"):
        store.dispatch("score", lambda score: score + 200)

    background.draw()
    player.run()
    enemy.run()
    bullet.run()
    hud.run()
コード例 #2
0
def run():
    global title

    animation_completed = False

    if title.get_curr_frame() < title.get_final_frame() - 1:
        title.update()
    else:
        animation_completed = True
        title.set_curr_frame(0)

    window.set_background_color((0, 0, 0))
    title.draw()

    if animation_completed:
        aux_name = input("Qual seu nome? \n")

        while len(aux_name) > 9 or len(aux_name) < 3:
            print("Por favor, insira um nome entre 3 e 9 caracteres.\n")
            aux_name = input("Qual seu nome? \n")

        Database().save_score(aux_name.lower(), store.get("score"), store.get("wave"))

        return True

    else:
        return False
コード例 #3
0
def run():
    # PRINT WAVE
    window.draw_text(
        "wave: {}".format(store.get("wave")),
        940,
        770,
        "./src/assets/fonts/pixel.ttf",
        size=20,
        color=(255, 255, 255),
    )

    window.draw_text(
        "score: {}".format(store.get("score")),
        710,
        770,
        "./src/assets/fonts/pixel.ttf",
        size=20,
        color=(255, 255, 255),
    )

    # PRINT LIFE
    window.draw_text(
        "life: {}".format(store.get("player").life),
        55,
        770,
        "./src/assets/fonts/pixel.ttf",
        size=20,
        color=(255, 255, 255),
    )
コード例 #4
0
def run():
    if keyboard.key_pressed("esc"):
        store.dispatch("state", value=1)
        window.delay(150)

    # POWER
    if mouse.is_over_object(power):
        power.set_curr_frame(1)
        if mouse.is_button_pressed(1) and store.get("score") > cost_strength():
            aux_str = cost_strength()
            store.dispatch("score", lambda score: score - aux_str)

            store.get("player").strenght = update_strength()

            window.delay(150)
    else:
        power.set_curr_frame(0)

    # LIFE
    if mouse.is_over_object(life):
        life.set_curr_frame(1)
        if mouse.is_button_pressed(1) and store.get("score") > cost_life():
            aux_life = cost_life()
            store.dispatch("score", lambda score: score - aux_life)

            store.get("player").max_life += update_life()

            window.delay(150)
    else:
        life.set_curr_frame(0)

    # HEAL
    if mouse.is_over_object(heal):
        heal.set_curr_frame(1)
        if mouse.is_button_pressed(1) and store.get("score") > cost_heal():
            aux_heal = cost_heal()
            store.dispatch("score", lambda score: score - aux_heal)

            update_heal()
            store.get("player").life = store.get("player").max_life

            window.delay(150)
    else:
        heal.set_curr_frame(0)

    window.set_background_color((0, 0, 0))

    # SCORE
    window.draw_text(
        "score: {}".format(store.get("score")),
        title.x + 30,
        title.y + title.height + 30,
        "./src/assets/fonts/pixel.ttf",
        size=24,
        color=(255, 255, 255),
    )

    # PRICE AND OWNED POWER
    window.draw_text(
        "price: {}".format(cost_strength()),
        power.x + power.width + 25,
        power.y + 10,
        "./src/assets/fonts/pixel.ttf",
        size=16,
        color=(255, 255, 255),
    )

    window.draw_text(
        "owned: {}".format(store.get("owned_strength")),
        power.x + power.width + 25,
        power.y + 50,
        "./src/assets/fonts/pixel.ttf",
        size=16,
        color=(255, 255, 255),
    )

    # PRICE AND OWNED LIFE
    window.draw_text(
        "price: {}".format(cost_life()),
        life.x + life.width + 25,
        life.y + 10,
        "./src/assets/fonts/pixel.ttf",
        size=16,
        color=(255, 255, 255),
    )

    window.draw_text(
        "owned: {}".format(store.get("owned_life")),
        life.x + life.width + 25,
        life.y + 50,
        "./src/assets/fonts/pixel.ttf",
        size=16,
        color=(255, 255, 255),
    )

    # PRICE HEAL
    window.draw_text(
        "price: {}".format(cost_heal()),
        heal.x + heal.width + 25,
        heal.y + 10,
        "./src/assets/fonts/pixel.ttf",
        size=16,
        color=(255, 255, 255),
    )

    title.draw()
    power.draw()
    life.draw()
    heal.draw()
コード例 #5
0
def run():
    global wave

    # SPAWN
    if len(store.get("enemy_mtx")) == 0:
        wave += 1
        enemy_mtx = []
        level = randint(1, 3)
        enemy_type = randint(1, 5)
        boss_type = randint(1, 2)
        level_constructor = open("./src/assets/levels/level" + str(level) + ".txt", "r")
        line = level_constructor.readline()
        lin = 0
        while lin < 17:
            for col in range(len(line)):
                if line[col] == "1" or (line[col] == "2" and wave % 3 == 0):
                    if line[col] == "1":
                        enemy = Entity(
                            window,
                            "./src/assets/actors/enemies/minion{}/running_right.png".format(
                                enemy_type
                            ),
                            8,
                        )
                        enemy.strenght = config.ENEMY_DAMAGE + get_strenght_minion(wave)
                        enemy.velocity = config.ENEMY_VELOCITY + get_velocity(wave)
                        enemy.life = config.ENEMY_LIFE + get_life_minion(wave)

                    elif line[col] == "2" and wave % 3 == 0:
                        enemy = Entity(
                            window,
                            "./src/assets/actors/enemies/boss{}/running_right.png".format(
                                boss_type
                            ),
                            8,
                        )
                        enemy.strenght = config.BOSS_DAMAGE + get_strenght_boss(wave)
                        enemy.life = config.BOSS_LIFE + get_life_boss(wave)
                        enemy.velocity = config.BOSS_VELOCITY + get_velocity(wave)
                        enemy.is_boss = True

                    enemy.set_position(
                        col * (config.WIDTH / 22)
                        + (config.WIDTH / 22) / 2
                        - enemy.animation.width / 2,
                        lin * (config.HEIGHT / 17)
                        + (config.HEIGHT / 17) / 2
                        - enemy.animation.height,
                    )
                    enemy_mtx.append(enemy)

            line = level_constructor.readline()
            lin += 1

        store.dispatch("enemy_mtx", value=enemy_mtx)

    # MOVEMENT
    for enemy in store.get("enemy_mtx"):
        enemy_direction = math.Vector2(
            store.get("player").animation.x - enemy.animation.x,
            store.get("player").animation.y - enemy.animation.y,
        )
        enemy_direction.normalize_ip()
        enemy_direction *= enemy.velocity + wave
        enemy.move(enemy_direction)

    # COLISSION
    for enemy1 in range(len(store.get("enemy_mtx"))):
        for enemy2 in range(enemy1 + 1, len(store.get("enemy_mtx"))):
            if store.get("enemy_mtx")[enemy1].animation.collided(
                store.get("enemy_mtx")[enemy2].animation
            ):
                if store.get("enemy_mtx")[enemy1].distance_to(
                    store.get("player")
                ) < store.get("enemy_mtx")[enemy2].distance_to(store.get("player")):
                    new_vel_length = (
                        store.get("enemy_mtx")[enemy2].velocity_vector.length() - 30
                    )
                    if new_vel_length == 0:
                        new_vel_length = 1
                    store.get("enemy_mtx")[enemy2].velocity_vector.normalize_ip()
                    store.get("enemy_mtx")[enemy2].velocity_vector *= new_vel_length
                    store.get("enemy_mtx")[enemy2].move(
                        store.get("enemy_mtx")[enemy2].velocity_vector
                    )
                else:
                    new_vel_length = (
                        store.get("enemy_mtx")[enemy1].velocity_vector.length() - 30
                    )
                    if new_vel_length == 0:
                        new_vel_length = 1
                    store.get("enemy_mtx")[enemy1].velocity_vector.normalize_ip()
                    store.get("enemy_mtx")[enemy1].velocity_vector *= new_vel_length
                    store.get("enemy_mtx")[enemy1].move(
                        store.get("enemy_mtx")[enemy1].velocity_vector
                    )

    # DRAW
    for enemy in store.get("enemy_mtx"):
        enemy.update()
        enemy.render()

    store.dispatch("wave", value=wave)
コード例 #6
0
def run():
    global bullet_mtx
    global bullet_vel
    global player_can_shoot
    global bullet_cooldown

    # DEFAULT
    bullet_vel.update(0)
    # PLAYER SHOOT
    if player_can_shoot == False and bullet_cooldown >= 0:
        bullet_cooldown -= 5
    if bullet_cooldown <= 0:
        player_can_shoot = True
        bullet_cooldown = config.BULLET_COOLDOWN

    if (keyboard.key_pressed("left") and keyboard.key_pressed("right") == False
            and player_can_shoot == True):
        bullet_vel.x = -1
    if (keyboard.key_pressed("right") and keyboard.key_pressed("left") == False
            and player_can_shoot == True):
        bullet_vel.x = 1
    if (keyboard.key_pressed("up") and keyboard.key_pressed("down") == False
            and player_can_shoot == True):
        bullet_vel.y = -1
    if (keyboard.key_pressed("down") and keyboard.key_pressed("up") == False
            and player_can_shoot == True):
        bullet_vel.y = 1

    if bullet_vel != math.Vector2(0):
        bullet_vel.normalize_ip()
        bullet_vel *= config.BULLET_VELOCITY
        bullet = store.get("player").shoot(
            "./src/assets/actors/bullet/bullet.png", 1, deepcopy(bullet_vel))
        bullet_mtx.append(bullet)
        player_can_shoot = False

    # BULLET COLLISION
    for enemy in store.get("enemy_mtx"):
        for bullet in bullet_mtx:
            if bullet.collide(enemy):
                enemy.life -= store.get("player").strenght
                bullet_mtx.remove(bullet)
                if enemy.life <= 0:
                    store.get("enemy_mtx").remove(enemy)
                    if enemy.is_boss:
                        store.dispatch("score", lambda score: score + 200)
                    else:
                        aux_score = get_score(store.get("wave"))
                        store.dispatch("score",
                                       lambda score: score + aux_score)
    # DESTROY BULLET
    for bullet in bullet_mtx:
        if (bullet.animation.x >= config.WIDTH or bullet.animation.x <= 0
                or bullet.animation.y >= config.HEIGHT
                or bullet.animation.y <= 48):
            bullet_mtx.remove(bullet)

    # DRAW
    if len(bullet_mtx) != 0:
        for bullet in bullet_mtx:
            bullet.update()
            bullet.render()
コード例 #7
0
def run():
    global vel_vector

    # DEFAULT
    player.set_state("idle")
    vel_vector.update(0, 0)

    # CHECKING COLLISION
    if player.animation.x <= 1:
        player.set_colliding(True, "left")
        player.set_position(player.animation.x + 1, player.animation.y)
    elif player.animation.x + player.animation.width >= window.width:
        player.set_colliding(True, "right")
        player.set_position(player.animation.x - 1, player.animation.y)

    if player.animation.y + (player.animation.height / 2) <= 96:
        player.set_colliding(True, "up")
        player.set_position(player.animation.x, player.animation.y + 1)
    elif player.animation.y + player.animation.height >= window.height:
        player.set_colliding(True, "down")
        player.set_position(player.animation.x, player.animation.y - 1)

    # RESET COLLISION
    if player.colliding["left"] == True and keyboard.key_pressed("d"):
        player.colliding["left"] = False
    if player.colliding["right"] == True and keyboard.key_pressed("a"):
        player.colliding["right"] = False
    if player.colliding["up"] == True and keyboard.key_pressed("s"):
        player.colliding["up"] = False
    if player.colliding["down"] == True and keyboard.key_pressed("w"):
        player.colliding["down"] = False

    # MOVING
    if (keyboard.key_pressed("d") == True
            and keyboard.key_pressed("a") == False
            and player.colliding["right"] == False):
        vel_vector.x = 1
        player.set_direction("right")
        player.set_state("running")
    elif (keyboard.key_pressed("a") == True
          and keyboard.key_pressed("d") == False
          and player.colliding["left"] == False):
        vel_vector.x = -1
        player.set_direction("left")
        player.set_state("running")

    if (keyboard.key_pressed("w") == True
            and keyboard.key_pressed("s") == False
            and player.colliding["up"] == False):
        vel_vector.y = -1
        player.set_state("running")
    elif (keyboard.key_pressed("s") == True
          and keyboard.key_pressed("w") == False
          and player.colliding["down"] == False):
        vel_vector.y = 1
        player.set_state("running")

    # COLLISION WITH ENEMY
    for enemy in store.get("enemy_mtx"):
        if player.collide(enemy) and player.staggered == False:
            player.damage(enemy.strenght)
            player.staggered = True

    # RESET COLLISION WITH ENEMY
    if player.staggered:
        player.damage_cooldown -= window.delta_time() * 1000
        if player.damage_cooldown <= 0:
            player.damage_cooldown = config.DAMAGE_COOLDOWN
            player.staggered = False

    # ANIMATION
    if player.staggered:
        if player.state["idle"]:
            if player.direction["right"]:
                player.set_animation(
                    "./src/assets/actors/jorge/idle_right_staggered.png", 8)
            elif player.direction["left"]:
                player.set_animation(
                    "./src/assets/actors/jorge/idle_left_staggered.png", 8)
        elif player.state["running"]:
            if player.direction["right"]:
                player.set_animation(
                    "./src/assets/actors/jorge/running_right_staggered.png", 8)
            elif player.direction["left"]:
                player.set_animation(
                    "./src/assets/actors/jorge/running_left_staggered.png", 8)
        else:
            if player.direction["right"]:
                player.set_animation(
                    "./src/assets/actors/jorge/idle_right_staggered.png", 8)
            elif player.direction["left"]:
                player.set_animation(
                    "./src/assets/actors/jorge/idle_left_staggered.png", 8)

    else:
        if player.state["idle"]:
            if player.direction["right"]:
                player.set_animation(
                    "./src/assets/actors/jorge/idle_right.png", 8)
            elif player.direction["left"]:
                player.set_animation("./src/assets/actors/jorge/idle_left.png",
                                     8)
        elif player.state["running"]:
            if player.direction["right"]:
                player.set_animation(
                    "./src/assets/actors/jorge/running_right.png", 8)
            elif player.direction["left"]:
                player.set_animation(
                    "./src/assets/actors/jorge/running_left.png", 8)
        else:
            if player.direction["right"]:
                player.set_animation(
                    "./src/assets/actors/jorge/idle_right.png", 8)
            elif player.direction["left"]:
                player.set_animation("./src/assets/actors/jorge/idle_left.png",
                                     8)

    if vel_vector != math.Vector2(0):
        vel_vector.normalize_ip()
    vel_vector *= config.VELOCITY_PLAYER

    player.move(vel_vector)
    player.update()
    player.render()

    store.dispatch("player", value=player)
コード例 #8
0
from environment import config
from environment.instances import window, keyboard, store

from screen import menu, play, powerup, gameover, rank

if __name__ == "__main__":
    while store.get("game_started"):
        # MENU SCREEN
        if store.get("state") == 0:
            menu.run()

        # PLAY SCREEN
        elif store.get("state") == 1:
            play.run()

        # POWER UP SCREEN
        elif store.get("state") == 2:
            powerup.run()

        # GAME OVER SCREEN
        elif store.get("state") == 3:
            if gameover.run():
                play.reset()
                store.dispatch("state", value=0)
                window.delay(150)

        # RANK SCREEN
        elif store.get("state") == 4:
            rank.run()

        window.update()
コード例 #9
0
def cost_heal():
    return int(100 * (1.5)**store.get("owned_heal"))
コード例 #10
0
def cost_life():
    return int(100 * (1.4)**store.get("owned_life"))
コード例 #11
0
def update_strength():
    store.dispatch("owned_strength", lambda strength: strength + 1)
    return int(50 * exp(0.1255 * store.get("owned_strength")))
コード例 #12
0
def cost_strength():
    return int(100 * (1.3)**store.get("owned_strength"))