game: add godot project
This commit is contained in:
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")
|
||||
}
|
Reference in New Issue
Block a user