adapted monster structure and save game

This commit is contained in:
Luca 2024-09-22 13:44:49 +02:00
parent 04873e3880
commit aa4afc4c4b
22 changed files with 358 additions and 183 deletions

View file

@ -1,12 +1,10 @@
extends Node3D
# Game.gd - Main Entrypoint for the game
@onready var ui: UI = $UI
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
SaveGame.load()
# Update the UI when the Inventory (global) changes
Inventory.inventory_changed.connect(ui._update_ui)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass

View file

@ -1,7 +1,9 @@
class_name Monster
extends CharacterBody3D
@export var stats: MonsterStats
signal level_up
@export var stats: MonsterData = MonsterData.new()
var spawn_point: Vector3 = Vector3(0, 0, 0)
@ -9,7 +11,6 @@ var spawn_point: Vector3 = Vector3(0, 0, 0)
@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.

View file

@ -7,7 +7,7 @@ extends Node3D
# monsters are only spawned, if the player is not looking
# list that holds all spawnable monsters
@export var spawnable_monsters: Array[MonsterStats]
@export var spawnable_monsters: Array[MonsterData]
# ignore spawning only if visible
@export var ignore_visibility: bool = false
@ -71,7 +71,7 @@ func spawn() -> void:
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)
print("Spawning Mob \"%s\"" % monster_to_spawn.stats.display_name)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:

View file

@ -17,6 +17,10 @@ func _process(delta) -> void:
if save_timer >= time_to_save:
save_timer_reached.emit()
save_timer = 0.0
# Save the game
SaveGame.save()
save_button_held_down = false
else:
save_timer_incremented.emit(ceili((save_timer / time_to_save) * 100))

27
scenes/ui/ingame_menu.gd Normal file
View file

@ -0,0 +1,27 @@
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")
func _ready() -> void:
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)
func _update_player_info() -> void:
#%PlayerName.text =
pass

113
scenes/ui/ingame_menu.tscn Normal file
View file

@ -0,0 +1,113 @@
[gd_scene load_steps=8 format=3 uid="uid://bbvbnrcjatkrb"]
[ext_resource type="Script" path="res://scenes/ui/ingame_menu.gd" id="1_beinb"]
[ext_resource type="FontFile" uid="uid://bjaavdnopfh0q" path="res://assets/fonts/aoboshi_one/AoboshiOne-Regular.ttf" id="2_1e4kf"]
[ext_resource type="Texture2D" uid="uid://bhh31i3wgww43" path="res://assets/textures/Game Icons/Vector/2x/singleplayer.png" id="2_c2ia0"]
[ext_resource type="Texture2D" uid="uid://c737p2osplq2o" path="res://assets/textures/Xbox Series/Vector/xbox_button_x_outline.svg" id="3_kgfth"]
[ext_resource type="Texture2D" uid="uid://cxry7h4q17lir" path="res://assets/textures/Game Icons/Vector/2x/star.png" id="3_oo4iu"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_co4a0"]
bg_color = Color(0.9, 0.9, 0.9, 1)
corner_radius_top_left = 64
corner_radius_top_right = 64
corner_radius_bottom_right = 64
corner_radius_bottom_left = 64
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_flvbu"]
[node name="IngameMenu" type="MarginContainer"]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_beinb")
[node name="MarginContainer" type="MarginContainer" parent="."]
layout_mode = 2
theme_override_constants/margin_left = 50
theme_override_constants/margin_top = 50
theme_override_constants/margin_right = 50
theme_override_constants/margin_bottom = 50
[node name="PanelContainer" type="PanelContainer" parent="MarginContainer"]
layout_mode = 2
theme_override_styles/panel = SubResource("StyleBoxFlat_co4a0")
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer/PanelContainer"]
layout_mode = 2
[node name="PlayerInfo" type="MarginContainer" parent="MarginContainer/PanelContainer/VBoxContainer"]
layout_mode = 2
theme_override_constants/margin_left = 40
theme_override_constants/margin_top = 30
theme_override_constants/margin_right = 40
[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer/PanelContainer/VBoxContainer/PlayerInfo"]
layout_mode = 2
[node name="PlayerThumbnail" type="TextureRect" parent="MarginContainer/PanelContainer/VBoxContainer/PlayerInfo/HBoxContainer"]
self_modulate = Color(0, 0, 0, 1)
layout_mode = 2
texture = ExtResource("2_c2ia0")
expand_mode = 3
[node name="PlayerName" type="Label" parent="MarginContainer/PanelContainer/VBoxContainer/PlayerInfo/HBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
theme_override_colors/font_color = Color(0, 0, 0, 1)
text = "PLAYER_NAME"
vertical_alignment = 1
[node name="MoneyValue" type="Label" parent="MarginContainer/PanelContainer/VBoxContainer/PlayerInfo/HBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
theme_override_colors/font_color = Color(0, 0, 0, 1)
text = "1.000.000"
vertical_alignment = 1
[node name="CurrencyIcon" type="TextureRect" parent="MarginContainer/PanelContainer/VBoxContainer/PlayerInfo/HBoxContainer"]
self_modulate = Color(0.941789, 0.802506, 0.327877, 1)
layout_mode = 2
texture = ExtResource("3_oo4iu")
expand_mode = 3
[node name="MonsterInfoTitle" type="MarginContainer" parent="MarginContainer/PanelContainer/VBoxContainer"]
layout_mode = 2
theme_override_constants/margin_left = 40
theme_override_constants/margin_top = 30
theme_override_constants/margin_right = 40
[node name="Label" type="Label" parent="MarginContainer/PanelContainer/VBoxContainer/MonsterInfoTitle"]
layout_mode = 2
size_flags_horizontal = 3
theme_override_colors/font_color = Color(0, 0, 0, 1)
theme_override_fonts/font = ExtResource("2_1e4kf")
theme_override_font_sizes/font_size = 36
text = "Your Monsters"
vertical_alignment = 1
[node name="MonsterListEntryContainer" type="MarginContainer" parent="MarginContainer/PanelContainer/VBoxContainer"]
layout_mode = 2
size_flags_vertical = 2
theme_override_constants/margin_left = 20
theme_override_constants/margin_right = 20
[node name="CloseButtonContainer" type="MarginContainer" parent="MarginContainer/PanelContainer/VBoxContainer"]
layout_mode = 2
theme_override_constants/margin_bottom = 32
[node name="CloseButton" type="Button" parent="MarginContainer/PanelContainer/VBoxContainer/CloseButtonContainer"]
unique_name_in_owner = true
self_modulate = Color(0, 0, 0, 1)
custom_minimum_size = Vector2(120, 120)
layout_mode = 2
size_flags_horizontal = 4
theme_override_styles/focus = SubResource("StyleBoxEmpty_flvbu")
icon = ExtResource("3_kgfth")
flat = true
icon_alignment = 1
expand_icon = true
[connection signal="pressed" from="MarginContainer/PanelContainer/VBoxContainer/CloseButtonContainer/CloseButton" to="." method="_on_close_button_pressed"]

View file

@ -1,75 +0,0 @@
[gd_scene load_steps=6 format=3 uid="uid://bbvbnrcjatkrb"]
[ext_resource type="Script" path="res://scripts/monster_list.gd" id="1_jk76e"]
[ext_resource type="FontFile" uid="uid://bjaavdnopfh0q" path="res://assets/fonts/aoboshi_one/AoboshiOne-Regular.ttf" id="2_hunv3"]
[ext_resource type="Texture2D" uid="uid://c737p2osplq2o" path="res://assets/textures/Xbox Series/Vector/xbox_button_x_outline.svg" id="3_08jy5"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_co4a0"]
bg_color = Color(0.9, 0.9, 0.9, 1)
corner_radius_top_left = 64
corner_radius_top_right = 64
corner_radius_bottom_right = 64
corner_radius_bottom_left = 64
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_flvbu"]
[node name="MonsterList" type="MarginContainer"]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_jk76e")
[node name="MarginContainer" type="MarginContainer" parent="."]
layout_mode = 2
theme_override_constants/margin_left = 50
theme_override_constants/margin_top = 50
theme_override_constants/margin_right = 50
theme_override_constants/margin_bottom = 50
[node name="PanelContainer" type="PanelContainer" parent="MarginContainer"]
layout_mode = 2
theme_override_styles/panel = SubResource("StyleBoxFlat_co4a0")
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer/PanelContainer"]
layout_mode = 2
[node name="MarginContainer" type="MarginContainer" parent="MarginContainer/PanelContainer/VBoxContainer"]
layout_mode = 2
theme_override_constants/margin_left = 40
theme_override_constants/margin_top = 30
theme_override_constants/margin_right = 40
[node name="Label" type="Label" parent="MarginContainer/PanelContainer/VBoxContainer/MarginContainer"]
layout_mode = 2
size_flags_horizontal = 3
theme_override_colors/font_color = Color(0, 0, 0, 1)
theme_override_fonts/font = ExtResource("2_hunv3")
theme_override_font_sizes/font_size = 36
text = "Your Monsters"
vertical_alignment = 1
[node name="MonsterListEntryContainer" type="MarginContainer" parent="MarginContainer/PanelContainer/VBoxContainer"]
layout_mode = 2
size_flags_vertical = 2
theme_override_constants/margin_left = 20
theme_override_constants/margin_right = 20
[node name="MarginContainer2" type="MarginContainer" parent="MarginContainer/PanelContainer/VBoxContainer"]
layout_mode = 2
theme_override_constants/margin_bottom = 32
[node name="CloseButton" type="Button" parent="MarginContainer/PanelContainer/VBoxContainer/MarginContainer2"]
unique_name_in_owner = true
self_modulate = Color(0, 0, 0, 1)
custom_minimum_size = Vector2(120, 120)
layout_mode = 2
size_flags_horizontal = 4
theme_override_styles/focus = SubResource("StyleBoxEmpty_flvbu")
icon = ExtResource("3_08jy5")
flat = true
icon_alignment = 1
expand_icon = true
[connection signal="pressed" from="MarginContainer/PanelContainer/VBoxContainer/MarginContainer2/CloseButton" to="." method="_on_close_button_pressed"]

View file

@ -12,17 +12,10 @@ func _process(delta: float) -> void:
pass
func populate(monster) -> void:
# thumbnail
# id
# name
# level
# health
# healthprogress
# experience
%MonsterID.text = str(0)
%MonsterName.text = monster.name
%MonsterName.text = monster.display_name
%MonsterLevel.text = "Lvl. %s" % monster.level
%HealthProgressBar.value = monster.health
%HealthProgressBar.max_value = monster.max_health
%ExperienceProgressBar.value = monster.experience
%ExperienceProgressBar.max_value = monster.experience_for_next_level
%HealthProgressBar.max_value = monster.health
%ExperienceProgressBar.value = monster.xp
%ExperienceProgressBar.max_value = monster.base_xp_for_next_level

View file

@ -1,7 +1,7 @@
extends CanvasLayer
class_name UI
@onready var monster_list: MarginContainer = %MonsterList
@onready var ingame_menu: MarginContainer = %IngameMenu
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
@ -12,12 +12,15 @@ func _process(delta: float) -> void:
pass
func _on_ingame_controls_menu_button_clicked() -> void:
monster_list.visible = true
ingame_menu.visible = true
# Updates the whole UI
func _update_ui() -> void:
# Updating the player info
ingame_menu._update_player_info()
# Updating the monster list
monster_list._update_monster_list()
ingame_menu._update_monster_list()
print("UI updated")
@ -34,9 +37,8 @@ func _on_ingame_controls_save_timer_incremented(value) -> void:
func _on_ingame_controls_save_timer_reached() -> void:
%SavePercentage.text = "Saved!"
print("Saved Game")
%IngameControls.disable_save_button()
await get_tree().create_timer(1.0).timeout
%IngameControls.enable_save_button()
$SaveUI.visible = false
%SavePercentage.text = "0 % ..."
%SavePercentage.text = "0%"

View file

@ -4,7 +4,7 @@
[ext_resource type="Script" path="res://scripts/camera_controls.gd" id="1_x56x6"]
[ext_resource type="PackedScene" uid="uid://dt00rjsodtady" path="res://scenes/ui/main_menu.tscn" id="3_tcmm8"]
[ext_resource type="PackedScene" uid="uid://1anjhvi173g3" path="res://scenes/ui/ingame_controls.tscn" id="4_likk0"]
[ext_resource type="PackedScene" uid="uid://bbvbnrcjatkrb" path="res://scenes/ui/monster_list.tscn" id="5_qjqu1"]
[ext_resource type="PackedScene" uid="uid://bbvbnrcjatkrb" path="res://scenes/ui/ingame_menu.tscn" id="5_qjqu1"]
[node name="UI" type="CanvasLayer"]
script = ExtResource("1_vyi3s")
@ -56,7 +56,7 @@ vertical_alignment = 1
[node name="IngameControls" parent="." instance=ExtResource("4_likk0")]
unique_name_in_owner = true
[node name="MonsterList" parent="." instance=ExtResource("5_qjqu1")]
[node name="IngameMenu" parent="." instance=ExtResource("5_qjqu1")]
unique_name_in_owner = true
visible = false

View file

@ -2,8 +2,8 @@
[ext_resource type="PackedScene" uid="uid://be5bc5gjbo875" path="res://scenes/player/player.tscn" id="1_ra6oo"]
[ext_resource type="PackedScene" uid="uid://dawpmu4vvv3rs" path="res://scenes/monster_spawnpoint/monster_spawnpoint.tscn" id="3_esgto"]
[ext_resource type="Script" path="res://resources/monster_stats.gd" id="3_iktqp"]
[ext_resource type="Resource" uid="uid://ym438vedcdyl" path="res://resources/monsters/DebugMonster1.tres" id="4_3y7gi"]
[ext_resource type="Script" path="res://resources/monster_data.gd" id="3_iktqp"]
[ext_resource type="Resource" uid="uid://0xqaef8uftnv" path="res://resources/monsters/debuggy.tres" id="4_noslo"]
[sub_resource type="PlaneMesh" id="PlaneMesh_wak6a"]
size = Vector2(1000, 1000)
@ -52,6 +52,6 @@ environment = SubResource("Environment_rwve8")
[node name="MonsterSpawnpoint" parent="." instance=ExtResource("3_esgto")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -5.6673, 0, -8.88992)
spawnable_monsters = Array[ExtResource("3_iktqp")]([ExtResource("4_3y7gi")])
spawnable_monsters = Array[ExtResource("3_iktqp")]([ExtResource("4_noslo")])
ignore_visibility = true
max_monsters = 1