Skip to content

Commit

Permalink
fix: prevent multiple pieces from adding at once
Browse files Browse the repository at this point in the history
User input was causing do_next_action to fire multiple times, which in
some cases led to multiple pieces starting at once. This adds a new
feature - add_piece_next_tick() - to opt-in to a new piece being added
on the next tick. We should still prevent next_action from firing
multiple times, but that's next and this is more resilient for all actions.
  • Loading branch information
russmatney committed Jun 22, 2024
1 parent af78636 commit 72b859e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
18 changes: 16 additions & 2 deletions src/BloxBucket.gd
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ func maybe_tick():
tick()

func tick():
if add_piece_on_tick:
add_piece_on_tick = false
start_next_piece()
resume_auto_ticking()
return

# step the grid forward
var any_change = grid.step(rule_inputs)

Expand All @@ -139,12 +145,17 @@ func pause_auto_ticking():
func resume_auto_ticking():
auto_ticking = true

var add_piece_on_tick = false
func add_piece_next_tick():
add_piece_on_tick = true

## on grid update ################################################

func do_next_action():
if action_queue.is_empty():
if grid_state == BloxGrid.STATE_SETTLING:
start_next_piece()
if not current_piece:
add_piece_next_tick()
maybe_tick()
return

Expand All @@ -158,7 +169,7 @@ func on_grid_update(state):
pause_auto_ticking()

match (state):
BloxGrid.STATE_SPLITTING, BloxGrid.STATE_CLEARING:
BloxGrid.STATE_SPLITTING, BloxGrid.STATE_CLEARING, BloxGrid.STATE_SETTLING:
# clear to prevent any user action
current_piece = null
_: pass
Expand Down Expand Up @@ -254,6 +265,9 @@ func on_rows_cleared(rows: Array):
## start_next_piece ################################################

func start_next_piece():
if current_piece:
Log.warn("already have a current_piece!?")

if len(piece_queue) < 4:
queue_pieces()

Expand Down
6 changes: 5 additions & 1 deletion src/BloxGame.gd
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@ var score = 0

@onready var next_piece_grid: GridContainer = $%PieceQueueGridContainer

@onready var crtv_effect = $%CRTVEffect

## ready #############################################

func _ready():
grid = bucket.grid

grid.on_groups_cleared.connect(func(groups):
for cells in groups:
add_to_score_label(len(cells)))
add_to_score_label(len(cells))
# TODO crtv_effect abberation tween
)
grid.on_rows_cleared.connect(func(rows):
for cells in rows:
add_to_score_label(len(cells)))
Expand Down
3 changes: 2 additions & 1 deletion src/BloxGame.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ shader_parameter/overlay = true
shader_parameter/scanlines_opacity = 0.2
shader_parameter/scanlines_width = 0.1
shader_parameter/grille_opacity = 0.2
shader_parameter/resolution = Vector2(640, 480)
shader_parameter/resolution = Vector2(1920, 1440)
shader_parameter/pixelate = true
shader_parameter/roll = true
shader_parameter/roll_speed = 1.2
Expand Down Expand Up @@ -155,6 +155,7 @@ custom_minimum_size = Vector2(2.08165e-12, 64)
layout_mode = 2

[node name="CRTVEffect" type="ColorRect" parent="UI"]
unique_name_in_owner = true
material = SubResource("ShaderMaterial_2o1j2")
anchors_preset = 15
anchor_right = 1.0
Expand Down

0 comments on commit 72b859e

Please sign in to comment.