81 lines
2.2 KiB
Python
81 lines
2.2 KiB
Python
import assets
|
|
import arcade
|
|
import controls
|
|
import gamestate
|
|
import math
|
|
|
|
from objects import BalthasarRenderer, OverworldMap, DIR_UP, DIR_LEFT, DIR_DOWN, DIR_RIGHT
|
|
|
|
WALK_SPEED = 48
|
|
|
|
balthasar = BalthasarRenderer()
|
|
overworld = OverworldMap()
|
|
|
|
btrans_active = False
|
|
btrans_timer = 0
|
|
btrans_sound = None
|
|
BTRANS_PULSE_DUR = 0.25
|
|
BTRANS_DURATION = 0.75
|
|
|
|
def start_battle(battle_id):
|
|
global btrans_active, btrans_timer, btrans_sound
|
|
gamestate.gamestates["battle"].battle_id = battle_id
|
|
btrans_sound = assets.sounds["sfx_encounter"].play()
|
|
btrans_active = True
|
|
btrans_timer = 0
|
|
|
|
def switch(game):
|
|
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
|
|
btrans_active = False
|
|
btrans_sound.stop()
|
|
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
|
|
balthasar.set_direction(DIR_DOWN)
|
|
elif controls.is_control_pressed(2): # Bal
|
|
balthasar.set_direction(DIR_LEFT)
|
|
elif controls.is_control_pressed(3): # Jobb
|
|
balthasar.set_direction(DIR_RIGHT)
|
|
|
|
walking = False
|
|
|
|
if controls.is_control_held(0): # Fel
|
|
overworld.scroll_y -= WALK_SPEED * dt
|
|
walking = True
|
|
elif controls.is_control_held(1): # Le
|
|
overworld.scroll_y += WALK_SPEED * dt
|
|
walking = True
|
|
|
|
if controls.is_control_held(2): # Bal
|
|
overworld.scroll_x += WALK_SPEED * dt
|
|
walking = True
|
|
elif controls.is_control_held(3): # Jobb
|
|
overworld.scroll_x -= WALK_SPEED * dt
|
|
walking = True
|
|
|
|
balthasar.set_walking(walking)
|
|
|
|
def draw(game):
|
|
overworld.render(game)
|
|
balthasar.render(game)
|