Tutorial code 1
This commit is contained in:
parent
2ad6a0bc3a
commit
15e86c7940
@ -1,6 +1,7 @@
|
|||||||
board=klass()
|
board=klass()
|
||||||
|
|
||||||
function board:init(ruleset)
|
function board:init(watcher,ruleset)
|
||||||
|
self.watcher=watcher
|
||||||
self.ruleset=ruleset
|
self.ruleset=ruleset
|
||||||
self.cursor=cursor:new(self)
|
self.cursor=cursor:new(self)
|
||||||
self.animator=animator:new()
|
self.animator=animator:new()
|
||||||
@ -45,7 +46,7 @@ function board:init(ruleset)
|
|||||||
|
|
||||||
local seed=seeds:choose(self.ruleset.pool)
|
local seed=seeds:choose(self.ruleset.pool)
|
||||||
printh("chosen seed: "..tostr(seed,2))
|
printh("chosen seed: "..tostr(seed,2))
|
||||||
self:deal(seeds:choose(self.ruleset.pool))
|
self:deal(watcher.seed or seeds:choose(self.ruleset.pool))
|
||||||
end
|
end
|
||||||
|
|
||||||
function board:deal(seed)
|
function board:deal(seed)
|
||||||
@ -75,6 +76,7 @@ end
|
|||||||
|
|
||||||
function board:on_idle()
|
function board:on_idle()
|
||||||
self:find_automove()
|
self:find_automove()
|
||||||
|
self.watcher:update(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
function board:pre_move(card)
|
function board:pre_move(card)
|
||||||
@ -83,6 +85,7 @@ end
|
|||||||
|
|
||||||
function board:on_move()
|
function board:on_move()
|
||||||
self:find_automove()
|
self:find_automove()
|
||||||
|
self.watcher:update(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
function board:is_won()
|
function board:is_won()
|
||||||
@ -177,6 +180,8 @@ function board:draw()
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self.watcher:draw(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
slot=klass()
|
slot=klass()
|
||||||
|
3
main.p8
3
main.p8
@ -16,6 +16,9 @@ __lua__
|
|||||||
#include state_manager.lua
|
#include state_manager.lua
|
||||||
#include state_gameround.lua
|
#include state_gameround.lua
|
||||||
#include state_ironman.lua
|
#include state_ironman.lua
|
||||||
|
#include tutorial_watcher.lua
|
||||||
|
#include tutorial.lua
|
||||||
|
#include text.lua
|
||||||
#include main.lua
|
#include main.lua
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
state_gameround=klass()
|
state_gameround=klass()
|
||||||
function state_gameround:init(ruleset)
|
function state_gameround:init(watcher,ruleset)
|
||||||
self.board=board:new(ruleset)
|
self.board=board:new(watcher,ruleset)
|
||||||
end
|
end
|
||||||
function state_gameround:enter() end
|
function state_gameround:enter() end
|
||||||
function state_gameround:exit() end
|
function state_gameround:exit() end
|
||||||
|
|
||||||
function state_gameround:suspend() end
|
|
||||||
function state_gameround:reenter() end
|
function state_gameround:reenter() end
|
||||||
|
function state_gameround:suspend() end
|
||||||
|
|
||||||
function state_gameround:update()
|
function state_gameround:update()
|
||||||
self.board:update()
|
self.board:update()
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
state_ironman=klass()
|
state_ironman=klass()
|
||||||
function state_ironman:init(ruleset)
|
function state_ironman:init()
|
||||||
self.level=1
|
self.level=1
|
||||||
|
self.tutorial_enabled=true
|
||||||
end
|
end
|
||||||
|
|
||||||
function state_ironman:enter() self:on_enter() end
|
function state_ironman:enter() self:on_enter() end
|
||||||
@ -14,8 +15,10 @@ function state_ironman:on_enter()
|
|||||||
local level=self.level
|
local level=self.level
|
||||||
self.level+=1
|
self.level+=1
|
||||||
if level <= #progression then
|
if level <= #progression then
|
||||||
print("adding another state")
|
local watcher_fn=tutorial[level]
|
||||||
main.state_manager:push(state_gameround:new(progression[level]))
|
local watcher=tutorial_watcher:new()
|
||||||
|
if (self.tutorial_enabled and watcher_fn) watcher=watcher_fn()
|
||||||
|
main.state_manager:push(state_gameround:new(watcher, progression[level]))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
9
text.lua
Normal file
9
text.lua
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
function measure_text(s)
|
||||||
|
local w=0
|
||||||
|
local lines=split(s,"\n")
|
||||||
|
for l in all(lines) do
|
||||||
|
w=max(w,print(l,0,128))
|
||||||
|
end
|
||||||
|
local h=#lines*6
|
||||||
|
return w,h
|
||||||
|
end
|
12
tutorial.lua
Normal file
12
tutorial.lua
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
tutorial={
|
||||||
|
[1]=function()
|
||||||
|
return tutorial_watcher:new(10,{
|
||||||
|
tutorial_stage:new(
|
||||||
|
"slot",1,2,
|
||||||
|
tutorial_move_slot(1,1),
|
||||||
|
"stack on 5! (🅾️)",
|
||||||
|
function(b) return b:can_take_input() end
|
||||||
|
)
|
||||||
|
})
|
||||||
|
end
|
||||||
|
}
|
59
tutorial_watcher.lua
Normal file
59
tutorial_watcher.lua
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
tutorial_watcher=klass()
|
||||||
|
function tutorial_watcher:init(seed,stages)
|
||||||
|
self.seed=seed
|
||||||
|
self._stages=stages
|
||||||
|
end
|
||||||
|
function tutorial_watcher:update(board)
|
||||||
|
local stage=self._stages[1]
|
||||||
|
if (stage) stage:update(board)
|
||||||
|
end
|
||||||
|
function tutorial_watcher:active_stage(board)
|
||||||
|
local stage=self._stages[1]
|
||||||
|
if (stage and stage:active()) return stage
|
||||||
|
end
|
||||||
|
function tutorial_watcher:draw(board)
|
||||||
|
local stage=self:active_stage()
|
||||||
|
if (not stage) return
|
||||||
|
local layouts=board.ruleset.layouts
|
||||||
|
-- stop("calling: "..stage._layout_name)
|
||||||
|
local layout=layouts[stage._layout_name](layouts,stage._layout_arg)
|
||||||
|
local x,y=layout:place_card(stage._layout_arg_2)
|
||||||
|
|
||||||
|
local tx=stage._text
|
||||||
|
local w,h=measure_text(tx)
|
||||||
|
x+=4
|
||||||
|
x-=w\2
|
||||||
|
y+=25
|
||||||
|
local lx=x+w\2
|
||||||
|
line(lx,y-9,lx,y,15)
|
||||||
|
rectfill(x-2,y-2,x+w,y+h,1)
|
||||||
|
rect(x-2,y-2,x+w,y+h,15)
|
||||||
|
print(tx,x,y,15)
|
||||||
|
end
|
||||||
|
|
||||||
|
tutorial_stage=klass()
|
||||||
|
function tutorial_stage:init(layout_name,layout_arg,layout_arg_2,move,text,requirement_cb)
|
||||||
|
self._layout_name=layout_name
|
||||||
|
self._layout_arg=layout_arg
|
||||||
|
self._layout_arg_2=layout_arg_2
|
||||||
|
self._move=move
|
||||||
|
self._text=text
|
||||||
|
self._requirement_cb=requirement_cb
|
||||||
|
self._enabled=not self._requirement_cb
|
||||||
|
end
|
||||||
|
|
||||||
|
function tutorial_stage:update(board)
|
||||||
|
if (not self._enabled and self._requirement_cb(board)) self._enabled=true
|
||||||
|
end
|
||||||
|
|
||||||
|
function tutorial_stage:active()
|
||||||
|
return self._enabled
|
||||||
|
end
|
||||||
|
|
||||||
|
-- todo: restart?
|
||||||
|
function tutorial_move_undo()
|
||||||
|
return "undo"
|
||||||
|
end
|
||||||
|
function tutorial_move_slot(slot_src,slot_dst)
|
||||||
|
return tostr(slot_src).."->"..tostr(slot_dst)
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user