ft: predator mostly done
This commit is contained in:
@@ -1,16 +1,18 @@
|
||||
extends CharacterBody2D
|
||||
|
||||
@export var attack_duration = 0.4
|
||||
@export var attack_cooldown_duration = 0.6
|
||||
@export var attack_duration: float = 0.4
|
||||
@export var attack_cooldown_duration: float = 0.6
|
||||
|
||||
@onready var attack_area: Area2D = $AttackArea
|
||||
@onready var attack_timer: Timer = $AttackTimer
|
||||
@onready var attack_cooldown_timer: Timer = $AttackCooldownTimer
|
||||
@onready var sprite: AnimatedSprite2D = $AnimatedSprite2D
|
||||
|
||||
@export var speed = 200
|
||||
var damage = 10
|
||||
var can_attack = true
|
||||
# TODO: these stats are shared across most entities; extract to resource?
|
||||
@export var speed: int = 200
|
||||
var damage: int = 10
|
||||
var can_attack: bool = true
|
||||
var desired_rotation: float = 0
|
||||
|
||||
func _ready() -> void:
|
||||
var screen_size = get_viewport_rect().size
|
||||
@@ -20,6 +22,7 @@ func _ready() -> void:
|
||||
attack_timer.wait_time = attack_duration
|
||||
attack_cooldown_timer.wait_time = attack_cooldown_duration
|
||||
|
||||
|
||||
func _process(delta):
|
||||
velocity = Vector2.ZERO
|
||||
if Input.is_action_pressed("move_right"):
|
||||
@@ -33,10 +36,15 @@ func _process(delta):
|
||||
if Input.is_action_pressed("try_attack"):
|
||||
try_attack()
|
||||
|
||||
|
||||
if not velocity.is_zero_approx():
|
||||
self.rotation = atan2(velocity.y, velocity.x)
|
||||
self.desired_rotation = atan2(velocity.y, velocity.x)
|
||||
|
||||
# smoothly rotate
|
||||
if self.rotation != self.desired_rotation:
|
||||
self.rotation = lerp_angle(self.rotation, self.desired_rotation, clampf(4 * delta, 0, 1))
|
||||
|
||||
move_and_collide(speed * velocity * delta)
|
||||
#position += speed * velocity * delta
|
||||
position = GameManager.get_boundaried_position(position)
|
||||
|
||||
func try_attack() -> void:
|
||||
@@ -60,7 +68,7 @@ func _on_cooldown_timeout() -> void:
|
||||
|
||||
func _on_attack_hit(body: Node2D) -> void:
|
||||
var hit_hittable = false
|
||||
if body.is_in_group("prey") or body.is_in_group("predators"):
|
||||
if body.is_in_group("prey") or body.is_in_group("predator"):
|
||||
if body.has_method("handle_damage"):
|
||||
body.handle_damage(damage, self)
|
||||
hit_hittable = true
|
||||
@@ -70,3 +78,7 @@ func _on_attack_hit(body: Node2D) -> void:
|
||||
await get_tree().create_timer(0.2).timeout
|
||||
sprite.play("default")
|
||||
# TODO: resource handling logic
|
||||
|
||||
func handle_damage(dmg: int, src: Node) -> void:
|
||||
# TODO: damage logic
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user