0,]']±>Sï}WÿÍu§ðp8·d%qy)6o;]ÉA¦ösï÷ôôô”°ÂVl†3 1 then snd = 0 end end end -- playsound function getDir() local tDir = dir[rnd(1, 6)] if bot.ld == nil then return tDir else if bot.ld == tDir then getDir() else return tDir end end end --getdir function move() mset(bot.x, bot.y, floorT) if rnd(1, 2) == rnd(1, 2) or d == nil then d = getDir() end if moveValid(d) then bot.d = d bot.x = bot.x + d.x bot.y = bot.y + d.y end end --move function moveValid(d) if bot.x + d.x > maxX - 2 or bot.x + d.x < minX + 2 or bot.y + d.y > maxY - 2 or bot.y + d.y < minY + 2 then return false else return true end end -- moveValid function countFloor() floor = {} local obj = {} local ft = 0 for xi = minX, maxX do for yi = minY, maxY do if mget(xi, yi) == floorT then ft = ft + 1 if xi == char.x or yi == char.y then obj = { x = xi, y = yi, free = 1} else obj = { x = xi, y = yi, free = 0} end table.insert(floor, obj) end end end return ft end --countFloor function buildLevel() while countFloor() < maxFloor do move() end mode = 2 end --buildLevel function gameOver() timer = timer + 1 cls(0) map(30, 0, 30, 17, 0, 0) print ("Game Over you scored : "..score, 40, 40, 12) print ("Enter your intials (3 letters)", 40, 48, 12) if string.len(name) < 3 then letter = getKey() if letter == "bs" then name = string.sub(name,1,string.len(name) - 1) elseif letter ~= "*" then name = name..letter end end print(name..string.rep("_",3 - string.len(name)),40,56, 12) if timer >= 500 and string.len(name) == 3 then writeHighScore() saveHighScore() mode = 7 timer = 0 level = 1 end end --gameover function reStart() cls(0) map(30, 0, 30, 17, 0, 0) print ("Press R to play again or Q to Quit ", 40, 40, 12) if key(17) then exit() end if key(18) then mode = 0 end if key(52) then deleteHighScore() end end -- reStart function startScreen() timer = timer + 1 cls(0) map(30, 0, 30, 17, 0, 0) -- print("You are a proud parent crab looking afrer", 10,10, 12) print("BW Jam Game Level "..level, 16,10, 12, false, 2) -- print("put them in the saftey of the rock pool", 10, 26, 12) -- print("but they keep tunnling out and escaping.", 10, 32, 12) print("Collect the sculls avoid Obstacles ", 10, 23, 12) print("Get ready to move "..(5 - math.floor(timer/60)).. " press S to start", 10, 31, 12) print("Move with the arrow keys or controller", 10, 39, 12) print("Collect sheild powerups then",10, 47, 12) print("press space to use the shield", 10, 55, 12) displayHighScore(50, 62) if timer > 300 or key(19) then mode = 3 end end -- startscreen function displayLevel() t = t + 1 cls() map(minX, MinY, maxX + 1, maxY + 1) moveChar() moveObst() drawChar() drawObs() drawSculls() drawShields() highLightChar() if t > 120 then mode = 5 end end -- displaylevel function playGame() cls() map(minX, MinY, maxX + 1, maxY + 1) moveChar() checkShieldAct() moveObst() drawChar() drawObs() drawSculls() drawShields() colliCharScull() if char.shieldLife == 0 then colliCharObst() end colliCharShield() displayUi() playSound() if lives < 1 then mode = 6 end if tblLen(sculls) < 1 then level = level + 1 lives = lives + level mode = 1 timer = 0 end end -- drawlevel function moveChar() -- char direction 0 - still, 4 - right, 8 - left if btnp(1, 6, 6) and not colliWall(char,"d") then char.y = char.y + char.ySpeed char.dir = 0 elseif btnp(3, 6, 6) and not colliWall(char, "r") then char.x = char.x + char.xSpeed char.dir = 4 elseif btnp(2, 6, 6) and not colliWall(char, "l") then char.x = char.x - char.xSpeed char.dir = 8 elseif btnp(0, 6, 6) and not colliWall(char, "u") then char.y = char.y - char.ySpeed char.dir = 0 else char.dir = 0 end end -- movechar function checkShieldAct() if char.shields > 0 and char.shieldLife < 1 then if key(48) then char.shields = char.shields - 1 char.shieldLife = 180 end end end --checkshieldact function drawChar() spr(char.sprno + (math.floor(char.frame) * char.w) + char.dir, char.x * 8, char.y * 8, 0, 1, 0, 0, char.w, char.h) if char.shieldLife > 0 then circb((char.x * 8) + 3, (char.y * 8) + 4, 4, 12) char.shieldLife = char.shieldLife - 1 end char.frame = char.frame + char.sSpeed if char.frame >= char.sframes then char.frame = 0 end end -- drawchar function highLightChar() if hlRad % 5 then circb((char.x * 8) + 4, (char.y * 8) + 4,hlRad, 12) end hlRad = hlRad + 1 if hlRad > hlRadMax then hlRad = 10 end end -- highlightchar function drawObs() local obj = {} for i, obj in ipairs(obst) do spr(obj.sprno + (math.floor(obj.frame) * obj.w) + obj.dir, obj.x * 8, obj.y * 8, 0, 1, 0, 0, obj.w, obj.h) obj.frame = obj.frame + obj.sSpeed if obj.frame >= obj.sframes then obj.frame = 0 end end end -- drawObs function drawShields() local obj = {} for i, obj in ipairs(shieldt) do spr(obj.sprno, obj.x * 8, obj.y * 8, 0, 1, 0, 0, obj.w, obj.h) end end -- drawshield function moveObst() local obj = {} for i, obj in ipairs(obst) do if obj.ySpeed > 0 then if not colliWall(obj,"d") then obj.y = obj.y + obj.ySpeed else obj.ySpeed = obj.ySpeed * -1 end end if obj.ySpeed < 0 then if not colliWall(obj,"u") then obj.y = obj.y + obj.ySpeed else obj.ySpeed = obj.ySpeed * -1 end end if obj.xSpeed > 0 then if not colliWall(obj,"r") then obj.x = obj.x + obj.xSpeed else obj.xSpeed = obj.xSpeed * -1 end end if obj.xSpeed < 0 then if not colliWall(obj,"l") then obj.x = obj.x + obj.xSpeed else obj.xSpeed = obj.xSpeed * -1 end end end end -- moveobst function drawSculls() local obj = {} for i, obj in ipairs(sculls) do spr(obj.sprno, obj.x * 8, obj.y * 8, 0, 1, 0, 0, obj.w, obj.h) end end -- drawsculls function displayUi() print("Score : "..score.." Lives : "..lives .." Level : "..level.." Sh : "..char.shields, 10, 1, 12) end -- display ui function colliCharScull() local obj = {} for i, obj in ipairs(sculls) do if objCollide(char, obj) then score = score + 100 sfx(2, "A-2", 15, 2, 8, 2) table.remove(sculls, i) end end end -- collicharscull function colliCharShield() local obj = {} for i, obj in ipairs(shieldt) do if objCollide(char, obj) then char.shields = char.shields + 1 table.remove(shieldt, i) end end end -- collicharshield function colliCharObst() local obj = {} for i, obj in ipairs(obst) do if objCollide(char, obj) then lives = lives - 1 char.x = startX -- move character back to start pos char.y = startY sfx(3, "F-2", 10, 2, 8, 2) end end end -- collicharobst function colliWall(obj, dir) local y = 0 local x = 0 if dir == "r" then x = math.floor(obj.x) else x = roundUp(obj.x) end if dir == "d" then y = math.floor(obj.y) else y = roundUp(obj.y) end if dir == "l" and mget(x - 1 , y) == wallT then return true elseif dir == "r" and mget(x + 1, y) == wallT then return true elseif dir == "d" and mget(x , y + 1) == wallT then return true elseif dir == "u" and mget(x, y - 1) == wallT then return true end end -- colliwall function tblLen(tbl) local len = 0 local obj = {} for i, obj in ipairs(tbl) do len = len + 1 end return len end -- tbllen function objCollide(objA, objB) local object1Left = (objA.x * 8) local object1Right = (objA.x * 8) + (objA.w * 8) - 1 local object1Top = (objA.y * 8) local object1Base = (objA.y * 8) + (objA.h * 8) - 1 local object2Left = (objB.x * 8) local object2Right = (objB.x * 8) + (objB.w * 8) - 1 local object2Top = (objB.y * 8) local object2Base = (objB.y * 8) + (objB.h * 8) - 1 if (object1Left < object2Right) and (object1Right > object2Left) and (object1Top < object2Base) and (object1Base > object2Top) then return true else return false end -- if end -- oc function loadHighScores() local memloc = 0 for i = 1, 8, 1 do local obj = {} obj.name = "" for i2 = 1, 3, 1 do obj.name = obj.name .. string.char(pmem(memloc)) memloc = memloc + 1 end obj.score = pmem(memloc) memloc = memloc + 1 table.insert(highScore, obj) end end -- loadhighscores function displayHighScore(xpos, ypos) local obj = {} print("High scores table", xpos, ypos, 12) for i, obj in ipairs(highScore) do if i < 9 then print(i.." - "..obj.name.." ... "..obj.score, xpos,ypos +(i * 8), 12) end end end -- displayhighscore function deleteHighScore() local obj = {} for i, obj in ipairs(highScore) do obj.name = " " obj.score = 0 end saveHighScore() end -- deletehighscore function writeHighScore() -- add players score and sort local obj = {} obj.name = name obj.score = score table.insert(highScore,obj) table.sort(highScore,function (k1, k2) return k1.score > k2.score end ) end -- writeHighScore function saveHighScore() local memloc = 0 local obj = {} for i, obj in ipairs(highScore) do for i2 = 1, 3, 1 do pmem(memloc, string.byte(obj.name, i2)) --obj.name[i2]) memloc = memloc + 1 end pmem(memloc, obj.score) memloc = memloc + 1 obj = {} end end -- savehighscore function getKey() local let = "*" for i,l in ipairs(keys) do if keyp(i,120,6) then let = l break end end return let end function roundUp(no) if no - math.floor(no) > 0 then return (no + 1) else return no end end -- roundUp