Untitled

 avatar
Kandif
plain_text
2 years ago
871 B
7
Indexable
Never
extends Node2D

var score = 0
var lives = 3

onready var player = $Paddle

onready var ball = $Ball
	
func _on_Area2D_body_entered(body):
	if body is RigidBody2D:
		lives -= 1
		$lives.text = "LIVES:"+str(lives)
		var ballx = ball.duplicate()
		ballx.connect("body_entered",self,"_on_Ball_body_entered")
		ballx.contact_monitor = true
		ballx.contacts_reported = 3
		add_child(ballx)
		ball = ballx
		if player !=null:
			ballx.global_position = player.get_node("Sprite").global_position + Vector2(0,-30)
		body.queue_free()
		if lives==0:
			get_tree().reload_current_scene()

func _on_Ball_body_entered(body):
	if body.is_in_group("brick"):
		body.remove_brick()
		score += 5
		$score.text = "SCORE:"+str(score)
		if get_tree().get_nodes_in_group("brick").size() == 0:
			$lives.text = "YOU WIN"
			$Ball.linear_velocity = Vector2(0,0)