the-crypt/ai/Script/ogre.gd

55 lines
1.3 KiB
GDScript3
Raw Normal View History

2020-07-19 23:45:39 -05:00
extends Enemy
2020-07-20 14:24:15 -05:00
var contact_damage = 0.5
2020-07-23 14:43:42 -05:00
export var stationary: bool = false
2020-07-19 23:45:39 -05:00
onready var Spr = $Sprite
onready var DamageCD = $DamageCD
2020-07-20 14:24:15 -05:00
onready var Hurtbox = $Area2D
2020-07-19 23:45:39 -05:00
func _ready():
2020-07-23 14:43:42 -05:00
gravity = 100
2020-07-20 14:24:15 -05:00
speed = 50
2020-07-23 12:16:10 -05:00
health = 5
2020-07-19 23:45:39 -05:00
func _physics_process(delta):
2020-07-20 23:24:09 -05:00
if knockback != Vector2.ZERO:
knockback = lerp(knockback, Vector2.ZERO, 0.5)
move_and_slide(-knockback * knockback_amount)
if knockback.x < 1 and -1 < knockback.x and knockback.y < 1 and -1 < knockback.y:
knockback = Vector2.ZERO
return
var player = Player.position
2020-07-19 23:45:39 -05:00
var distance = global_position.distance_to(player)
2020-07-23 14:43:42 -05:00
if distance <= 200 and is_on_floor():
2020-07-19 23:45:39 -05:00
if player.x > global_position.x:
Spr.flip_h = false
velocity.x = speed
elif player.x < global_position.x:
Spr.flip_h = true
velocity.x = -speed
2020-07-23 14:43:42 -05:00
if stationary:
velocity.x = 0
2020-07-20 00:10:29 -05:00
if health <= 0:
queue_free()
2020-07-19 23:45:39 -05:00
if not is_on_floor():
2020-07-23 14:43:42 -05:00
velocity.y = gravity
if is_on_floor() and is_on_wall():
velocity.y = -100
print("jump")
velocity = move_and_slide(velocity, Vector2.UP)
2020-07-20 14:24:15 -05:00
deal_damage()
func deal_damage():
if DamageCD.is_stopped():
for body in Hurtbox.get_overlapping_bodies():
if body.has_method("get_type") && body.get_type() == "player":
body.health -= contact_damage
DamageCD.start()
2020-07-21 01:07:58 -05:00
func do_knockback(normal):
if Spr.flip_h == true:
knockback = Vector2(-4, -4)
else:
knockback = Vector2(4, 0)