diff --git a/res/sprite/balthasar.png b/res/sprite/balthasar.png new file mode 100644 index 0000000..d0231a2 Binary files /dev/null and b/res/sprite/balthasar.png differ diff --git a/res/sprite/evil.png b/res/sprite/evil.png deleted file mode 100644 index ac16253..0000000 Binary files a/res/sprite/evil.png and /dev/null differ diff --git a/res/sprite/overworld_sheet.png b/res/sprite/overworld_sheet.png new file mode 100644 index 0000000..b76a9c0 Binary files /dev/null and b/res/sprite/overworld_sheet.png differ diff --git a/src/assets.py b/src/assets.py index cc491d1..12e0d74 100644 --- a/src/assets.py +++ b/src/assets.py @@ -1,7 +1,9 @@ import arcade sprites = { - "cursor": arcade.load_texture("res/sprite/handcursor.png"), - "font": arcade.load_spritesheet("res/sprite/font.png"), - "panel": arcade.load_spritesheet("res/sprite/panel.png"), + "cursor" : arcade.load_texture("res/sprite/handcursor.png"), + "font" : arcade.load_spritesheet("res/sprite/font.png"), + "panel" : arcade.load_spritesheet("res/sprite/panel.png"), + "balthasar": arcade.load_spritesheet("res/sprite/balthasar.png"), + "overworld": arcade.load_spritesheet("res/sprite/overworld_sheet.png"), } diff --git a/src/gamestate.py b/src/gamestate.py index c9979b8..ce7d60a 100644 --- a/src/gamestate.py +++ b/src/gamestate.py @@ -1,9 +1,11 @@ import gamestates.none import gamestates.title +import gamestates.overworld gamestates = { "none": gamestates.none, - "title": gamestates.title + "title": gamestates.title, + "overworld": gamestates.overworld } gamestate = "none" diff --git a/src/gamestates/none.py b/src/gamestates/none.py index 52bddd2..eca8e8c 100644 --- a/src/gamestates/none.py +++ b/src/gamestates/none.py @@ -2,4 +2,4 @@ import gamestate # Azért létezik ez a "none" gamestate hogy meghívja az elsö gamestate init() funkcióját def update(dt): - gamestate.switch_gamestate("title") + gamestate.switch_gamestate("overworld") diff --git a/src/gamestates/overworld.py b/src/gamestates/overworld.py new file mode 100644 index 0000000..f117bf0 --- /dev/null +++ b/src/gamestates/overworld.py @@ -0,0 +1,130 @@ +import arcade +import assets +import controls +import menu +import text +import renderers +import math + +DIR_DOWN = 0 +DIR_UP = 1 +DIR_RIGHT = 2 +DIR_LEFT = 3 + +B_SPRITE_WIDHT = 16 +B_SPRITE_HEIGHT = 24 +B_SPRITE_WALKING = 3 + +OVERWORLD_LB_X = 0 +OVERWORLD_LB_Y = 0 +OVERWORLD_TILE_WIDTH = 16 +OVERWORLD_TILE_HEIGHT = 16 +OVERWORLD_MAP = [ + [1,0,0,0], + [1,0,1,0], + [0,1,0,0], + [0,0,0,0], +] + + + +class BalthasarController: + def __init__(self): + self.direction = DIR_UP + self.walking = False + self.anim_timer = 0 + + def set_direction(self, direction): + self.direction = direction + + def set_walking(self, walking): + self.walking = walking + if walking == False: + self.anim_timer = 0 + + def update(self): + self.anim_timer += 1 + if self.anim_timer > 30: + self.anim_timer = 0 + + def render(self, game): + sprite_h = self.direction if self.direction < 3 else 2 + sprite_v = 1 if (self.walking and self.anim_timer <= 15) else 0 + flip_h = self.direction == DIR_LEFT + + sprite = assets.sprites["balthasar"].get_texture(arcade.LBWH(B_SPRITE_WIDHT*sprite_h, B_SPRITE_HEIGHT*sprite_v, B_SPRITE_WIDHT, B_SPRITE_HEIGHT)) + arcade.draw_texture_rect( + sprite.flip_horizontally() if flip_h else sprite, + arcade.LBWH((game.screen_width / 2) - (B_SPRITE_WIDHT / 2), (game.screen_height / 2) - (B_SPRITE_HEIGHT / 2), B_SPRITE_WIDHT, B_SPRITE_HEIGHT), + pixelated=True + ) + +class OverworldMap: + def __init__(self): + self.sprites = [] + + x = 0 + y = len(OVERWORLD_MAP) + for row in OVERWORLD_MAP: + for tile in row: + self.sprites.append([ + assets.sprites["overworld"].get_texture(arcade.LBWH((tile % 16) * 16, (tile // 16) * 12, OVERWORLD_TILE_WIDTH, OVERWORLD_TILE_HEIGHT)), + arcade.LBWH( + (x * OVERWORLD_TILE_WIDTH), + (y * OVERWORLD_TILE_HEIGHT), + OVERWORLD_TILE_WIDTH, + OVERWORLD_TILE_HEIGHT + ) + ]) + x += 1 + y -= 1 + x = 0 + + + def render(self, game): + for s in self.sprites: + arcade.draw_texture_rect( + s[0], + s[1].move( + (game.screen_width / 2), + (game.screen_height / 2) + ), + pixelated=True + ) + +controller = BalthasarController() +overworld = OverworldMap() + +def switch(): + pass + +def update(dt): + controller.update() + + if controls.is_control_pressed(0): # Fel + controller.set_direction(DIR_UP) + elif controls.is_control_pressed(1): # Le + controller.set_direction(DIR_DOWN) + elif controls.is_control_pressed(2): # Bal + controller.set_direction(DIR_LEFT) + elif controls.is_control_pressed(3): # Jobb + controller.set_direction(DIR_RIGHT) + + if controls.is_control_held(0): # Fel + + controller.set_walking(True) + elif controls.is_control_held(1): # Le + + controller.set_walking(True) + elif controls.is_control_held(2): # Bal + + controller.set_walking(True) + elif controls.is_control_held(3): # Jobb + + controller.set_walking(True) + else: + controller.set_walking(False) + +def draw(game): + controller.render(game) + overworld.render(game) \ No newline at end of file