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
|
|
@ -14,7 +14,7 @@ var idle: bool = false
|
|||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
var model_instance = data.model.instantiate()
|
||||
var model_instance: Node = data.model.instantiate()
|
||||
frequency = randf_range(1.0, 4.0)
|
||||
amplitude = randf_range(1.0, 6.0)
|
||||
spawn_point = position
|
||||
|
|
@ -26,20 +26,20 @@ func _physics_process(delta: float) -> void:
|
|||
return
|
||||
|
||||
time += delta
|
||||
var x_movement = sin(time * frequency) * amplitude
|
||||
var y_movement = sin(time * 25) * 4.0
|
||||
var z_movement = cos(time * frequency) * amplitude
|
||||
|
||||
var x_movement: float = sin(time * frequency) * amplitude
|
||||
var y_movement: float = sin(time * 25) * 4.0
|
||||
var z_movement: float = cos(time * frequency) * amplitude
|
||||
|
||||
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():
|
||||
var collision = get_slide_collision(0)
|
||||
var collider = collision.get_collider()
|
||||
|
||||
var collision: KinematicCollision3D = get_slide_collision(0)
|
||||
var collider: Object = collision.get_collider()
|
||||
|
||||
# if the monster collided with the player...
|
||||
if collider.name == "Player":
|
||||
velocity = Vector3.ZERO
|
||||
|
|
@ -50,7 +50,7 @@ func faint() -> void:
|
|||
self.queue_free()
|
||||
|
||||
func attack_enemy(enemy: Monster) -> int:
|
||||
var damage = data.attack_enemy(enemy.data)
|
||||
var damage: int = data.attack_enemy(enemy.data)
|
||||
return damage
|
||||
|
||||
func take_damage(amount: int) -> void:
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
class_name MonsterSpawnpoint
|
||||
extends Node3D
|
||||
|
||||
@onready var monster_tscn = preload("res://entities/monster/monster.tscn")
|
||||
@onready var monster_tscn: PackedScene = preload("res://entities/monster/monster.tscn")
|
||||
|
||||
# a spawnpoint that can spawn monsters
|
||||
# monsters are only spawned, if the player is not looking
|
||||
|
|
@ -10,10 +10,10 @@ extends Node3D
|
|||
@export var spawnable_monsters: Array[MonsterSpawnpointProbability]
|
||||
|
||||
## Minimum Level the spawnable monsters have
|
||||
@export var min_level = 1
|
||||
@export var min_level: int = 1
|
||||
|
||||
## Maximum level the spawnable monsters can have
|
||||
@export var max_level = 1
|
||||
@export var max_level: int = 1
|
||||
|
||||
## Ignore spawning only if visible
|
||||
@export var ignore_visibility: bool = false
|
||||
|
|
@ -46,15 +46,15 @@ var active_monsters: Array[Monster] = []
|
|||
func _ready() -> void:
|
||||
if spawnable_monsters.is_empty():
|
||||
printerr("Spawnpoint (%s) does not have monsters to spawn." % self.name)
|
||||
|
||||
|
||||
spawn_timer.wait_time = spawn_cooldown
|
||||
spawn_timer.autostart = true
|
||||
spawn_timer.timeout.connect(spawn)
|
||||
add_child(spawn_timer)
|
||||
spawn_timer.start()
|
||||
|
||||
|
||||
spawn_point = position
|
||||
|
||||
|
||||
label.text = "%s / %s" % [len(active_monsters), max_monsters]
|
||||
|
||||
|
||||
|
|
@ -62,42 +62,42 @@ func spawn() -> void:
|
|||
if len(active_monsters) >= max_monsters:
|
||||
#print("Spawnpoint reached maximum amount of monsters")
|
||||
return
|
||||
|
||||
|
||||
if ignore_visibility == false and $VisibleOnScreenNotifier3D.is_on_screen():
|
||||
#print("Spawnpoint is visible on screen. Not spawning a monster.")
|
||||
return
|
||||
|
||||
|
||||
# TODO: Add a check to not spawn enemies X units near the player
|
||||
|
||||
|
||||
# instantiate a monster .tscn scene
|
||||
var monster_to_spawn = monster_tscn.instantiate()
|
||||
|
||||
var monster_to_spawn: Node = monster_tscn.instantiate()
|
||||
|
||||
# Create a new MonsterData for the monster to spawn
|
||||
var monster_data: MonsterData = MonsterData.new()
|
||||
|
||||
|
||||
# Get a random monster data as a template
|
||||
var random := randi() % spawnable_monsters.size()
|
||||
var random: int = randi() % spawnable_monsters.size()
|
||||
var template_data : MonsterData = spawnable_monsters[random].monster_data
|
||||
monster_data.set_values(template_data.unique_id, {}, randi_range(min_level, max_level))
|
||||
|
||||
|
||||
## Heal the wild monster fully
|
||||
monster_data.heal(9999)
|
||||
|
||||
|
||||
## Set the data of the Node3D monster to spawn
|
||||
monster_to_spawn.data = monster_data
|
||||
|
||||
|
||||
# keep track of the current monster
|
||||
active_monsters.append(monster_to_spawn)
|
||||
label.text = "%s / %s" % [len(active_monsters), max_monsters]
|
||||
|
||||
|
||||
# calculate the position of the monster and add the offset of the spawnpoint itself
|
||||
var monster_position = Vector3(position.x, position.y + 1, position.z)
|
||||
var monster_position: Vector3 = Vector3(position.x, position.y + 1, position.z)
|
||||
monster_to_spawn.position = monster_position
|
||||
|
||||
var debug_level_node = get_parent_node_3d()
|
||||
|
||||
var debug_level_node: Node3D = get_parent_node_3d()
|
||||
debug_level_node.add_child(monster_to_spawn)
|
||||
#print("Spawning Mob \"%s\"" % monster_to_spawn.data.display_name)
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
time += delta
|
||||
|
|
|
|||
|
|
@ -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