Added playable character loading

main
Skyball2000 2023-03-29 13:50:48 +02:00
parent 25d3305a79
commit e4993f39af
6 changed files with 45 additions and 13 deletions

View File

@ -1,7 +1,7 @@
[ [
{ {
"name": "0-tutorial", "name": "0-tutorial",
"theme": "cave", "theme": "tutorial",
"abilities": [ "abilities": [
], ],
"file": "0-tutorial.csv" "file": "0-tutorial.csv"

View File

@ -13,6 +13,8 @@ from level.elements.static.SimpleBlockLevelElement import SimpleBlockLevelElemen
from level.elements.static.UnknownTileLevelElement import UnknownTileLevelElement from level.elements.static.UnknownTileLevelElement import UnknownTileLevelElement
from physics import ConstantsParser from physics import ConstantsParser
from physics.SpriteManager import SpriteManager, DrawLayers from physics.SpriteManager import SpriteManager, DrawLayers
from physics.sprites.PlayerSprite import PlayerSprite
from sprite.PositionScale import PositionScale
from sprite.SpritesheetManager import SpritesheetManager from sprite.SpritesheetManager import SpritesheetManager
TILES = { TILES = {
@ -62,6 +64,12 @@ class LoadedLevel:
if name in TILES: if name in TILES:
element = TILES[name](tile, self) element = TILES[name](tile, self)
elif name == 'C':
ghost_character = PlayerSprite(self.spritesheet_manager.get_sheet("ghost_character"))
ghost_character.position_scale = PositionScale((position[0], position[1]), (1, 1))
self.sprite_manager.add_ui_element(DrawLayers.OBJECTS, ghost_character)
elif not name == '': elif not name == '':
print(f"Unknown tile at {position}: {name}") print(f"Unknown tile at {position}: {name}")
element = UnknownTileLevelElement(tile, self) element = UnknownTileLevelElement(tile, self)

View File

@ -1,16 +1,30 @@
from abc import abstractmethod from abc import abstractmethod
from level.Level import Level
from level.elements.LoadedLevel import LoadedLevel
from level.selection.ScreenManager import ScreenManager from level.selection.ScreenManager import ScreenManager
from physics.SpriteManager import SpriteManager from physics.SpriteManager import SpriteManager
from physics.TickData import TickData
from sprite.SpritesheetManager import SpritesheetManager from sprite.SpritesheetManager import SpritesheetManager
from ui_elements.KeyManager import KeyManager
class LevelScreenManager(ScreenManager): class LevelScreenManager(ScreenManager):
def __init__(self, sprite_manager: SpriteManager, spritesheet_manager: SpritesheetManager, main_loop): def __init__(self, sprite_manager: SpriteManager, spritesheet_manager: SpritesheetManager, main_loop,
level: Level):
super().__init__(sprite_manager, spritesheet_manager, main_loop) super().__init__(sprite_manager, spritesheet_manager, main_loop)
self.level = level
self.loaded_level = LoadedLevel(sprite_manager, spritesheet_manager)
self.loaded_level.load_level(self.level)
def initialize(self): def initialize(self):
pass pass
def destroy(self): def destroy(self):
super().destroy() super().destroy()
self.loaded_level.destroy_level()
def tick(self, tick_data: TickData):
if tick_data.key_manager.is_keymap_down(KeyManager.KEY_ESCAPE):
self.main_loop.select_level_selection()

View File

@ -1,5 +1,3 @@
from abc import abstractmethod
from level.Level import Level from level.Level import Level
from level.LevelManager import LevelManager from level.LevelManager import LevelManager
from level.selection.ScreenManager import ScreenManager from level.selection.ScreenManager import ScreenManager

View File

@ -1,6 +1,7 @@
from abc import abstractmethod from abc import abstractmethod
from physics.SpriteManager import SpriteManager from physics.SpriteManager import SpriteManager
from physics.TickData import TickData
from sprite.SpritesheetManager import SpritesheetManager from sprite.SpritesheetManager import SpritesheetManager
from ui_elements.UiElement import UiElement from ui_elements.UiElement import UiElement
@ -24,3 +25,6 @@ class ScreenManager:
def destroy(self): def destroy(self):
for element in self.elements: for element in self.elements:
self.sprite_manager.remove_ui_element(element) self.sprite_manager.remove_ui_element(element)
def tick(self, tick_data: TickData):
pass

View File

@ -71,6 +71,8 @@ class MainLoop:
self.game_state = self.GAME_STATE_MENU self.game_state = self.GAME_STATE_MENU
self.set_game_state(self.GAME_STATE_LEVEL_SELECTION) self.set_game_state(self.GAME_STATE_LEVEL_SELECTION)
self.level: Optional[Level] = None
def update_position_scale(self, position_scale: PositionScale): def update_position_scale(self, position_scale: PositionScale):
self.screen_transform = position_scale self.screen_transform = position_scale
self.window_size = ( self.window_size = (
@ -83,9 +85,13 @@ class MainLoop:
self.screen = pygame.display.set_mode((self.window_size[0], self.window_size[1])) self.screen = pygame.display.set_mode((self.window_size[0], self.window_size[1]))
def select_level(self, level: Level): def select_level(self, level: Level):
print(level.name) print('Loading level', level.name)
self.level = level
self.set_game_state(self.GAME_STATE_LEVEL) self.set_game_state(self.GAME_STATE_LEVEL)
def select_level_selection(self):
self.set_game_state(self.GAME_STATE_LEVEL_SELECTION)
def set_game_state(self, game_state: str): def set_game_state(self, game_state: str):
self.game_state = game_state self.game_state = game_state
@ -98,7 +104,7 @@ class MainLoop:
) )
elif self.game_state == self.GAME_STATE_LEVEL: elif self.game_state == self.GAME_STATE_LEVEL:
self.screen_manager = LevelScreenManager( self.screen_manager = LevelScreenManager(
self.sprite_manager, self.spritesheet_manager, self self.sprite_manager, self.spritesheet_manager, self, self.level
) )
elif self.game_state == self.GAME_STATE_LEVEL_SELECTION: elif self.game_state == self.GAME_STATE_LEVEL_SELECTION:
self.screen_manager = LevelSelectionScreenManager( self.screen_manager = LevelSelectionScreenManager(
@ -130,13 +136,15 @@ class MainLoop:
quit() quit()
self.screen.fill((0, 0, 0)) self.screen.fill((0, 0, 0))
self.sprite_manager.tick(
TickData(apply_frame_rate(1, self.frame_rate), tick_data = TickData(apply_frame_rate(1, self.frame_rate),
pygame_events, pygame_events,
self.key_manager, self.key_manager,
click_events, click_events,
self.screen_transform) self.screen_transform)
)
self.screen_manager.tick(tick_data)
self.sprite_manager.tick(tick_data)
self.sprite_manager.draw(self.screen, self.screen_transform) self.sprite_manager.draw(self.screen, self.screen_transform)
pygame.display.update() pygame.display.update()