-- Scene: Classic Yoink -- created by Neil Carter -- converted to Lua by Charles McGarvey LogInfo("-----", "Scene: Classic", "Created by Neil Carter", "Converted to Lua by Charles McGarvey", "-----") -- Scene API: -- -- Functions: -- SetBounds(point1, point2) -- ResetTransform() -- Translate(x, y, z) -- Scale(x, y, z) or Scale(xyz) -- Rotate(axis, degree) or Rotate(x, y, z) -- SetTexture(name) -- DrawTilemap({width = $num, [surface = TOP | LEFT | RIGHT], tiles}) -- DrawTile(tile, [u_scale]) -- -- Globals: -- detail - level of detail of the scene (HIGH, MEDIUM, or LOW) SetBounds({-5, 0, -6}, {45, 15, 7}) -- Left end tower block -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- Front ResetTransform() Translate(-5, 0, 2) SetTexture("TowerBlock1") DrawTilemap({ width = 5, 2, 2, 2, 2, 2, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 4, 4, 4, 4, 4}) -- Right side ResetTransform() Rotate(Y, 90) Translate(0, 0, 2) DrawTilemap({ width = 5, surface = RIGHT, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 4, 5, 5, 5, 4}) -- Top ResetTransform() Rotate(X, 90) Translate(-5, 15, -3) DrawTilemap({ width = 5, surface = TOP, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3}) -- Leftmost background tower block -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- Front if detail > LOW then ResetTransform() Translate(0, 0, -3) DrawTilemap({ width = 7, 2, 2, 2, 2, 2, 2, 2, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 6, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 4, 4, 5, 5, 5, 4, 4}) -- Right side ResetTransform() Rotate(Y, 90) Translate(7, 0, -3) DrawTilemap({ width = 6, 2, 2, 2, 2, 2, 2, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 4, 4, 4, 4, 4, 4}) -- Top ResetTransform() Rotate(X, 90) Translate(-2, 8, -9) DrawTilemap({ width = 9, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3}) end -- Foreground building with pitched roof -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- Left wall ResetTransform() Rotate(Y, -90) Translate(10, 0, -2) SetTexture("Building") DrawTilemap({ width = 4, surface = LEFT, -1, 9, 11, -1, 9, 10, 12, 11, 15, 7, 7, 16, 3, 5, 6, 4, 3, 6, 5, 4}) -- Right wall ResetTransform() Rotate(Y, -90) Translate(13, 0, -2) DrawTilemap({ width = 4, surface = RIGHT, -1, 9, 11, -1, 9, 10, 12, 11, 15, 7, 7, 16, 3, 5, 6, 4, 3, 8, 5, 4}) -- Front wall ResetTransform() Translate(10, 0, 2) DrawTilemap({ width = 3, 15, 7, 16, 3, 5, 4, 3, 6, 4}) -- Pitched roof ResetTransform() Rotate(X, 135) Scale(1, 1.5, 1.5) Translate(10, 5, 0) DrawTilemap({ width = 3, 13, 13, 13, 13, 13, 13}) -- Finial ResetTransform() Translate(10, 5, -0.00001) DrawTilemap({ width = 3, 18, 18, 18}) -- Cheaty invisible platform -- This draws nothing but creates a platform on the roof for walking. ResetTransform() Rotate(X, 90) Translate(10, 5, 0) DrawTilemap({ width = 3, surface = TOP, -1, -1, -1}) -- The ground -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- Courtyard ResetTransform() Rotate(X, 90) Translate(-3, 0, -3) SetTexture("Scenery") DrawTilemap({ width = 13, surface = TOP, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1, -1, -1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1, -1, -1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1, -1, -1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}) -- Front grass if detail > MEDIUM then ResetTransform() Scale(8, 1, 1) Translate(1, -0.5, 2) DrawTile({ 2, u_scale = 8}) -- Back grass ResetTransform() Scale(8, 1, 1) Translate(1, -0.5, -2) DrawTile({ 2, u_scale = 8 }) -- Left grass ResetTransform() Scale(4, 1, 1) Rotate(Y, -90) Translate(1, -0.5, -2) DrawTile({ 2, u_scale = 4 }) -- Right grass ResetTransform() Scale(4, 1, 1) Rotate(Y, -90) Translate(9, -0.5, -2) DrawTile({ 2, u_scale = 4 }) -- Fence behind house ResetTransform() Scale(11, 1, 1) Translate(7, 0, -3) DrawTile({ 4, u_scale = 11 }) end -- Background building with pitched roof -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- Front wall if detail > LOW then ResetTransform() Translate(19, 0, -3) SetTexture("Building") DrawTilemap({ width = 4, -1, 9, 11, -1, 9, 10, 12, 11, 15, 7, 7, 16, 3, 6, 5, 4, 3, 5, 6, 4, 3, 8, 5, 4}) -- Left wall ResetTransform() Rotate(Y, -90) Translate(19, 0, -6) DrawTilemap({ width = 3, 15, 1, 16, 3, 7, 4, 3, 5, 4, 3, 0, 4}) -- Right wall ResetTransform() Rotate(Y, -90) Translate(23, 0, -6) DrawTilemap({ width = 3, 15, 0, 16, 3, 7, 4, 3, 6, 4, 3, 2, 4}) -- Left pitched roof ResetTransform() Rotate(X, 135) Scale(1, 1.5, 1.5) Rotate(Y, -90) Translate(21, 6, -6) DrawTilemap({ width = 3, 13, 13, 13, 13, 13, 13}) -- Right pitched roof ResetTransform() Rotate(X, -135) Scale(1, 1.5, 1.5) Rotate(Y, -90) Translate(21, 6, -6) DrawTilemap({ width = 3, 13, 13, 13, 13, 13, 13}) -- Finial ResetTransform() Rotate(Y, -90) Translate(21, 6, -6) DrawTilemap({ width = 3, 18, 18, 18}) end -- More ground to the right -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- Ground under house ResetTransform() Rotate(X, 90) Translate(10, 0, -3) SetTexture("Scenery") DrawTilemap({ width = 3, surface = TOP, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 1, 1}) -- Left part of center courtyard ResetTransform() Rotate(X, 90) Translate(13, 0, -3) DrawTilemap({ width = 8, surface = TOP, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0}) -- Front grass if detail > MEDIUM then ResetTransform() Scale(12, 1, 1) Translate(14, -0.5, 2) DrawTile({ 2, u_scale = 12 }) -- Back grass ResetTransform() Scale(4, 1, 1) Translate(14, -0.5, -2) DrawTile({ 2, u_scale = 4 }) -- Front grass next to door ResetTransform() Translate(13, -0.5, 0) DrawTile({ 2, u_scale = 1 }) -- Back grass next to door ResetTransform() Translate(13, -0.5, -1) DrawTile({ 2, u_scale = 1 }) -- Left grass ResetTransform() Rotate(Y, -90) Translate(14, -0.5, -2) DrawTilemap({ width = 4, 2, -1, 2, 2}) -- Grass left of house ResetTransform() Rotate(Y, -90) Translate(18, -0.5, -3) DrawTile({ 2, u_scale = 1 }) -- Grass right of house ResetTransform() Rotate(Y, -90) Translate(24, -0.5, -3) DrawTile({ 2, u_scale = 1 }) -- Front grass in center ResetTransform() Scale(4, 1, 1) Translate(19, -0.5, 1) DrawTile({ 2, u_scale = 4 }) -- Back grass in center ResetTransform() Scale(4, 1, 1) Translate(19, -0.5, -1) DrawTile({ 2, u_scale = 4 }) -- Left grass in center ResetTransform() Scale(2, 1, 1) Rotate(Y, -90) Translate(19, -0.5, -1) DrawTile({ 2, u_scale = 2 }) -- Right grass in center ResetTransform() Scale(2, 1, 1) Rotate(Y, -90) Translate(23, -0.5, -1) DrawTile({ 2, u_scale = 2 }) end -- Right part of center courtyard ResetTransform() Rotate(X, 90) Translate(21, 0, -3) DrawTilemap({ width = 7, surface = TOP, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1}) -- Fence to right of back house if detail > MEDIUM then ResetTransform() Scale(4, 1, 1) Translate(24, 0, -3) DrawTile({ 4, u_scale = 4 }) -- Grass in front of fence ResetTransform() Scale(4, 1, 1) Translate(24, -0.5, -2) DrawTile({ 2, u_scale = 4 }) -- Grass to left of tower block ResetTransform() Scale(2, 1, 1) Rotate(Y, -90) Translate(26, -0.5, 2) DrawTile({ 2, u_scale = 2 }) -- Grass to right of tower block ResetTransform() Scale(2, 1, 1) Rotate(Y, -90) Translate(35, -0.5, 2) DrawTile({ 2, u_scale = 2 }) -- Next bit of grass ResetTransform() Scale(5, 1, 1) Translate(35, -0.5, 2) DrawTile({ 2, u_scale = 5 }) -- Back grass ResetTransform() Scale(6, 1, 1) Translate(34, -0.5, -2) DrawTile({ 2, u_scale = 6 }) -- Extra bit of back grass ResetTransform() Rotate(Y, -90) Translate(34, -0.5, -3) DrawTile({ 2, u_scale = 1 }) end -- Ground around tower block ResetTransform() Rotate(X, 90) Translate(28, 0, 1) DrawTilemap({ width = 5, surface = TOP, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}) -- Rightmost ground ResetTransform() Rotate(X, 90) Translate(33, 0, -3) DrawTilemap({ width = 10, surface = TOP, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, 0, 1, 1, 1, 1, 1, 1, -1, -1, -1}) -- Right foreground tower block -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- Front ResetTransform() Translate(28, 0, 1) SetTexture("TowerBlock1") DrawTilemap({ width = 5, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 4, 4, 4, 4, 4}) -- Right side ResetTransform() Rotate(Y, 90) Translate(33, 0, 1) DrawTilemap({ width = 6, surface = RIGHT, 2, 2, 2, 2, 2, 2, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 5, 4, 5, 5, 4, 5}) -- Left side ResetTransform() Rotate(Y, 90) Translate(28, 0, 1) DrawTilemap({ width = 6, surface = LEFT, 2, 2, 2, 2, 2, 2, 0, 1, 6, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 5, 4, 5, 5, 4, 5}) -- Top ResetTransform() Rotate(X, 90) Translate(28, 7, -5) DrawTilemap({ width = 5, surface = TOP, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3}) -- Right end tower block -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- Front ResetTransform() Translate(40, 0, 2) DrawTilemap({ width = 5, 2, 2, 2, 2, 2, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 6, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 6, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 4, 4, 4, 4, 4}) -- Left side ResetTransform() Rotate(Y, 90) Translate(40, 0, 2) DrawTilemap({ width = 5, surface = LEFT, 2, 2, 2, 2, 2, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 5, 4}) -- Top ResetTransform() Rotate(X, 90) Translate(40, 15, -3) DrawTilemap({ width = 5, surface = TOP, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3}) -- Background -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ResetTransform() Translate(-0.32, -0.28, -27) Scale(105, 52, 1) SetTexture("BackgroundFar") DrawTile() Translate(0, 0, 5) SetTexture("BackgroundNear") DrawTile({ blend = detail > LOW and true or false }) -- Trees -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ SetTexture("Trees") -- Left courtyard if detail > LOW then ResetTransform() Scale(3) Translate(7.75, -0.1, -2.5) DrawTile(1) end -- Center courtyard ResetTransform() Scale(3) Translate(19, -0.1, -0.5) DrawTile(0) ResetTransform() Scale(3) Translate(20.25, -0.1, 0.5) DrawTile(1) -- Right courtyard if detail > LOW then ResetTransform() Scale(3) Translate(34, -0.1, -2.75) DrawTile(1) ResetTransform() Scale(3) Translate(36, -0.1, -3.5) DrawTile(0) ResetTransform() Scale(3) Translate(37, -0.1, -2.25) DrawTile(1) end -- Functions: -- DisplayText(text, seconds) -- Yield(seconds) -- SpawnItem(what, coords, timeout) -- SpawnRandomItem(coords, timeout) -- SpawnCharacter(what, coords, ai level) -- SpawnHeroine(coords) -- PlaySound(name) -- PlayMusic(name) -- BeginNewWave() -- Events: -- Think() is called periodically -- BadGuyDied(enemy) -- HeroineDied(player) -- Globals: -- numberOfBadGuys --do --SpawnHeroine({5, 5}) --local waveNum = BeginNewWave() --PopulateScene(waveNum) --end -- Events --------- Event = {} function Event:Think() end function Event:BadGuyDied(enemy) if numberOfBadGuys == 0 then local waveNum = BeginNewWave() PopulateScene(waveNum) end if math.random() <= 0.2 then SpawnRandomItem(enemy.position) end end -- Helper functions ------------------- function PopulateScene(waveNum) -- spawn some robot troopers local numBadGuys = math.random(3, 2 * waveNum) for i = 0, numBadGuys do SpawnCharacter("RobotTrooper", RandomSpawnPlace(), RandomSkillLevel()) end -- spawn some alien warriors if waveNum >= 10 then numBadGuys = math.random(3, 2 * waveNum) for i = 0, numBadGuys do SpawnCharacter("AlienWarrior", RandomSpawnPlace(), RandomSkillLevel()) end end -- spawn some jetbots if waveNum >= 20 then numBadGuys = math.random(3, 2 * waveNum) for i = 0, numBadGuys do SpawnCharacter("Jetbot", RandomSpawnPlace(), RandomSkillLevel()) end end end function RandomSpawnPlace() return {5, 5} end function RandomSkillLevel() return "dumb" end -- vim: ts=4 sw=4 tw=80