From 3e2afc1de654ff72094d860f0636140f20f9c399 Mon Sep 17 00:00:00 2001 From: Zakarya Date: Mon, 9 Oct 2023 18:33:33 -0700 Subject: [PATCH] Add a leveling system --- data/character/character.gd | 17 ++++++++- data/character/character.tscn | 67 ++++++++++++++++++++++++++++++++--- 2 files changed, 79 insertions(+), 5 deletions(-) diff --git a/data/character/character.gd b/data/character/character.gd index c0dcd8e..7faf677 100644 --- a/data/character/character.gd +++ b/data/character/character.gd @@ -6,17 +6,22 @@ var accel = 10 var immobile = false var inventory = { + "points": 0, "stone": 0, "wood": 0, "food": 0 } var status = { "health": 100, - "stamina": 100 + "stamina": 100, + "level": 1 } var current_tool = "none" +func get_total_points_for_next_level(): #Yes, this name is very long. Deal with it + return status.level*10 + func change_tool(tool): current_tool = tool $body_pivot/body/tool.texture = load(game_data.tools[tool].image) @@ -40,15 +45,25 @@ func _process(delta): var hit_object = $body_pivot/raycast.get_collider() if hit_object.type == "resource": inventory[hit_object.resource_type] += 1 + inventory.points += 1 hit_object.get_node("animation").play("hit") #update inventory HUD $hud/inventory/stone_label.text = str(inventory.stone) $hud/inventory/wood_label.text = str(inventory.wood) + $hud/level/points.text = str(inventory.points) + "/" + str(get_total_points_for_next_level()) + $hud/level/level_bar.value = inventory.points #update status HUD $hud/bars/health.value = status.health $hud/bars/stamina.value = status.stamina + $hud/level/level.text = "Level " + str(status.level) + $hud/level/level_bar.max_value = get_total_points_for_next_level() + + #level up + if inventory.points >= (get_total_points_for_next_level()): + inventory.points -= get_total_points_for_next_level() + status.level += 1 func _input(event): if event is InputEventMouseMotion: diff --git a/data/character/character.tscn b/data/character/character.tscn index 0b78904..8b01c75 100644 --- a/data/character/character.tscn +++ b/data/character/character.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=13 format=3 uid="uid://4dsm0l7s6vki"] +[gd_scene load_steps=16 format=3 uid="uid://4dsm0l7s6vki"] [ext_resource type="Texture2D" uid="uid://gfxfxkfu8uk4" path="res://textures/character/character.svg" id="1_f7cgp"] [ext_resource type="Script" path="res://data/character/character.gd" id="1_qlitf"] @@ -31,6 +31,16 @@ _data = { "hit": SubResource("Animation_gkjmi") } +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_tb4rh"] +bg_color = Color(0, 0, 0, 0.392157) +corner_radius_top_left = 4 +corner_radius_top_right = 4 +corner_radius_bottom_right = 4 +corner_radius_bottom_left = 4 + +[sub_resource type="Theme" id="Theme_h3iw6"] +Panel/styles/panel = SubResource("StyleBoxFlat_tb4rh") + [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_5s1x0"] bg_color = Color(0.184314, 0.184314, 0.184314, 1) corner_radius_top_left = 10 @@ -52,6 +62,13 @@ corner_radius_top_right = 10 corner_radius_bottom_right = 10 corner_radius_bottom_left = 10 +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_1p646"] +bg_color = Color(0, 0.698039, 1, 1) +corner_radius_top_left = 10 +corner_radius_top_right = 10 +corner_radius_bottom_right = 10 +corner_radius_bottom_left = 10 + [node name="character" type="CharacterBody2D"] collision_layer = 3 script = ExtResource("1_qlitf") @@ -85,10 +102,11 @@ texture = ExtResource("3_c34pt") z_index = 10 layout_mode = 3 anchors_preset = 0 -offset_left = -432.0 +offset_left = -512.0 offset_top = -256.0 -offset_right = 464.0 -offset_bottom = 272.0 +offset_right = 512.0 +offset_bottom = 256.0 +theme = SubResource("Theme_h3iw6") script = ExtResource("3_eogh2") [node name="bars" type="Panel" parent="hud"] @@ -181,3 +199,44 @@ text = "0" horizontal_alignment = 2 vertical_alignment = 1 clip_text = true + +[node name="level" type="Panel" parent="hud"] +layout_mode = 1 +anchors_preset = 7 +anchor_left = 0.5 +anchor_top = 1.0 +anchor_right = 0.5 +anchor_bottom = 1.0 +offset_left = -192.0 +offset_top = -80.0 +offset_right = 192.0 +grow_horizontal = 2 +grow_vertical = 0 + +[node name="level" type="Label" parent="hud/level"] +layout_mode = 0 +offset_left = 8.0 +offset_right = 376.0 +offset_bottom = 26.0 +text = "Level 0" +horizontal_alignment = 1 +clip_text = true + +[node name="level_bar" type="ProgressBar" parent="hud/level"] +offset_left = 16.0 +offset_top = 32.0 +offset_right = 368.0 +offset_bottom = 40.0 +theme_override_styles/background = SubResource("StyleBoxFlat_5s1x0") +theme_override_styles/fill = SubResource("StyleBoxFlat_1p646") +show_percentage = false + +[node name="points" type="Label" parent="hud/level"] +layout_mode = 0 +offset_left = 8.0 +offset_top = 48.0 +offset_right = 376.0 +offset_bottom = 74.0 +text = "0/100" +horizontal_alignment = 1 +clip_text = true