BRICKBREAKER LIVE/SCORE UPDATED

 avatar
Kandif
plain_text
a month ago
911 B
11
Indexable
Never
extends Node2D

var score = 0
var lives = 3

@onready var player = $Paddle
@onready var ball = $Ball

@export_file("*.tscn") var gameover:String
@export_file("*.tscn") var next_level:String
	
func _on_area_2d_body_entered(body):
	if body is RigidBody2D:
		lives -= 1
		$GameLabel/Lives.text = "LIVES: "+str(lives)
		var ballx = ball.duplicate()
		ball = ballx
		ballx.linear_velocity = Vector2(200,-200)
		call_deferred("add_child",ballx)
		if player !=null:
			ballx.global_position = player.get_node("Sprite2D").global_position + Vector2(0,-30)
		body.queue_free()
		if lives==0:
			get_tree().change_scene_to_file(gameover)

func _on_ball_body_entered(body):
	if body.is_in_group("brick"):
		body.remove_brick()
		score += 5
		$GameLabel/Score.text = "SCORE: "+str(score)
		if get_tree().get_nodes_in_group("brick").size() == 0:
			get_tree().change_scene_to_file(next_level)
Leave a Comment