Add marketplace component for skill unlocking and update related resources

This commit is contained in:
2025-04-27 17:09:54 +02:00
parent 49a652a5b1
commit fd78f4f5b3
17 changed files with 257 additions and 13 deletions

View File

@@ -1,4 +1,4 @@
[gd_scene load_steps=26 format=3 uid="uid://bqi5s710xb1ju"]
[gd_scene load_steps=29 format=3 uid="uid://bqi5s710xb1ju"]
[ext_resource type="Script" path="res://scripts/player.gd" id="1_8j4h4"]
[ext_resource type="Texture2D" uid="uid://b7gp0gqvkv8j4" path="res://sprites/MrBrick_base.png" id="2_bc55y"]
@@ -14,8 +14,11 @@
[ext_resource type="Script" path="res://scripts/components/invulnerability_component.gd" id="14_jopig"]
[ext_resource type="Script" path="res://scripts/components/can_be_launched_component.gd" id="16_kemlv"]
[ext_resource type="Resource" uid="uid://dw5ee2lpeypnb" path="res://resources/skills/brick_throw.tres" id="16_smbir"]
[ext_resource type="Resource" uid="uid://2glvryih82t1" path="res://resources/skills/fire_brick.tres" id="17_6y5qu"]
[ext_resource type="Script" path="res://scripts/components/trigger_lever_component.gd" id="17_hglfj"]
[ext_resource type="AudioStream" uid="uid://duj2q0rqytaxg" path="res://sfx/jump.wav" id="18_pysae"]
[ext_resource type="Resource" uid="uid://cx5fsbexblp60" path="res://resources/skills/ice_brick.tres" id="18_umfbf"]
[ext_resource type="Resource" uid="uid://cdp8sex36vdq2" path="res://resources/skills/explosive_brick.tres" id="19_5wjb7"]
[ext_resource type="AudioStream" uid="uid://bmfn6p88gy575" path="res://sfx/player_hurt.wav" id="19_7anly"]
[ext_resource type="AudioStream" uid="uid://ycgtf6wj7mto" path="res://sfx/heal.wav" id="20_bptj5"]
[ext_resource type="Script" path="res://scripts/skill_manager.gd" id="20_ppfy7"]
@@ -124,7 +127,7 @@ root = NodePath("..")
[node name="SkillManager" type="Node" parent="."]
script = ExtResource("20_ppfy7")
available_skills = Array[ExtResource("21_d0oiv")]([ExtResource("22_vnsgd"), ExtResource("16_smbir")])
available_skills = Array[ExtResource("21_d0oiv")]([ExtResource("22_vnsgd"), ExtResource("17_6y5qu"), ExtResource("16_smbir"), ExtResource("18_umfbf"), ExtResource("19_5wjb7")])
[node name="SkillUnlockerComponent" type="Node" parent="." node_paths=PackedStringArray("skill_manager")]
script = ExtResource("23_qsv2c")

View File

@@ -113,7 +113,7 @@ root = NodePath("..")
[node name="IceEffectComponent" type="Node" parent="." node_paths=PackedStringArray("status_effect_component")]
script = ExtResource("11_pq0k7")
components_to_disable = [NodePath("../SideToSideMovement"), NodePath("../PeriodicShootingComponent")]
components_to_disable = [NodePath("../SideToSideMovement"), NodePath("../PeriodicShootingComponent"), NodePath("../DamageComponent")]
status_effect_component = NodePath("../StatusEffectComponent")
[node name="sfx_hurt" type="AudioStreamPlayer2D" parent="."]

View File

@@ -25,7 +25,7 @@ frame = 80
[node name="BulletComponent" type="Node" parent="." node_paths=PackedStringArray("root", "area2d", "visibility_notifier", "timer")]
script = ExtResource("2_hjcob")
root = NodePath("..")
speed = 120.0
speed = 330.0
area2d = NodePath("..")
visibility_notifier = NodePath("../VisibleOnScreenNotifier2D")
life_time = 2.0

View File

@@ -25,7 +25,7 @@ frame = 80
[node name="BulletComponent" type="Node" parent="." node_paths=PackedStringArray("root", "area2d", "visibility_notifier", "timer")]
script = ExtResource("2_ilnf5")
root = NodePath("..")
speed = 120.0
speed = 250.0
area2d = NodePath("..")
visibility_notifier = NodePath("../VisibleOnScreenNotifier2D")
life_time = 2.0

58
objects/marketplace.tscn Normal file
View File

@@ -0,0 +1,58 @@
[gd_scene load_steps=11 format=3 uid="uid://dlm2ri562fynd"]
[ext_resource type="LabelSettings" uid="uid://rvn5ivivfvv6" path="res://resources/ui/hud_label_settings.tres" id="1_7r0u8"]
[ext_resource type="Script" path="res://scripts/marketplace.gd" id="1_ncpyg"]
[ext_resource type="FontFile" uid="uid://xm0vbusjr7b7" path="res://fonts/PressStart2P-Regular.ttf" id="2_ho1tm"]
[ext_resource type="Script" path="res://scripts/resources/skill_data.gd" id="2_pg4mc"]
[ext_resource type="Resource" uid="uid://dw5ee2lpeypnb" path="res://resources/skills/brick_throw.tres" id="3_bk5yi"]
[ext_resource type="Resource" uid="uid://cdp8sex36vdq2" path="res://resources/skills/explosive_brick.tres" id="4_tx0n3"]
[ext_resource type="Resource" uid="uid://2glvryih82t1" path="res://resources/skills/fire_brick.tres" id="5_fqx8e"]
[ext_resource type="Resource" uid="uid://cx5fsbexblp60" path="res://resources/skills/ice_brick.tres" id="6_6665y"]
[ext_resource type="Resource" uid="uid://d3bjre2etov1n" path="res://resources/skills/magnetic.tres" id="7_ukny6"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_c56bj"]
bg_color = Color(0, 0, 0, 1)
[node name="Marketplace" type="Control" node_paths=PackedStringArray("grid")]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_ncpyg")
skill_data = Array[ExtResource("2_pg4mc")]([ExtResource("3_bk5yi"), ExtResource("4_tx0n3"), ExtResource("5_fqx8e"), ExtResource("6_6665y"), ExtResource("7_ukny6")])
grid = NodePath("Panel/VBoxContainer/GridContainer")
font = ExtResource("2_ho1tm")
[node name="Panel" type="Panel" parent="."]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
theme_override_styles/panel = SubResource("StyleBoxFlat_c56bj")
[node name="VBoxContainer" type="VBoxContainer" parent="Panel"]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
theme_override_constants/separation = 8
[node name="Label" type="Label" parent="Panel/VBoxContainer"]
layout_mode = 2
text = "marketplace"
label_settings = ExtResource("1_7r0u8")
horizontal_alignment = 1
uppercase = true
[node name="GridContainer" type="GridContainer" parent="Panel/VBoxContainer"]
layout_mode = 2
size_flags_vertical = 3
theme_override_constants/h_separation = 8
theme_override_constants/v_separation = 8
columns = 3

View File

@@ -54,6 +54,11 @@ coins=""
levers=""
player=""
[gui]
theme/custom_font="res://fonts/PressStart2P-Regular.ttf"
theme/default_font_antialiasing=0
[input]
left={
@@ -87,6 +92,11 @@ unlock_skills={
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194332,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
show_marketplace={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":66,"key_label":0,"unicode":98,"location":0,"echo":false,"script":null)
]
}
[layer_names]

View File

@@ -1,4 +1,4 @@
[gd_resource type="Resource" load_steps=2 format=3 uid="uid://vql535ckoeqm"]
[gd_resource type="Resource" script_class="CollectableResource" load_steps=2 format=3 uid="uid://vql535ckoeqm"]
[ext_resource type="Script" path="res://scripts/resources/collectable_resource.gd" id="1_veemo"]

View File

@@ -0,0 +1,17 @@
[gd_resource type="Resource" script_class="SkillData" load_steps=4 format=3 uid="uid://cdp8sex36vdq2"]
[ext_resource type="PackedScene" uid="uid://5surx230gfw3" path="res://objects/exploding_brick.tscn" id="1_6pfoa"]
[ext_resource type="PackedScene" uid="uid://coayig4dxelo2" path="res://objects/player_skills/brick_throw_skill.tscn" id="2_e0o8w"]
[ext_resource type="Script" path="res://scripts/resources/skill_data.gd" id="3_cgsq1"]
[resource]
script = ExtResource("3_cgsq1")
name = "Explosive brick"
description = "Allows you to throw explosive bricks at enemies"
node = ExtResource("2_e0o8w")
config = {
"brick_scene": ExtResource("1_6pfoa"),
"player_controller": NodePath("."),
"timer": NodePath("ThrowTimer")
}
cost = 180

View File

@@ -0,0 +1,17 @@
[gd_resource type="Resource" script_class="SkillData" load_steps=4 format=3 uid="uid://2glvryih82t1"]
[ext_resource type="PackedScene" uid="uid://daau4j5hbklk0" path="res://objects/fire_brick.tscn" id="1_2g43l"]
[ext_resource type="Script" path="res://scripts/resources/skill_data.gd" id="1_2j5ko"]
[ext_resource type="PackedScene" uid="uid://coayig4dxelo2" path="res://objects/player_skills/brick_throw_skill.tscn" id="1_g53fp"]
[resource]
script = ExtResource("1_2j5ko")
name = "Fire brick"
description = "Allows you to throw fire bricks at enemies"
node = ExtResource("1_g53fp")
config = {
"brick_scene": ExtResource("1_2g43l"),
"player_controller": NodePath("."),
"timer": NodePath("ThrowTimer")
}
cost = 150

View File

@@ -0,0 +1,17 @@
[gd_resource type="Resource" script_class="SkillData" load_steps=4 format=3 uid="uid://cx5fsbexblp60"]
[ext_resource type="PackedScene" uid="uid://bcmx07k12gcsc" path="res://objects/ice_brick.tscn" id="1_ci3d1"]
[ext_resource type="PackedScene" uid="uid://coayig4dxelo2" path="res://objects/player_skills/brick_throw_skill.tscn" id="1_rflri"]
[ext_resource type="Script" path="res://scripts/resources/skill_data.gd" id="2_pspkt"]
[resource]
script = ExtResource("2_pspkt")
name = "Ice brick"
description = "Allows you to throw ice bricks at enemies"
node = ExtResource("1_rflri")
config = {
"brick_scene": ExtResource("1_ci3d1"),
"player_controller": NodePath("."),
"timer": NodePath("ThrowTimer")
}
cost = 150

View File

@@ -1,5 +1,6 @@
[gd_resource type="Resource" script_class="SkillData" load_steps=3 format=3 uid="uid://d3bjre2etov1n"]
[gd_resource type="Resource" script_class="SkillData" load_steps=4 format=3 uid="uid://d3bjre2etov1n"]
[ext_resource type="Texture2D" uid="uid://cvhoq7aubxlmq" path="res://sprites/ui/magnetic_skill_icon.png" id="1_16qcg"]
[ext_resource type="PackedScene" uid="uid://cunyndudjh2he" path="res://objects/player_skills/magnetic_skill.tscn" id="1_er41s"]
[ext_resource type="Script" path="res://scripts/resources/skill_data.gd" id="1_r01oq"]
@@ -14,3 +15,4 @@ config = {
"root": NodePath(".")
}
cost = 70
icon = ExtResource("1_16qcg")

View File

@@ -1,4 +1,4 @@
[gd_scene load_steps=31 format=4 uid="uid://h60obxmju6mo"]
[gd_scene load_steps=32 format=4 uid="uid://h60obxmju6mo"]
[ext_resource type="Texture2D" uid="uid://djifxc5x0dyrw" path="res://sprites/ppc_tileset.png" id="1_5lb42"]
[ext_resource type="TileSet" uid="uid://cl4bn8lofqvky" path="res://tileset/village/tileset_village.tres" id="1_d680t"]
@@ -19,6 +19,7 @@
[ext_resource type="Script" path="res://addons/phantom_camera/scripts/resources/tween_resource.gd" id="14_mjvn7"]
[ext_resource type="PackedScene" uid="uid://dtjrpkhssq32a" path="res://objects/bg.tscn" id="14_ws5fk"]
[ext_resource type="PackedScene" uid="uid://bqom4cm7r18db" path="res://objects/killzone.tscn" id="20_8a4vc"]
[ext_resource type="PackedScene" uid="uid://dlm2ri562fynd" path="res://objects/marketplace.tscn" id="20_ss8k0"]
[ext_resource type="PackedScene" uid="uid://d0s2abysa86rq" path="res://objects/child.tscn" id="21_8rhdx"]
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_cagp7"]
@@ -480,5 +481,18 @@ position = Vector2(877, -577)
[node name="HUD" parent="CanvasLayer" instance=ExtResource("1_gbpkv")]
[node name="Marketplace" parent="CanvasLayer" node_paths=PackedStringArray("root", "skill_unlocker") instance=ExtResource("20_ss8k0")]
visible = false
custom_minimum_size = Vector2(480, 240)
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
root = NodePath(".")
skill_unlocker = NodePath("../../Brick Player/SkillUnlockerComponent")
[node name="Killzone" parent="." instance=ExtResource("20_8a4vc")]
position = Vector2(0, 990)
[editable path="Brick Player"]

View File

@@ -28,7 +28,6 @@ func _process(_delta: float) -> void:
return
if damage_timer:
return
process_entity_and_apply_damage(current_target)
@@ -63,6 +62,9 @@ func process_entity_and_apply_damage(body: Node2D) -> void:
func on_area2d_body_entered(body: Node2D) -> void:
current_target = body
if not check_if_processing_is_on():
return
if damage_timer:
damage_timer.start()
@@ -77,8 +79,16 @@ func on_area2d_body_exited(body: Node2D) -> void:
func on_area2d_area_entered(area: Area2D) -> void:
if not check_if_processing_is_on():
return
if area == area2d:
return
var parent := area.get_parent()
if parent.has_node("DamageComponent"):
process_entity_and_apply_damage(parent)
func check_if_processing_is_on() -> bool:
return self.process_mode == PROCESS_MODE_INHERIT or self.process_mode == PROCESS_MODE_ALWAYS

View File

@@ -6,19 +6,20 @@ extends Node
@onready var game_manager: GM = $"/root/GameManager"
func try_unlock_skill(skill_data: SkillData) -> void:
func try_unlock_skill(skill_data: SkillData) -> bool:
if not game_manager:
return
return false
if game_manager.is_skill_unlocked(skill_data.name):
return
return false
if game_manager.get_coins() < skill_data.cost:
return
return false
game_manager.remove_coins(skill_data.cost)
game_manager.unlock_skill(skill_data.name)
skill_manager.add_skill(skill_data)
return true
func _input(event: InputEvent) -> void:

61
scripts/marketplace.gd Normal file
View File

@@ -0,0 +1,61 @@
class_name Marketplace
extends Node
@export var root: Control
@export var skill_data: Array[SkillData] = []
@export var grid: GridContainer
@export var font: Font
@export var skill_unlocker: SkillUnlockerComponent
@onready var game_manager: GM = $"/root/GameManager"
func _ready() -> void:
if not skill_unlocker:
return
var skills_to_unlock: Array[SkillData] = []
for skill in skill_data:
if skill in game_manager.player_state['unlocked_skills']:
continue
skills_to_unlock.append(skill)
for skill in skills_to_unlock:
create_upgrade_button(skill)
func _input(event: InputEvent) -> void:
if event.is_action_pressed("show_marketplace"):
if root.is_visible():
root.hide()
else:
root.show()
func create_upgrade_button(skill: SkillData):
var button := Button.new()
button.text = skill.name + " " + str(skill.cost)
button.flat = true
button.icon = skill.icon
button.pressed.connect(func () -> void: _on_button_pressed(skill))
grid.add_child(button)
func remove_button(skill: SkillData):
for child in grid.get_children():
if child.text == skill.name + str(skill.cost):
child.queue_free()
break
func _on_button_pressed(skill: SkillData) -> void:
if not skill_unlocker:
return
if skill_unlocker.try_unlock_skill(skill):
print("Skill unlocked: ", skill.name)
remove_button(skill)

Binary file not shown.

After

Width:  |  Height:  |  Size: 318 B

View File

@@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://cvhoq7aubxlmq"
path="res://.godot/imported/magnetic_skill_icon.png-4a6b2c3056ce865bede1ca2b90518c94.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://sprites/ui/magnetic_skill_icon.png"
dest_files=["res://.godot/imported/magnetic_skill_icon.png-4a6b2c3056ce865bede1ca2b90518c94.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1