gmtk-2024/scripts/entity.gd

34 lines
679 B
GDScript3
Raw Normal View History

class_name Entity extends CharacterBody2D
@export var health = null
@export var speed = null
@export var damage = null
@export var kb_speed = null
func _init(initial_health: int, speed_multiplier: int, attack_damage: int) -> void:
health = initial_health
speed = speed_multiplier
damage = attack_damage
kb_speed = 0
func _physics_process(delta: float) -> void:
var init_velocity = velocity
velocity.x = 0
velocity.y = 0
if init_velocity.x == 0:
init_velocity.x = 1
if kb_speed > 0:
velocity.x = -sign(init_velocity.x) * kb_speed
kb_speed = 0
move_and_slide()
velocity = init_velocity
func take_knockback(speed: int) -> void:
kb_speed = speed