cleanup, folder restructure and ui restructure

This commit is contained in:
Luca 2024-09-20 19:32:32 +02:00
parent 6ce579026b
commit b24117740b
28 changed files with 473 additions and 367 deletions

View file

@ -1,13 +0,0 @@
extends Control
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
Inventory.connect("inventory_changed", update_inventory)
pass # Replace with function body.
func update_inventory() -> void:
var m = Inventory.monsters[0]
var string = "%s Lvl %s, %s/%s" % [m.name, m.level, m.health, m.max_health]
$MonsterList/Monster1.text = string
print("Updating inventory")

View file

@ -1,53 +0,0 @@
class_name Monster
extends CharacterBody3D
@export var stats: MonsterStats
var spawn_point: Vector3 = Vector3(0, 0, 0)
# DEBUG MOVEMENT
@onready var time: float = 16.0
@onready var frequency: float = 1.0
@onready var amplitude: float = 0.5
var in_battle: bool = false
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
var model_instance = stats.model.instantiate()
frequency = randf_range(1.0, 4.0)
amplitude = randf_range(1.0, 6.0)
spawn_point = position
add_child(model_instance)
func _physics_process(delta: float) -> void:
if in_battle:
velocity = Vector3.ZERO
return
time += delta
var x_movement = sin(time * frequency) * amplitude
var z_movement = cos(time * frequency) * amplitude
velocity = Vector3(x_movement, 0, z_movement)
# if move_and_slide reports collisions
if move_and_slide():
var collision = get_slide_collision(0)
var collider = collision.get_collider()
# if the monster collided with the player...
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)

View file

@ -1,16 +1,23 @@
extends MarginContainer
class_name MonsterList
@onready var monster_list_entry_container: MarginContainer = $MarginContainer/PanelContainer/VBoxContainer/MonsterListEntryContainer
@onready var monster_list_entry = preload("res://scenes/ui/monster_list_entry.tscn")
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
visible = false
func _on_close_button_pressed() -> void:
visible = false
pass # Replace with function body.
func _update_monster_list() -> void:
for i in Inventory.monsters.size():
var monster = Inventory.monsters[i]
var entry = monster_list_entry.instantiate()
# populate the new entry
entry.populate(Inventory.monsters[i])
# add it to the list
monster_list_entry_container.add_child(entry)

View file

@ -1,82 +0,0 @@
class_name MonsterSpawnpoint
extends Node3D
@onready var monster_tscn = preload("res://scenes/monster.tscn")
# a spawnpoint that can spawn monsters
# monsters are only spawned, if the player is not looking
# list that holds all spawnable monsters
@export var spawnable_monsters: Array[MonsterStats]
# ignore spawning only if visible
@export var ignore_visibility: bool = false
# the maximum amount of spawned monsters
# no monsters will spawn, when this number is reached
@export var max_monsters: int = 5
# the maximum lifetime a monster can be in the world
# a monster is then deleted if the following conditions are met:
# the monster has exceeded its maximum lifetime and it is not on screen
# TODO: figure out how to check for the exceeded lifetime and delete
@export var max_lifetime: float = 60.0 # seconds
# only spawn a monster every x seconds
@export var spawn_cooldown: float = 3.0 # seconds
@onready var spawn_timer: Timer = Timer.new()
@onready var time: float = 16.0
@onready var frequency: float = 1.0
@onready var amplitude: float = 0.5
@onready var spawn_point: Vector3 = Vector3(0, 0, 0)
@onready var label: Label3D = $Label3D
# a spawnpoint should keep track of spawned entities
var active_monsters: Array[Monster] = []
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
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
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()
monster_to_spawn.stats = spawnable_monsters[0]
# 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)
monster_to_spawn.position = monster_position
var debug_level_node = get_parent_node_3d()
debug_level_node.add_child(monster_to_spawn)
print("Spawning Mob \"%s\"" % monster_to_spawn.stats.name)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
time += delta
var diamond_rotation: float = sin(time * frequency) * amplitude
var diamond_height: float = sin(time * frequency) * amplitude
$Diamond.rotation.y = diamond_rotation
$Diamond.position.y = 2.0 + diamond_height

View file

@ -1,76 +0,0 @@
extends CharacterBody3D
@onready var animated_mesh = $GobotSkin
var in_battle: bool = false
const SPEED = 5.0
const JUMP_VELOCITY = 4.5
func _physics_process(delta: float) -> void:
if in_battle == true:
return
animated_mesh.idle()
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
animated_mesh.fall()
# Handle jump.
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")
$CameraRoot.rotation.y += camera_input_dir.x * 0.2
# 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")
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()
# 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
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
velocity.z = move_toward(velocity.z, 0, SPEED)
move_and_slide()
if velocity.length() < 0.05:
animated_mesh.idle()
# what happens when a battle starts?
# 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)
in_battle = true
velocity = Vector3.ZERO
animated_mesh.idle()
await get_tree().create_timer(2.0).timeout
print("timer over")
in_battle = false