game: add rat enemy
This commit is contained in:
34
assets/sprites/small_bat.png.import
Normal file
34
assets/sprites/small_bat.png.import
Normal file
@@ -0,0 +1,34 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://chtjfq3bmonhj"
|
||||
path="res://.godot/imported/small_bat.png-8cac10440ad9b69c99d6007471ff8d06.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://assets/sprites/small_bat.png"
|
||||
dest_files=["res://.godot/imported/small_bat.png-8cac10440ad9b69c99d6007471ff8d06.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
|
@@ -6,6 +6,7 @@ extends CharacterBody2D
|
||||
@export var default_contact_damage: float = 0.0
|
||||
@export var target_distance: float = 6.0
|
||||
@export var path_update_interval: float = 1.5
|
||||
@export var xp_dropped: float = 5.0
|
||||
|
||||
@onready var target_cast: RayCast2D = $TargetCast
|
||||
@onready var animation_player: AnimationPlayer = $AnimationPlayer
|
||||
@@ -97,7 +98,7 @@ func _do_nav_agent_movement():
|
||||
func check_contact_damage():
|
||||
if default_contact_damage == 0.0:
|
||||
return
|
||||
if global_position.distance_to(target.global_position) > target_distance:
|
||||
if global_position.distance_to(target.global_position) > target_distance + 2:
|
||||
return
|
||||
deal_contact_damage()
|
||||
|
||||
@@ -140,7 +141,7 @@ func die():
|
||||
|
||||
func drop_xp_orb() -> void:
|
||||
var orb: XPOrb = preload("res://scenes/xp_orb.tscn").instantiate()
|
||||
orb.value = 5
|
||||
orb.value = xp_dropped
|
||||
orb.position = position
|
||||
get_parent().call_deferred("add_child", orb)
|
||||
|
||||
|
@@ -12,7 +12,7 @@ shader_parameter/flash_amount = 0.0
|
||||
size = Vector2(32, 32)
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_satqt"]
|
||||
radius = 6.0
|
||||
radius = 4.0
|
||||
|
||||
[sub_resource type="Animation" id="Animation_satqt"]
|
||||
length = 0.001
|
||||
@@ -60,7 +60,7 @@ _data = {
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_pkqou"]
|
||||
|
||||
[node name="EnemyBase" type="CharacterBody2D"]
|
||||
[node name="EnemyBase" type="CharacterBody2D" groups=["damagable", "enemy"]]
|
||||
collision_layer = 2
|
||||
collision_mask = 3
|
||||
script = ExtResource("1_qty17")
|
||||
|
1
scenes/enemies/enemy_bat.gd
Normal file
1
scenes/enemies/enemy_bat.gd
Normal file
@@ -0,0 +1 @@
|
||||
extends EnemyBase
|
1
scenes/enemies/enemy_bat.gd.uid
Normal file
1
scenes/enemies/enemy_bat.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bfhmjpjwdh25o
|
24
scenes/enemies/enemy_bat.tscn
Normal file
24
scenes/enemies/enemy_bat.tscn
Normal file
@@ -0,0 +1,24 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://du4t4vydra4rm"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://b7vq8xspnlyeu" path="res://scenes/enemies/enemy_base.tscn" id="1_4r40l"]
|
||||
[ext_resource type="Script" uid="uid://bfhmjpjwdh25o" path="res://scenes/enemies/enemy_bat.gd" id="2_1jj4k"]
|
||||
[ext_resource type="Texture2D" uid="uid://chtjfq3bmonhj" path="res://assets/sprites/small_bat.png" id="2_608ut"]
|
||||
|
||||
[node name="EnemyBat" instance=ExtResource("1_4r40l")]
|
||||
collision_mask = 2
|
||||
script = ExtResource("2_1jj4k")
|
||||
move_speed = 175.0
|
||||
max_health = 6.0
|
||||
default_contact_damage = 5.0
|
||||
target_distance = 2.0
|
||||
xp_dropped = 8.0
|
||||
|
||||
[node name="Sprite2D" parent="." index="0"]
|
||||
texture = ExtResource("2_608ut")
|
||||
|
||||
[node name="TargetCast" parent="." index="2"]
|
||||
collision_mask = 0
|
||||
collide_with_bodies = false
|
||||
|
||||
[node name="ShapeCast2D" parent="." index="6"]
|
||||
visible = false
|
@@ -9,6 +9,7 @@ extends Node2D
|
||||
@onready var timer: Timer = $Timer
|
||||
|
||||
const ENEMY_RAT = preload("res://scenes/enemies/enemy_rat.tscn")
|
||||
const ENEMY_BAT = preload("res://scenes/enemies/enemy_bat.tscn")
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
@@ -21,8 +22,15 @@ func _ready() -> void:
|
||||
func _on_timer_timeout() -> void:
|
||||
var enemies = get_tree().get_nodes_in_group(GlobalConst.GROUP_ENEMY)
|
||||
GlobalConst.sig_debug_stats_set.emit("enemy_count", "%s" % len(enemies))
|
||||
var next_enemy: PackedScene
|
||||
match randi() % 2:
|
||||
0:
|
||||
next_enemy = ENEMY_BAT
|
||||
1:
|
||||
next_enemy = ENEMY_RAT
|
||||
|
||||
if len(enemies) < max_enemies:
|
||||
var new_enemy = ENEMY_RAT.instantiate()
|
||||
var new_enemy = next_enemy.instantiate()
|
||||
new_enemy.position = _get_spawn_pos()
|
||||
new_enemy.target = target
|
||||
add_child(new_enemy)
|
||||
|
Reference in New Issue
Block a user