Pushed main changes

main
Yan Wittmann 2023-03-26 15:01:58 +02:00
parent cd8fa05c41
commit 7f6e37d8bc
1 changed files with 46 additions and 23 deletions

View File

@ -5,13 +5,13 @@ import pygame
from level.LevelManager import LevelManager from level.LevelManager import LevelManager
from physics.SpriteManager import SpriteManager, DrawLayers from physics.SpriteManager import SpriteManager, DrawLayers
from physics.TickData import TickData from physics.TickData import TickData
from sprite.DynamicSprite import DynamicSprite from physics.controllers.PlayerSprite import PlayerSprite
from sprite.PositionScale import PositionScale from sprite.PositionScale import PositionScale
from sprite.SpritesheetManager import SpritesheetManager from sprite.SpritesheetManager import SpritesheetManager
from sprite.Sprite import Sprite from sprite.Sprite import Sprite
from sprite.StaticSprite import StaticSprite from sprite.StaticSprite import StaticSprite
from ui_elements.ClickEvent import ClickEvent from ui_elements.ClickEvent import ClickEvent
from ui_elements.KeyEvent import KeyEvent from ui_elements.KeyManager import KeyManager
from ui_elements.TextLabel import TextLabel from ui_elements.TextLabel import TextLabel
what_to_run = 'physics' what_to_run = 'physics'
@ -45,33 +45,57 @@ elif what_to_run == 'physics':
frame_rate = 59.52 frame_rate = 59.52
spritesheet_manager = SpritesheetManager("data/sprites", "data/sprites/sprites.json") spritesheet_manager = SpritesheetManager("data/sprites", "data/sprites/sprites.json")
sprite_manager = SpriteManager() sprite_manager = SpriteManager()
key_manager = KeyManager()
test_1_sprite = DynamicSprite(spritesheet_manager.get_sheet("test_1")) # test_1_sprite = DynamicSprite(spritesheet_manager.get_sheet("test_1"))
test_1_sprite.position_scale = PositionScale((10, -100), (1, 1)) # test_1_sprite.position_scale = PositionScale((10, -100), (1, 1))
sprite_manager.add_ui_element(DrawLayers.OBJECTS, test_1_sprite) # sprite_manager.add_ui_element(DrawLayers.OBJECTS, test_1_sprite)
test_3_sprite = DynamicSprite(spritesheet_manager.get_sheet("test_1")) # test_3_sprite = DynamicSprite(spritesheet_manager.get_sheet("test_1"))
test_3_sprite.position_scale = PositionScale((130, 100), (1, 1)) # test_3_sprite.position_scale = PositionScale((130, 100), (1, 1))
test_3_sprite.motion = (-9, -10) # test_3_sprite.motion = (-9, -10)
sprite_manager.add_ui_element(DrawLayers.OBJECTS, test_3_sprite) # sprite_manager.add_ui_element(DrawLayers.OBJECTS, test_3_sprite)
test_2_sprite = StaticSprite(spritesheet_manager.get_sheet("test_1")) # test_2_sprite = StaticSprite(spritesheet_manager.get_sheet("test_1"))
test_2_sprite.position_scale = PositionScale((10, 80), (1, 1)) # test_2_sprite.position_scale = PositionScale((10, 80), (1, 1))
sprite_manager.add_ui_element(DrawLayers.OBJECTS, test_2_sprite) # sprite_manager.add_ui_element(DrawLayers.OBJECTS, test_2_sprite)
text_1 = TextLabel("Frame: 0", 10, 110, 50, alignment="left") for x in range(0, 8):
floor_sprite = StaticSprite(spritesheet_manager.get_sheet("test_1"))
floor_sprite.position_scale = PositionScale((x * 16, 100), (1, 1))
sprite_manager.add_ui_element(DrawLayers.OBJECTS, floor_sprite)
for x in range(0, 8):
floor_sprite = StaticSprite(spritesheet_manager.get_sheet("test_1"))
floor_sprite.position_scale = PositionScale((x * 16, 0), (1, 1))
sprite_manager.add_ui_element(DrawLayers.OBJECTS, floor_sprite)
for x in range(0, 6):
floor_sprite = StaticSprite(spritesheet_manager.get_sheet("test_1"))
floor_sprite.position_scale = PositionScale((0, x * 16), (1, 1))
sprite_manager.add_ui_element(DrawLayers.OBJECTS, floor_sprite)
for x in range(0, 6):
floor_sprite = StaticSprite(spritesheet_manager.get_sheet("test_1"))
floor_sprite.position_scale = PositionScale((130, x * 16), (1, 1))
sprite_manager.add_ui_element(DrawLayers.OBJECTS, floor_sprite)
ghost_character = PlayerSprite(spritesheet_manager.get_sheet("ghost_character"))
ghost_character.position_scale = PositionScale((90, 50), (1, 1))
sprite_manager.add_ui_element(DrawLayers.OBJECTS, ghost_character)
text_1 = TextLabel("Frame: 0", 2, 110, 50, alignment="left")
text_1.position_scale.scale = (0.1, 0.1) text_1.position_scale.scale = (0.1, 0.1)
sprite_manager.add_ui_element(DrawLayers.UI, text_1) sprite_manager.add_ui_element(DrawLayers.UI, text_1)
counter = 0 ghost_character.debug_label = text_1
frame_counter = 0
while True: while True:
clock.tick(frame_rate) clock.tick(frame_rate)
skip = True skip = False
pygame_events: list[pygame.event.Event] = pygame.event.get() pygame_events: list[pygame.event.Event] = pygame.event.get()
key_events: list[KeyEvent] = KeyEvent.create_events(pygame_events) key_manager.update_key_events(pygame_events)
click_events: list[ClickEvent] = ClickEvent.create_events(pygame_events, screen_transform) click_events: list[ClickEvent] = ClickEvent.create_events(pygame_events, screen_transform)
for event in pygame_events: for event in pygame_events:
@ -79,18 +103,17 @@ elif what_to_run == 'physics':
pygame.quit() pygame.quit()
quit() quit()
for key_event in key_events: if key_manager.is_keymap_down(KeyManager.KEY_RIGHT):
if key_event.is_keymap_down(KeyEvent.KEY_RIGHT): skip = False
skip = False
if skip: if skip:
continue continue
counter += 1 frame_counter += 1
text_1.set_text(f"Frame: {counter}") # text_1.set_text(f"Frame: {frame_counter}")
screen.fill((0, 0, 0)) screen.fill((0, 0, 0))
sprite_manager.tick(TickData(apply_frame_rate(1), pygame_events, key_events, click_events, screen_transform)) sprite_manager.tick(TickData(apply_frame_rate(1), pygame_events, key_manager, click_events, screen_transform))
sprite_manager.draw(screen, screen_transform) sprite_manager.draw(screen, screen_transform)
pygame.display.update() pygame.display.update()