Level1 _ updated

mail@pastecode.io avatar
unknown
plain_text
2 years ago
703 B
7
Indexable
extends Node2D

var score = 0
var lives = 3

var ball = preload("res://Game/Ball.tscn")

func _on_Area2D_body_entered(body):
	if body is RigidBody2D:
		lives -= 1
		$GameLabel/Lives.text = "LIVES: "+str(lives)
		var ballx = ball.instance()
		add_child(ballx)
		ballx.global_position = $Paddle.global_position + Vector2(0,-20)
		body.queue_free()
		if lives==0:
			get_tree().change_scene("res://Game/GameOver.tscn")

func _on_Ball_body_entered(body):
	if body.is_in_group("brick"):
		score += 5
		$GameLabel/Score.text = "SCORE: "+str(score)
		body.remove_brick()
		if get_tree().get_nodes_in_group("brick").size()-1 == 0:
			get_tree().change_scene("res://Levels/Level2.tscn")