Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add state machine #56

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions app/models/brick.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
class Brick < Engine::Model
include State

WIDTH = 75
HEIGHT = 40
PADDING = 5

attr_accessor :exploded
alias :exploded? :exploded
state Idle, events: [:explode]
# events :explode

def initialize(x, y, color: nil)
@x = x
Expand All @@ -16,16 +18,21 @@ def initialize(x, y, color: nil)
@exploded = false
end

def explode!
@exploded = true
end
class Idle < State
on_event :explode, transition_to: Exploding

def render
if exploded?
$args.outputs.sounds << "app/assets/sounds/blip.wav"
else
$args.outputs.solids << [x, y, width, height, *color]
$args.outputs.borders << [x, y, width, height, *border]
def render
$args.outputs.solids << [@parent.x, @parent.y, @parent.width, @parent.height, *@parent.color]
$args.outputs.borders << [@parent.x, @parent.y, @parent.width, @parent.height, *@parent.border]
end
end

class Exploding < State
include Sound

on_enter { play_sound "app/assets/sounds/blip.wav" }
on_tick { transition_to Exploded }
end

class Exploded < State; end
end