From 6a91d3e6db00fc4c3670139e9e76845117b2e090 Mon Sep 17 00:00:00 2001 From: markojozsef Date: Sun, 4 Oct 2026 16:43:56 +0200 Subject: [PATCH] Csata transition --- src/gamestates/none.py | 2 +- src/gamestates/overworld.py | 126 +++++++++--------------------------- src/objects.py | 100 ++++++++++++++++++++++++++++ 3 files changed, 131 insertions(+), 97 deletions(-) create mode 100644 src/objects.py diff --git a/src/gamestates/none.py b/src/gamestates/none.py index f37c04b..8bb4861 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(game, dt): - gamestate.switch_gamestate(game, "battle") + gamestate.switch_gamestate(game, "overworld") diff --git a/src/gamestates/overworld.py b/src/gamestates/overworld.py index af89b4b..d9b7ffe 100644 --- a/src/gamestates/overworld.py +++ b/src/gamestates/overworld.py @@ -1,114 +1,48 @@ import arcade -import assets import controls -import menu -import text -import renderers +import gamestate 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_WIDTH = 4 -OVERWORLD_HEIGHT = 4 -OVERWORLD_MAP = [ - [5,3,3,6], - [1,0,0,2], - [1,0,0,2], - [7,4,4,8], -] +from objects import BalthasarRenderer, OverworldMap, DIR_UP, DIR_LEFT, DIR_DOWN, DIR_RIGHT WALK_SPEED = 48 -class BalthasarRenderer: - 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 = [] - - self.scroll_x = 0 - self.scroll_y = 0 - - 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 % 4) * OVERWORLD_TILE_WIDTH, (tile // 4) * OVERWORLD_TILE_HEIGHT, - 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( - self.scroll_x + (game.screen_width / 2) - ((OVERWORLD_WIDTH * OVERWORLD_TILE_WIDTH) / 2), - self.scroll_y + (game.screen_height / 2) - ((OVERWORLD_HEIGHT * OVERWORLD_TILE_HEIGHT) / 2) - ), - pixelated=True - ) - balthasar = BalthasarRenderer() overworld = OverworldMap() +btrans_active = False +btrans_timer = 0 +BTRANS_PULSE_DUR = 0.25 +BTRANS_DURATION = 0.75 + +def start_battle(battle_id): + global btrans_active, btrans_timer + gamestate.gamestates["battle"].battle_id = battle_id + btrans_active = True + btrans_timer = 0 + def switch(game): - pass + in_battle_transition = False def update(game, dt): + global btrans_active, btrans_timer + if btrans_active: + btrans_timer += dt + + if btrans_timer >= BTRANS_DURATION: + game.mos_enabled = False + gamestate.switch_gamestate(game,"battle") + + game.mos_enabled = True + cycle_progress = (btrans_timer % BTRANS_PULSE_DUR) / BTRANS_PULSE_DUR + game.mosaic = max(1, math.floor(cycle_progress * 16)) + return + balthasar.update() + if controls.is_control_pressed(4): # DEBUG: battle + start_battle(0) + if controls.is_control_pressed(0): # Fel balthasar.set_direction(DIR_UP) elif controls.is_control_pressed(1): # Le diff --git a/src/objects.py b/src/objects.py new file mode 100644 index 0000000..5dee8e6 --- /dev/null +++ b/src/objects.py @@ -0,0 +1,100 @@ +import assets +import arcade + +# Main character(balthasar) renderer +DIR_DOWN = 0 +DIR_UP = 1 +DIR_RIGHT = 2 +DIR_LEFT = 3 + +B_SPRITE_WIDHT = 16 +B_SPRITE_HEIGHT = 24 +B_SPRITE_WALKING = 3 + + +class BalthasarRenderer: + 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 + ) + +# Overworld Map + +OVERWORLD_LB_X = 0 +OVERWORLD_LB_Y = 0 +OVERWORLD_TILE_WIDTH = 16 +OVERWORLD_TILE_HEIGHT = 16 +OVERWORLD_WIDTH = 4 +OVERWORLD_HEIGHT = 4 +OVERWORLD_MAP = [ + [5,3,3,6], + [1,0,0,2], + [1,0,0,2], + [7,4,4,8], +] + +class OverworldMap: + def __init__(self): + self.sprites = [] + + self.scroll_x = 0 + self.scroll_y = 0 + + 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 % 4) * OVERWORLD_TILE_WIDTH, (tile // 4) * OVERWORLD_TILE_HEIGHT, + 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( + self.scroll_x + (game.screen_width / 2) - ((OVERWORLD_WIDTH * OVERWORLD_TILE_WIDTH) / 2), + self.scroll_y + (game.screen_height / 2) - ((OVERWORLD_HEIGHT * OVERWORLD_TILE_HEIGHT) / 2) + ), + pixelated=True + ) + +