mirror of
https://github.com/Steffo99/hella-farm.git
synced 2024-11-21 23:54:23 +00:00
Spawn a sheep with right click
This commit is contained in:
parent
d3480156b0
commit
fa394f8cd2
7 changed files with 68 additions and 12 deletions
|
@ -16,7 +16,7 @@ var value: int = 0
|
|||
func change(amount: int):
|
||||
var old = value
|
||||
value = amount
|
||||
changed.emit(old, value)
|
||||
changed.emit(value, old)
|
||||
|
||||
func increase(amount: int = 1):
|
||||
if amount < 0:
|
||||
|
|
|
@ -8,8 +8,12 @@ signal dragged(node: Draggable)
|
|||
signal dropped(node: Draggable)
|
||||
|
||||
|
||||
@export var sheep_spawn_cost: int = 5
|
||||
|
||||
|
||||
@onready var game: MainGame = MainGame.get_via_group(self)
|
||||
@onready var gold_display: GoldDisplay = %"GoldDisplay"
|
||||
@onready var sheep_spawner: Spawner = %"SheepSpawner"
|
||||
|
||||
var dragging: Draggable = null
|
||||
|
||||
|
@ -58,6 +62,13 @@ func _input(event: InputEvent) -> void:
|
|||
drag()
|
||||
else:
|
||||
drop()
|
||||
elif event.button_index == MOUSE_BUTTON_RIGHT:
|
||||
if event.pressed:
|
||||
var counter: Counter = game.inventory.get_counter(&"Gold")
|
||||
if counter.value >= sheep_spawn_cost:
|
||||
counter.decrease(sheep_spawn_cost)
|
||||
sheep_spawner.spawn()
|
||||
|
||||
|
||||
func _physics_process(_delta: float) -> void:
|
||||
position += (game.camera.get_global_mouse_position() - global_position)
|
||||
|
|
|
@ -1,10 +1,16 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://col1q3elvkfwk"]
|
||||
[gd_scene load_steps=8 format=3 uid="uid://col1q3elvkfwk"]
|
||||
|
||||
[ext_resource type="Script" path="res://scenes/game/cursor.gd" id="1_1og6v"]
|
||||
[ext_resource type="PackedScene" uid="uid://cu750c7yd57qa" path="res://scenes/game/gold_display.tscn" id="2_5c4iq"]
|
||||
[ext_resource type="Script" path="res://behaviours/spawner.gd" id="3_tutfd"]
|
||||
[ext_resource type="PackedScene" uid="uid://bc2bm8lbol18w" path="res://entities/sheep.tscn" id="4_7isfg"]
|
||||
[ext_resource type="PackedScene" uid="uid://8jkesanu4hrn" path="res://behaviours/tracker.tscn" id="5_ewy4o"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_j2mj5"]
|
||||
radius = 4.0
|
||||
radius = 48.0
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_dc2ul"]
|
||||
radius = 8.0
|
||||
|
||||
[node name="Cursor" type="Area2D" groups=["cursor"]]
|
||||
z_index = 100
|
||||
|
@ -14,7 +20,18 @@ script = ExtResource("1_1og6v")
|
|||
|
||||
[node name="Shape" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource("CircleShape2D_j2mj5")
|
||||
debug_color = Color(1, 1, 1, 1)
|
||||
debug_color = Color(0, 0.411765, 0, 0)
|
||||
|
||||
[node name="GoldDisplay" parent="." instance=ExtResource("2_5c4iq")]
|
||||
unique_name_in_owner = true
|
||||
|
||||
[node name="SheepSpawner" type="Node2D" parent="." node_paths=PackedStringArray("blocking_tracker")]
|
||||
unique_name_in_owner = true
|
||||
script = ExtResource("3_tutfd")
|
||||
scene = ExtResource("4_7isfg")
|
||||
blocking_tracker = NodePath("Tracker")
|
||||
|
||||
[node name="Tracker" parent="SheepSpawner" instance=ExtResource("5_ewy4o")]
|
||||
|
||||
[node name="Shape" type="CollisionShape2D" parent="SheepSpawner/Tracker"]
|
||||
shape = SubResource("CircleShape2D_dc2ul")
|
||||
|
|
|
@ -9,8 +9,18 @@ class_name GoldDisplay
|
|||
func set_text(value: int) -> void:
|
||||
label.text = "%d €" % value
|
||||
|
||||
|
||||
func display(value: int):
|
||||
func increase(value: int):
|
||||
set_text(value)
|
||||
animator.stop()
|
||||
animator.play(&"collect")
|
||||
animator.play(&"increase")
|
||||
|
||||
func decrease(value: int):
|
||||
set_text(value)
|
||||
animator.stop()
|
||||
animator.play(&"decrease")
|
||||
|
||||
func change(new: int, old: int):
|
||||
if new > old:
|
||||
increase(new)
|
||||
elif old > new:
|
||||
decrease(new)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=6 format=3 uid="uid://cu750c7yd57qa"]
|
||||
[gd_scene load_steps=7 format=3 uid="uid://cu750c7yd57qa"]
|
||||
|
||||
[ext_resource type="Script" path="res://scenes/game/gold_display.gd" id="1_poqth"]
|
||||
|
||||
|
@ -18,7 +18,7 @@ tracks/0/keys = {
|
|||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_8n0bl"]
|
||||
resource_name = "collect"
|
||||
resource_name = "increase"
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
|
@ -32,10 +32,26 @@ tracks/0/keys = {
|
|||
"values": [Vector2(1.4, 1.4), Vector2(1, 1)]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_rd1cq"]
|
||||
resource_name = "decrease"
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath(".:scale")
|
||||
tracks/0/interp = 2
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0, 1),
|
||||
"transitions": PackedFloat32Array(1, 1),
|
||||
"update": 0,
|
||||
"values": [Vector2(0.6, 0.6), Vector2(1, 1)]
|
||||
}
|
||||
|
||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_bj0k7"]
|
||||
_data = {
|
||||
"RESET": SubResource("Animation_3gb4u"),
|
||||
"collect": SubResource("Animation_8n0bl")
|
||||
"decrease": SubResource("Animation_rd1cq"),
|
||||
"increase": SubResource("Animation_8n0bl")
|
||||
}
|
||||
|
||||
[sub_resource type="LabelSettings" id="LabelSettings_1jb4h"]
|
||||
|
|
|
@ -18,5 +18,5 @@ static func get_via_group(node: Node) -> MainGame:
|
|||
func _ready():
|
||||
# Set up the gold display
|
||||
var gold_counter = inventory.get_counter(&"Gold")
|
||||
gold_counter.changed.connect(cursor.gold_display.display.unbind(1))
|
||||
gold_counter.changed.connect(cursor.gold_display.change)
|
||||
cursor.gold_display.set_text(gold_counter.value)
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
[gd_scene load_steps=18 format=3 uid="uid://cxj5aud02f40j"]
|
||||
[gd_scene load_steps=19 format=3 uid="uid://cxj5aud02f40j"]
|
||||
|
||||
[ext_resource type="Script" path="res://scenes/game/main_game.gd" id="1_wiglu"]
|
||||
[ext_resource type="PackedScene" uid="uid://dm068vaseh45n" path="res://scenes/game/game_camera.tscn" id="2_db5xs"]
|
||||
[ext_resource type="PackedScene" uid="uid://cu6mvnfa01nb6" path="res://scenes/game/inventory.tscn" id="2_jhbbf"]
|
||||
[ext_resource type="Texture2D" uid="uid://d13j4br4hxek6" path="res://scenes/game/tileset_grass.png" id="2_o7bg5"]
|
||||
[ext_resource type="PackedScene" uid="uid://brvbtvt4em32" path="res://behaviours/counter.tscn" id="3_we8s5"]
|
||||
[ext_resource type="Texture2D" uid="uid://ki0xyx6gvkty" path="res://scenes/game/tileset_flowers.png" id="4_dlm0d"]
|
||||
[ext_resource type="PackedScene" uid="uid://col1q3elvkfwk" path="res://scenes/game/cursor.tscn" id="5_g504x"]
|
||||
[ext_resource type="PackedScene" uid="uid://b3gydtrenbw3n" path="res://entities/skull.tscn" id="6_5k7gy"]
|
||||
|
@ -840,6 +841,7 @@ script = ExtResource("1_wiglu")
|
|||
|
||||
[node name="Inventory" parent="." instance=ExtResource("2_jhbbf")]
|
||||
unique_name_in_owner = true
|
||||
counter_scene = ExtResource("3_we8s5")
|
||||
|
||||
[node name="FloorTileMap" type="TileMap" parent="."]
|
||||
scale = Vector2(2, 2)
|
||||
|
|
Loading…
Reference in a new issue