Exemplo n.º 1
0
    def gamelogic(layer, tilesets):
        x = 0
        y = 0

        for data in layer['data']:
            if data > 0:
                for t in tilesets:
                    if (t['firstgid'] <= data):
                        tileset = t
                        break

                id = data - t['firstgid'] + 1

                if id == 1:  #block
                    c = Entity()
                    c.set_collider(Collider())
                    c.set_position(sf.Vector2(x, y))
                elif id == 2:  #blob spawn
                    m = Blob()
                    m.set_position(sf.Vector2(x, y))
                elif id == 6:  #purple spawn
                    m = Purple()
                    m.set_position(sf.Vector2(x, y))
                elif id == 10:  #purple spawn
                    m = Witch()
                    m.set_position(sf.Vector2(x, y))
                elif id == 3:  #player spawn
                    p = Player()
                    p.set_position(sf.Vector2(x, y))
                    Scene.current().camera.set_parent(p)

            x += 1
            if (x >= layer['width']):
                x = 0
                y += 1
Exemplo n.º 2
0
    def gamelogic(layer, tilesets):
        x = 0
        y = 0

        for data in layer['data']:
            if data > 0:
                for t in tilesets:
                    if(t['firstgid'] <= data):
                        tileset = t
                        break;

                id = data - t['firstgid'] +1

                if id==1: #block
                    c = Entity()
                    c.set_collider(Collider())
                    c.set_position(sf.Vector2(x,y))
                elif id==2: #blob spawn
                    m = Blob()
                    m.set_position(sf.Vector2(x,y))
                elif id==6: #purple spawn
                    m = Purple()
                    m.set_position(sf.Vector2(x,y))
                elif id==10: #purple spawn
                    m = Witch()
                    m.set_position(sf.Vector2(x,y))
                elif id==3: #player spawn
                    p = Player()
                    p.set_position(sf.Vector2(x,y))
                    Scene.current().camera.set_parent(p)

            x += 1
            if(x >= layer['width']):
                x = 0
                y += 1
Exemplo n.º 3
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)
Exemplo n.º 4
0
from pygame import math

from classes.entity import Entity

from environment import config
from environment.instances import window, keyboard, store

player = Entity(window, "./src/assets/actors/jorge/idle_right.png", 8)
player.set_position(10, window.height / 2)

vel_vector = math.Vector2(0, 0)

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


def reset():
    global vel_vector

    player.__init__(window, "./src/assets/actors/jorge/idle_right.png", 8)
    player.set_position(10, window.height / 2)
    vel_vector = math.Vector2(0, 0)

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


def run():
    global vel_vector

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