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#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#
|
#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,,,,,,,,,,,,,,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#
|
||||||
#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,,,,,,,,,,,,,,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#
|
#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,,,,,,,,,,,,,,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#
|
||||||
|
|
|
|
@ -1,7 +1,7 @@
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"name": "1-1",
|
"name": "1-1",
|
||||||
"theme": "ghost",
|
"theme": "tutorial",
|
||||||
"abilities": [
|
"abilities": [
|
||||||
"dash"
|
"dash"
|
||||||
],
|
],
|
||||||
|
|
|
@ -88,5 +88,34 @@
|
||||||
"height": 36
|
"height": 36
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "tutorial_block_full",
|
||||||
|
"subsheets": [
|
||||||
|
{
|
||||||
|
"id": "1",
|
||||||
|
"delays": [
|
||||||
|
1
|
||||||
|
],
|
||||||
|
"width": 16,
|
||||||
|
"height": 16
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "2",
|
||||||
|
"delays": [
|
||||||
|
1
|
||||||
|
],
|
||||||
|
"width": 16,
|
||||||
|
"height": 16
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "3",
|
||||||
|
"delays": [
|
||||||
|
1
|
||||||
|
],
|
||||||
|
"width": 16,
|
||||||
|
"height": 16
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
|
@ -5,9 +5,12 @@ DYNAMIC = 'dynamic'
|
||||||
|
|
||||||
class LevelElementSymbols:
|
class LevelElementSymbols:
|
||||||
SOLID_BLOCK = {
|
SOLID_BLOCK = {
|
||||||
'symbol': '#',
|
|
||||||
'type': STATIC,
|
'type': STATIC,
|
||||||
'sprite_id': '_block'
|
'sprite_id': '_block_full',
|
||||||
|
'themed': True
|
||||||
|
}
|
||||||
|
SOLID_BLOCK_TOP = {
|
||||||
|
|
||||||
}
|
}
|
||||||
SOLID_BLOCK_LEFT = {
|
SOLID_BLOCK_LEFT = {
|
||||||
'type': STATIC,
|
'type': STATIC,
|
||||||
|
@ -26,7 +29,7 @@ class LevelElementSymbols:
|
||||||
'sprite_id': '_gate'
|
'sprite_id': '_gate'
|
||||||
}
|
}
|
||||||
GOAL_DOOR = {
|
GOAL_DOOR = {
|
||||||
'type':STATIC,
|
'type': STATIC,
|
||||||
'sprite_id': '_goal_door'
|
'sprite_id': '_goal_door'
|
||||||
}
|
}
|
||||||
SMALL_SPIKE = {
|
SMALL_SPIKE = {
|
||||||
|
@ -34,7 +37,7 @@ class LevelElementSymbols:
|
||||||
'sprite_id': '_small_spike'
|
'sprite_id': '_small_spike'
|
||||||
}
|
}
|
||||||
LEVER = {
|
LEVER = {
|
||||||
'type':STATIC,
|
'type': STATIC,
|
||||||
'sprite_id': '_lever'
|
'sprite_id': '_lever'
|
||||||
}
|
}
|
||||||
PLAYER = {
|
PLAYER = {
|
||||||
|
@ -44,13 +47,16 @@ class LevelElementSymbols:
|
||||||
|
|
||||||
dict = {
|
dict = {
|
||||||
'#': SOLID_BLOCK,
|
'#': SOLID_BLOCK,
|
||||||
|
'+': SOLID_BLOCK,
|
||||||
'l': SOLID_BLOCK_RIGHT,
|
'l': SOLID_BLOCK_RIGHT,
|
||||||
'r': SOLID_BLOCK_LEFT,
|
'r': SOLID_BLOCK_LEFT,
|
||||||
'': AIR,
|
'': AIR,
|
||||||
'g': GATE,
|
'G': GATE,
|
||||||
'd': GOAL_DOOR,
|
'D': GOAL_DOOR,
|
||||||
'x': SMALL_SPIKE,
|
'x': SMALL_SPIKE,
|
||||||
'h': LEVER,
|
'L': LEVER,
|
||||||
'P': PLAYER
|
'P': PLAYER
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BLOCKS_LIST = [SOLID_BLOCK, SOLID_BLOCK_RIGHT, SOLID_BLOCK_LEFT]
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
import sys
|
|
||||||
import os
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from level.Level import Level
|
from level.Level import Level
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from level.elements.LevelElement import LevelElement
|
from level.elements.StaticLevelElement import StaticLevelElement
|
||||||
from sprite.StaticSprite import StaticSprite
|
from sprite.Spritesheet import Spritesheet
|
||||||
|
|
||||||
|
|
||||||
class BlockElement(LevelElement):
|
class BlockElement(StaticLevelElement):
|
||||||
def __init__(self, x_position : int, y_position : int, sprite : StaticSprite):
|
def __init__(self, spritesheet: Spritesheet):
|
||||||
super().__init__(x_position, y_position, sprite)
|
super().__init__(spritesheet)
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
from LevelElement import LevelElement
|
from StaticLevelElement import StaticLevelElement
|
||||||
from sprite.StaticSprite import StaticSprite
|
from sprite.Spritesheet import Spritesheet
|
||||||
|
|
||||||
|
|
||||||
class InteractableElement(LevelElement):
|
class InteractableElement(StaticLevelElement):
|
||||||
def __init__(self, x_position : int, y_position : int, sprite : StaticSprite, block_id : str, requires : list[str]):
|
def __init__(self, spritesheet: Spritesheet, block_id: str, requires: list[str]):
|
||||||
super().__init__(x_position, y_position, sprite)
|
super().__init__(spritesheet)
|
||||||
self.block_id = block_id
|
self.block_id = block_id
|
||||||
self.requires = requires
|
self.requires = requires
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
from sprite.StaticSprite import StaticSprite
|
|
||||||
|
|
||||||
class LevelElement:
|
|
||||||
def __init__(self,x_position : int, y_position : int, sprite : StaticSprite):
|
|
||||||
self.x_position = x_position
|
|
||||||
self.y_position = y_position
|
|
||||||
self.sprite = sprite
|
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
from level.Level import Level
|
from level.Level import Level
|
||||||
from level.LevelElementSymbols import LevelElementSymbols
|
from level.LevelElementSymbols import LevelElementSymbols
|
||||||
from level.elements.BlockElement import BlockElement
|
from level.elements.BlockElement import BlockElement
|
||||||
from level.elements.InteractableElement import InteractableElement
|
|
||||||
from physics.SpriteManager import SpriteManager, DrawLayers
|
from physics.SpriteManager import SpriteManager, DrawLayers
|
||||||
from sprite.SpritesheetManager import SpritesheetManager
|
from sprite.SpritesheetManager import SpritesheetManager
|
||||||
from sprite.StaticSprite import StaticSprite
|
|
||||||
|
|
||||||
BLOCK_SIZE = (12, 12)
|
BLOCK_SIZE = (12, 12)
|
||||||
|
|
||||||
|
|
||||||
class LoadedLevel:
|
class LoadedLevel:
|
||||||
def __init__(self, sprite_manager: SpriteManager, spritesheet_manager: SpritesheetManager):
|
def __init__(self, sprite_manager: SpriteManager, spritesheet_manager: SpritesheetManager):
|
||||||
self.sprite_manager = sprite_manager
|
self.sprite_manager = sprite_manager
|
||||||
|
@ -15,25 +15,25 @@ class LoadedLevel:
|
||||||
|
|
||||||
def load_level(self, level: Level):
|
def load_level(self, level: Level):
|
||||||
for row_number, row in enumerate(level.tiles):
|
for row_number, row in enumerate(level.tiles):
|
||||||
self.blocks.append([])
|
|
||||||
for tile_number, tile in enumerate(row):
|
for tile_number, tile in enumerate(row):
|
||||||
x_position = row_number * BLOCK_SIZE[0]
|
position = (tile_number * BLOCK_SIZE[0], row_number * BLOCK_SIZE[1])
|
||||||
y_position = tile_number * BLOCK_SIZE[1]
|
|
||||||
if LevelElementSymbols.dict[tile] != LevelElementSymbols.PLAYER and LevelElementSymbols.dict[tile] != LevelElementSymbols.AIR:
|
tile_element = LevelElementSymbols.dict[tile['name']]
|
||||||
sprite = StaticSprite(self.spritesheet_manager.get_sheet(level.theme + LevelElementSymbols.dict[tile]['sprite_id']))
|
|
||||||
sprite.position_scale.position = (x_position, y_position)
|
sprite = None
|
||||||
|
|
||||||
|
if tile_element in LevelElementSymbols.BLOCKS_LIST:
|
||||||
|
spritesheet = self.spritesheet_manager.get_sheet(level.theme + tile_element['sprite_id'])
|
||||||
|
sprite = BlockElement(spritesheet)
|
||||||
sprite.set_animation_state('1')
|
sprite.set_animation_state('1')
|
||||||
|
sprite.position_scale.position = position
|
||||||
|
|
||||||
|
# tile['id'], tile['requirements']
|
||||||
|
|
||||||
|
if sprite is not None:
|
||||||
self.sprite_manager.add_ui_element(DrawLayers.OBJECTS, sprite)
|
self.sprite_manager.add_ui_element(DrawLayers.OBJECTS, sprite)
|
||||||
if(tile['id'] is None):
|
|
||||||
self.blocks[row_number].append(BlockElement(x_position, y_position, sprite))
|
|
||||||
else:
|
|
||||||
self.blocks[row_number].append(InteractableElement(x_position, y_position, sprite,tile['id'], tile['requirements']))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def destroy_level(self):
|
def destroy_level(self):
|
||||||
del self.blocks
|
for block in self.blocks:
|
||||||
|
self.sprite_manager.remove_ui_element(block)
|
||||||
|
del self.blocks
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
from sprite.Spritesheet import Spritesheet
|
||||||
|
from sprite.StaticSprite import StaticSprite
|
||||||
|
|
||||||
|
|
||||||
|
class StaticLevelElement(StaticSprite):
|
||||||
|
def __init__(self, spritesheet: Spritesheet):
|
||||||
|
super().__init__(spritesheet)
|
|
@ -3,6 +3,7 @@ import random
|
||||||
import pygame
|
import pygame
|
||||||
|
|
||||||
from level.LevelManager import LevelManager
|
from level.LevelManager import LevelManager
|
||||||
|
from level.elements.LoadedLevel import LoadedLevel
|
||||||
from physics.SpriteManager import SpriteManager, DrawLayers
|
from physics.SpriteManager import SpriteManager, DrawLayers
|
||||||
from physics.TickData import TickData
|
from physics.TickData import TickData
|
||||||
from physics.controllers.PlayerSprite import PlayerSprite
|
from physics.controllers.PlayerSprite import PlayerSprite
|
||||||
|
@ -14,7 +15,7 @@ from ui_elements.ClickEvent import ClickEvent
|
||||||
from ui_elements.KeyManager import KeyManager
|
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 = 'level'
|
||||||
|
|
||||||
|
|
||||||
def apply_frame_rate(number: float):
|
def apply_frame_rate(number: float):
|
||||||
|
@ -28,11 +29,41 @@ def apply_frame_rate(number: float):
|
||||||
|
|
||||||
|
|
||||||
if what_to_run == 'level':
|
if what_to_run == 'level':
|
||||||
csv_parse_test = LevelManager('data/levels')
|
screen_transform = PositionScale((0, 0), (1.5, 1.5))
|
||||||
csv_parse_test.load_from_config('data/levels/levels.json')
|
|
||||||
print(csv_parse_test.levels[0])
|
pygame.init()
|
||||||
for row in csv_parse_test.levels[0].tiles:
|
screen = pygame.display.set_mode((12 * 71 * 1.5, 12 * 40 * 1.5))
|
||||||
print(row)
|
pygame.display.set_caption("PM GAME")
|
||||||
|
clock = pygame.time.Clock()
|
||||||
|
frame_rate = 30
|
||||||
|
|
||||||
|
spritesheet_manager = SpritesheetManager("data/sprites", "data/sprites/sprites.json")
|
||||||
|
sprite_manager = SpriteManager()
|
||||||
|
key_manager = KeyManager()
|
||||||
|
|
||||||
|
parsed_levels_manager = LevelManager('data/levels')
|
||||||
|
parsed_levels_manager.load_from_config('data/levels/levels.json')
|
||||||
|
|
||||||
|
generated_level = LoadedLevel(sprite_manager, spritesheet_manager)
|
||||||
|
generated_level.load_level(parsed_levels_manager.levels[0])
|
||||||
|
|
||||||
|
while True:
|
||||||
|
clock.tick(frame_rate)
|
||||||
|
|
||||||
|
pygame_events: list[pygame.event.Event] = pygame.event.get()
|
||||||
|
key_manager.update_key_events(pygame_events)
|
||||||
|
click_events: list[ClickEvent] = ClickEvent.create_events(pygame_events, screen_transform)
|
||||||
|
|
||||||
|
for event in pygame_events:
|
||||||
|
if event.type == pygame.QUIT:
|
||||||
|
pygame.quit()
|
||||||
|
quit()
|
||||||
|
|
||||||
|
screen.fill((0, 0, 0))
|
||||||
|
|
||||||
|
sprite_manager.tick(TickData(apply_frame_rate(1), pygame_events, key_manager, click_events, screen_transform))
|
||||||
|
sprite_manager.draw(screen, screen_transform)
|
||||||
|
pygame.display.update()
|
||||||
|
|
||||||
|
|
||||||
elif what_to_run == 'physics':
|
elif what_to_run == 'physics':
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
class PositionScale:
|
class PositionScale:
|
||||||
def __init__(self, position: tuple[int, int] = (0, 0), scale: tuple[int, int] = (1, 1)):
|
def __init__(self, position: tuple[float, float] = (0, 0), scale: tuple[float, float] = (1, 1)):
|
||||||
self.position = position
|
self.position = position
|
||||||
self.scale = scale
|
self.scale = scale
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue