Basic health attack and hud
This commit is contained in:
parent
fe89b4a00d
commit
2716319c40
11 changed files with 371 additions and 5 deletions
|
@ -41,7 +41,7 @@
|
||||||
[ext_resource type="StyleBox" uid="uid://0jfr1uwuog0s" path="res://Assets/UI/Slider/v/background.tres" id="39_dl1e4"]
|
[ext_resource type="StyleBox" uid="uid://0jfr1uwuog0s" path="res://Assets/UI/Slider/v/background.tres" id="39_dl1e4"]
|
||||||
[ext_resource type="FontFile" uid="uid://dqdeftjkwxe64" path="res://Assets/Fonts/Dogica/dogicapixel.ttf" id="40_bmcvq"]
|
[ext_resource type="FontFile" uid="uid://dqdeftjkwxe64" path="res://Assets/Fonts/Dogica/dogicapixel.ttf" id="40_bmcvq"]
|
||||||
|
|
||||||
[sub_resource type="Image" id="Image_iuu86"]
|
[sub_resource type="Image" id="Image_r3hqn"]
|
||||||
data = {
|
data = {
|
||||||
"data": PackedByteArray(255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0),
|
"data": PackedByteArray(255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0),
|
||||||
"format": "RGBA8",
|
"format": "RGBA8",
|
||||||
|
@ -51,7 +51,7 @@ data = {
|
||||||
}
|
}
|
||||||
|
|
||||||
[sub_resource type="ImageTexture" id="ImageTexture_g5bup"]
|
[sub_resource type="ImageTexture" id="ImageTexture_g5bup"]
|
||||||
image = SubResource("Image_iuu86")
|
image = SubResource("Image_r3hqn")
|
||||||
|
|
||||||
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_sj7h5"]
|
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_sj7h5"]
|
||||||
|
|
||||||
|
|
79
Prefabs/end_screen.tscn
Normal file
79
Prefabs/end_screen.tscn
Normal file
|
@ -0,0 +1,79 @@
|
||||||
|
[gd_scene load_steps=3 format=3 uid="uid://daolbixcph5r6"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" path="res://Scripts/end_screen.gd" id="1_qyrmd"]
|
||||||
|
[ext_resource type="Theme" uid="uid://b0b3fxesfrpb7" path="res://Assets/UI/Theme.tres" id="3_2gqe3"]
|
||||||
|
|
||||||
|
[node name="EndScreen" type="Control" node_paths=PackedStringArray("default_focus", "won_label", "lost_label")]
|
||||||
|
process_mode = 3
|
||||||
|
layout_mode = 3
|
||||||
|
anchors_preset = 15
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
||||||
|
script = ExtResource("1_qyrmd")
|
||||||
|
default_focus = NodePath("CanvasLayer/VBoxContainer/CenterContainer/RetryButton")
|
||||||
|
won_label = NodePath("CanvasLayer/VBoxContainer/CenterContainer3/Label")
|
||||||
|
lost_label = NodePath("CanvasLayer/VBoxContainer/CenterContainer3/Label2")
|
||||||
|
|
||||||
|
[node name="CanvasLayer" type="CanvasLayer" parent="."]
|
||||||
|
process_mode = 3
|
||||||
|
|
||||||
|
[node name="ColorRect" type="ColorRect" parent="CanvasLayer"]
|
||||||
|
anchors_preset = 15
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
||||||
|
color = Color(0.576471, 0.831373, 0.709804, 0.392157)
|
||||||
|
|
||||||
|
[node name="VBoxContainer" type="VBoxContainer" parent="CanvasLayer"]
|
||||||
|
custom_minimum_size = Vector2(500, 600)
|
||||||
|
anchors_preset = 15
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
||||||
|
theme = ExtResource("3_2gqe3")
|
||||||
|
theme_override_constants/separation = 10
|
||||||
|
alignment = 1
|
||||||
|
|
||||||
|
[node name="CenterContainer3" type="CenterContainer" parent="CanvasLayer/VBoxContainer"]
|
||||||
|
custom_minimum_size = Vector2(0, 200)
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="Label" type="Label" parent="CanvasLayer/VBoxContainer/CenterContainer3"]
|
||||||
|
layout_mode = 2
|
||||||
|
text = "You won against 500 bunnies!"
|
||||||
|
|
||||||
|
[node name="Label2" type="Label" parent="CanvasLayer/VBoxContainer/CenterContainer3"]
|
||||||
|
layout_mode = 2
|
||||||
|
text = "You died!"
|
||||||
|
|
||||||
|
[node name="CenterContainer" type="CenterContainer" parent="CanvasLayer/VBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="RetryButton" type="Button" parent="CanvasLayer/VBoxContainer/CenterContainer"]
|
||||||
|
custom_minimum_size = Vector2(500, 40)
|
||||||
|
layout_mode = 2
|
||||||
|
text = "Retry"
|
||||||
|
|
||||||
|
[node name="CenterContainer2" type="CenterContainer" parent="CanvasLayer/VBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="MainMenuButton" type="Button" parent="CanvasLayer/VBoxContainer/CenterContainer2"]
|
||||||
|
custom_minimum_size = Vector2(500, 40)
|
||||||
|
layout_mode = 2
|
||||||
|
text = "Main Menu"
|
||||||
|
|
||||||
|
[node name="CenterContainer4" type="CenterContainer" parent="CanvasLayer/VBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="QuitButton" type="Button" parent="CanvasLayer/VBoxContainer/CenterContainer4"]
|
||||||
|
custom_minimum_size = Vector2(500, 40)
|
||||||
|
layout_mode = 2
|
||||||
|
text = "Quit"
|
||||||
|
|
||||||
|
[connection signal="pressed" from="CanvasLayer/VBoxContainer/CenterContainer/RetryButton" to="." method="_on_retry_button_pressed"]
|
||||||
|
[connection signal="pressed" from="CanvasLayer/VBoxContainer/CenterContainer2/MainMenuButton" to="." method="_on_main_menu_button_pressed"]
|
||||||
|
[connection signal="pressed" from="CanvasLayer/VBoxContainer/CenterContainer4/QuitButton" to="." method="_on_quit_button_pressed"]
|
198
Scenes/GameHealthAttack.tscn
Normal file
198
Scenes/GameHealthAttack.tscn
Normal file
File diff suppressed because one or more lines are too long
|
@ -1,7 +1,7 @@
|
||||||
[gd_scene load_steps=16 format=3 uid="uid://bnutmwl2vuvqe"]
|
[gd_scene load_steps=16 format=3 uid="uid://bnutmwl2vuvqe"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://Scripts/UI/MainMenuManager.gd" id="1_35kaq"]
|
[ext_resource type="Script" path="res://Scripts/UI/MainMenuManager.gd" id="1_35kaq"]
|
||||||
[ext_resource type="PackedScene" uid="uid://c4btepmue6d7p" path="res://Scenes/Game.tscn" id="2_kitxe"]
|
[ext_resource type="PackedScene" uid="uid://by4hwxoiky1k4" path="res://Scenes/GameHealthAttack.tscn" id="2_ab00d"]
|
||||||
[ext_resource type="PackedScene" uid="uid://btxarutbkchmb" path="res://Prefabs/Settings Menu.tscn" id="3_q44re"]
|
[ext_resource type="PackedScene" uid="uid://btxarutbkchmb" path="res://Prefabs/Settings Menu.tscn" id="3_q44re"]
|
||||||
[ext_resource type="Theme" uid="uid://b0b3fxesfrpb7" path="res://Assets/UI/Theme.tres" id="4_bajby"]
|
[ext_resource type="Theme" uid="uid://b0b3fxesfrpb7" path="res://Assets/UI/Theme.tres" id="4_bajby"]
|
||||||
[ext_resource type="Texture2D" uid="uid://tjxkew3m4v8m" path="res://Assets/Sprites/UI/Shadow.png" id="5_btlv0"]
|
[ext_resource type="Texture2D" uid="uid://tjxkew3m4v8m" path="res://Assets/Sprites/UI/Shadow.png" id="5_btlv0"]
|
||||||
|
@ -70,7 +70,7 @@ grow_vertical = 2
|
||||||
size_flags_horizontal = 6
|
size_flags_horizontal = 6
|
||||||
size_flags_vertical = 3
|
size_flags_vertical = 3
|
||||||
script = ExtResource("1_35kaq")
|
script = ExtResource("1_35kaq")
|
||||||
game_scene = ExtResource("2_kitxe")
|
game_scene = ExtResource("2_ab00d")
|
||||||
settings_scene = ExtResource("3_q44re")
|
settings_scene = ExtResource("3_q44re")
|
||||||
default_focus = NodePath("VBoxContainer/MarginBox2/ButtonsVbox/PlayButton")
|
default_focus = NodePath("VBoxContainer/MarginBox2/ButtonsVbox/PlayButton")
|
||||||
autostart_animations = Array[NodePath]([NodePath("Decorations/Left Decor/Jesus/AnimationPlayer"), NodePath("Decorations/Right Decor/GoodBunny/AnimationPlayer")])
|
autostart_animations = Array[NodePath]([NodePath("Decorations/Left Decor/Jesus/AnimationPlayer"), NodePath("Decorations/Right Decor/GoodBunny/AnimationPlayer")])
|
||||||
|
|
|
@ -6,6 +6,7 @@ class_name Bunny
|
||||||
@export var max_distance_to_player := 500.0
|
@export var max_distance_to_player := 500.0
|
||||||
@export var agent : NavigationAgent2D
|
@export var agent : NavigationAgent2D
|
||||||
@export var speed := 3.0
|
@export var speed := 3.0
|
||||||
|
@export var damage_given : float = 4.0
|
||||||
|
|
||||||
var health : int
|
var health : int
|
||||||
var team : int
|
var team : int
|
||||||
|
@ -31,11 +32,16 @@ var random_goal_spread_factor := 2.5
|
||||||
var random_move_location_spread_factor := 8.0
|
var random_move_location_spread_factor := 8.0
|
||||||
var random_angle_change := deg_to_rad(4.0)
|
var random_angle_change := deg_to_rad(4.0)
|
||||||
|
|
||||||
|
@export var attack_delay : float = 6.0
|
||||||
|
var attack_cooldown_left : float = 0
|
||||||
|
var first_attack : bool = true
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
func _physics_process(delta):
|
func _physics_process(delta):
|
||||||
randomize()
|
randomize()
|
||||||
|
attack_cooldown_left -= delta
|
||||||
|
|
||||||
if abs(player.velocity.length() - last_player_velocity) > 100.0:
|
if abs(player.velocity.length() - last_player_velocity) > 100.0:
|
||||||
time_since_got_player = max_pos_check_time
|
time_since_got_player = max_pos_check_time
|
||||||
|
@ -60,6 +66,12 @@ func _physics_process(delta):
|
||||||
time_since_got_move_location = 10.0
|
time_since_got_move_location = 10.0
|
||||||
else:
|
else:
|
||||||
move_and_collide(move_velocity)
|
move_and_collide(move_velocity)
|
||||||
|
elif attack_cooldown_left <= 0 and BunnyMaster.bunnies_attacking < BunnyMaster.max_bunnies_allowed_to_attack_at_once:
|
||||||
|
BunnyMaster.bunnies_attacking += 1
|
||||||
|
attack_cooldown_left = attack_delay
|
||||||
|
player.take_damage(damage_given)
|
||||||
|
get_tree().create_timer(3.0).connect("timeout",Callable(self, "reduce_attack_count"), 0)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
animation_player.stop()
|
animation_player.stop()
|
||||||
time_since_got_player += delta
|
time_since_got_player += delta
|
||||||
|
@ -67,7 +79,10 @@ func _physics_process(delta):
|
||||||
last_player_velocity = player.velocity.length()
|
last_player_velocity = player.velocity.length()
|
||||||
last_target_position = agent.target_position
|
last_target_position = agent.target_position
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
func reduce_attack_count():
|
||||||
|
BunnyMaster.bunnies_attacking -= 1
|
||||||
|
|
||||||
func update_target_pos():
|
func update_target_pos():
|
||||||
agent.target_position = Vector2(player.global_position) + Vector2(randf() - 0.5 , randf() - 0.5) * 2 * random_goal_spread_factor
|
agent.target_position = Vector2(player.global_position) + Vector2(randf() - 0.5 , randf() - 0.5) * 2 * random_goal_spread_factor
|
||||||
pass
|
pass
|
||||||
|
@ -84,6 +99,10 @@ func heal(health_amount : int):
|
||||||
func on_death():
|
func on_death():
|
||||||
for callback in on_death_callbacks:
|
for callback in on_death_callbacks:
|
||||||
callback.call(self)
|
callback.call(self)
|
||||||
|
BunnyMaster.bunnies_alive -= 1
|
||||||
|
if BunnyMaster.bunnies_alive <= 0:
|
||||||
|
player.end_screen_displayer.call("show_victory_screen")
|
||||||
|
get_tree().paused = true
|
||||||
pass
|
pass
|
||||||
|
|
||||||
func sub_on_death(callback : Callable):
|
func sub_on_death(callback : Callable):
|
||||||
|
|
|
@ -6,6 +6,9 @@ class_name BunnyGenerator
|
||||||
@export var player_save_distance : float = 400
|
@export var player_save_distance : float = 400
|
||||||
@onready var BunnyPrefab : PackedScene = load(bunny_prefab.resource_path)
|
@onready var BunnyPrefab : PackedScene = load(bunny_prefab.resource_path)
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
BunnyMaster.bunnies_alive = 500
|
||||||
|
|
||||||
func spawn_bunny(pos : Vector2, team : int, health : int) -> Bunny:
|
func spawn_bunny(pos : Vector2, team : int, health : int) -> Bunny:
|
||||||
var bunny = BunnyPrefab.instantiate()
|
var bunny = BunnyPrefab.instantiate()
|
||||||
self.add_child(bunny)
|
self.add_child(bunny)
|
||||||
|
|
6
Scripts/EntitySystem/BunnyMaster.gd
Normal file
6
Scripts/EntitySystem/BunnyMaster.gd
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
extends Node
|
||||||
|
|
||||||
|
@export var max_bunnies_allowed_to_attack_at_once : int = 5
|
||||||
|
|
||||||
|
var bunnies_alive : int
|
||||||
|
var bunnies_attacking : int = 0
|
|
@ -3,6 +3,13 @@ extends CharacterBody2D
|
||||||
@export var speed = 200
|
@export var speed = 200
|
||||||
@export_range(0, 1) var damping_factor = 0.6
|
@export_range(0, 1) var damping_factor = 0.6
|
||||||
@export var animation_player : AnimationPlayer
|
@export var animation_player : AnimationPlayer
|
||||||
|
@export var end_screen_displayer : Node
|
||||||
|
@export var health_label : Label
|
||||||
|
|
||||||
|
var health : float = 100
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
health = 100
|
||||||
|
|
||||||
func _physics_process(delta : float):
|
func _physics_process(delta : float):
|
||||||
update_player_movement(delta)
|
update_player_movement(delta)
|
||||||
|
@ -25,7 +32,21 @@ func update_player_movement(delta : float):
|
||||||
# Update Objects Physics calculations
|
# Update Objects Physics calculations
|
||||||
self.move_and_slide()
|
self.move_and_slide()
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
func take_damage(dmg : float):
|
||||||
|
if health >= dmg and health >= 0:
|
||||||
|
health -= dmg
|
||||||
|
health_label.text = "%d" % [health]
|
||||||
|
else:
|
||||||
|
health_label.text = "You Died!"
|
||||||
|
die()
|
||||||
|
|
||||||
|
|
||||||
|
func die():
|
||||||
|
end_screen_displayer.call("show_loss_screen")
|
||||||
|
get_tree().paused = true
|
||||||
|
pass
|
||||||
|
|
||||||
func update_player_animation():
|
func update_player_animation():
|
||||||
match get_move_input_vector():
|
match get_move_input_vector():
|
||||||
Vector2.ZERO: animation_player.play("Idle")
|
Vector2.ZERO: animation_player.play("Idle")
|
||||||
|
|
|
@ -7,6 +7,7 @@ extends Control
|
||||||
func _ready():
|
func _ready():
|
||||||
for child in get_children():
|
for child in get_children():
|
||||||
child.visible = false
|
child.visible = false
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
func _input(event):
|
func _input(event):
|
||||||
|
|
38
Scripts/end_screen.gd
Normal file
38
Scripts/end_screen.gd
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
extends Control
|
||||||
|
|
||||||
|
@export var menu_scene : String = "res://Scenes/Main Menu.tscn"
|
||||||
|
@export var default_focus : Button
|
||||||
|
@export var won_label : Label
|
||||||
|
@export var lost_label : Label
|
||||||
|
|
||||||
|
# Called when the node enters the scene tree for the first time.
|
||||||
|
func _ready():
|
||||||
|
get_tree().paused = false
|
||||||
|
for child in get_children():
|
||||||
|
child.visible = false
|
||||||
|
pass # Replace with function body.
|
||||||
|
|
||||||
|
func show_victory_screen():
|
||||||
|
for child in get_children():
|
||||||
|
child.visible = true
|
||||||
|
lost_label.visible = false
|
||||||
|
|
||||||
|
func show_loss_screen():
|
||||||
|
for child in get_children():
|
||||||
|
child.visible = true
|
||||||
|
won_label.visible = false
|
||||||
|
|
||||||
|
func _on_quit_button_pressed():
|
||||||
|
get_tree().quit()
|
||||||
|
pass
|
||||||
|
|
||||||
|
func _on_retry_button_pressed():
|
||||||
|
get_tree().paused = false
|
||||||
|
get_tree().reload_current_scene()
|
||||||
|
pass
|
||||||
|
|
||||||
|
func _on_main_menu_button_pressed():
|
||||||
|
get_tree().paused = false
|
||||||
|
load(menu_scene)
|
||||||
|
get_tree().change_scene_to_file(menu_scene)
|
||||||
|
pass
|
|
@ -23,6 +23,7 @@ buses/default_bus_layout="res://Assets/Music/default_bus_layout.tres"
|
||||||
|
|
||||||
GlobalSettings="*res://Scripts/SaveSystem/GlobalSettings.gd"
|
GlobalSettings="*res://Scripts/SaveSystem/GlobalSettings.gd"
|
||||||
Save="*res://Scripts/SaveSystem/GameDataSaver.gd"
|
Save="*res://Scripts/SaveSystem/GameDataSaver.gd"
|
||||||
|
BunnyMaster="*res://Scripts/EntitySystem/BunnyMaster.gd"
|
||||||
|
|
||||||
[display]
|
[display]
|
||||||
|
|
||||||
|
|
Reference in a new issue