game: add godot project
This commit is contained in:
78
scenes/attacks/attack_sword.gd
Normal file
78
scenes/attacks/attack_sword.gd
Normal file
@@ -0,0 +1,78 @@
|
||||
extends Node2D
|
||||
|
||||
@export var default_attack_time: float = 0.5
|
||||
@export var default_damage: float = 5.0
|
||||
|
||||
@onready var trigger_area: Area2D = $TriggerArea
|
||||
@onready var trigger_collision: CollisionShape2D = $TriggerArea/TriggerCollision
|
||||
@onready var timer: Timer = $Timer
|
||||
@onready var attack_path: Path2D = $AttackPath
|
||||
@onready var path_follow_2d: PathFollow2D = $AttackPath/PathFollow2D
|
||||
@onready var attack_area: Area2D = $AttackPath/PathFollow2D/Sprite2D/AttackArea
|
||||
|
||||
var damage: float
|
||||
var current_target: Node2D = null
|
||||
var current_progress: float = 0.0
|
||||
var damaged_this_attack: Array = []
|
||||
|
||||
func _ready() -> void:
|
||||
attack_path.visible = false
|
||||
damage = default_damage
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if timer.is_stopped():
|
||||
timer.start()
|
||||
if current_progress == 1.0:
|
||||
reset_attack()
|
||||
if current_target and is_instance_valid(current_target) and not current_target.is_queued_for_deletion():
|
||||
track_target(current_target)
|
||||
attack_path.visible = true
|
||||
|
||||
# Do attack animation
|
||||
current_progress += delta / default_attack_time
|
||||
current_progress = clampf(current_progress, 0.0, 1.0)
|
||||
path_follow_2d.progress_ratio = current_progress
|
||||
|
||||
func reset_attack() -> void:
|
||||
current_target = null
|
||||
attack_path.visible = false
|
||||
current_progress = 0.0
|
||||
damaged_this_attack = []
|
||||
position = Vector2.ZERO
|
||||
rotation = 0.0
|
||||
|
||||
func set_target(body: Node2D):
|
||||
current_target = body
|
||||
|
||||
func track_target(body: Node2D):
|
||||
if not current_target or not is_instance_valid(body) or body.is_queued_for_deletion():
|
||||
print_debug("target deleted or queued for deletion")
|
||||
return
|
||||
var mid_distance = attack_path.curve.get_baked_length() / 2
|
||||
var mid_point: Vector2 = attack_path.curve.sample_baked(mid_distance)
|
||||
var offset = body.global_position - to_global(mid_point)
|
||||
var desired_dir = (body.global_position - to_global(mid_point)).normalized()
|
||||
var start_point_global = attack_path.to_global(attack_path.curve.sample_baked(0))
|
||||
var end_point_global = attack_path.to_global(attack_path.curve.sample_baked(attack_path.curve.get_baked_length()))
|
||||
var curve_dir = (start_point_global - end_point_global).normalized()
|
||||
var angle_diff = curve_dir.angle_to(desired_dir)
|
||||
if rotation == 0.0:
|
||||
rotation = curve_dir.angle_to(desired_dir)
|
||||
print_debug("tracked target")
|
||||
position += offset
|
||||
|
||||
func _on_timer_timeout() -> void:
|
||||
if trigger_area.has_overlapping_bodies():
|
||||
for body in trigger_area.get_overlapping_bodies():
|
||||
if body.is_in_group(GlobalConst.GROUP_ENEMY):
|
||||
set_target(body)
|
||||
|
||||
func _on_attack_area_body_entered(body: Node2D) -> void:
|
||||
if not attack_path.visible:
|
||||
return
|
||||
if body in damaged_this_attack:
|
||||
return
|
||||
if body.is_in_group(GlobalConst.GROUP_ENEMY) and body.is_in_group(GlobalConst.GROUP_DAMAGEABLE):
|
||||
body.take_damage(damage)
|
||||
damaged_this_attack.append(body)
|
1
scenes/attacks/attack_sword.gd.uid
Normal file
1
scenes/attacks/attack_sword.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://db326gu8abue5
|
55
scenes/attacks/attack_sword.tscn
Normal file
55
scenes/attacks/attack_sword.tscn
Normal file
@@ -0,0 +1,55 @@
|
||||
[gd_scene load_steps=6 format=3 uid="uid://cdojqe2m4kxx1"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://dycw7c3484dir" path="res://assets/sprites/sword.png" id="1_3fwwl"]
|
||||
[ext_resource type="Script" uid="uid://db326gu8abue5" path="res://scenes/attacks/attack_sword.gd" id="1_frsqi"]
|
||||
|
||||
[sub_resource type="Curve2D" id="Curve2D_frsqi"]
|
||||
bake_interval = 2.0
|
||||
_data = {
|
||||
"points": PackedVector2Array(0, 0, 0, 0, 0, 0, 0, 0, 25, 10, 150, 0)
|
||||
}
|
||||
point_count = 2
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_frsqi"]
|
||||
size = Vector2(13.9997, 46.999)
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_3fwwl"]
|
||||
radius = 267.002
|
||||
|
||||
[node name="AttackSword" type="Node2D"]
|
||||
script = ExtResource("1_frsqi")
|
||||
|
||||
[node name="AttackPath" type="Path2D" parent="."]
|
||||
curve = SubResource("Curve2D_frsqi")
|
||||
|
||||
[node name="PathFollow2D" type="PathFollow2D" parent="AttackPath"]
|
||||
loop = false
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="AttackPath/PathFollow2D"]
|
||||
position = Vector2(0.322462, -0.946582)
|
||||
rotation = 0.328329
|
||||
scale = Vector2(1, 1)
|
||||
texture = ExtResource("1_3fwwl")
|
||||
|
||||
[node name="AttackArea" type="Area2D" parent="AttackPath/PathFollow2D/Sprite2D"]
|
||||
collision_layer = 0
|
||||
collision_mask = 2
|
||||
|
||||
[node name="AttackCollision" type="CollisionShape2D" parent="AttackPath/PathFollow2D/Sprite2D/AttackArea"]
|
||||
position = Vector2(-0.0328934, -4.50646)
|
||||
shape = SubResource("RectangleShape2D_frsqi")
|
||||
|
||||
[node name="TriggerArea" type="Area2D" parent="."]
|
||||
visible = false
|
||||
collision_layer = 0
|
||||
collision_mask = 2
|
||||
|
||||
[node name="TriggerCollision" type="CollisionShape2D" parent="TriggerArea"]
|
||||
shape = SubResource("CircleShape2D_3fwwl")
|
||||
|
||||
[node name="Timer" type="Timer" parent="."]
|
||||
one_shot = true
|
||||
autostart = true
|
||||
|
||||
[connection signal="body_entered" from="AttackPath/PathFollow2D/Sprite2D/AttackArea" to="." method="_on_attack_area_body_entered"]
|
||||
[connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"]
|
52
scenes/enemies/enemy.gd
Normal file
52
scenes/enemies/enemy.gd
Normal file
@@ -0,0 +1,52 @@
|
||||
extends CharacterBody2D
|
||||
|
||||
@export var target: CollisionObject2D
|
||||
@export var default_move_speed: float = 100
|
||||
@export var default_max_health: float = 10.0
|
||||
@export var default_contact_damage: float = 5.0
|
||||
|
||||
@onready var contact_damage_cd: Timer = $ContactDamageCD
|
||||
@onready var animation_player: AnimationPlayer = $AnimationPlayer
|
||||
|
||||
var move_speed: float
|
||||
var health: float
|
||||
var max_health: float
|
||||
var god_mode: bool = false
|
||||
|
||||
func _ready() -> void:
|
||||
move_speed = default_move_speed
|
||||
max_health = default_max_health
|
||||
health = max_health
|
||||
GlobalConst.sig_debug_enemy_god_mode.connect(enemy_god_mode_toggle)
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if target:
|
||||
var direction = global_position.direction_to(target.global_position)
|
||||
var distance = global_position.distance_to(target.global_position)
|
||||
if distance > 4:
|
||||
velocity = direction * move_speed
|
||||
move_and_slide()
|
||||
else:
|
||||
deal_damage()
|
||||
|
||||
func take_damage(value: float):
|
||||
if god_mode:
|
||||
return
|
||||
health -= value
|
||||
if health <= 0:
|
||||
die()
|
||||
|
||||
func deal_damage():
|
||||
if target.is_in_group("damagable"):
|
||||
if contact_damage_cd.is_stopped():
|
||||
target.take_damage(default_contact_damage)
|
||||
contact_damage_cd.start()
|
||||
|
||||
func die():
|
||||
queue_free()
|
||||
|
||||
func cheer_anim():
|
||||
animation_player.play("jump")
|
||||
|
||||
func enemy_god_mode_toggle(toggle_on: bool) -> void:
|
||||
god_mode = toggle_on
|
1
scenes/enemies/enemy.gd.uid
Normal file
1
scenes/enemies/enemy.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://ctigdofipl4q5
|
65
scenes/enemies/enemy.tscn
Normal file
65
scenes/enemies/enemy.tscn
Normal file
@@ -0,0 +1,65 @@
|
||||
[gd_scene load_steps=7 format=3 uid="uid://bn8c0cgecvjxl"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://5x5wimok8uw2" path="res://assets/sprites/roguelikeChar_transparent.png" id="1_6xk8f"]
|
||||
[ext_resource type="Script" uid="uid://ctigdofipl4q5" path="res://scenes/enemies/enemy.gd" id="1_8e3ao"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_6xk8f"]
|
||||
radius = 6.7082
|
||||
|
||||
[sub_resource type="Animation" id="Animation_8e3ao"]
|
||||
resource_name = "jump"
|
||||
length = 0.7
|
||||
loop_mode = 1
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Sprite2D:position")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0, 0.3),
|
||||
"transitions": PackedFloat32Array(1, 1),
|
||||
"update": 0,
|
||||
"values": [Vector2(0, 0), Vector2(0, -7)]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_38ino"]
|
||||
length = 0.001
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Sprite2D:position")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 0,
|
||||
"values": [Vector2(0, 0)]
|
||||
}
|
||||
|
||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_38ino"]
|
||||
_data = {
|
||||
&"RESET": SubResource("Animation_38ino"),
|
||||
&"jump": SubResource("Animation_8e3ao")
|
||||
}
|
||||
|
||||
[node name="Enemy" type="CharacterBody2D" groups=["damagable", "enemy"]]
|
||||
collision_layer = 2
|
||||
script = ExtResource("1_8e3ao")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
texture = ExtResource("1_6xk8f")
|
||||
region_enabled = true
|
||||
region_rect = Rect2(17, 53, 16, 14)
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource("CircleShape2D_6xk8f")
|
||||
|
||||
[node name="ContactDamageCD" type="Timer" parent="."]
|
||||
one_shot = true
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||
libraries = {
|
||||
&"": SubResource("AnimationLibrary_38ino")
|
||||
}
|
19
scenes/main.gd
Normal file
19
scenes/main.gd
Normal file
@@ -0,0 +1,19 @@
|
||||
extends Node2D
|
||||
@onready var main_ui: MainUI = $MainUI
|
||||
@onready var main_camera: Camera2D = $MainCamera
|
||||
|
||||
func _ready():
|
||||
GlobalConst.sig_debug_camera_zoom.connect(debug_zoom)
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("ui_cancel"):
|
||||
print_debug("pause")
|
||||
main_ui.pause_ui.toggle_pause_ui()
|
||||
if event.is_action_pressed("debug_menu"):
|
||||
main_ui.debug_ui.toggle()
|
||||
|
||||
func debug_zoom(toggled_on: bool):
|
||||
if toggled_on:
|
||||
main_camera.zoom = Vector2(1, 1)
|
||||
else:
|
||||
main_camera.zoom = Vector2(2, 2)
|
1
scenes/main.gd.uid
Normal file
1
scenes/main.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://brb4ssksmtq8k
|
26
scenes/main.tscn
Normal file
26
scenes/main.tscn
Normal file
@@ -0,0 +1,26 @@
|
||||
[gd_scene load_steps=6 format=3 uid="uid://bjg50n7aab3ng"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://brb4ssksmtq8k" path="res://scenes/main.gd" id="1_jyhfs"]
|
||||
[ext_resource type="PackedScene" uid="uid://4xha2nhf8fya" path="res://scenes/test_level.tscn" id="1_o5qli"]
|
||||
[ext_resource type="PackedScene" uid="uid://ca2so8fm3q8fe" path="res://scenes/player.tscn" id="2_0wfyh"]
|
||||
[ext_resource type="PackedScene" uid="uid://b18uib08hvdpq" path="res://scenes/managers/main_ui.tscn" id="3_sugp2"]
|
||||
[ext_resource type="PackedScene" uid="uid://bn8c0cgecvjxl" path="res://scenes/enemies/enemy.tscn" id="5_tbgi4"]
|
||||
|
||||
[node name="Main" type="Node2D"]
|
||||
script = ExtResource("1_jyhfs")
|
||||
|
||||
[node name="MainUI" parent="." instance=ExtResource("3_sugp2")]
|
||||
|
||||
[node name="TestLevel" parent="." instance=ExtResource("1_o5qli")]
|
||||
|
||||
[node name="MainCamera" type="Camera2D" parent="."]
|
||||
zoom = Vector2(2, 2)
|
||||
process_callback = 0
|
||||
|
||||
[node name="Player" parent="." node_paths=PackedStringArray("camera", "main_ui") instance=ExtResource("2_0wfyh")]
|
||||
position = Vector2(1057, 798)
|
||||
camera = NodePath("../MainCamera")
|
||||
main_ui = NodePath("../MainUI")
|
||||
|
||||
[node name="Enemy" parent="." node_paths=PackedStringArray("target") instance=ExtResource("5_tbgi4")]
|
||||
target = NodePath("../Player")
|
15
scenes/managers/debug_ui.gd
Normal file
15
scenes/managers/debug_ui.gd
Normal file
@@ -0,0 +1,15 @@
|
||||
class_name DebugUI
|
||||
extends Control
|
||||
|
||||
func toggle():
|
||||
visible = !visible
|
||||
|
||||
func _on_zoom_check_toggled(toggled_on: bool) -> void:
|
||||
GlobalConst.sig_debug_camera_zoom.emit(toggled_on)
|
||||
|
||||
func _on_god_mode_check_toggled(toggled_on: bool) -> void:
|
||||
GlobalConst.sig_debug_god_mode.emit(toggled_on)
|
||||
|
||||
|
||||
func _on_enemy_god_mode_check_toggled(toggled_on: bool) -> void:
|
||||
GlobalConst.sig_debug_enemy_god_mode.emit(toggled_on)
|
1
scenes/managers/debug_ui.gd.uid
Normal file
1
scenes/managers/debug_ui.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://d2o6tqnqg2o25
|
11
scenes/managers/main_ui.gd
Normal file
11
scenes/managers/main_ui.gd
Normal file
@@ -0,0 +1,11 @@
|
||||
class_name MainUI
|
||||
extends Control
|
||||
|
||||
@onready var pause_ui: PauseUI = $CanvasLayer/PauseUI
|
||||
@onready var player_ui: PlayerUI = $CanvasLayer/PlayerUI
|
||||
@onready var debug_ui: DebugUI = $CanvasLayer/DebugUI
|
||||
|
||||
func _ready() -> void:
|
||||
pause_ui.visible = false
|
||||
player_ui.visible = true
|
||||
debug_ui.visible = false
|
1
scenes/managers/main_ui.gd.uid
Normal file
1
scenes/managers/main_ui.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dcxc70fvu7kl2
|
126
scenes/managers/main_ui.tscn
Normal file
126
scenes/managers/main_ui.tscn
Normal file
@@ -0,0 +1,126 @@
|
||||
[gd_scene load_steps=5 format=3 uid="uid://b18uib08hvdpq"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://dcxc70fvu7kl2" path="res://scenes/managers/main_ui.gd" id="1_3a826"]
|
||||
[ext_resource type="Script" uid="uid://sjnxf0hj3egp" path="res://scenes/managers/pause_ui.gd" id="1_lke1m"]
|
||||
[ext_resource type="Script" uid="uid://dbq74tvxtpfjc" path="res://scenes/managers/player_ui.gd" id="3_gaipe"]
|
||||
[ext_resource type="Script" uid="uid://d2o6tqnqg2o25" path="res://scenes/managers/debug_ui.gd" id="4_217l8"]
|
||||
|
||||
[node name="MainUI" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_3a826")
|
||||
|
||||
[node name="CanvasLayer" type="CanvasLayer" parent="."]
|
||||
|
||||
[node name="PauseUI" type="Control" parent="CanvasLayer"]
|
||||
visible = false
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_lke1m")
|
||||
|
||||
[node name="CenterContainer" type="CenterContainer" parent="CanvasLayer/PauseUI"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="CanvasLayer/PauseUI/CenterContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="PanelContainer" type="PanelContainer" parent="CanvasLayer/PauseUI/CenterContainer/MarginContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="CanvasLayer/PauseUI/CenterContainer/MarginContainer/PanelContainer"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/margin_left = 60
|
||||
theme_override_constants/margin_top = 20
|
||||
theme_override_constants/margin_right = 60
|
||||
theme_override_constants/margin_bottom = 20
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="CanvasLayer/PauseUI/CenterContainer/MarginContainer/PanelContainer/MarginContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="ResumeButton" type="Button" parent="CanvasLayer/PauseUI/CenterContainer/MarginContainer/PanelContainer/MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "Resume"
|
||||
|
||||
[node name="NewGameBtuton" type="Button" parent="CanvasLayer/PauseUI/CenterContainer/MarginContainer/PanelContainer/MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "New Game"
|
||||
|
||||
[node name="OptionsButton" type="Button" parent="CanvasLayer/PauseUI/CenterContainer/MarginContainer/PanelContainer/MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "Options"
|
||||
|
||||
[node name="ExitButton" type="Button" parent="CanvasLayer/PauseUI/CenterContainer/MarginContainer/PanelContainer/MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "Exit"
|
||||
|
||||
[node name="PlayerUI" type="Control" parent="CanvasLayer"]
|
||||
visible = false
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
mouse_filter = 2
|
||||
script = ExtResource("3_gaipe")
|
||||
|
||||
[node name="CenterContainer" type="CenterContainer" parent="CanvasLayer/PlayerUI"]
|
||||
layout_mode = 0
|
||||
offset_right = 1280.0
|
||||
offset_bottom = 100.0
|
||||
|
||||
[node name="ProgressBar" type="ProgressBar" parent="CanvasLayer/PlayerUI/CenterContainer"]
|
||||
custom_minimum_size = Vector2(400, 0)
|
||||
layout_mode = 2
|
||||
|
||||
[node name="DebugUI" type="Control" parent="CanvasLayer"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("4_217l8")
|
||||
|
||||
[node name="PanelContainer" type="PanelContainer" parent="CanvasLayer/DebugUI"]
|
||||
layout_mode = 0
|
||||
offset_left = 37.0
|
||||
offset_top = 117.0
|
||||
offset_right = 317.0
|
||||
offset_bottom = 542.0
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="CanvasLayer/DebugUI/PanelContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="ZoomCheck" type="CheckButton" parent="CanvasLayer/DebugUI/PanelContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "Zoom out"
|
||||
|
||||
[node name="GodModeCheck" type="CheckButton" parent="CanvasLayer/DebugUI/PanelContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "God mode"
|
||||
|
||||
[node name="EnemyGodModeCheck" type="CheckButton" parent="CanvasLayer/DebugUI/PanelContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "Enemy god mode"
|
||||
|
||||
[connection signal="pressed" from="CanvasLayer/PauseUI/CenterContainer/MarginContainer/PanelContainer/MarginContainer/VBoxContainer/ResumeButton" to="CanvasLayer/PauseUI" method="_on_resume_button_pressed"]
|
||||
[connection signal="pressed" from="CanvasLayer/PauseUI/CenterContainer/MarginContainer/PanelContainer/MarginContainer/VBoxContainer/NewGameBtuton" to="CanvasLayer/PauseUI" method="_on_new_game_btuton_pressed"]
|
||||
[connection signal="pressed" from="CanvasLayer/PauseUI/CenterContainer/MarginContainer/PanelContainer/MarginContainer/VBoxContainer/OptionsButton" to="CanvasLayer/PauseUI" method="_on_options_button_pressed"]
|
||||
[connection signal="pressed" from="CanvasLayer/PauseUI/CenterContainer/MarginContainer/PanelContainer/MarginContainer/VBoxContainer/ExitButton" to="CanvasLayer/PauseUI" method="_on_exit_button_pressed"]
|
||||
[connection signal="toggled" from="CanvasLayer/DebugUI/PanelContainer/VBoxContainer/ZoomCheck" to="CanvasLayer/DebugUI" method="_on_zoom_check_toggled"]
|
||||
[connection signal="toggled" from="CanvasLayer/DebugUI/PanelContainer/VBoxContainer/GodModeCheck" to="CanvasLayer/DebugUI" method="_on_god_mode_check_toggled"]
|
||||
[connection signal="toggled" from="CanvasLayer/DebugUI/PanelContainer/VBoxContainer/EnemyGodModeCheck" to="CanvasLayer/DebugUI" method="_on_enemy_god_mode_check_toggled"]
|
29
scenes/managers/pause_ui.gd
Normal file
29
scenes/managers/pause_ui.gd
Normal file
@@ -0,0 +1,29 @@
|
||||
class_name PauseUI
|
||||
extends Control
|
||||
|
||||
func _ready() -> void:
|
||||
pass
|
||||
|
||||
func toggle_pause_ui() -> void:
|
||||
if visible:
|
||||
visible = false
|
||||
Engine.time_scale = 1.0
|
||||
return
|
||||
visible = true
|
||||
Engine.time_scale = 0
|
||||
|
||||
|
||||
func _on_resume_button_pressed() -> void:
|
||||
toggle_pause_ui()
|
||||
|
||||
|
||||
func _on_options_button_pressed() -> void:
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
func _on_exit_button_pressed() -> void:
|
||||
get_tree().quit(0)
|
||||
|
||||
|
||||
func _on_new_game_btuton_pressed() -> void:
|
||||
pass # Replace with function body.
|
1
scenes/managers/pause_ui.gd.uid
Normal file
1
scenes/managers/pause_ui.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://sjnxf0hj3egp
|
7
scenes/managers/player_ui.gd
Normal file
7
scenes/managers/player_ui.gd
Normal file
@@ -0,0 +1,7 @@
|
||||
class_name PlayerUI
|
||||
extends Control
|
||||
|
||||
@onready var hp_bar: ProgressBar = $CenterContainer/ProgressBar
|
||||
|
||||
func set_hp(value: float):
|
||||
hp_bar.value = value
|
1
scenes/managers/player_ui.gd.uid
Normal file
1
scenes/managers/player_ui.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dbq74tvxtpfjc
|
63
scenes/player.gd
Normal file
63
scenes/player.gd
Normal file
@@ -0,0 +1,63 @@
|
||||
extends CharacterBody2D
|
||||
|
||||
@export var camera: Camera2D
|
||||
@export var main_ui: MainUI
|
||||
@export var default_movement_speed: float = 200.0
|
||||
@export var default_max_health: float = 50.0
|
||||
|
||||
@onready var sprite_2d: Sprite2D = $Sprite2D
|
||||
|
||||
var movement_speed: float
|
||||
var max_health: float
|
||||
var health: float
|
||||
var dead: bool = false
|
||||
var death_anim_done: bool = false
|
||||
var god_mode: bool = false
|
||||
|
||||
func _ready() -> void:
|
||||
camera.position = global_position
|
||||
movement_speed = default_movement_speed
|
||||
max_health = default_max_health
|
||||
health = max_health
|
||||
main_ui.player_ui.set_hp(100)
|
||||
GlobalConst.sig_debug_god_mode.connect(toggle_god_mode)
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if dead:
|
||||
return
|
||||
var input_direction = Input.get_vector("left", "right", "up", "down")
|
||||
velocity = input_direction * movement_speed
|
||||
move_and_slide()
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
camera.position_smoothing_enabled = true
|
||||
camera.position = global_position
|
||||
if dead and !death_anim_done:
|
||||
death_animation(delta)
|
||||
|
||||
func take_damage(value: float) -> void:
|
||||
if dead or god_mode:
|
||||
return
|
||||
health -= value
|
||||
print_debug("player took damage. now has %s hp" % health)
|
||||
main_ui.player_ui.set_hp(health / max_health * 100)
|
||||
if health <= 0:
|
||||
die()
|
||||
|
||||
func die():
|
||||
dead = true
|
||||
remove_from_group("damagable")
|
||||
get_tree().call_group("enemy", "cheer_anim")
|
||||
sprite_2d.z_index += 10
|
||||
|
||||
func death_animation(delta: float):
|
||||
# Engine.time_scale = clampf(lerpf(Engine.time_scale, 0.25, 0.5), 0.25, 0.9*delta)
|
||||
camera.zoom = lerp(camera.zoom, Vector2(8,8), 0.99*delta)
|
||||
rotation_degrees = lerpf(rotation_degrees, 90, 0.99*delta)
|
||||
if rotation_degrees > 88:
|
||||
main_ui.pause_ui.toggle_pause_ui()
|
||||
death_anim_done = true
|
||||
|
||||
func toggle_god_mode(value: bool):
|
||||
god_mode = value
|
||||
|
1
scenes/player.gd.uid
Normal file
1
scenes/player.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cvqaxckx4num3
|
22
scenes/player.tscn
Normal file
22
scenes/player.tscn
Normal file
@@ -0,0 +1,22 @@
|
||||
[gd_scene load_steps=5 format=3 uid="uid://ca2so8fm3q8fe"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://5x5wimok8uw2" path="res://assets/sprites/roguelikeChar_transparent.png" id="1_3vyb7"]
|
||||
[ext_resource type="Script" uid="uid://cvqaxckx4num3" path="res://scenes/player.gd" id="1_g2els"]
|
||||
[ext_resource type="PackedScene" uid="uid://cdojqe2m4kxx1" path="res://scenes/attacks/attack_sword.tscn" id="3_qhqgy"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_3vyb7"]
|
||||
radius = 8.0
|
||||
|
||||
[node name="Player" type="CharacterBody2D" groups=["damagable", "player"]]
|
||||
collision_layer = 0
|
||||
script = ExtResource("1_g2els")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
texture = ExtResource("1_3vyb7")
|
||||
region_enabled = true
|
||||
region_rect = Rect2(0, 104, 16, 14)
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource("CircleShape2D_3vyb7")
|
||||
|
||||
[node name="AttackSword" parent="." instance=ExtResource("3_qhqgy")]
|
7
scenes/test_level.tscn
Normal file
7
scenes/test_level.tscn
Normal file
File diff suppressed because one or more lines are too long
7
scenes/tiles/tile_map.tscn
Normal file
7
scenes/tiles/tile_map.tscn
Normal file
File diff suppressed because one or more lines are too long
1939
scenes/tiles/tileset.tres
Normal file
1939
scenes/tiles/tileset.tres
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user