game: add godot project
This commit is contained in:
4
.editorconfig
Normal file
4
.editorconfig
Normal file
@@ -0,0 +1,4 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
9
global_const.gd
Normal file
9
global_const.gd
Normal file
@@ -0,0 +1,9 @@
|
||||
extends Node
|
||||
|
||||
signal sig_debug_camera_zoom(value: bool)
|
||||
signal sig_debug_god_mode(value: bool)
|
||||
signal sig_debug_enemy_god_mode(value: bool)
|
||||
|
||||
const GROUP_ENEMY = "enemy"
|
||||
const GROUP_DAMAGEABLE = "damagable"
|
||||
const GROUP_PLAYER = "player"
|
1
global_const.gd.uid
Normal file
1
global_const.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://byoow2csijave
|
1
icon.svg
Normal file
1
icon.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="128" height="128"><rect width="124" height="124" x="2" y="2" fill="#363d52" stroke="#212532" stroke-width="4" rx="14"/><g fill="#fff" transform="translate(12.322 12.322)scale(.101)"><path d="M105 673v33q407 354 814 0v-33z"/><path fill="#478cbf" d="m105 673 152 14q12 1 15 14l4 67 132 10 8-61q2-11 15-15h162q13 4 15 15l8 61 132-10 4-67q3-13 15-14l152-14V427q30-39 56-81-35-59-83-108-43 20-82 47-40-37-88-64 7-51 8-102-59-28-123-42-26 43-46 89-49-7-98 0-20-46-46-89-64 14-123 42 1 51 8 102-48 27-88 64-39-27-82-47-48 49-83 108 26 42 56 81zm0 33v39c0 276 813 276 814 0v-39l-134 12-5 69q-2 10-14 13l-162 11q-12 0-16-11l-10-65H446l-10 65q-4 11-16 11l-162-11q-12-3-14-13l-5-69z"/><path d="M483 600c0 34 58 34 58 0v-86c0-34-58-34-58 0z"/><circle cx="725" cy="526" r="90"/><circle cx="299" cy="526" r="90"/></g><g fill="#414042" transform="translate(12.322 12.322)scale(.101)"><circle cx="307" cy="532" r="60"/><circle cx="717" cy="532" r="60"/></g></svg>
|
After Width: | Height: | Size: 994 B |
37
icon.svg.import
Normal file
37
icon.svg.import
Normal file
@@ -0,0 +1,37 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://jra7ejwpo58h"
|
||||
path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://icon.svg"
|
||||
dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.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
|
||||
svg/scale=1.0
|
||||
editor/scale_with_editor_scale=false
|
||||
editor/convert_colors_with_editor_theme=false
|
75
project.godot
Normal file
75
project.godot
Normal file
@@ -0,0 +1,75 @@
|
||||
; Engine configuration file.
|
||||
; It's best edited using the editor UI and not directly,
|
||||
; since the parameters that go here are not all obvious.
|
||||
;
|
||||
; Format:
|
||||
; [section] ; section goes between []
|
||||
; param=value ; assign values to parameters
|
||||
|
||||
config_version=5
|
||||
|
||||
[application]
|
||||
|
||||
config/name="Slopvivors"
|
||||
run/main_scene="uid://bjg50n7aab3ng"
|
||||
config/features=PackedStringArray("4.4", "Forward Plus")
|
||||
config/icon="res://icon.svg"
|
||||
|
||||
[autoload]
|
||||
|
||||
GlobalConst="*res://global_const.gd"
|
||||
|
||||
[display]
|
||||
|
||||
window/size/viewport_width=1280
|
||||
window/size/viewport_height=720
|
||||
window/stretch/scale_mode="integer"
|
||||
|
||||
[global_group]
|
||||
|
||||
player="Group containing current player"
|
||||
enemy="Group containing all enemies"
|
||||
damagable="Can be damaged using take_damage"
|
||||
|
||||
[input]
|
||||
|
||||
left={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
right={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
up={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
down={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
debug_menu={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194332,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
click={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":1,"position":Vector2(90, 11),"global_position":Vector2(99, 59),"factor":1.0,"button_index":1,"canceled":false,"pressed":true,"double_click":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
[layer_names]
|
||||
|
||||
2d_physics/layer_1="Terrain"
|
||||
2d_physics/layer_2="Enemies"
|
||||
2d_physics/layer_3="Player"
|
||||
|
||||
[rendering]
|
||||
|
||||
textures/canvas_textures/default_texture_filter=0
|
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