Template
Code
State Machine
function _init() gsm = sm:new() gsm:setsts({ s_title, s_game, s_gameover }) gsm:init("title") end function _update() gsm:update() end function _draw() cls() gsm:draw() end |
State
s_game = state:new("game") function s_game:enter() psm = sm:new() psm:setsts({ ps_idle, ps_move, ps_dead:new() }) psm:init("idle") player:spawn(64, 96) end function s_game:update() psm:update() end function s_game:draw() psm:draw() player:draw() end |
Add State Properties
ps_dead = state:new("dead") function ps_dead:new(o) -- inherited state o = state.new(self, "dead") o.timer = 0 return o end function ps_dead:enter() start_shake(10, 10) end function ps_dead:update() update_shake() if self.timer >= 30 then gsm:trans("gameover") end self.timer += 1 end |
[Please log in to post a comment]