extends KinematicBody2D
var speed = 750
var increase_amount = 10
var rotation_speed = 2 # Adjust this value for rotation speed
var velocity = Vector2()
var collided = false
var player_dead = false # Add this variable
signal score_increment
func _ready():
randomize()
# Start a coroutine to handle the delay before the ball starts moving
start_countdown()
func start(pos):
position = pos
# Ensure the ball starts moving at an angle not too close to horizontal
var min_angle = deg2rad(45)
var max_angle = deg2rad(180)
var initial_angle = rand_range(min_angle, max_angle)
velocity = Vector2(speed, 0).rotated(initial_angle)
# Check if velocity is too horizontal and reassign if necessary
while abs(velocity.angle()) < min_angle or abs(velocity.angle()) > max_angle:
initial_angle = rand_range(min_angle, max_angle)
velocity = Vector2(speed, 0).rotated(initial_angle)
collided = false
func start_countdown():
# Wait for 3 seconds
yield(get_tree().create_timer(3), "timeout")
# After the wait, start the ball movement
start(position)
func _physics_process(delta):
if player_dead:
# Stop the ball by setting velocity to zero
velocity = Vector2()
else:
if velocity != Vector2(): # Check if velocity is initialized
# Move the ball and check for collision
var collision = move_and_collide(velocity * delta)
if collision:
# Reflect the velocity based on the collision normal
velocity = velocity.bounce(collision.normal)
if collision.collider.is_in_group("Paws") and not collided:
print("Collided with Paw")
emit_signal("score_increment")
speed += increase_amount
# Maintain direction but increase speed
velocity = velocity.normalized() * speed
collided = true
print(speed)
else:
collided = false
# Apply rotation
rotation += rotation_speed * delta
else:
print("Velocity not initialized")
# Call this function to initialize the ball with an initial position
func init_ball(start_pos: Vector2):
start(start_pos)
# Call this function to stop the ball when the player dies
func set_player_dead(is_dead: bool):
player_dead = is_dead
extends KinematicBody2D
var speed = 750
var increase_amount = 10
var rotation_speed = 2 # Adjust this value for rotation speed
var velocity = Vector2()
var collided = false
var player_dead = false # Add this variable
signal score_increment
func _ready():
randomize()
area.connect("player_death", self, "_on_player_death")
# Start a coroutine to handle the delay before the ball starts moving
start_countdown()
func start(pos):
position = pos
# Ensure the ball starts moving at an angle not too close to horizontal
var min_angle = deg2rad(45)
var max_angle = deg2rad(180)
var initial_angle = rand_range(min_angle, max_angle)
velocity = Vector2(speed, 0).rotated(initial_angle)
# Check if velocity is too horizontal and reassign if necessary
while abs(velocity.angle()) < min_angle or abs(velocity.angle()) > max_angle:
initial_angle = rand_range(min_angle, max_angle)
velocity = Vector2(speed, 0).rotated(initial_angle)
collided = false
func start_countdown():
# Wait for 3 seconds
yield(get_tree().create_timer(3), "timeout")
# After the wait, start the ball movement
start(position)
func _physics_process(delta):
if player_dead:
# Stop the ball by setting velocity to zero
velocity = Vector2()
else:
if velocity != Vector2(): # Check if velocity is initialized
# Move the ball and check for collision
var collision = move_and_collide(velocity * delta)
if collision:
# Reflect the velocity based on the collision normal
velocity = velocity.bounce(collision.normal)
if collision.collider.is_in_group("Paws") and not collided:
print("Collided with Paw")
emit_signal("score_increment")
speed += increase_amount
# Maintain direction but increase speed
velocity = velocity.normalized() * speed
collided = true
print(speed)
else:
collided = false
# Apply rotation
rotation += rotation_speed * delta
else:
print("Velocity not initialized")
# Call this function to initialize the ball with an initial position
func init_ball(start_pos: Vector2):
start(start_pos)
# Call this function to stop the ball when the player dies
func _on_player_death(is_dead: bool):
player_dead = is_dead
extends Area2D
signal death
signal player_death
func _ready():
connect("body_entered", self, "_on_Area2D_body_entered")
func _on_Area2D_body_entered(body):
print("Body entered:", body.name)
if body.is_in_group("Ball"):
print("deleted")
emit_signal("death")
emit_signal("player_death")
I tried to connect my signal to call that function but i am getting an error
I deleted area.connect("player_death", self, "_on_player_death") this from my ball script because it was the first error and then after it there is this.