Files
idlebreakout/balls/ball.gd
T

44 lines
1.0 KiB
GDScript
Raw Normal View History

extends CharacterBody2D
@export var speed: float = 5
@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():
_velocity.x = 200#speed * _speed_mult * _direction.x * delta
_velocity.y = 250#speed * _speed_mult * _direction.y * delta
func _physics_process(delta):
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()
if collide.get_collider() is Block:
print(true)
collide.get_collider().take_damage(strength)
func _invert_x():
_velocity.x *= -1
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")