Csata transition
This commit is contained in:
@@ -2,4 +2,4 @@ import gamestate
|
|||||||
|
|
||||||
# Azért létezik ez a "none" gamestate hogy meghívja az elsö gamestate init() funkcióját
|
# Azért létezik ez a "none" gamestate hogy meghívja az elsö gamestate init() funkcióját
|
||||||
def update(game, dt):
|
def update(game, dt):
|
||||||
gamestate.switch_gamestate(game, "battle")
|
gamestate.switch_gamestate(game, "overworld")
|
||||||
|
|||||||
@@ -1,114 +1,48 @@
|
|||||||
import arcade
|
import arcade
|
||||||
import assets
|
|
||||||
import controls
|
import controls
|
||||||
import menu
|
import gamestate
|
||||||
import text
|
|
||||||
import renderers
|
|
||||||
import math
|
import math
|
||||||
|
|
||||||
DIR_DOWN = 0
|
from objects import BalthasarRenderer, OverworldMap, DIR_UP, DIR_LEFT, DIR_DOWN, DIR_RIGHT
|
||||||
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],
|
|
||||||
]
|
|
||||||
|
|
||||||
WALK_SPEED = 48
|
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()
|
balthasar = BalthasarRenderer()
|
||||||
overworld = OverworldMap()
|
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):
|
def switch(game):
|
||||||
pass
|
in_battle_transition = False
|
||||||
|
|
||||||
def update(game, dt):
|
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()
|
balthasar.update()
|
||||||
|
|
||||||
|
if controls.is_control_pressed(4): # DEBUG: battle
|
||||||
|
start_battle(0)
|
||||||
|
|
||||||
if controls.is_control_pressed(0): # Fel
|
if controls.is_control_pressed(0): # Fel
|
||||||
balthasar.set_direction(DIR_UP)
|
balthasar.set_direction(DIR_UP)
|
||||||
elif controls.is_control_pressed(1): # Le
|
elif controls.is_control_pressed(1): # Le
|
||||||
|
|||||||
100
src/objects.py
Normal file
100
src/objects.py
Normal file
@@ -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
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user