From d020b067afe3572fca667d3a4edf3a3778b4247e Mon Sep 17 00:00:00 2001 From: Marco Date: Fri, 25 Apr 2025 11:29:21 +0200 Subject: [PATCH] Vending Machines --- Resources/Items/Heart_Pickup.tres | 3 +- Resources/Items/Power_Pickup.tres | 3 +- Resources/Items/Shield_Pickup.tres | 3 +- Scenes/HUD/VendingMachineUi.tscn | 102 ++++++++++++++++++ .../control_pad_gray_keycard.tscn | 5 +- Scenes/Items/Blue_Keycard.tscn | 5 +- Scenes/Maps/Roguelike.tscn | 1 - Scenes/Maps/RogueliteMaps/ShopRoom1.tscn | 14 +-- Scenes/Props/VendingMachine.tscn | 26 ++--- Scenes/test.tscn | 17 ++- Scripts/Actors/VendingMachine.cs | 28 +++++ Scripts/Actors/VendingMachine.cs.uid | 1 + Scripts/GameManager.cs | 4 +- Scripts/Resources/LootItem.cs | 1 + Scripts/UI/VendingMachineUi.cs | 69 ++++++++++++ Scripts/UI/VendingMachineUi.cs.uid | 1 + 16 files changed, 249 insertions(+), 34 deletions(-) create mode 100644 Scenes/HUD/VendingMachineUi.tscn create mode 100644 Scripts/Actors/VendingMachine.cs create mode 100644 Scripts/Actors/VendingMachine.cs.uid create mode 100644 Scripts/UI/VendingMachineUi.cs create mode 100644 Scripts/UI/VendingMachineUi.cs.uid diff --git a/Resources/Items/Heart_Pickup.tres b/Resources/Items/Heart_Pickup.tres index 4144f9a0..4690af5e 100644 --- a/Resources/Items/Heart_Pickup.tres +++ b/Resources/Items/Heart_Pickup.tres @@ -13,10 +13,11 @@ metadata/_custom_type_script = "uid://bxgjw8wis5l0t" [resource] script = ExtResource("1_hyh2l") ItemName = &"Health" -ShortName = null +ShortName = &"Health" ItemDescription = &"Gives back 25% of Max Health on use" ItemKey = &"HEALTH" Item = 4 +Price = 3 ItemEffect = SubResource("Resource_vsvqq") Amount = 1 Max = 10 diff --git a/Resources/Items/Power_Pickup.tres b/Resources/Items/Power_Pickup.tres index 245cba98..c3ea0b6f 100644 --- a/Resources/Items/Power_Pickup.tres +++ b/Resources/Items/Power_Pickup.tres @@ -6,10 +6,11 @@ [resource] script = ExtResource("1_vw5ht") ItemName = &"Power" -ShortName = null +ShortName = &"Power" ItemDescription = &"Necessary for upgrades" ItemKey = &"POWER" Item = 10 +Price = 1 Amount = 1 Max = 100 PickupIfMaxed = false diff --git a/Resources/Items/Shield_Pickup.tres b/Resources/Items/Shield_Pickup.tres index 1e6f964d..3621cd1d 100644 --- a/Resources/Items/Shield_Pickup.tres +++ b/Resources/Items/Shield_Pickup.tres @@ -13,10 +13,11 @@ metadata/_custom_type_script = "uid://bxgjw8wis5l0t" [resource] script = ExtResource("2_xsuq5") ItemName = &"Shield Charge" -ShortName = null +ShortName = &"Shield" ItemDescription = &"Recharges the shield by 25%" ItemKey = &"SHIELD" Item = 8 +Price = 3 ItemEffect = SubResource("Resource_qh6j2") Amount = 1 Max = 10 diff --git a/Scenes/HUD/VendingMachineUi.tscn b/Scenes/HUD/VendingMachineUi.tscn new file mode 100644 index 00000000..501a527f --- /dev/null +++ b/Scenes/HUD/VendingMachineUi.tscn @@ -0,0 +1,102 @@ +[gd_scene load_steps=8 format=3 uid="uid://ca0g1jnl6n0pl"] + +[ext_resource type="Theme" uid="uid://dnsadvmunm76k" path="res://Resources/Styles/MainMenuButtons.tres" id="1_2iadx"] +[ext_resource type="Script" uid="uid://dwj7p7ydustm5" path="res://Scripts/UI/VendingMachineUi.cs" id="1_dy2e4"] +[ext_resource type="StyleBox" uid="uid://ctw2hju32l3rg" path="res://Resources/Styles/PixelStyleBoxRed.tres" id="2_isscq"] +[ext_resource type="Texture2D" uid="uid://b2vmpi57d7vwy" path="res://Sprites/Items/Shield_Extend.png" id="3_4n8rt"] +[ext_resource type="Texture2D" uid="uid://dlkqy5jgchwy" path="res://Sprites/Items/Heart_Pickup.png" id="4_4n8rt"] +[ext_resource type="Texture2D" uid="uid://4x3ouxyxjqjc" path="res://Sprites/Items/Credits_Pickup.png" id="4_dy2e4"] +[ext_resource type="Texture2D" uid="uid://bjdsi4x8m42ky" path="res://Sprites/Items/Power_Pickup.png" id="5_dy2e4"] + +[node name="VendingMachineUi" type="CanvasLayer" node_paths=PackedStringArray("MoneyLabel", "ItemsContainer")] +layer = 2 +script = ExtResource("1_dy2e4") +MoneyLabel = NodePath("PanelContainer/VBoxContainer/HBoxContainer3/Label") +ItemsContainer = NodePath("PanelContainer/VBoxContainer/HBoxContainer2") + +[node name="PanelContainer" type="PanelContainer" parent="."] +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -143.5 +offset_top = -71.5 +offset_right = 143.5 +offset_bottom = 71.5 +grow_horizontal = 2 +grow_vertical = 2 +size_flags_horizontal = 4 +theme = ExtResource("1_2iadx") +theme_override_styles/panel = ExtResource("2_isscq") + +[node name="VBoxContainer" type="VBoxContainer" parent="PanelContainer"] +layout_mode = 2 + +[node name="HBoxContainer" type="HBoxContainer" parent="PanelContainer/VBoxContainer"] +layout_mode = 2 + +[node name="Label" type="Label" parent="PanelContainer/VBoxContainer/HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 10 +text = "Buy" + +[node name="Button" type="Button" parent="PanelContainer/VBoxContainer/HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 10 +text = "X" + +[node name="HBoxContainer2" type="HBoxContainer" parent="PanelContainer/VBoxContainer"] +process_mode = 3 +layout_mode = 2 +size_flags_vertical = 3 +alignment = 1 + +[node name="Button" type="Button" parent="PanelContainer/VBoxContainer/HBoxContainer2"] +layout_mode = 2 +size_flags_horizontal = 3 +text = "Shield Extension +(20)" +icon = ExtResource("3_4n8rt") +autowrap_mode = 3 +icon_alignment = 1 +vertical_icon_alignment = 0 +expand_icon = true + +[node name="Button2" type="Button" parent="PanelContainer/VBoxContainer/HBoxContainer2"] +layout_mode = 2 +size_flags_horizontal = 3 +text = "Health +(15)" +icon = ExtResource("4_4n8rt") +autowrap_mode = 2 +icon_alignment = 1 +vertical_icon_alignment = 0 +expand_icon = true + +[node name="Button3" type="Button" parent="PanelContainer/VBoxContainer/HBoxContainer2"] +layout_mode = 2 +size_flags_horizontal = 3 +text = "Power +(10)" +icon = ExtResource("5_dy2e4") +autowrap_mode = 2 +icon_alignment = 1 +vertical_icon_alignment = 0 +expand_icon = true + +[node name="HBoxContainer3" type="HBoxContainer" parent="PanelContainer/VBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 4 +size_flags_vertical = 10 +alignment = 2 + +[node name="TextureRect" type="TextureRect" parent="PanelContainer/VBoxContainer/HBoxContainer3"] +layout_mode = 2 +texture = ExtResource("4_dy2e4") + +[node name="Label" type="Label" parent="PanelContainer/VBoxContainer/HBoxContainer3"] +layout_mode = 2 +text = "123456" + +[connection signal="pressed" from="PanelContainer/VBoxContainer/HBoxContainer/Button" to="." method="Close"] diff --git a/Scenes/Interactable/control_pad_gray_keycard.tscn b/Scenes/Interactable/control_pad_gray_keycard.tscn index 3ef61e06..7a08b019 100644 --- a/Scenes/Interactable/control_pad_gray_keycard.tscn +++ b/Scenes/Interactable/control_pad_gray_keycard.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=10 format=3 uid="uid://db5dwj6nqo8fn"] +[gd_scene load_steps=11 format=3 uid="uid://db5dwj6nqo8fn"] [ext_resource type="Script" uid="uid://6n7duf35c52l" path="res://Scripts/Interactables/RogueliteDoorLock.cs" id="1_jm4yx"] +[ext_resource type="Script" uid="uid://epnwjptvks3t" path="res://Scripts/Resources/LootItem.cs" id="2_q2yjn"] [ext_resource type="Resource" uid="uid://oa8s6xydriib" path="res://Resources/Items/Generic_Keycard.tres" id="3_q2yjn"] [ext_resource type="Texture2D" uid="uid://c1hcyxn2og2kq" path="res://Sprites/Actors/Key_Reader.png" id="4_bkia3"] [ext_resource type="Texture2D" uid="uid://dsf7jj36mk0xp" path="res://Sprites/Actors/KeyReaderOverlay.png" id="5_smh4i"] @@ -40,7 +41,7 @@ animations = [{ collision_layer = 4 collision_mask = 2 script = ExtResource("1_jm4yx") -Requirements = [ExtResource("3_q2yjn")] +Requirements = Array[ExtResource("2_q2yjn")]([ExtResource("3_q2yjn")]) [node name="CollisionShape2D" type="CollisionShape2D" parent="."] shape = SubResource("CircleShape2D_vvpve") diff --git a/Scenes/Items/Blue_Keycard.tscn b/Scenes/Items/Blue_Keycard.tscn index 9353e629..f529a0b0 100644 --- a/Scenes/Items/Blue_Keycard.tscn +++ b/Scenes/Items/Blue_Keycard.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=7 format=3 uid="uid://d0yes7huiyisw"] +[gd_scene load_steps=8 format=3 uid="uid://d0yes7huiyisw"] [ext_resource type="PackedScene" uid="uid://dxs3ks2ucaxl4" path="res://Scenes/Items/Red_Keycard.tscn" id="1_8f4hq"] +[ext_resource type="Script" uid="uid://epnwjptvks3t" path="res://Scripts/Resources/LootItem.cs" id="2_as2n7"] [ext_resource type="Resource" uid="uid://cj5aa7btaw6q0" path="res://Resources/Items/Blue_Keycard.tres" id="2_woclw"] [ext_resource type="Texture2D" uid="uid://bvybqletsvqgk" path="res://Sprites/Items/BlueKeycard_Small.png" id="3_k20dr"] @@ -27,7 +28,7 @@ animations = [{ }] [node name="BlueKeycard" instance=ExtResource("1_8f4hq")] -LootTable = [ExtResource("2_woclw")] +LootTable = Array[ExtResource("2_as2n7")]([ExtResource("2_woclw")]) [node name="AnimatedSprite2D" parent="." index="1"] sprite_frames = SubResource("SpriteFrames_gbw5v") diff --git a/Scenes/Maps/Roguelike.tscn b/Scenes/Maps/Roguelike.tscn index bed87af1..fb143766 100644 --- a/Scenes/Maps/Roguelike.tscn +++ b/Scenes/Maps/Roguelike.tscn @@ -70,6 +70,5 @@ autoplay = true [node name="Minimap" type="CanvasLayer" parent="." node_paths=PackedStringArray("RoomManager")] script = ExtResource("16_pfafs") RoomManager = NodePath("../Maps") -CellSize = 4 [connection signal="ManagerReady" from="." to="Maps" method="InitSpawning"] diff --git a/Scenes/Maps/RogueliteMaps/ShopRoom1.tscn b/Scenes/Maps/RogueliteMaps/ShopRoom1.tscn index ae45927f..55f87954 100644 --- a/Scenes/Maps/RogueliteMaps/ShopRoom1.tscn +++ b/Scenes/Maps/RogueliteMaps/ShopRoom1.tscn @@ -1,13 +1,10 @@ -[gd_scene load_steps=11 format=4 uid="uid://cv1c7ymi8ab17"] +[gd_scene load_steps=8 format=4 uid="uid://cv1c7ymi8ab17"] [ext_resource type="Script" uid="uid://b2j00riayxkit" path="res://Scripts/Controllers/RogueliteRoom.cs" id="1_36sk4"] [ext_resource type="Resource" uid="uid://cwtma7mxged8a" path="res://Resources/RogueliteMaps/ShopRoom1.tres" id="2_36sk4"] -[ext_resource type="PackedScene" uid="uid://l84on3kv2s52" path="res://Scenes/Door_Horizontal.tscn" id="3_as6dh"] -[ext_resource type="PackedScene" uid="uid://bc64lr3vlwchq" path="res://Scenes/Door_Vertical.tscn" id="4_ii5ao"] -[ext_resource type="PackedScene" uid="uid://b0k2grrc8xp1l" path="res://Scenes/Props/BigTank.tscn" id="4_r367v"] +[ext_resource type="PackedScene" uid="uid://cl7s06sk106uo" path="res://Scenes/Props/VendingMachine.tscn" id="5_g23xn"] [ext_resource type="TileSet" uid="uid://6k28roiljylj" path="res://Tilesets/factory_tileset.tres" id="5_o7s04"] [ext_resource type="Script" uid="uid://krean0uywtms" path="res://Scripts/TilemapAvoidance.cs" id="6_l5c4m"] -[ext_resource type="PackedScene" uid="uid://cnhgvn2salyxl" path="res://Scenes/Items/Icicle_Repeater.tscn" id="7_ii5ao"] [sub_resource type="NavigationPolygon" id="NavigationPolygon_rlq0q"] vertices = PackedVector2Array(166, 58, 294, 58, 294, 134, 166, 134, 166, 150, 154, 150, 154, 134, 154, 58, 26, 134, 26, 58, 166, 10, 154, 10) @@ -23,9 +20,6 @@ size = Vector2(272, 85) process_mode = 1 script = ExtResource("1_36sk4") RoomResource = ExtResource("2_36sk4") -DoorPrefab = ExtResource("3_as6dh") -VerticalDoorPrefab = ExtResource("4_ii5ao") -WallPrefab = ExtResource("4_r367v") [node name="Tilemaps" type="Node2D" parent="." groups=["navigation_polygon_source_geometry_group"]] @@ -51,8 +45,8 @@ metadata/_edit_lock_ = true [node name="Actors" type="Node2D" parent="Tilemaps"] metadata/_edit_lock_ = true -[node name="IcicleRepeater" parent="Tilemaps/Actors" instance=ExtResource("7_ii5ao")] -position = Vector2(159, 91) +[node name="VendingMachine" parent="Tilemaps/Actors" instance=ExtResource("5_g23xn")] +position = Vector2(98, 53) [node name="EnemySpawners" type="Node2D" parent="."] diff --git a/Scenes/Props/VendingMachine.tscn b/Scenes/Props/VendingMachine.tscn index e6ff7cf5..295282f6 100644 --- a/Scenes/Props/VendingMachine.tscn +++ b/Scenes/Props/VendingMachine.tscn @@ -1,8 +1,11 @@ -[gd_scene load_steps=10 format=3 uid="uid://cl7s06sk106uo"] +[gd_scene load_steps=13 format=3 uid="uid://cl7s06sk106uo"] -[ext_resource type="Script" uid="uid://cpx2fxtumgmud" path="res://Scenes/Barrel.cs" id="1_1necu"] -[ext_resource type="PackedScene" uid="uid://dlnw4ear5tsv3" path="res://Scenes/Props/VendingMachine_Broken.tscn" id="2_1necu"] +[ext_resource type="Script" uid="uid://bg20enqj6y6c8" path="res://Scripts/Actors/VendingMachine.cs" id="1_hlj8y"] +[ext_resource type="PackedScene" uid="uid://ca0g1jnl6n0pl" path="res://Scenes/HUD/VendingMachineUi.tscn" id="2_lo43l"] [ext_resource type="Texture2D" uid="uid://cg75fgm412pt7" path="res://Sprites/Props/VendingMachine.png" id="3_1necu"] +[ext_resource type="Resource" uid="uid://clr1gln7nxa1o" path="res://Resources/Items/Power_Pickup.tres" id="3_oeilh"] +[ext_resource type="Resource" uid="uid://dodwpect0ldjf" path="res://Resources/Items/Heart_Pickup.tres" id="4_8fr44"] +[ext_resource type="Resource" uid="uid://bhbufxodybsw4" path="res://Resources/Items/Shield_Pickup.tres" id="5_0a7ay"] [sub_resource type="AtlasTexture" id="AtlasTexture_wa2ji"] atlas = ExtResource("3_1necu") @@ -39,14 +42,12 @@ size = Vector2(14, 24) [sub_resource type="RectangleShape2D" id="RectangleShape2D_vguns"] size = Vector2(13, 20) -[node name="VendingMachine" type="Area2D" groups=["Destroyable"]] -collision_layer = 64 -collision_mask = 10 -script = ExtResource("1_1necu") -Health = 8.0 -ExplosionRadius = 0.0 -ExplosionDamage = 0.0 -DebrisScene = ExtResource("2_1necu") +[node name="VendingMachine" type="Area2D" groups=["Destroyable", "Interactable"]] +collision_layer = 4 +collision_mask = 0 +script = ExtResource("1_hlj8y") +UiScene = ExtResource("2_lo43l") +Items = Array[Object]([ExtResource("3_oeilh"), ExtResource("4_8fr44"), ExtResource("5_0a7ay")]) metadata/_edit_group_ = true [node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."] @@ -61,11 +62,10 @@ visible = false position = Vector2(0, -8) shape = SubResource("RectangleShape2D_0nhpj") -[node name="RigidBody2D" type="RigidBody2D" parent="."] +[node name="RigidBody2D" type="StaticBody2D" parent="."] position = Vector2(0, -8) collision_layer = 64 collision_mask = 10 -gravity_scale = 0.0 [node name="CollisionShape2D" type="CollisionShape2D" parent="RigidBody2D"] visible = false diff --git a/Scenes/test.tscn b/Scenes/test.tscn index 3eeafa7b..874436a4 100644 --- a/Scenes/test.tscn +++ b/Scenes/test.tscn @@ -372,6 +372,7 @@ metadata/_edit_lock_ = true [node name="Navigation" type="Node2D" parent="."] [node name="NavigationRegion2D" type="NavigationRegion2D" parent="Navigation"] +visible = false navigation_polygon = SubResource("NavigationPolygon_j86ly") [node name="Parallax2D" type="Parallax2D" parent="."] @@ -623,7 +624,16 @@ position = Vector2(-545, -503) position = Vector2(-527, -504) [node name="CreditsPickup" parent="Parallax2D/Factory Tilemaps/Debug Room" instance=ExtResource("30_pniyx")] -position = Vector2(-751, -412) +position = Vector2(-860, -454) + +[node name="CreditsPickup2" parent="Parallax2D/Factory Tilemaps/Debug Room" instance=ExtResource("30_pniyx")] +position = Vector2(-859, -475) + +[node name="CreditsPickup3" parent="Parallax2D/Factory Tilemaps/Debug Room" instance=ExtResource("30_pniyx")] +position = Vector2(-872, -464) + +[node name="CreditsPickup4" parent="Parallax2D/Factory Tilemaps/Debug Room" instance=ExtResource("30_pniyx")] +position = Vector2(-873.778, -451.047) [node name="ShieldPickup" parent="Parallax2D/Factory Tilemaps/Debug Room" instance=ExtResource("31_5ews6")] position = Vector2(-751, -395) @@ -641,7 +651,7 @@ position = Vector2(-735, -412) position = Vector2(-843, -345) [node name="Blue Box" parent="Parallax2D/Factory Tilemaps/Debug Room" instance=ExtResource("37_gtga7")] -position = Vector2(-832, -396) +position = Vector2(-890, -380) [node name="SwitchBox" parent="Parallax2D/Factory Tilemaps/Debug Room" node_paths=PackedStringArray("Targets") instance=ExtResource("38_qnbhd")] position = Vector2(-686, -484) @@ -675,6 +685,9 @@ Script = SubResource("Resource_f37sa") [node name="Fridge" parent="Parallax2D/Factory Tilemaps/Debug Room" instance=ExtResource("115_dferh")] position = Vector2(-736, -438) +[node name="VendingMachine" parent="Parallax2D/Factory Tilemaps/Debug Room" instance=ExtResource("87_gqbl6")] +position = Vector2(-840, -423) + [node name="Part2" type="Node2D" parent="Parallax2D/Factory Tilemaps"] y_sort_enabled = true diff --git a/Scripts/Actors/VendingMachine.cs b/Scripts/Actors/VendingMachine.cs new file mode 100644 index 00000000..2161317a --- /dev/null +++ b/Scripts/Actors/VendingMachine.cs @@ -0,0 +1,28 @@ +using System.Linq; +using Cirno.Scripts.Resources; +using Cirno.Scripts.UI; +using Godot; +using Godot.Collections; + +namespace Cirno.Scripts.Actors; + +public partial class VendingMachine : Interactable +{ + [Export] public PackedScene UiScene { get; private set; } + + [Export] public Array Items { get; set; } + + + public override bool Activate(ActivationType activationType = ActivationType.Toggle) + { + GameManager.Instance.ChangeState(GameState.Shop); + + var ui = UiScene.Instantiate(); + + ui.Items = Items.ToArray(); + + this.AddChild(ui); + + return true; + } +} \ No newline at end of file diff --git a/Scripts/Actors/VendingMachine.cs.uid b/Scripts/Actors/VendingMachine.cs.uid new file mode 100644 index 00000000..4a92ba0f --- /dev/null +++ b/Scripts/Actors/VendingMachine.cs.uid @@ -0,0 +1 @@ +uid://bg20enqj6y6c8 diff --git a/Scripts/GameManager.cs b/Scripts/GameManager.cs index c0cf6db9..9fe0ae90 100644 --- a/Scripts/GameManager.cs +++ b/Scripts/GameManager.cs @@ -344,6 +344,7 @@ public partial class GameManager : Node2D { case GameState.Paused: case GameState.Dialogue: + case GameState.Shop: case GameState.Inventory: GetTree().SetPause(true); //Input.MouseMode = Input.MouseModeEnum.Visible; @@ -404,5 +405,6 @@ public enum GameState Playing, Dialogue, Controlling, - Inventory + Inventory, + Shop } \ No newline at end of file diff --git a/Scripts/Resources/LootItem.cs b/Scripts/Resources/LootItem.cs index 56951a29..d2abdaba 100644 --- a/Scripts/Resources/LootItem.cs +++ b/Scripts/Resources/LootItem.cs @@ -11,6 +11,7 @@ public partial class LootItem : Resource [Export] public StringName ItemDescription { get; set; } [Export] public StringName ItemKey { get; set; } [Export] public ItemTypes Item; + [Export] public int Price { get; set; } [Export] public ItemEffectResource ItemEffect { get; private set; } [Export] public WeaponResource WeaponData { get; set; } [Export] public int Amount; diff --git a/Scripts/UI/VendingMachineUi.cs b/Scripts/UI/VendingMachineUi.cs new file mode 100644 index 00000000..0dc15683 --- /dev/null +++ b/Scripts/UI/VendingMachineUi.cs @@ -0,0 +1,69 @@ +using System.Linq; +using Cirno.Scripts.Resources; +using Godot; +using Godot.Collections; + +namespace Cirno.Scripts.UI; + +public partial class VendingMachineUi : CanvasLayer +{ + [Export] public Label MoneyLabel { get; private set; } + [Export] public Container ItemsContainer { get; private set; } + + public LootItem[] Items { get; set; } = new LootItem[3]; + + public override void _Ready() + { + FillItems(); + } + + private void FillItems() + { + var buttons = ItemsContainer.GetChildren().Cast