2024-07-23 18:22:05 +02:00
|
|
|
extends CharacterBody2D
|
|
|
|
|
|
|
|
|
|
@export var speed: float = 5
|
2024-07-23 20:07:13 +02:00
|
|
|
@export var strength: int = 1
|
|
|
|
|
|
|
|
|
|
const _speed_mult: float = 20
|
|
|
|
|
var _direction: Vector2 = Vector2(-1.0, -0.5)
|
|
|
|
|
var _velocity: Vector2
|
|
|
|
|
|
|
|
|
|
var deg: float
|
|
|
|
|
|
|
|
|
|
func _ready():
|
2024-07-23 20:33:27 +02:00
|
|
|
_velocity.x = 400#speed * _speed_mult * _direction.x * delta
|
|
|
|
|
_velocity.y = 450#speed * _speed_mult * _direction.y * delta
|
2024-07-23 20:07:13 +02:00
|
|
|
|
2024-07-23 18:22:05 +02:00
|
|
|
|
|
|
|
|
func _physics_process(delta):
|
|
|
|
|
|
2024-07-23 20:07:13 +02:00
|
|
|
var collide = move_and_collide(_velocity * delta)
|
|
|
|
|
if collide:
|
|
|
|
|
deg = rad_to_deg(collide.get_angle())
|
|
|
|
|
if (deg >= 45 and deg < 135) or (deg >= 225 and deg < 315):
|
|
|
|
|
_invert_x()
|
|
|
|
|
if (deg >= 135 and deg < 225) or deg < 45 or deg >= 315:
|
|
|
|
|
_invert_y()
|
2024-07-23 20:33:27 +02:00
|
|
|
print(collide.get_collider())
|
|
|
|
|
if collide.get_collider().get_parent() is Block:
|
2024-07-23 20:07:13 +02:00
|
|
|
print(true)
|
2024-07-23 20:33:27 +02:00
|
|
|
collide.get_collider().get_parent().take_damage(strength)
|
2024-07-23 18:22:05 +02:00
|
|
|
|
2024-07-23 20:07:13 +02:00
|
|
|
func _invert_x():
|
|
|
|
|
_velocity.x *= -1
|
2024-07-23 18:22:05 +02:00
|
|
|
|
2024-07-23 20:07:13 +02:00
|
|
|
func _invert_y():
|
|
|
|
|
_velocity.y *= -1
|
|
|
|
|
|
|
|
|
|
func has_collided():
|
|
|
|
|
pass
|
|
|
|
|
#if $Raycasts/North.is_colliding() or $Raycasts/South.is_colliding():
|
|
|
|
|
#_invert_y()
|
|
|
|
|
#print("y")
|
|
|
|
|
#if $Raycasts/West.is_colliding() or $Raycasts/East.is_colliding():
|
|
|
|
|
#_invert_x()
|
|
|
|
|
#print("x")
|