From 0cc20ef435eabb35a9ca8301b6d4df02377eb60a Mon Sep 17 00:00:00 2001 From: Kilokem Date: Tue, 29 Apr 2025 14:29:25 +0200 Subject: [PATCH] Selling mechanism --- Assets/Others/cross.png | Bin 0 -> 3243 bytes Assets/Others/cross.png.import | 34 +++++++++++++++++++++++++++++++++ Game/Accesories/deleter.gd | 19 ++++++++++++++++++ Game/Accesories/deleter.gd.uid | 1 + Game/Accesories/deleter.tscn | 21 ++++++++++++++++++++ Game/Maps/map_1.gd | 8 +++----- Game/Mobs/enemy.gd | 3 --- Game/Traps/stick_trap.tscn | 6 ++++-- Game/sidepanel.gd | 27 ++++++++++++++++++++++++-- Game/sidepanel.tscn | 29 +++++++++++++++++++++++----- 10 files changed, 131 insertions(+), 17 deletions(-) create mode 100644 Assets/Others/cross.png create mode 100644 Assets/Others/cross.png.import create mode 100644 Game/Accesories/deleter.gd create mode 100644 Game/Accesories/deleter.gd.uid create mode 100644 Game/Accesories/deleter.tscn diff --git a/Assets/Others/cross.png b/Assets/Others/cross.png new file mode 100644 index 0000000000000000000000000000000000000000..385e0f02ed2fdccb71df575aeada37709a909ab4 GIT binary patch literal 3243 zcmeAS@N?(olHy`uVBq!ia0y~yUf$*t3in(S`ysrJELyXMMK&vH#rG zWA7vx9xQ*^wEpM)cZ>`S^V}R58C;mS7!-tn7EWwnV(4HIVQ^4cz`&ry$jTtVslm|T zL0CyfO!2+l?LWLB=Ks*S_vwB*Gx6Gqw&6iF)CRl!55+eLyNd{e!AgLkbI+EgdTw^_ zU1J8D*7C`ZH#9OaoFFGCuv=*o_jO_Rx!xzl*Iu#A4xctXVoWQ(AyTAas7nrvi=9hsI zB`^~g>%QlfKTFk&+fcs~l%*IzMZ?@jx>OErP|2_vQCjZ~|1(|Yc=f;8Hq)tBHUJCi z19jKue19i-<9*EO+7GPfxX*DNPXrdz6Ns$VF{2fuMg)}&?;(Xx-1De&ADk`s%d{K+ zNugfe0#$7B#o*HC@42mWY~zmYZL)s)o%#_{(FLgsO4mKz^Woy1Vwv{c?^frK*b>4W zWWZv&VSWkBA9la&+smK)dwThO9H^kit&Nms7}ykGN%0?1Sbw_DQaAm3!{dtc<_D>m zKi2=cVEX*;s{D^J&!hBzFK385X?;}tz6O=OLepm1F;D}8W8d?b>^Jim8{U6rv!`O- z12v!*6#^q$?vcLbb*bIy3=cL}oUWfw#oP_5X`F2i?!0!xmYLy?N$dwx>g73befE#p Y;N4lJ+ef@5fV~d}Pgg&ebxsLQ0E;FNumAu6 literal 0 HcmV?d00001 diff --git a/Assets/Others/cross.png.import b/Assets/Others/cross.png.import new file mode 100644 index 0000000..3a676ec --- /dev/null +++ b/Assets/Others/cross.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://d4ghsettixo4j" +path="res://.godot/imported/cross.png-a27c4978685dc96222b2454fe6caff77.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Assets/Others/cross.png" +dest_files=["res://.godot/imported/cross.png-a27c4978685dc96222b2454fe6caff77.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 diff --git a/Game/Accesories/deleter.gd b/Game/Accesories/deleter.gd new file mode 100644 index 0000000..fb4b68c --- /dev/null +++ b/Game/Accesories/deleter.gd @@ -0,0 +1,19 @@ +extends Node2D + +const LIST_OF_ENTITIES = ["ArcherTower", "WizardTower", "MortarTower", "Mine", "StickTrap", "Wall"] +func _ready() -> void: + set_process_input(true) + +func _process(delta: float) -> void: + position = get_viewport().get_mouse_position() + +func _input(event): + if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.pressed: + if abs(position) <= get_viewport().get_mouse_position(): + var list_of_entities = get_node("Area2D").get_overlapping_bodies() + for i in list_of_entities: + for j in LIST_OF_ENTITIES: + if i.get_parent().name.contains(j): + i.get_parent().queue_free() + queue_free() + pass diff --git a/Game/Accesories/deleter.gd.uid b/Game/Accesories/deleter.gd.uid new file mode 100644 index 0000000..3435987 --- /dev/null +++ b/Game/Accesories/deleter.gd.uid @@ -0,0 +1 @@ +uid://d0umyo4x3npp6 diff --git a/Game/Accesories/deleter.tscn b/Game/Accesories/deleter.tscn new file mode 100644 index 0000000..8e43cd5 --- /dev/null +++ b/Game/Accesories/deleter.tscn @@ -0,0 +1,21 @@ +[gd_scene load_steps=4 format=3 uid="uid://fqjve5d7uj0t"] + +[ext_resource type="Texture2D" uid="uid://d4ghsettixo4j" path="res://Assets/Others/cross.png" id="1_veida"] +[ext_resource type="Script" uid="uid://d0umyo4x3npp6" path="res://Game/Accesories/deleter.gd" id="1_y3iui"] + +[sub_resource type="CircleShape2D" id="CircleShape2D_y3iui"] +radius = 20.0 + +[node name="Deleter" type="Node2D"] +script = ExtResource("1_y3iui") + +[node name="Sprite2D" type="Sprite2D" parent="."] +scale = Vector2(0.04, 0.04) +texture = ExtResource("1_veida") + +[node name="Area2D" type="Area2D" parent="."] +scale = Vector2(0.1, 0.1) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"] +scale = Vector2(10, 10) +shape = SubResource("CircleShape2D_y3iui") diff --git a/Game/Maps/map_1.gd b/Game/Maps/map_1.gd index 02617c0..1b5e937 100644 --- a/Game/Maps/map_1.gd +++ b/Game/Maps/map_1.gd @@ -8,10 +8,9 @@ const COBOLD = preload("res://Game/Mobs/cobold.tscn") const enemies = [FORKMAN, COBOLD, ORK] -var lives = 20 func _ready() -> void: - get_node("SidePanel").Update_Lives(lives) + get_node("SidePanel").Update_Lifes(20) func _on_timer_timeout() -> void: @@ -25,9 +24,8 @@ func spawnMonster(): path_2d.add_child(path) func decrease_life(damage) -> void: - lives -= damage - get_node("SidePanel").Update_Lives(lives) - if lives <= 0: + get_node("SidePanel").Update_Lifes(-damage) + if get_node("SidePanel").get_Lifes() <= 0: game_over() func game_over()-> void: diff --git a/Game/Mobs/enemy.gd b/Game/Mobs/enemy.gd index 5f3964f..46861da 100644 --- a/Game/Mobs/enemy.gd +++ b/Game/Mobs/enemy.gd @@ -122,12 +122,9 @@ func enemy_hurt(amount) -> void: adjust_health_bar() func AnimatedSprite2D_animation_finished() -> void: - print("Switching to walk animation. Current Speed Scale:", - get_node("CharacterBody2D/AnimatedSprite2D").speed_scale) get_node("CharacterBody2D/AnimatedSprite2D").play("walk") - func Collision_Handler(body: Node2D): if body.get_parent().name.contains("StickTrap"): if not body.get_parent().get_if_moving_state(): diff --git a/Game/Traps/stick_trap.tscn b/Game/Traps/stick_trap.tscn index c64b8fc..8545412 100644 --- a/Game/Traps/stick_trap.tscn +++ b/Game/Traps/stick_trap.tscn @@ -13,12 +13,14 @@ script = ExtResource("1_metvu") [node name="CharacterBody2D" type="CharacterBody2D" parent="."] [node name="Sprite2D" type="Sprite2D" parent="CharacterBody2D"] -position = Vector2(8, 0) -scale = Vector2(1.5, 1) +position = Vector2(8, 8) +scale = Vector2(1.5, 0.5) texture = ExtResource("1_dnq4b") offset = Vector2(10, 0) [node name="Sprite2D2" type="Sprite2D" parent="CharacterBody2D"] +position = Vector2(0, 8) +scale = Vector2(1, 0.5) texture = ExtResource("2_metvu") offset = Vector2(-10, 0) diff --git a/Game/sidepanel.gd b/Game/sidepanel.gd index ef17e5a..cba296e 100644 --- a/Game/sidepanel.gd +++ b/Game/sidepanel.gd @@ -15,14 +15,32 @@ const ARCHER_TOWER = preload("res://Game/Towers/archer_tower.tscn") @onready var wizardtowerspawn: Button = $HBoxContainer4/HBoxContainer2/Button3 const WIZARD_TOWER = preload("res://Game/Towers/wizard_tower.tscn") + +@onready var delete_tower_button: Button = $HBoxContainer4/HBoxContainer5/Button4 +const DELETER = preload("res://Game/Accesories/deleter.tscn") + +var lives = 0 + func _ready() -> void: stickspawner.connect("button_up", Spawn_Stick) minespawner.connect("button_up", Spawn_Mine) archertowerspawn.connect("button_up", Spawn_Archer) wizardtowerspawn.connect("button_up", Spawn_wizard) + delete_tower_button.connect("button_up", Spawn_Deleter) + +func set_Lifes(amount) -> void: + lives = amount -func Update_Lives(lives) -> void: - livelabel.text = "Lives: " + str(lives) +func get_Lifes(): + return lives + +func Update_Lifes(amount) -> void: + lives += amount + livelabel.text = "Lives: " + str(lives) + + +func Update_Coins(coins) -> void: + livelabel.text = "Lives: " + str(coins) func Spawn_Stick() -> void: var stick = STICK_TRAP.instantiate() @@ -45,3 +63,8 @@ func Spawn_wizard() -> void: tower.name = "WizardTower-" + str(randi()) get_parent().add_child(tower) pass + +func Spawn_Deleter() -> void: + var deleter = DELETER.instantiate() + get_parent().add_child(deleter) + pass diff --git a/Game/sidepanel.tscn b/Game/sidepanel.tscn index ee0ef3c..85f8e9e 100644 --- a/Game/sidepanel.tscn +++ b/Game/sidepanel.tscn @@ -39,21 +39,21 @@ theme_override_constants/separation = 30 alignment = 1 [node name="Button2" type="Button" parent="HBoxContainer4/HBoxContainer2"] -custom_minimum_size = Vector2(120, 0) +custom_minimum_size = Vector2(90, 0) layout_mode = 2 size_flags_horizontal = 4 size_flags_vertical = 4 text = "Archer" [node name="Button3" type="Button" parent="HBoxContainer4/HBoxContainer2"] -custom_minimum_size = Vector2(120, 0) +custom_minimum_size = Vector2(90, 0) layout_mode = 2 size_flags_horizontal = 4 size_flags_vertical = 4 text = "Wizard" [node name="Button4" type="Button" parent="HBoxContainer4/HBoxContainer2"] -custom_minimum_size = Vector2(120, 0) +custom_minimum_size = Vector2(90, 0) layout_mode = 2 size_flags_horizontal = 4 size_flags_vertical = 4 @@ -65,19 +65,38 @@ theme_override_constants/separation = 30 alignment = 1 [node name="Button2" type="Button" parent="HBoxContainer4/HBoxContainer4"] -custom_minimum_size = Vector2(120, 0) +custom_minimum_size = Vector2(90, 0) layout_mode = 2 size_flags_horizontal = 4 size_flags_vertical = 4 text = "Sticks" [node name="Button3" type="Button" parent="HBoxContainer4/HBoxContainer4"] -custom_minimum_size = Vector2(120, 0) +custom_minimum_size = Vector2(90, 0) layout_mode = 2 size_flags_horizontal = 4 size_flags_vertical = 4 text = "Mine" +[node name="Button4" type="Button" parent="HBoxContainer4/HBoxContainer4"] +custom_minimum_size = Vector2(90, 0) +layout_mode = 2 +size_flags_horizontal = 4 +size_flags_vertical = 4 +text = "Wall" + +[node name="HBoxContainer5" type="HBoxContainer" parent="HBoxContainer4"] +layout_mode = 2 +theme_override_constants/separation = 120 +alignment = 1 + +[node name="Button4" type="Button" parent="HBoxContainer4/HBoxContainer5"] +custom_minimum_size = Vector2(90, 0) +layout_mode = 2 +size_flags_horizontal = 4 +size_flags_vertical = 4 +text = "Sell" + [node name="HBoxContainer3" type="HBoxContainer" parent="HBoxContainer4"] layout_mode = 2 theme_override_constants/separation = 120