186 lines
4.1 KiB
Text
186 lines
4.1 KiB
Text
-- Forge tutorial 2, "A platformer": types from the kit, entities dragged into place, rules on
|
|
-- the enter event, and a second room reached through a door. Continues from tutorial 1.
|
|
TUTORIAL = { number = 2, name = "02-platformer", tag = "TUTORIAL2" }
|
|
dofile("testScripts/tutorialDrive.singe")
|
|
|
|
local frames = 0
|
|
local stage = 0
|
|
local game = nil
|
|
|
|
tutorialBegin("01-tenMinutes")
|
|
|
|
|
|
-- Lights a type in the types panel with the arrow keys, as a reader would.
|
|
local function lightType(name)
|
|
local names = {}
|
|
local from, to = 1, 1
|
|
|
|
for typeName in pairs(FORGE.game.types) do
|
|
names[#names + 1] = typeName
|
|
end
|
|
table.sort(names)
|
|
for at, typeName in ipairs(names) do
|
|
if typeName == FORGE.typeName then
|
|
from = at
|
|
end
|
|
if typeName == name then
|
|
to = at
|
|
end
|
|
end
|
|
for _ = 1, math.abs(to - from) do
|
|
key((to > from) and SCANCODE.DOWN or SCANCODE.UP)
|
|
end
|
|
end
|
|
|
|
|
|
-- A type from the kit: A adds one, and the form names it, gives it a sprite from the kit, and
|
|
-- makes it a trigger.
|
|
local function kitType(name, file, anchor)
|
|
key(SCANCODE.MAIN_2)
|
|
key(SCANCODE.A)
|
|
form("name", name)
|
|
form("look", "sprite")
|
|
form("look.file", file)
|
|
if anchor then
|
|
form("look.anchor", anchor)
|
|
end
|
|
form("behaviours", "trigger")
|
|
end
|
|
|
|
|
|
-- An entity of the lit type, added and dragged to a spot.
|
|
local function place(x, y)
|
|
key(SCANCODE.MAIN_1)
|
|
key(SCANCODE.A)
|
|
local entry = forgeRoom().entities[FORGE.selected]
|
|
|
|
forgePress(entry.x, entry.y)
|
|
forgeDrag(x, y)
|
|
forgeRelease()
|
|
debugPrint(string.format("%s placed %s at %d, %d (held was %s)", TUTORIAL.tag, entry.id, entry.x, entry.y, tostring(FORGE.selected)))
|
|
end
|
|
|
|
|
|
local function step()
|
|
if stage == 1 then
|
|
kitType("coin", "coin.png")
|
|
tutorialShot("coinType")
|
|
|
|
elseif stage == 2 then
|
|
place(300, 392)
|
|
key(SCANCODE.D)
|
|
forgePress(320, 412)
|
|
forgeDrag(420, 392)
|
|
forgeRelease()
|
|
key(SCANCODE.D)
|
|
forgePress(440, 412)
|
|
forgeDrag(560, 300)
|
|
forgeRelease()
|
|
tutorialShot("coins")
|
|
|
|
elseif stage == 3 then
|
|
kitType("spike", "spike.png", "feet")
|
|
place(640, 420)
|
|
kitType("door", "door.png", "feet")
|
|
place(700, 420)
|
|
tutorialShot("placed")
|
|
|
|
elseif stage == 4 then
|
|
-- The first rule: a coin is taken.
|
|
key(SCANCODE.MAIN_3)
|
|
key(SCANCODE.N)
|
|
form("note", "Take a coin")
|
|
key(SCANCODE.E)
|
|
pick("enter")
|
|
form("a", "coin")
|
|
form("b", "hero")
|
|
key(SCANCODE.T)
|
|
pick("addScore")
|
|
form("amount", 10)
|
|
key(SCANCODE.T)
|
|
pick("destroy")
|
|
key(SCANCODE.T)
|
|
pick("playSound")
|
|
form("file", "coin.wav")
|
|
tutorialShot("rule")
|
|
|
|
elseif stage == 5 then
|
|
key(SCANCODE.N)
|
|
form("note", "Spikes hurt")
|
|
key(SCANCODE.E)
|
|
pick("enter")
|
|
form("a", "spike")
|
|
form("b", "hero")
|
|
key(SCANCODE.T)
|
|
pick("moveTo")
|
|
form("entity", "hero")
|
|
form("x", 200)
|
|
form("y", 380)
|
|
key(SCANCODE.T)
|
|
pick("playSound")
|
|
form("file", "hit.wav")
|
|
key(SCANCODE.N)
|
|
form("note", "Through the door")
|
|
key(SCANCODE.E)
|
|
pick("enter")
|
|
form("a", "door")
|
|
form("b", "hero")
|
|
key(SCANCODE.T)
|
|
pick("goTo")
|
|
form("room", "cave")
|
|
form("entity", "hero")
|
|
form("x", 60)
|
|
form("y", 380)
|
|
tutorialShot("rules")
|
|
|
|
elseif stage == 6 then
|
|
-- The second room: ground, a coin, and the readout.
|
|
key(SCANCODE.MAIN_1)
|
|
key(SCANCODE.N)
|
|
form("name", "cave")
|
|
key(SCANCODE.MAIN_2)
|
|
lightType("ground")
|
|
place(360, 440)
|
|
key(SCANCODE.MAIN_2)
|
|
lightType("readout")
|
|
place(12, 12)
|
|
key(SCANCODE.MAIN_2)
|
|
lightType("coin")
|
|
place(400, 392)
|
|
tutorialShot("cave")
|
|
|
|
elseif stage == 7 then
|
|
key(SCANCODE.S)
|
|
local built = tutorialEnd()
|
|
local mine = onOverlayUpdate
|
|
|
|
dofile(built)
|
|
game = onOverlayUpdate
|
|
onOverlayUpdate = mine
|
|
authorKeyDown(0, SCANCODE.RIGHT.value)
|
|
|
|
elseif stage == 10 then
|
|
tutorialShot("playing")
|
|
elseif stage == 12 then
|
|
local coins = authorCount and authorCount("coin") or -1
|
|
|
|
debugPrint(TUTORIAL.tag .. " after running right the score is " .. tostring(AUTHOR_VARS and AUTHOR_VARS.score) .. " and " .. tostring(coins) .. " coins remain")
|
|
debugPrint(TUTORIAL.tag .. " RESULT done")
|
|
singeQuit()
|
|
end
|
|
end
|
|
|
|
|
|
function onOverlayUpdate()
|
|
frames = frames + 1
|
|
if frames % 12 == 0 and stage < 12 then
|
|
stage = stage + 1
|
|
step()
|
|
end
|
|
if game ~= nil then
|
|
return game()
|
|
end
|
|
forgeDraw(nil, nil)
|
|
|
|
return OVERLAY_UPDATED
|
|
end
|