added first theme progress and switched all files to use static typing
This commit is contained in:
parent
c9458f3627
commit
b5ace17da9
2665 changed files with 50249 additions and 476 deletions
|
|
@ -4,26 +4,27 @@ extends CharacterBody3D
|
|||
@onready var camera: Camera3D = %Camera3D
|
||||
|
||||
## State
|
||||
@export var battle_state := Global.BattleState.NOT_IN_BATTLE
|
||||
@export var battle_state: Enums.BattleState = Enums.BattleState.NOT_IN_BATTLE
|
||||
var in_battle: bool = false
|
||||
var player_monster: Monster = null
|
||||
var enemy: Monster = null
|
||||
|
||||
## Movement
|
||||
const SPEED = 5.0
|
||||
const JUMP_VELOCITY = 4.5
|
||||
const SPEED : float = 5.0
|
||||
const JUMP_VELOCITY : float = 4.5
|
||||
|
||||
func _ready() -> void:
|
||||
# Set the global reference to the player
|
||||
Utils.set_player(self)
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
# If the player is in a battle, handle it via start_battle and then handle_battle
|
||||
if battle_state != Global.BattleState.NOT_IN_BATTLE:
|
||||
if battle_state != Enums.BattleState.NOT_IN_BATTLE:
|
||||
return
|
||||
|
||||
|
||||
animated_mesh.idle()
|
||||
|
||||
|
||||
# Add the gravity.
|
||||
if not is_on_floor():
|
||||
velocity += get_gravity() * delta
|
||||
|
|
@ -33,33 +34,33 @@ func _physics_process(delta: float) -> void:
|
|||
if Input.is_action_just_pressed("ui_accept"):
|
||||
print("jump")
|
||||
animated_mesh.run()
|
||||
|
||||
|
||||
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
|
||||
velocity.y = JUMP_VELOCITY
|
||||
|
||||
|
||||
# Camera rotation
|
||||
var camera_input_dir := Input.get_vector("joystick_right_left", "joystick_right_right", "joystick_right_left", "joystick_right_right")
|
||||
var camera_input_dir : Vector2 = Input.get_vector("joystick_right_left", "joystick_right_right", "joystick_right_left", "joystick_right_right")
|
||||
$CameraRoot.rotation.y += camera_input_dir.x
|
||||
|
||||
# Get the input direction and handle the movement / deceleration.
|
||||
# As good practice, you should replace UI actions with custom gameplay actions.
|
||||
var input_dir := Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
|
||||
|
||||
var input_dir : Vector2 = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
|
||||
|
||||
if input_dir.length() > 0 and is_on_floor():
|
||||
animated_mesh.run()
|
||||
if input_dir.length() > 0 and not is_on_floor():
|
||||
animated_mesh.fall()
|
||||
|
||||
var direction := (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
||||
|
||||
var direction : Vector3 = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
||||
|
||||
# Rotate the direction with the camera, so that the cameras forward direction
|
||||
# is the joysticks and the players forward direction
|
||||
direction = direction.rotated(Vector3.UP, $CameraRoot.rotation.y)
|
||||
|
||||
|
||||
# Move character to the direction
|
||||
if direction.length() != 0:
|
||||
$GobotSkin.rotation.y = atan2(direction.x,direction.z)
|
||||
|
||||
|
||||
if direction:
|
||||
velocity.x = direction.x * SPEED
|
||||
velocity.z = direction.z * SPEED
|
||||
|
|
@ -68,127 +69,144 @@ func _physics_process(delta: float) -> void:
|
|||
velocity.z = move_toward(velocity.z, 0, SPEED)
|
||||
|
||||
move_and_slide()
|
||||
|
||||
|
||||
if velocity.length() < 0.05:
|
||||
animated_mesh.idle()
|
||||
|
||||
|
||||
func on_save_game(saved_data : Array[SavedData]):
|
||||
var data = SavedData.new()
|
||||
func on_save_game(saved_data : Array[SavedData]) -> void:
|
||||
var data : SavedData = SavedData.new()
|
||||
data.position = global_position
|
||||
data.scene_path = scene_file_path
|
||||
saved_data.append(data)
|
||||
|
||||
func on_before_load_game():
|
||||
|
||||
|
||||
func on_before_load_game() -> void:
|
||||
get_parent().remove_child(self)
|
||||
queue_free()
|
||||
|
||||
func on_load_game(saved_data: SavedData):
|
||||
|
||||
func on_load_game(saved_data: SavedData) -> void:
|
||||
global_position = saved_data.position
|
||||
|
||||
|
||||
# Update the global reference to the player
|
||||
Utils.set_player(self)
|
||||
|
||||
|
||||
func handle_battle() -> void:
|
||||
match battle_state:
|
||||
Global.BattleState.STARTED:
|
||||
# disable battle_UI
|
||||
# UI.battle_ui.disable()
|
||||
|
||||
Enums.BattleState.STARTED:
|
||||
# Start with disabled UI
|
||||
UI.battle_ui.disable()
|
||||
UI.battle_ui.set_message("A wild %s appeared!" % enemy.data.name)
|
||||
await get_tree().create_timer(3.0).timeout
|
||||
battle_state = Global.BattleState.PLAYER_TURN
|
||||
battle_state = Enums.BattleState.PLAYER_TURN
|
||||
handle_battle()
|
||||
Global.BattleState.PLAYER_TURN:
|
||||
|
||||
Enums.BattleState.PLAYER_TURN:
|
||||
UI.battle_ui.set_message("What will you do?")
|
||||
# todo: enable battle_ui again
|
||||
# UI.battle_ui.enable()
|
||||
UI.battle_ui.enable()
|
||||
UI.battle_ui.update()
|
||||
Global.BattleState.ENEMY_TURN:
|
||||
|
||||
Enums.BattleState.ENEMY_TURN:
|
||||
UI.battle_ui.disable()
|
||||
# If the enemy has no health left, we win
|
||||
if enemy.data.current_health <= 0:
|
||||
print("win")
|
||||
battle_state = Global.BattleState.WIN
|
||||
battle_state = Enums.BattleState.WIN
|
||||
handle_battle()
|
||||
return
|
||||
|
||||
|
||||
UI.battle_ui.set_message("What will the enemy do?")
|
||||
await get_tree().create_timer(3.0).timeout
|
||||
await get_tree().create_timer(2.0).timeout
|
||||
|
||||
# The enemy can currently only attack
|
||||
var damage_amount: int = enemy.attack_enemy(player_monster)
|
||||
UI.battle_ui.set_message("The enemy attacked you for %s damage!" % str(damage_amount))
|
||||
|
||||
await get_tree().create_timer(1.0).timeout
|
||||
UI.battle_ui.update()
|
||||
battle_state = Global.BattleState.PLAYER_TURN
|
||||
battle_state = Enums.BattleState.PLAYER_TURN
|
||||
handle_battle()
|
||||
Global.BattleState.CATCH:
|
||||
print("Catch")
|
||||
|
||||
Enums.BattleState.CATCH:
|
||||
print("TODO: Catch")
|
||||
await get_tree().create_timer(3.0).timeout
|
||||
Global.BattleState.WIN:
|
||||
|
||||
Enums.BattleState.WIN:
|
||||
UI.battle_ui.disable()
|
||||
UI.battle_ui.set_message("You won!")
|
||||
await get_tree().create_timer(3.0).timeout
|
||||
battle_state = Global.BattleState.NOT_IN_BATTLE
|
||||
await get_tree().create_timer(2.0).timeout
|
||||
|
||||
# End the battle and reset some states
|
||||
battle_state = Enums.BattleState.NOT_IN_BATTLE
|
||||
enemy.queue_free()
|
||||
player_monster.queue_free()
|
||||
UI.ingame_menu.update()
|
||||
UI.show_battle_ui(false)
|
||||
UI.show_ingame_controls(true)
|
||||
Global.BattleState.LOSE:
|
||||
var gained_xp: int = player_monster.data.calculate_gained_xp(enemy.data)
|
||||
player_monster.data.add_xp(gained_xp)
|
||||
print("You gained %s xp!" % str(gained_xp))
|
||||
|
||||
Enums.BattleState.LOSE:
|
||||
print("LOSE")
|
||||
await get_tree().create_timer(3.0).timeout
|
||||
|
||||
|
||||
|
||||
|
||||
## This method sets up a battle between the player and an enemy monster
|
||||
func start_battle(p_enemy: Monster) -> void:
|
||||
# Don't start a battle if we are already in one
|
||||
# TODO: Maybe add a cooldown of 1.5s after the battle ended
|
||||
if battle_state != Global.BattleState.NOT_IN_BATTLE:
|
||||
if battle_state != Enums.BattleState.NOT_IN_BATTLE:
|
||||
return
|
||||
|
||||
|
||||
# Stop the player
|
||||
velocity = Vector3.ZERO
|
||||
animated_mesh.idle()
|
||||
|
||||
|
||||
# Set the current enemy
|
||||
enemy = p_enemy
|
||||
|
||||
|
||||
# Get the loccal z axis of the camera to position the player
|
||||
var local_z = camera.global_transform.basis.z
|
||||
|
||||
var local_z: Vector3 = camera.global_transform.basis.z
|
||||
|
||||
# Get the new player and monster positions
|
||||
var new_player_position = camera.global_transform.origin + local_z * 3
|
||||
var monster_position = camera.global_transform.origin + local_z * 3
|
||||
|
||||
var new_player_position: Vector3 = camera.global_transform.origin + local_z * 3
|
||||
var monster_position: Vector3 = camera.global_transform.origin + local_z * 3
|
||||
|
||||
# Set the players new position
|
||||
position = Vector3(new_player_position.x, position.y, new_player_position.z)
|
||||
|
||||
|
||||
# Change the UI
|
||||
UI.show_battle_ui(true)
|
||||
UI.show_ingame_controls(false)
|
||||
|
||||
|
||||
# Create the player's monster
|
||||
player_monster = Monster.new()
|
||||
|
||||
|
||||
# Get the data from the party
|
||||
var monster_data : MonsterData = SaveManager.current_save.party[0]
|
||||
|
||||
|
||||
# And add it to the monster
|
||||
player_monster.data = monster_data
|
||||
player_monster.idle = true
|
||||
player_monster.position = Vector3(monster_position.x, position.y + 1, monster_position.z)
|
||||
add_child(player_monster)
|
||||
|
||||
|
||||
# Get into the battle and switch between the states
|
||||
battle_state = Global.BattleState.STARTED
|
||||
battle_state = Enums.BattleState.STARTED
|
||||
handle_battle()
|
||||
|
||||
|
||||
func attack_enemy():
|
||||
func attack_enemy() -> void:
|
||||
UI.battle_ui.disable()
|
||||
UI.battle_ui.set_message("You attacked the enemy!")
|
||||
await get_tree().create_timer(1.0).timeout
|
||||
|
||||
|
||||
# this should rather be player_monster.attack_enemy(enemy) for correct values
|
||||
enemy.take_damage(7)
|
||||
enemy.take_damage(10)
|
||||
UI.battle_ui.update()
|
||||
await get_tree().create_timer(1.0).timeout
|
||||
battle_state = Global.BattleState.ENEMY_TURN
|
||||
battle_state = Enums.BattleState.ENEMY_TURN
|
||||
handle_battle()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue