38 lines
1016 B
GDScript
38 lines
1016 B
GDScript
extends CharacterBody2D
|
|
class_name Enemy
|
|
|
|
@onready var sprite_2d: Sprite2D = $Sprite2D
|
|
|
|
var color := Color.WHITE
|
|
@export var speed = 100
|
|
var lives: int = 1
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
velocity = Vector2.ZERO
|
|
if Input.is_action_pressed("ui_down"):
|
|
velocity += Vector2.DOWN
|
|
if Input.is_action_pressed("ui_up"):
|
|
velocity += Vector2.UP
|
|
if Input.is_action_pressed("ui_left"):
|
|
velocity += Vector2.LEFT
|
|
if Input.is_action_pressed("ui_right"):
|
|
velocity += Vector2.RIGHT
|
|
velocity = velocity.normalized() * speed
|
|
move_and_slide()
|
|
for i in range(get_slide_collision_count()):
|
|
var collision := get_slide_collision(i)
|
|
if collision.get_collider() is Chest:
|
|
var buff: Buff = collision.get_collider().open(self)
|
|
if buff:
|
|
match(buff.color):
|
|
buff.colors.RED:
|
|
lives += 1
|
|
color.r -= 0.25
|
|
buff.colors.GREEN:
|
|
#$Camera2D.zoom -= Vector2(0.4, 0.4)
|
|
color.g -= 0.25
|
|
buff.colors.BLUE:
|
|
speed += 12
|
|
color.b -= 0.25
|
|
sprite_2d.modulate = color
|