NEW BRICK LEVEL FINAL
Kandif
plain_text
3 years ago
1.1 kB
41
Indexable
extends Node2D
var score = 0
var lives = 3
onready var player = $Player
onready var ball = $Ball
export var gameover:PackedScene
export var next_level:PackedScene
func _ready():
score = Global.score
lives = Global.lives
$GameLabel/Score.text = "SCORE: "+str(score)
$GameLabel/Lives.text = "LIVES: "+str(lives)
func _on_Area2D_body_entered(body):
if body is RigidBody2D:
lives -= 1
$GameLabel/Lives.text = "LIVES: "+str(lives)
var ballx = ball.duplicate()
ball = ballx
ballx.connect("body_entered",self,"_on_Ball_body_entered")
ballx.linear_velocity = Vector2(150,-150)
add_child(ballx)
if player !=null:
ballx.global_position = player.get_node("Sprite").global_position + Vector2(0,-30)
body.queue_free()
if lives==0:
get_tree().change_scene_to(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:
Global.score = score
Global.lives = lives
get_tree().change_scene_to(next_level)
Editor is loading...