Coins system, and finished mortar

This commit is contained in:
2025-04-30 08:57:16 +02:00
parent 6ffc9d3ba9
commit 7d79d3f60f
15 changed files with 253 additions and 37 deletions

BIN
Assets/Others/coin.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 500 B

View File

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

7
Game/Accesories/coin.gd Normal file
View File

@ -0,0 +1,7 @@
extends Node2D
func _ready() -> void:
get_node("AnimatedSprite2D").play("play")
func _on_animated_sprite_2d_animation_finished() -> void:
queue_free()

View File

@ -0,0 +1 @@
uid://bnlds4rbalemh

106
Game/Accesories/coin.tscn Normal file
View File

@ -0,0 +1,106 @@
[gd_scene load_steps=16 format=3 uid="uid://c0dx3pgd0ne6s"]
[ext_resource type="Texture2D" uid="uid://dt4vc3gt4q4uw" path="res://Assets/Others/coin.png" id="1_d0jd2"]
[ext_resource type="Script" uid="uid://bnlds4rbalemh" path="res://Game/Accesories/coin.gd" id="1_i1rwy"]
[sub_resource type="AtlasTexture" id="AtlasTexture_i1rwy"]
atlas = ExtResource("1_d0jd2")
region = Rect2(0, 0, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_0gpge"]
atlas = ExtResource("1_d0jd2")
region = Rect2(16, 0, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_lv51c"]
atlas = ExtResource("1_d0jd2")
region = Rect2(32, 0, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_dct4o"]
atlas = ExtResource("1_d0jd2")
region = Rect2(48, 0, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_a6l1g"]
atlas = ExtResource("1_d0jd2")
region = Rect2(64, 0, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_n10rj"]
atlas = ExtResource("1_d0jd2")
region = Rect2(80, 0, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_nkbqs"]
atlas = ExtResource("1_d0jd2")
region = Rect2(96, 0, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_5q8xe"]
atlas = ExtResource("1_d0jd2")
region = Rect2(112, 0, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_6mtpg"]
atlas = ExtResource("1_d0jd2")
region = Rect2(128, 0, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_neox4"]
atlas = ExtResource("1_d0jd2")
region = Rect2(144, 0, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_ecwsf"]
atlas = ExtResource("1_d0jd2")
region = Rect2(160, 0, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_oa6qk"]
atlas = ExtResource("1_d0jd2")
region = Rect2(176, 0, 16, 16)
[sub_resource type="SpriteFrames" id="SpriteFrames_ibmyn"]
animations = [{
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_i1rwy")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_0gpge")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_lv51c")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_dct4o")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_a6l1g")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_n10rj")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_nkbqs")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_5q8xe")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_6mtpg")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_neox4")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_ecwsf")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_oa6qk")
}],
"loop": false,
"name": &"play",
"speed": 18.0
}]
[node name="Coin" type="Node2D"]
script = ExtResource("1_i1rwy")
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
scale = Vector2(2, 2)
sprite_frames = SubResource("SpriteFrames_ibmyn")
animation = &"play"
[connection signal="animation_finished" from="AnimatedSprite2D" to="." method="_on_animated_sprite_2d_animation_finished"]

View File

@ -12,6 +12,8 @@ var midpoint = 0
var t = 0.0
var duration = 0.5
static var NAMES = ["Forkman", "Cobold", "Ork"]
func _ready() -> void:
starterpos = global_position
targetpos = target.global_position
@ -34,6 +36,12 @@ func _process(delta: float) -> void:
position = bezier(t)
if t >= 1.0:
get_node("CharacterBody2D/AnimatedSprite2D").play("hit")
var killalll = get_node("Area2D").get_overlapping_bodies()
for i in killalll:
for j in NAMES:
if i.get_parent().name.contains(j):
i.get_parent().enemy_hurt(hitpoint)
set_process(false)
elif target and speed > 0:
# Get the direction vector from the bullet to the target

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=10 format=3 uid="uid://cwcgq1vk643ha"]
[gd_scene load_steps=11 format=3 uid="uid://cwcgq1vk643ha"]
[ext_resource type="Script" uid="uid://dqvdgdobuo2rf" path="res://Game/Bullets/bullet.gd" id="1_yml18"]
[ext_resource type="Texture2D" uid="uid://t8y1d33eiffp" path="res://Assets/Bullets/mortarbullet (1).png" id="2_yml18"]
@ -42,6 +42,8 @@ animations = [{
"speed": 8.0
}]
[sub_resource type="CircleShape2D" id="CircleShape2D_tjven"]
[node name="Rock" type="Node2D"]
script = ExtResource("1_yml18")
@ -56,4 +58,10 @@ scale = Vector2(0.4, 0.4)
sprite_frames = SubResource("SpriteFrames_yml18")
autoplay = "default"
[node name="Area2D" type="Area2D" parent="."]
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
scale = Vector2(3, 3)
shape = SubResource("CircleShape2D_tjven")
[connection signal="animation_finished" from="CharacterBody2D/AnimatedSprite2D" to="." method="_on_animated_sprite_2d_animation_finished"]

View File

@ -11,6 +11,7 @@ const enemies = [FORKMAN, COBOLD, ORK]
func _ready() -> void:
get_node("SidePanel").Update_Lifes(20)
get_node("SidePanel").Update_Coins(200)
func _on_timer_timeout() -> void:

View File

@ -4,6 +4,7 @@ var speed = 0
var health = 0
var shield = 0
var damage = 0
var value = 0
var current_health = 0
var current_shield = 0
@ -12,6 +13,8 @@ var last_position: Vector2 = Vector2.ZERO # for previous position
static var NAMES = ["Forkman", "Cobold", "Ork"]
const COIN = preload("res://Game/Accesories/coin.tscn")
func _ready() -> void:
last_position = get_parent().position
get_node("CharacterBody2D/Area2D").body_entered.connect(Collision_Handler)
@ -54,18 +57,21 @@ func set_character_data():
health = 100
shield = 100
damage = 2
value = 20
"Ork":
self.name = "Ork-" + str(randi())
speed = 80
health = 150
shield = 200
damage = 5
value = 30
"Cobold":
self.name = "Cobold-" + str(randi())
speed = 200
health = 50
shield = 0
damage = 1
value = 10
adjust_speed_of_animation() #adjust animation speed based on the character speed
current_health = health
@ -117,6 +123,10 @@ func enemy_hurt(amount) -> void:
current_health -= amount
if current_health <= 0:
get_parent().get_parent().get_parent().get_node("SidePanel").Update_Coins(value)
var coin = COIN.instantiate()
coin.position = self.global_position
get_parent().get_parent().add_child(coin)
get_parent().queue_free()
else:
adjust_health_bar()

View File

@ -29,7 +29,7 @@ collision_mask = 2
position = Vector2(-1, -68)
shape = SubResource("RectangleShape2D_bhlym")
[node name="MortarPart(3)" type="Sprite2D" parent="CharacterBody2D"]
[node name="lifter - 1" type="Sprite2D" parent="CharacterBody2D"]
position = Vector2(0.800001, 18.6)
scale = Vector2(0.4, 0.4)
texture = ExtResource("1_sq58r")
@ -39,7 +39,7 @@ position = Vector2(4.40004, 18)
scale = Vector2(0.4, 0.4)
texture = ExtResource("2_bhlym")
[node name="MortarPart(1)" type="Sprite2D" parent="CharacterBody2D"]
[node name="lifter - 2" type="Sprite2D" parent="CharacterBody2D"]
position = Vector2(0.800001, 31.6)
scale = Vector2(0.4, 0.4)
texture = ExtResource("3_82ftk")

View File

@ -11,6 +11,9 @@ const ARROW = preload("res://Game/Bullets/arrow.tscn")
const MAGIC = preload("res://Game/Bullets/magic.tscn")
const ROCK = preload("res://Game/Bullets/rock.tscn")
var lifter = false
var lifteramount = 0
func _ready() -> void:
follower = true
get_node("CharacterBody2D/Area2D").body_entered.connect(choose_target)
@ -24,6 +27,18 @@ func _process(delta: float) -> void:
if not target:
if get_node("CharacterBody2D/Area2D").get_overlapping_bodies():
choose_target(null)
if lifter:
lifteramount += 4
if lifteramount <= 40:
get_node("CharacterBody2D/lifter - 1").position.y -= 4
get_node("CharacterBody2D/lifter - 2").position.y -= 4
elif lifteramount >= 40 and lifteramount <= 80:
get_node("CharacterBody2D/lifter - 1").position.y += 4
get_node("CharacterBody2D/lifter - 2").position.y += 4
elif lifteramount >= 80:
lifteramount = 0
lifter = false
func set_properties() -> void:
if self.name.contains("ArcherTower"):
@ -36,7 +51,7 @@ func set_properties() -> void:
hitpoint = 10
if self.name.contains("MortarTower"): #??? not sure if necessary yet
get_node("Timer").wait_time = 5
hitpoint = 10
hitpoint = 80
func get_if_moving_state():
return follower
@ -50,11 +65,11 @@ func choose_target(body : Node2D) -> void:
if not follower:
var surroinding_enemies = get_node("CharacterBody2D/Area2D").get_overlapping_bodies()
target = surroinding_enemies[0]
if self.name.contains("ArcherTower"):
if self.name.contains("ArcherTower") or self.name.contains("MortarTower"):
for i in surroinding_enemies:
if i.get_parent().get_progress() > target.get_parent().get_progress():
target = i
if self.name.contains("WizardTower") or self.name.contains("MortarTower"):
if self.name.contains("WizardTower"):
for i in surroinding_enemies:
if i.get_parent().get_progress() < target.get_parent().get_progress():
target = i
@ -88,5 +103,5 @@ func shoot() -> void:
rock.set_targe(target)
rock.set_hitpoint(hitpoint)
get_parent().add_child(rock)
lifter = true
pass

View File

@ -47,10 +47,10 @@ texture = ExtResource("2_3ht3o")
[node name="ProgressBar" type="ProgressBar" parent="CharacterBody2D"]
custom_minimum_size = Vector2(40, 1)
offset_left = -20.0
offset_top = 29.0
offset_right = 20.0
offset_bottom = 37.0
offset_left = -21.0
offset_top = 32.0
offset_right = 19.0
offset_bottom = 40.0
theme_override_styles/background = SubResource("StyleBoxFlat_3ht3o")
theme_override_styles/fill = SubResource("StyleBoxFlat_bxxpj")
value = 100.0

View File

@ -1,6 +1,7 @@
extends Panel
@onready var livelabel: Label = $HBoxContainer4/HBoxContainer3/Label
@onready var coinlabel: Label = $HBoxContainer4/HBoxContainer/Label
@onready var stickspawner: Button = $HBoxContainer4/HBoxContainer4/Button2
const STICK_TRAP = preload("res://Game/Traps/stick_trap.tscn")
@ -24,16 +25,33 @@ const MORTAR_TOWER = preload("res://Game/Towers/mortar_tower.tscn")
const DELETER = preload("res://Game/Accesories/deleter.tscn")
var lives = 0
var coins = 0
func _ready() -> void:
stickspawner.connect("button_up", Spawn_Stick)
stickspawner.tooltip_text = "Cost: 10\nReturn: 5"
minespawner.connect("button_up", Spawn_Mine)
minespawner.tooltip_text = "Cost: 40\nReturn: 10"
wallspawner.connect("button_down", Spawn_Wall)
wallspawner.tooltip_text = "Cost: 60\nReturn: 0"
archertowerspawn.connect("button_up", Spawn_Archer)
archertowerspawn.tooltip_text = "Cost: 120\nReturn: 60"
wizardtowerspawn.connect("button_up", Spawn_wizard)
wizardtowerspawn.tooltip_text = "Cost: 100\nReturn: 30"
mortartowerspawn.connect("button_up", Spawn_Mortar)
mortartowerspawn.tooltip_text = "Cost: 160\nReturn: 80"
delete_tower_button.connect("button_up", Spawn_Deleter)
func _process(delta : float)-> void:
coinlabel.text = "Coins: " + str(coins)
livelabel.text = "Lives: " + str(lives)
func set_Lifes(amount) -> void:
lives = amount
@ -42,46 +60,52 @@ func get_Lifes():
func Update_Lifes(amount) -> void:
lives += amount
livelabel.text = "Lives: " + str(lives)
func Update_Coins(coins) -> void:
livelabel.text = "Lives: " + str(coins)
func Update_Coins(amount) -> void:
coins += amount
func Spawn_Stick() -> void:
var stick = STICK_TRAP.instantiate()
stick.name = "StickTrap-" + str(randi())
get_parent().add_child(stick)
if coins >= 10:
coins -= 10
var stick = STICK_TRAP.instantiate()
stick.name = "StickTrap-" + str(randi())
get_parent().add_child(stick)
func Spawn_Mine() -> void:
var mine = MINE.instantiate()
mine.name = "Mine-" + str(randi())
get_parent().add_child(mine)
if coins >= 40:
coins -= 40
var mine = MINE.instantiate()
mine.name = "Mine-" + str(randi())
get_parent().add_child(mine)
func Spawn_Wall() -> void:
var wall = WALL.instantiate()
wall.name = "Wall-" + str(randi())
get_parent().add_child(wall)
if coins >= 60:
coins -= 60
var wall = WALL.instantiate()
wall.name = "Wall-" + str(randi())
get_parent().add_child(wall)
func Spawn_Archer() -> void:
var tower = ARCHER_TOWER.instantiate()
tower.name = "ArcherTower-" + str(randi())
get_parent().add_child(tower)
pass
if coins >= 120:
coins -= 120
var tower = ARCHER_TOWER.instantiate()
tower.name = "ArcherTower-" + str(randi())
get_parent().add_child(tower)
func Spawn_wizard() -> void:
var tower = WIZARD_TOWER.instantiate()
tower.name = "WizardTower-" + str(randi())
get_parent().add_child(tower)
pass
if coins >= 100:
coins -= 100
var tower = WIZARD_TOWER.instantiate()
tower.name = "WizardTower-" + str(randi())
get_parent().add_child(tower)
func Spawn_Mortar() -> void:
var tower = MORTAR_TOWER.instantiate()
tower.name = "MortarTower-" + str(randi())
get_parent().add_child(tower)
pass
if coins >= 160:
coins -= 160
var tower = MORTAR_TOWER.instantiate()
tower.name = "MortarTower-" + str(randi())
get_parent().add_child(tower)
func Spawn_Deleter() -> void:
var deleter = DELETER.instantiate()
get_parent().add_child(deleter)
pass

1
coin.gd Normal file
View File

@ -0,0 +1 @@
extends Node2D

1
coin.gd.uid Normal file
View File

@ -0,0 +1 @@
uid://dat6nr5qsvo7a