Added Shoes and Shop

This commit is contained in:
ObeseTermite 2024-10-05 22:32:17 -07:00
parent 7bfe46d388
commit afd8500d4e
15 changed files with 277 additions and 3 deletions

View file

@ -1,10 +1,12 @@
[gd_scene load_steps=3 format=3 uid="uid://cpnkpl8rmrt00"]
[gd_scene load_steps=4 format=3 uid="uid://cpnkpl8rmrt00"]
[ext_resource type="Script" path="res://scripts/gui.gd" id="1_42w6u"]
[ext_resource type="Theme" uid="uid://d0ir0t347wqv7" path="res://etc/default_theme.tres" id="2_54lln"]
[ext_resource type="PackedScene" uid="uid://b7uugh755ycyl" path="res://scenes/item_counter.tscn" id="3_3e23f"]
[node name="Gui" type="CanvasLayer"]
script = ExtResource("1_42w6u")
ItemCounter = ExtResource("3_3e23f")
[node name="List" type="VBoxContainer" parent="."]
offset_right = 40.0
@ -19,3 +21,11 @@ text = "$100"
layout_mode = 2
theme = ExtResource("2_54lln")
text = "No Contract"
[node name="Items" type="GridContainer" parent="."]
anchors_preset = 1
anchor_left = 1.0
anchor_right = 1.0
offset_left = -102.0
offset_bottom = 40.0
grow_horizontal = 0

30
scenes/item.tscn Normal file
View file

@ -0,0 +1,30 @@
[gd_scene load_steps=6 format=3 uid="uid://bpkffb4ww8y1m"]
[ext_resource type="Script" path="res://scripts/item.gd" id="1_akiij"]
[ext_resource type="Texture2D" uid="uid://dcbrw64m2btod" path="res://sprites/runningshoes.png" id="2_161ch"]
[ext_resource type="PackedScene" uid="uid://dpwqurhly8osd" path="res://scenes/interactible_manager.tscn" id="3_t5lie"]
[ext_resource type="PackedScene" uid="uid://sk2uc8hcxhcj" path="res://scenes/physical_dialogue.tscn" id="4_q3xmh"]
[sub_resource type="CircleShape2D" id="CircleShape2D_mxuxo"]
radius = 116.44
[node name="Item" type="Area2D"]
script = ExtResource("1_akiij")
[node name="Sprite2D" type="Sprite2D" parent="."]
scale = Vector2(0.5, 0.5)
texture = ExtResource("2_161ch")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("CircleShape2D_mxuxo")
[node name="InteractibleManager" parent="." node_paths=PackedStringArray("ItemShown") instance=ExtResource("3_t5lie")]
ItemShown = NodePath("../Dialogue")
[node name="Dialogue" parent="." instance=ExtResource("4_q3xmh")]
offset_top = -202.455
offset_bottom = -162.455
DefaultText = "Running Shoes"
[connection signal="body_entered" from="." to="InteractibleManager" method="_on_body_entered"]
[connection signal="body_exited" from="." to="InteractibleManager" method="_on_body_exited"]

28
scenes/item_counter.tscn Normal file
View file

@ -0,0 +1,28 @@
[gd_scene load_steps=3 format=3 uid="uid://b7uugh755ycyl"]
[ext_resource type="Texture2D" uid="uid://dcbrw64m2btod" path="res://sprites/runningshoes.png" id="1_0n0wt"]
[ext_resource type="Script" path="res://scripts/item_counter.gd" id="1_ehwcf"]
[node name="ItemCounter" type="Control" node_paths=PackedStringArray("ItemTexture")]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_ehwcf")
ItemTexture = NodePath("Container/TextureRect")
[node name="Container" type="HBoxContainer" parent="."]
layout_mode = 0
offset_right = 72.0
offset_bottom = 67.0
[node name="Label" type="Label" parent="Container"]
layout_mode = 2
text = "1"
[node name="TextureRect" type="TextureRect" parent="Container"]
layout_mode = 2
texture = ExtResource("1_0n0wt")
expand_mode = 2

43
scenes/shop.tscn Normal file
View file

@ -0,0 +1,43 @@
[gd_scene load_steps=8 format=3 uid="uid://cj8fahvh47awi"]
[ext_resource type="Script" path="res://scripts/shop.gd" id="1_h51g3"]
[ext_resource type="PackedScene" uid="uid://bpkffb4ww8y1m" path="res://scenes/item.tscn" id="2_h1qhl"]
[ext_resource type="Texture2D" uid="uid://c7mn6cfykqmq3" path="res://sprites/shop.png" id="2_y2xf4"]
[ext_resource type="PackedScene" uid="uid://dpwqurhly8osd" path="res://scenes/interactible_manager.tscn" id="4_3g8xt"]
[ext_resource type="PackedScene" uid="uid://sk2uc8hcxhcj" path="res://scenes/physical_dialogue.tscn" id="5_o6r5s"]
[sub_resource type="CircleShape2D" id="CircleShape2D_put5l"]
radius = 389.155
[sub_resource type="RectangleShape2D" id="RectangleShape2D_sdg4f"]
size = Vector2(409, 181)
[node name="Shop" type="Area2D"]
script = ExtResource("1_h51g3")
text = "I sell nice items here"
ItemScenes = Array[PackedScene]([ExtResource("2_h1qhl")])
[node name="Sprite2D" type="Sprite2D" parent="."]
texture = ExtResource("2_y2xf4")
metadata/_edit_lock_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(8, 150)
shape = SubResource("CircleShape2D_put5l")
[node name="Wall" type="StaticBody2D" parent="."]
position = Vector2(-4, 149)
[node name="CollisionShape2D" type="CollisionShape2D" parent="Wall"]
position = Vector2(7.5, 15.5)
shape = SubResource("RectangleShape2D_sdg4f")
metadata/_edit_lock_ = true
[node name="InteractibleManager" parent="." node_paths=PackedStringArray("ItemShown") instance=ExtResource("4_3g8xt")]
ItemShown = NodePath("../Dialogue")
[node name="Dialogue" parent="." instance=ExtResource("5_o6r5s")]
DefaultText = "You can buy very nice items here"
[connection signal="body_entered" from="." to="InteractibleManager" method="_on_body_entered"]
[connection signal="body_exited" from="." to="InteractibleManager" method="_on_body_exited"]

View file

@ -20,6 +20,8 @@ texture = ExtResource("1_k0xkm")
shape = SubResource("CircleShape2D_gpdtu")
[node name="Camera2D" type="Camera2D" parent="."]
zoom = Vector2(0.2, 0.2)
editor_draw_screen = false
script = ExtResource("3_87vjt")
zoom_max = 1.0

View file

@ -17,7 +17,7 @@ func _ready() -> void:
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
if Input.is_action_pressed("interact") and InteractibleManager.selected and not Player.ActiveContract:
if Input.is_action_just_pressed("interact") and InteractibleManager.selected and not Player.ActiveContract:
Player.ActiveContract = Destination
Destination.WaitingCash = Money
queue_free()

View file

@ -6,6 +6,12 @@ extends CanvasLayer
@onready var CurrentAddress = $List/CurrentAddress
@onready var ItemTextures = {"Shoes" : preload("res://sprites/runningshoes.png")}
@onready var ItemGrid = $Items
@export var ItemCounter : PackedScene
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
@ -19,3 +25,15 @@ func _process(delta: float) -> void:
CurrentAddress.text = Player.ActiveContract.get_address()
else:
CurrentAddress.text = "No Active Contract"
func add_item(name: String):
if not ItemGrid.has_node(name):
var newItem = ItemCounter.instantiate()
newItem.name = name
newItem.Count = 1
ItemGrid.add_child(newItem)
ItemGrid.get_node(name).ItemTexture.texture = ItemTextures[name]
else:
ItemGrid.get_node(name).Count += 1

35
scripts/item.gd Normal file
View file

@ -0,0 +1,35 @@
extends Area2D
@onready var Dialogue : Control = $Dialogue
@onready var InteractibleManager = $InteractibleManager
var Player : Node2D
@export var Cost : int = 100
var items = ["Shoes"]
@onready var item = items.pick_random()
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
Player = get_tree().get_first_node_in_group("player")
match item:
"Shoes":
Cost = 200
Dialogue.DialogueLabel.text += " - $" + str(Cost)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
if Input.is_action_just_pressed("interact") and InteractibleManager.selected and Player.Money >= Cost:
Player.Money -= Cost
if item == "Shoes":
Player.Speed += 300
Player.GUI.add_item("Shoes")
queue_free()

15
scripts/item_counter.gd Normal file
View file

@ -0,0 +1,15 @@
extends Control
@onready var ItemCountLabel = $Container/Label
var Count = 0
@export var ItemTexture : TextureRect
# 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:
ItemCountLabel.text = str(Count)

View file

@ -3,6 +3,8 @@ extends CharacterBody2D
@export var Speed = 2500
@export var FrictionMult = 5
@export var GUI : CanvasLayer
@onready var Sprite : Sprite2D = $Sprite2D
var SpriteTurningSpeed = 5
@ -41,7 +43,7 @@ func _physics_process(delta: float) -> void:
velocity += direction * Speed * delta
velocity = velocity.move_toward(Vector2(0,0), delta * clamp(velocity.length() * FrictionMult, 1000, 10000))
velocity = velocity.move_toward(Vector2(0,0), delta * clamp(velocity.length() * FrictionMult, 1000, 100000))
if velocity.length() > 0.1:
Sprite.rotation = rotate_toward(Sprite.rotation,velocity.angle(),delta*SpriteTurningSpeed)

23
scripts/shop.gd Normal file
View file

@ -0,0 +1,23 @@
extends Area2D
@export var text : String
@onready var Dialogue : Control = $Dialogue
@export var ItemSpawnPositions : Array[Node2D]
@export var ItemScenes : Array[PackedScene]
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
Dialogue.DialogueLabel.text = text
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
for i in range(0, ItemSpawnPositions.size()):
if ItemSpawnPositions[i].get_child_count() == 0:
var newItem = ItemScenes.pick_random().instantiate()
ItemSpawnPositions[i].add_child(newItem)

BIN
sprites/runningshoes.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://dcbrw64m2btod"
path="res://.godot/imported/runningshoes.png-fc03bf35fccdbd211d139a650fc28649.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://sprites/runningshoes.png"
dest_files=["res://.godot/imported/runningshoes.png-fc03bf35fccdbd211d139a650fc28649.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

BIN
sprites/shop.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

34
sprites/shop.png.import Normal file
View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://c7mn6cfykqmq3"
path="res://.godot/imported/shop.png-57e68c0ab25a46877254610d478b5179.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://sprites/shop.png"
dest_files=["res://.godot/imported/shop.png-57e68c0ab25a46877254610d478b5179.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