added green attack, enemy
This commit is contained in:
parent
f852b0a30e
commit
2bf9db610e
43 changed files with 673 additions and 246 deletions
|
|
@ -4,8 +4,7 @@ class_name Enemy extends Entity
|
|||
@export var flee_range: float = 20.0
|
||||
@export var approach_range: float = 100.0
|
||||
|
||||
@onready var nav_agent: NavigationAgent2D = $NavigationAgent2D
|
||||
@onready var sprite = $Anim
|
||||
@onready var nav_agent: NavigationAgent2D;
|
||||
|
||||
var current_charge: float = 0.0
|
||||
var target_node: Node2D
|
||||
|
|
@ -13,6 +12,8 @@ var target_node: Node2D
|
|||
func _ready() -> void:
|
||||
add_to_group("enemy")
|
||||
target_node = get_tree().get_first_node_in_group("player")
|
||||
nav_agent = NavigationAgent2D.new()
|
||||
add_child(nav_agent)
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if not target_node: return
|
||||
|
|
@ -31,7 +32,7 @@ func _physics_process(delta: float) -> void:
|
|||
else:
|
||||
_handle_attack_charge(delta)
|
||||
|
||||
sprite.flip_h = target_node.position.x > position.x
|
||||
main_visual.flip_h = target_node.position.x > position.x
|
||||
scale = Vector2.ONE * (1 + (current_charge * 0.2))
|
||||
|
||||
super._physics_process(delta)
|
||||
|
|
|
|||
68
scripts/grenade.gd
Normal file
68
scripts/grenade.gd
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
extends MaskAbility
|
||||
|
||||
@export var max_bounces := 5
|
||||
@export var speed := 1.4
|
||||
@export var max_height = 100.
|
||||
@export var explosion : PackedScene
|
||||
|
||||
@onready var sprite : Sprite2D = $Sprite2D
|
||||
var traveled: float = 0.0
|
||||
|
||||
var bouncing = false
|
||||
var target : Enemy = null
|
||||
var bounces := max_bounces
|
||||
var already_hit : Array[Enemy] = []
|
||||
|
||||
func mask_ready():
|
||||
super.mask_ready()
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if traveled < 1:
|
||||
if target:
|
||||
target_position = target.position
|
||||
traveled += speed * delta
|
||||
|
||||
global_position = start_position.lerp(target_position, traveled)
|
||||
|
||||
var arc_y = 4 * max_height * traveled * (1 - traveled)
|
||||
|
||||
sprite.position.y = -arc_y
|
||||
elif bouncing and bounces > 0:
|
||||
if target:
|
||||
target.damage()
|
||||
change_target()
|
||||
else:
|
||||
global_position = target_position
|
||||
sprite.position.y = 0
|
||||
|
||||
func change_target():
|
||||
var enemies = get_tree().get_nodes_in_group("enemy")
|
||||
var dist := 100000.
|
||||
var closest : Entity = null
|
||||
for e : Enemy in enemies:
|
||||
if e in already_hit: continue
|
||||
var e_dist = e.global_position.distance_to(global_position)
|
||||
if e_dist < dist:
|
||||
dist = e_dist
|
||||
closest = e
|
||||
bounces -= 1
|
||||
target = null
|
||||
if dist < 60:
|
||||
target = closest
|
||||
already_hit.append(closest)
|
||||
start_position = global_position
|
||||
target_position = closest.global_position
|
||||
traveled = 0
|
||||
var explo = explosion.instantiate()
|
||||
explo.emitting = true
|
||||
add_child(explo)
|
||||
|
||||
func _on_hitbox_hit_entity(entity : Entity) -> void:
|
||||
if from_player:
|
||||
for c in _get_all_children(self):
|
||||
if c is Hitbox:
|
||||
c.enabled = false
|
||||
bouncing = true
|
||||
target = entity
|
||||
already_hit = [entity]
|
||||
#change_target()
|
||||
1
scripts/grenade.gd.uid
Normal file
1
scripts/grenade.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://6ep27l6iw1hi
|
||||
|
|
@ -1,30 +1,35 @@
|
|||
class_name Hitbox extends Area2D
|
||||
signal collided;
|
||||
signal hit_entity(entity : Entity);
|
||||
signal hit_obstacle;
|
||||
|
||||
var from_player = true
|
||||
var enabled = true
|
||||
@export var deal_damage = true
|
||||
|
||||
func _ready() -> void:
|
||||
collision_mask = 0xffff
|
||||
collision_mask = 1 | 2 | 4
|
||||
body_entered.connect(_on_body_entered)
|
||||
area_entered.connect(_on_area_entered)
|
||||
|
||||
func _on_area_entered(area : Area2D):
|
||||
if area is Hitbox:
|
||||
if area.from_player != from_player:
|
||||
collided.emit()
|
||||
hit_obstacle.emit()
|
||||
|
||||
func _on_body_entered(body: Node) -> void:
|
||||
print(body)
|
||||
if not enabled: return
|
||||
if body is Enemy and from_player:
|
||||
body.damage()
|
||||
collided.emit()
|
||||
body.knockback()
|
||||
if deal_damage:
|
||||
body.damage()
|
||||
body.knockback()
|
||||
|
||||
hit_entity.emit(body)
|
||||
|
||||
if body is Player and not from_player:
|
||||
body.damage()
|
||||
collided.emit()
|
||||
if deal_damage:
|
||||
body.damage()
|
||||
|
||||
hit_entity.emit(body)
|
||||
|
||||
if body is StaticBody2D or body is Hitbox:
|
||||
collided.emit()
|
||||
if body is StaticBody2D:
|
||||
hit_obstacle.emit()
|
||||
|
|
|
|||
|
|
@ -8,5 +8,5 @@ func spawn():
|
|||
get_tree().current_scene.add_child(entity)
|
||||
entity.global_position = global_position
|
||||
entity.scale.y = 5
|
||||
#create_tween().tween_property(entity, "scale:y", 1, 0.2)
|
||||
create_tween().tween_property(entity, "scale:y", 1, 0.2)
|
||||
entity.died.connect(finished.emit)
|
||||
|
|
|
|||
|
|
@ -17,5 +17,8 @@ func _physics_process(delta: float) -> void:
|
|||
rotation += rot_speed * delta
|
||||
position += dir * speed * delta
|
||||
|
||||
func _on_hitbox_collided() -> void:
|
||||
func _on_hitbox_hit_obstacle() -> void:
|
||||
queue_free()
|
||||
|
||||
func _on_hitbox_hit_entity(entity: Entity) -> void:
|
||||
queue_free()
|
||||
|
|
|
|||
|
|
@ -3,14 +3,18 @@ class_name WaveNode extends Node2D
|
|||
@export var spawn_interval := 0.2
|
||||
signal finished;
|
||||
var entities := 0;
|
||||
var started_wave = false
|
||||
|
||||
func _ready() -> void:
|
||||
entities = get_child_count()
|
||||
|
||||
func spawn_wave():
|
||||
if started_wave: return
|
||||
|
||||
started_wave = true
|
||||
if get_child_count() == 0:
|
||||
finished.emit()
|
||||
return;
|
||||
return
|
||||
|
||||
for c : Spawner in get_children():
|
||||
c.spawn();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue