114 lines
3.3 KiB
GDScript3
114 lines
3.3 KiB
GDScript3
extends Node
|
|
|
|
signal next_screen(screen_name)
|
|
|
|
var Ball = preload("res://ball/ball.tscn")
|
|
# List of levels
|
|
var Levels = [
|
|
# - Classic - #
|
|
preload("res://levels/level_01_01.tscn"), # "Breakout" - Disposition from the 1st breakout game
|
|
preload("res://levels/level_01_02.tscn"), # "Behind the wall" - Wall block
|
|
preload("res://levels/level_01_03.tscn"), # "Building" - Hard blocks
|
|
preload("res://levels/level_01_04.tscn"), # "Heart" - Half blocks
|
|
preload("res://levels/level_01_05.tscn"), # "Paw" - (no new block)
|
|
# - Hex - #
|
|
preload("res://levels/level_02_01.tscn"), # "Hive" - Hexagonal blocks
|
|
preload("res://levels/level_02_02.tscn"), # "Flowers" - Non-regular hexagons
|
|
preload("res://levels/level_02_03.tscn"), # "Leaves" - (no new block)
|
|
preload("res://levels/level_02_04.tscn"), # "Aquarium" - Fish blocks (+ Leaves)
|
|
preload("res://levels/level_02_05.tscn"), # "Stars" - Star3 blocks
|
|
# - Moving/Timing blocks - #
|
|
# "Invasion" - Left-right movement
|
|
# "Ghosts" - Blinking blocks : block appear / disappear
|
|
# "Gems" - Gravity blocks - cf. Boulder Dash
|
|
# "Many-Eyed Angel" - Blinking blocks 2 : wall / non-wall
|
|
# "Tris" - Falling blocks / appearing at random on the top
|
|
]
|
|
|
|
# Declare member variables here.
|
|
var ball = null # Ball on the field
|
|
var current_level = 0 # Index of the current levels
|
|
var level = null # Current level
|
|
var total_score = 0 # Score
|
|
var paused = false
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready():
|
|
pass
|
|
|
|
func init(level_index):
|
|
current_level = level_index
|
|
total_score = 0
|
|
update_score()
|
|
new_level()
|
|
new_ball()
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _process(_delta):
|
|
if not paused:
|
|
if Input.is_action_just_pressed('ui_accept'):
|
|
ball.detach()
|
|
if Input.is_action_just_pressed("ui_menu"):
|
|
emit_signal("next_screen", "pause")
|
|
|
|
func pause():
|
|
paused = true
|
|
$Paddle.pause()
|
|
ball.pause()
|
|
$BGM.stop()
|
|
|
|
func unpause():
|
|
$Paddle.unpause()
|
|
ball.unpause()
|
|
$BGM.play()
|
|
paused = false
|
|
|
|
func new_level():
|
|
level = Levels[current_level].instance()
|
|
level.connect("level_ended", self, "_on_level_ended")
|
|
level.connect("score_increased", self, "_on_score_increased")
|
|
$LevelName.text = level.level_name
|
|
call_deferred("add_child", level)
|
|
|
|
func new_ball():
|
|
ball = Ball.instance()
|
|
ball.init($Paddle.position, true)
|
|
var _connection = $Paddle.connect("moved", ball, "update_paddle_position")
|
|
ball.connect("ball_lost", self, "_on_ball_lost")
|
|
call_deferred("add_child", ball)
|
|
|
|
func _on_ball_lost():
|
|
total_score -= 1000
|
|
update_score()
|
|
new_ball()
|
|
|
|
func update_score():
|
|
$Score.text = str(total_score)
|
|
|
|
func get_score():
|
|
return total_score
|
|
|
|
func _on_score_increased(score):
|
|
total_score += score
|
|
update_score()
|
|
|
|
func _on_level_ended():
|
|
pause()
|
|
$LevelCleared.show()
|
|
$EndLevelTimer.start()
|
|
$JingleEnd.play()
|
|
|
|
|
|
func _on_EndLevelTimer_timeout():
|
|
$LevelCleared.hide()
|
|
unpause()
|
|
ball.disconnect("ball_lost", self, "_on_ball_lost")
|
|
level.queue_free()
|
|
ball.queue_free()
|
|
current_level = current_level + 1
|
|
if current_level >= Levels.size():
|
|
emit_signal("next_screen", "game_won")
|
|
else:
|
|
new_level()
|
|
new_ball()
|