this is my first year upon using Godot and have came up with a brickbreaking game where the blocks change color (red>blue) upon being hit via setting the textures. This reduces the counter by -1 each time the ball makes contact with the red block that turns blue (ball not to be confused with the larger, round paddle). The game ends when all blocks are blue.
However, the counter should not be reduced when the ball hits any blue block and I could not come up with a solution. The following scripts use singletons between the global.gd and the brick.gd scripts where score and texture changes occur.
To sum up, the counter should -1 when red blocks turn blue and should not be registered on the ball hitting any blue block.
This is my global:
var brick_counter = 0
var score = brick_counter
score -= 1
if (score <= 0):
print ("eat at Joe's")
And the brick script:
onready var area2d = get_node("Area2D")
var brick1 = load("res://sprites/brick.png")
var brick2 = load("res://sprites/brick_blue.png")
var texture_change = false
var score_stop = false
Global.score += 1
area2d.connect("body_entered", self, "_on_brick_body_entered")
var mysprite = get_node("sprite")
#if the ball hit the brick, the brick changes from red to blue
if body.get_name() == "ball":
texture_change = true
# if brick2:
# Global.brick_counter = Global.score
Any help on this little project of mine will be greatly appreciated.