fixes saving of party monsters, adds display of monster stats in battle ui
This commit is contained in:
parent
5748d34b34
commit
b09eee0805
9 changed files with 201 additions and 61 deletions
|
|
@ -10,6 +10,7 @@ var spawn_point: Vector3 = Vector3(0, 0, 0)
|
|||
@onready var frequency: float = 1.0
|
||||
@onready var amplitude: float = 0.5
|
||||
var in_battle: bool = false
|
||||
var idle: bool = false
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
|
|
@ -28,7 +29,11 @@ func _physics_process(delta: float) -> void:
|
|||
var x_movement = sin(time * frequency) * amplitude
|
||||
var y_movement = sin(time * 25) * 4.0
|
||||
var z_movement = cos(time * frequency) * amplitude
|
||||
velocity = Vector3(x_movement, y_movement, z_movement)
|
||||
|
||||
if not idle:
|
||||
velocity = Vector3(x_movement, y_movement, z_movement)
|
||||
else:
|
||||
velocity = Vector3(0, y_movement, 0)
|
||||
|
||||
# if move_and_slide reports collisions
|
||||
if move_and_slide():
|
||||
|
|
@ -39,15 +44,4 @@ func _physics_process(delta: float) -> void:
|
|||
if collider.name == "Player":
|
||||
velocity = Vector3.ZERO
|
||||
in_battle = true
|
||||
|
||||
# calculate players new position
|
||||
# from the camera 3 units backwards
|
||||
var camera = collider.find_child("Camera3D")
|
||||
|
||||
# local z axis of the camera
|
||||
var local_z = camera.global_transform.basis.z
|
||||
|
||||
var new_player_position = camera.global_transform.origin + local_z * 3
|
||||
|
||||
collider.start_battle(self, new_player_position)
|
||||
#rotate_toward(rotation.z, collider.rotation.z, 1.0)
|
||||
collider.start_battle(self)
|
||||
|
|
|
|||
|
|
@ -2,9 +2,13 @@ extends CharacterBody3D
|
|||
|
||||
@onready var animated_mesh = $GobotSkin
|
||||
var in_battle: bool = false
|
||||
var enemy: MonsterData = null
|
||||
const SPEED = 5.0
|
||||
const JUMP_VELOCITY = 4.5
|
||||
|
||||
func _ready() -> void:
|
||||
Utils.set_player(self)
|
||||
|
||||
func on_save_game(saved_data : Array[SavedData]):
|
||||
var data = SavedData.new()
|
||||
data.position = global_position
|
||||
|
|
@ -17,6 +21,9 @@ func on_before_load_game():
|
|||
|
||||
func on_load_game(saved_data: SavedData):
|
||||
global_position = saved_data.position
|
||||
|
||||
# Update the global reference to the player
|
||||
Utils.set_player(self)
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if in_battle == true:
|
||||
|
|
@ -76,29 +83,37 @@ func _physics_process(delta: float) -> void:
|
|||
# the player is positioned (mostly somewhere else than the current position)
|
||||
# ui changes
|
||||
# music changes
|
||||
func start_battle(enemy: Node3D, player_position: Vector3) -> void:
|
||||
position = Vector3(player_position.x, position.y, player_position.z)
|
||||
func start_battle(p_enemy: Node3D) -> void:
|
||||
enemy = p_enemy.data
|
||||
var camera: Camera3D = $CameraRoot/SpringArm3D/Camera3D
|
||||
# local z axis of the camera
|
||||
var local_z = camera.global_transform.basis.z
|
||||
var new_player_position = camera.global_transform.origin + local_z * 3
|
||||
var monster_position = camera.global_transform.origin + local_z * 2
|
||||
position = Vector3(new_player_position.x, position.y, new_player_position.z)
|
||||
|
||||
in_battle = true
|
||||
velocity = Vector3.ZERO
|
||||
animated_mesh.idle()
|
||||
UI.show_battle_ui(true)
|
||||
UI.show_ingame_controls(false)
|
||||
|
||||
# Spawn player monster
|
||||
var monster_data : MonsterData = SaveManager.current_save.party[0]
|
||||
var monster = Monster.new()
|
||||
monster.data = monster_data
|
||||
monster.idle = true
|
||||
print("%s (%s), Lv. %s, %s XP" % [monster.data.name, monster.data.nickname, monster.data.level, monster.data.xp])
|
||||
monster.position = Vector3(monster_position.x, position.y + 1, monster_position.z)
|
||||
add_child(monster)
|
||||
camera.look_at(monster.position, Vector3.UP, false)
|
||||
|
||||
# How to attack and finish the battle?
|
||||
|
||||
|
||||
await get_tree().create_timer(2.0).timeout
|
||||
|
||||
await get_tree().create_timer(5.0).timeout
|
||||
print("Battle over")
|
||||
remove_child(monster)
|
||||
monster.queue_free()
|
||||
in_battle = false
|
||||
|
||||
func save() -> Dictionary:
|
||||
var save_dict = {
|
||||
"player_transform": {
|
||||
"pos_x": global_position.x,
|
||||
"pos_y": global_position.y,
|
||||
"pos_z": global_position.z,
|
||||
"rot_x": global_rotation.x,
|
||||
"rot_y": global_rotation.y,
|
||||
"rot_z": global_rotation.z
|
||||
}
|
||||
}
|
||||
return save_dict
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue