Bombs game ending, and debugging.
This commit is contained in:
@ -8,7 +8,7 @@ const COBOLD = preload("res://Game/Mobs/cobold.tscn")
|
||||
|
||||
const enemies = [FORKMAN, COBOLD, ORK]
|
||||
|
||||
var lives = 20
|
||||
var lives = 2
|
||||
|
||||
func _ready() -> void:
|
||||
get_node("SidePanel").Update_Lives(lives)
|
||||
@ -28,5 +28,12 @@ func decrease_life(damage) -> void:
|
||||
lives -= damage
|
||||
get_node("SidePanel").Update_Lives(lives)
|
||||
if lives == 0:
|
||||
print("DEAD")
|
||||
game_over()
|
||||
|
||||
func game_over()-> void:
|
||||
get_node("Timer").stop()
|
||||
var enemy = get_node("Path2D").get_children()
|
||||
for i in enemy:
|
||||
i.get_children()[0].set_process(false)
|
||||
i.get_children()[0].name
|
||||
|
||||
|
@ -8,7 +8,9 @@ var damage = 0
|
||||
var current_health = 0
|
||||
var current_shield = 0
|
||||
|
||||
var last_position: Vector2 = Vector2.ZERO # To store the previous position
|
||||
var last_position: Vector2 = Vector2.ZERO # for previous position
|
||||
|
||||
static var NAMES = ["Forkman", "Cobold", "Ork"]
|
||||
|
||||
func _ready() -> void:
|
||||
last_position = get_parent().position
|
||||
@ -119,5 +121,14 @@ func AnimatedSprite2D_animation_finished() -> void:
|
||||
|
||||
func Collision_Handler(body: Node2D):
|
||||
if body.get_parent().name.contains("StickTrap"):
|
||||
enemy_hurt(25)
|
||||
get_node("CharacterBody2D/AnimatedSprite2D").play("hurt")
|
||||
if not body.get_parent().get_if_moving_state():
|
||||
enemy_hurt(25)
|
||||
get_node("CharacterBody2D/AnimatedSprite2D").play("hurt")
|
||||
if body.get_parent().name.contains("Mine"):
|
||||
if not body.get_parent().get_if_moving_state():
|
||||
var surrounding_enemies = body.get_node("Area2D").get_overlapping_bodies()
|
||||
for i in surrounding_enemies:
|
||||
if i. get_parent().name in NAMES:
|
||||
enemy_hurt(100)
|
||||
body.get_parent().Explode_Mine()
|
||||
|
||||
|
58
Game/Traps/mine.tscn
Normal file
58
Game/Traps/mine.tscn
Normal file
@ -0,0 +1,58 @@
|
||||
[gd_scene load_steps=9 format=3 uid="uid://ctbmgsp8dfel3"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://3gn70ilm20tw" path="res://Game/Traps/traps.gd" id="1_6fgim"]
|
||||
[ext_resource type="Texture2D" uid="uid://dn22pudsmyrrg" path="res://Assets/Traps/Mine/49.png" id="2_6m2fs"]
|
||||
[ext_resource type="Texture2D" uid="uid://sb3dotm5napj" path="res://Assets/Traps/Mine/54.png" id="3_57sxm"]
|
||||
[ext_resource type="Texture2D" uid="uid://by0c26bla5hce" path="res://Assets/Traps/Mine/55.png" id="4_a3dnl"]
|
||||
[ext_resource type="Texture2D" uid="uid://cspjuelhbbavu" path="res://Assets/Traps/Mine/56.png" id="5_a1ih2"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_m1bdk"]
|
||||
radius = 32.0
|
||||
|
||||
[sub_resource type="SpriteFrames" id="SpriteFrames_fp50i"]
|
||||
animations = [{
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": ExtResource("3_57sxm")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": ExtResource("4_a3dnl")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": ExtResource("5_a1ih2")
|
||||
}],
|
||||
"loop": false,
|
||||
"name": &"Explode",
|
||||
"speed": 3.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": ExtResource("2_6m2fs")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"idle",
|
||||
"speed": 0.0
|
||||
}]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_uiyu1"]
|
||||
|
||||
[node name="Mine" type="Node2D"]
|
||||
script = ExtResource("1_6fgim")
|
||||
|
||||
[node name="CharacterBody2D" type="CharacterBody2D" parent="."]
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="CharacterBody2D"]
|
||||
scale = Vector2(0.6, 0.6)
|
||||
shape = SubResource("CircleShape2D_m1bdk")
|
||||
|
||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="CharacterBody2D"]
|
||||
scale = Vector2(0.2, 0.207)
|
||||
sprite_frames = SubResource("SpriteFrames_fp50i")
|
||||
animation = &"Explode"
|
||||
autoplay = "idle"
|
||||
|
||||
[node name="Area2D" type="Area2D" parent="CharacterBody2D"]
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="CharacterBody2D/Area2D"]
|
||||
scale = Vector2(4, 4)
|
||||
shape = SubResource("CircleShape2D_uiyu1")
|
@ -4,14 +4,25 @@ var follower = false
|
||||
|
||||
func _ready() -> void:
|
||||
follower = true
|
||||
if name.contains("Mine"):
|
||||
get_node("CharacterBody2D/AnimatedSprite2D").connect("animation_finished", Callable(self, "Remove_Mine"))
|
||||
set_process_input(true)
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if follower:
|
||||
position = get_viewport().get_mouse_position()
|
||||
|
||||
func get_if_moving_state():
|
||||
return follower
|
||||
|
||||
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():
|
||||
follower = false
|
||||
|
||||
func Explode_Mine() -> void:
|
||||
get_node("CharacterBody2D/AnimatedSprite2D").scale = Vector2(1,1)
|
||||
get_node("CharacterBody2D/AnimatedSprite2D").play("Explode")
|
||||
|
||||
func Remove_Mine() -> void:
|
||||
queue_free()
|
||||
|
@ -5,8 +5,12 @@ extends Panel
|
||||
@onready var stickspawner: Button = $HBoxContainer4/HBoxContainer4/Button2
|
||||
const STICK_TRAP = preload("res://Game/Traps/stick_trap.tscn")
|
||||
|
||||
@onready var minespawner: Button = $HBoxContainer4/HBoxContainer4/Button3
|
||||
const MINE = preload("res://Game/Traps/mine.tscn")
|
||||
|
||||
func _ready() -> void:
|
||||
stickspawner.connect("button_up", Spawn_Stick)
|
||||
minespawner.connect("button_up", Spawn_Mine)
|
||||
|
||||
func Update_Lives(lives) -> void:
|
||||
livelabel.text = "Lives: " + str(lives)
|
||||
@ -15,3 +19,8 @@ func Spawn_Stick() -> void:
|
||||
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)
|
||||
|
Reference in New Issue
Block a user