Ejemplo n.º 1
0
def main():
    Graphics.init(Size(1280, 720))
    Time.init()

    line = GameObject()
    line.add_component(LineRenderer(Vector2(0, 0), Vector2(10, 10)))

    fps = GameObject()
    text = fps.add_component(Text)

    # game loop
    while True:
        # check for events
        for event in pygame.event.get():
            if event.type == QUIT or (event.type == KEYDOWN
                                      and event.key == K_ESCAPE):
                pygame.quit()
                sys.exit()

        update()

        text.text = str(int(Time.time))
        text.transform.position = text.transform.position + Vector2(1, 0)

        Graphics.draw()
Ejemplo n.º 2
0
    def spawn_enemy(self, index):
        definition = enemy.enemies_definitions[index]

        enemy_object = GameObject(
            map.get_tile_coords(
                map_settings.settings.enemies_path_coords[0][0] - 1,
                map_settings.settings.enemies_path_coords[0][1]), (1, 1), 0)

        # for f in file_utils.get_all_files_in_path(ENEMIES_PATH + definition.sprites_directory):
        #     print(f)

        enemy_object.add_component(DynamicSprite).init_component(
            pos=(0, -map.TILE_SIZE / 4),
            size=(map.TILE_SIZE, map.TILE_SIZE),
            angle=0,
            images_paths=file_utils.get_all_files_in_path(
                ENEMIES_PATH + definition.sprites_directory),
            alpha=True)

        enemy_object.add_component(DynamicSprite).init_component(
            pos=(0, -map.TILE_SIZE / 4),
            size=(map.TILE_SIZE, map.TILE_SIZE),
            angle=0,
            images_paths=file_utils.get_all_files_in_path(
                ENEMIES_PATH + definition.sprites_directory + "/reversed"),
            alpha=True)
        enemy_object.get_components(DynamicSprite)[1].change_activity(False)
        enemy_object.add_component(StaticSprite).init_component(
            pos=(250, -20),
            size=(map.TILE_SIZE, map.TILE_SIZE),
            angle=0,
            image_path=ENEMIES_PATH + "hp_bar.png",
            z_pos=800,
            alpha=True)

        enemy_object.add_component(Enemy).init_component(
            path_coords=map_settings.settings.enemies_path_coords,
            definition=definition,
            game_mode=self.game_mode)

        session_data.enemies_left -= 1
Ejemplo n.º 3
0
from game_object import GameObject
from game_scene import GameScene
from rect import Rect
from vector import Vector


class DisplayScene(Scene):
    def __init__(self, game_scene: GameScene):
        self.game_scene = game_scene
        self.screen_rect = Rect((0, 0), (10, 10))

    def on_enter(self, previous_scene: 'Scene' = None, multi_id: int = None):
        pygame.display.set_caption(self.game_scene.name)

    def draw(self, screen: pygame.Surface, multi_id: int = None):
        self.game_scene.render(screen, self.screen_rect, debug=True)

    def update(self, dt: int, multi_id: int = None):
        self.game_scene.game_objects[0].transform.rotation += dt / 100


test_obj = GameObject("TestObj")
transform = test_obj.add_component(Transform)
transform.pos = Vector(4, 4)
renderer = test_obj.add_component(SolidColorRenderer)
renderer.offset.x = 1
renderer.color = Color(1, 1, 0)
game_scene = GameScene("Test", [test_obj], Color(1., 1., 1.))
app = Application((640, 640), "", resizable=True)
app.run(DisplayScene(game_scene))