Different enemies with different properties

This commit is contained in:
2025-03-10 09:23:56 +01:00
parent 95fd58d6dc
commit eed544a9d8
4 changed files with 196 additions and 24 deletions

View File

@ -1,35 +1,62 @@
extends Node2D
@export var speed = 100
var speed = 0
var health = 0
var shield = 0
var current_health = 0
var current_shield = 0
var last_position: Vector2 = Vector2.ZERO # To store the previous position
func _ready() -> void:
last_position = get_parent().position # Set the initial position when the mob starts
last_position = get_parent().position
set_character_data()
adjust_health_bar()
func _process(delta: float) -> void:
move_character(delta)
func move_character(delta: float) -> void:
var path_follow = get_parent()
# Update the progress along the path
# Update the progress and prevent rotation
path_follow.set_progress(path_follow.get_progress() + speed * delta)
# Prevent rotation (lock rotation to 0)
path_follow.rotation = 0
# Get the current position on the path (mob's position)
#turn the character to to the way its headed
var current_position = path_follow.position
# Flip the character if moving left (when moving to the left, the x position decreases)
if current_position.x < last_position.x:
# Flip the character horizontally by inverting its scale on the x-axis
path_follow.scale.x = -abs(path_follow.scale.x)
else:
# Ensure the character is not flipped when moving right
path_follow.scale.x = abs(path_follow.scale.x)
# Update the last_position for the next frame
last_position = current_position
# If the mob reaches the end of the path, queue it for deletion
#if reached the end of the path remove both the path, and the character
if path_follow.get_progress_ratio() >= 0.999:
get_parent().queue_free()
func set_character_data():
match self.name:
"Forkman":
speed = 100
health = 100
shield = 100
"Swordman":
speed = 120
health = 100
shield = 100
current_health = health
current_shield = shield
func adjust_health_bar() -> void:
var health_bar = get_node("ProgressBar")
health_bar.value = health / current_health * 100
pass

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=24 format=3 uid="uid://dnoajr7rj2um7"]
[gd_scene load_steps=26 format=3 uid="uid://dnoajr7rj2um7"]
[ext_resource type="Script" uid="uid://sh6qqbl8fdrr" path="res://Game/Mobs/enemy.gd" id="1_pq2md"]
[ext_resource type="Texture2D" uid="uid://dl2w65j5jq0xc" path="res://Assets/Monsters/1/1_enemies_1_walk_000.png" id="1_ra45u"]
@ -22,6 +22,9 @@
[ext_resource type="Texture2D" uid="uid://cqvx47l53s1vc" path="res://Assets/Monsters/1/1_enemies_1_walk_018.png" id="19_lbdce"]
[ext_resource type="Texture2D" uid="uid://bi4gdl6ovax2j" path="res://Assets/Monsters/1/1_enemies_1_walk_019.png" id="20_garh6"]
[sub_resource type="CircleShape2D" id="CircleShape2D_ra45u"]
radius = 32.0
[sub_resource type="SpriteFrames" id="SpriteFrames_gxpsl"]
animations = [{
"frames": [{
@ -90,22 +93,35 @@ animations = [{
"speed": 20.0
}]
[sub_resource type="CircleShape2D" id="CircleShape2D_ra45u"]
radius = 32.0
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_pq2md"]
bg_color = Color(1, 0, 0, 1)
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_gxpsl"]
bg_color = Color(0, 1, 0, 1)
[node name="Forkman" type="Node2D"]
script = ExtResource("1_pq2md")
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
position = Vector2(1.625, 0)
scale = Vector2(0.206633, 0.191818)
[node name="CharacterBody2D" type="CharacterBody2D" parent="."]
[node name="CollisionShape2D" type="CollisionShape2D" parent="CharacterBody2D"]
scale = Vector2(0.5, 0.5)
shape = SubResource("CircleShape2D_ra45u")
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="CharacterBody2D"]
position = Vector2(10, 0)
scale = Vector2(0.2, 0.186)
sprite_frames = SubResource("SpriteFrames_gxpsl")
animation = &"walk"
autoplay = "walk"
[node name="CharacterBody2D" type="CharacterBody2D" parent="."]
[node name="CollisionShape2D" type="CollisionShape2D" parent="CharacterBody2D"]
position = Vector2(-5, 0)
scale = Vector2(0.5, 0.5)
shape = SubResource("CircleShape2D_ra45u")
[node name="ProgressBar" type="ProgressBar" parent="."]
offset_left = -15.0
offset_top = -30.0
offset_right = 15.0
offset_bottom = -24.0
theme_override_styles/background = SubResource("StyleBoxFlat_pq2md")
theme_override_styles/fill = SubResource("StyleBoxFlat_gxpsl")
value = 70.0
rounded = true
show_percentage = false

126
Game/Mobs/swordman.tscn Normal file
View File

@ -0,0 +1,126 @@
[gd_scene load_steps=26 format=3 uid="uid://dfwcvygt24m4f"]
[ext_resource type="Texture2D" uid="uid://dgwwy6rlst543" path="res://Assets/Monsters/2/2_enemies_1_walk_000.png" id="1_chb7j"]
[ext_resource type="Script" uid="uid://sh6qqbl8fdrr" path="res://Game/Mobs/enemy.gd" id="1_n3bbi"]
[ext_resource type="Texture2D" uid="uid://2whi44p3xj0p" path="res://Assets/Monsters/2/2_enemies_1_walk_001.png" id="2_n3bbi"]
[ext_resource type="Texture2D" uid="uid://do3bo71hr0otn" path="res://Assets/Monsters/2/2_enemies_1_walk_002.png" id="3_2ea55"]
[ext_resource type="Texture2D" uid="uid://ccdikiw6ql5m4" path="res://Assets/Monsters/2/2_enemies_1_walk_003.png" id="4_3owek"]
[ext_resource type="Texture2D" uid="uid://bx6buqbufrcwn" path="res://Assets/Monsters/2/2_enemies_1_walk_004.png" id="5_1uvyj"]
[ext_resource type="Texture2D" uid="uid://tqeds7vde35o" path="res://Assets/Monsters/2/2_enemies_1_walk_005.png" id="6_grkoa"]
[ext_resource type="Texture2D" uid="uid://bcuobi85ycc5t" path="res://Assets/Monsters/2/2_enemies_1_walk_006.png" id="7_851gl"]
[ext_resource type="Texture2D" uid="uid://bcvweagua2fgd" path="res://Assets/Monsters/2/2_enemies_1_walk_007.png" id="8_j27io"]
[ext_resource type="Texture2D" uid="uid://h38qu35ll5po" path="res://Assets/Monsters/2/2_enemies_1_walk_008.png" id="9_00kpv"]
[ext_resource type="Texture2D" uid="uid://b18spnchhjhk2" path="res://Assets/Monsters/2/2_enemies_1_walk_009.png" id="10_4coct"]
[ext_resource type="Texture2D" uid="uid://bqqts0duqrqnv" path="res://Assets/Monsters/2/2_enemies_1_walk_010.png" id="11_bg267"]
[ext_resource type="Texture2D" uid="uid://bn7fjtj2ojqma" path="res://Assets/Monsters/2/2_enemies_1_walk_011.png" id="12_a8lu2"]
[ext_resource type="Texture2D" uid="uid://s0wd5s61skeh" path="res://Assets/Monsters/2/2_enemies_1_walk_012.png" id="13_36qb6"]
[ext_resource type="Texture2D" uid="uid://b5pm5r0a5dsx3" path="res://Assets/Monsters/2/2_enemies_1_walk_013.png" id="14_u7bbl"]
[ext_resource type="Texture2D" uid="uid://dltw4wtskgpo5" path="res://Assets/Monsters/2/2_enemies_1_walk_014.png" id="15_wor3e"]
[ext_resource type="Texture2D" uid="uid://bk83p2mqrp3ri" path="res://Assets/Monsters/2/2_enemies_1_walk_015.png" id="16_qic3q"]
[ext_resource type="Texture2D" uid="uid://yggxgmf8fa70" path="res://Assets/Monsters/2/2_enemies_1_walk_016.png" id="17_gigtg"]
[ext_resource type="Texture2D" uid="uid://wfiqtbte7iy8" path="res://Assets/Monsters/2/2_enemies_1_walk_017.png" id="18_nxbbl"]
[ext_resource type="Texture2D" uid="uid://pkv6mxsmi8jm" path="res://Assets/Monsters/2/2_enemies_1_walk_018.png" id="19_hbbx0"]
[ext_resource type="Texture2D" uid="uid://dp7xripl4r4o1" path="res://Assets/Monsters/2/2_enemies_1_walk_019.png" id="20_lanmf"]
[sub_resource type="SpriteFrames" id="SpriteFrames_h86ts"]
animations = [{
"frames": [{
"duration": 1.0,
"texture": ExtResource("1_chb7j")
}, {
"duration": 1.0,
"texture": ExtResource("2_n3bbi")
}, {
"duration": 1.0,
"texture": ExtResource("3_2ea55")
}, {
"duration": 1.0,
"texture": ExtResource("4_3owek")
}, {
"duration": 1.0,
"texture": ExtResource("5_1uvyj")
}, {
"duration": 1.0,
"texture": ExtResource("6_grkoa")
}, {
"duration": 1.0,
"texture": ExtResource("7_851gl")
}, {
"duration": 1.0,
"texture": ExtResource("8_j27io")
}, {
"duration": 1.0,
"texture": ExtResource("9_00kpv")
}, {
"duration": 1.0,
"texture": ExtResource("10_4coct")
}, {
"duration": 1.0,
"texture": ExtResource("11_bg267")
}, {
"duration": 1.0,
"texture": ExtResource("12_a8lu2")
}, {
"duration": 1.0,
"texture": ExtResource("13_36qb6")
}, {
"duration": 1.0,
"texture": ExtResource("14_u7bbl")
}, {
"duration": 1.0,
"texture": ExtResource("15_wor3e")
}, {
"duration": 1.0,
"texture": ExtResource("16_qic3q")
}, {
"duration": 1.0,
"texture": ExtResource("17_gigtg")
}, {
"duration": 1.0,
"texture": ExtResource("18_nxbbl")
}, {
"duration": 1.0,
"texture": ExtResource("19_hbbx0")
}, {
"duration": 1.0,
"texture": ExtResource("20_lanmf")
}],
"loop": true,
"name": &"default",
"speed": 20.0
}]
[sub_resource type="CircleShape2D" id="CircleShape2D_j0lf0"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_n3bbi"]
bg_color = Color(1, 0, 0, 1)
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_2ea55"]
bg_color = Color(0, 1, 0, 1)
[node name="Swordman" type="Node2D"]
script = ExtResource("1_n3bbi")
[node name="CharacterBody2D" type="CharacterBody2D" parent="."]
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="CharacterBody2D"]
position = Vector2(10, 0)
scale = Vector2(0.18, 0.18)
sprite_frames = SubResource("SpriteFrames_h86ts")
autoplay = "default"
frame_progress = 0.554719
[node name="CollisionShape2D" type="CollisionShape2D" parent="CharacterBody2D"]
scale = Vector2(2, 2)
shape = SubResource("CircleShape2D_j0lf0")
[node name="ProgressBar" type="ProgressBar" parent="."]
offset_left = -15.0
offset_top = -30.0
offset_right = 15.0
offset_bottom = -24.0
theme_override_styles/background = SubResource("StyleBoxFlat_n3bbi")
theme_override_styles/fill = SubResource("StyleBoxFlat_2ea55")
value = 70.0
rounded = true
show_percentage = false