0,]']±>Sï}WÿÍuU¾@Y4(%qy)6o;]ÉA¦ösï÷ôôô”°ÂVl†3= 128 end function tryMoveBy(pe,dx,dy) local nP = { x = pe.x + dx, y = pe.y + dy } if collideObj(pe,nP) then return end local upL = { x = pe.x - 8 + dx, y = pe.y - 8 + dy } local upR = { x = pe.x - 1 + dx, y = pe.y - 8 + dy } local dwL = { x = pe.x - 8 + dx, y = pe.y - 1 + dy } local dwR = { x = pe.x - 1 + dx, y = pe.y - 1 + dy } if not (blockTheWay(dwR) or blockTheWay(dwL) or blockTheWay(upR) or blockTheWay(upL)) then pe.qdf = pe.qdf + 0.1 if pe.qdf >= 3 then pe.qdf = 1 end pe.x = pe.x + dx pe.y = pe.y + dy end end function updateEnemy(e) local d = { x = 0, y = 0 } if e.y < p.y then d.y = 0.5 elseif p.y < e.y then d.y = -0.5 end tryMoveBy(e,d.x,d.y) d = { x = 0, y = 0 } if e.x < p.x then d.x = 0.5 e.f = 0 elseif p.x < e.x then d.x = -0.5 e.f = 1 end tryMoveBy(e,d.x,d.y) end function update() local a = { 256,257 } local f = { p.f,p.f,1,0 } local d = { {x=0,y=-1}, {x=0,y=1}, {x=-1,y=0}, {x=1,y=0} } for b = 0,3 do if btn(b) then local dl = d[b+1] tryMoveBy(p,dl.x,dl.y) local an = math.floor(p.qdf) p.s = a[an] p.f = f[b+1] end end collideObj(p,p) for i,e in pairs(o) do if e.t == "e" then updateEnemy(e) end end end function drawMap() map() end function drawPlr() spr(p.s,p.x-8,p.y-8,2,1,p.f) end function drawObj() for i,o in pairs(o) do spr(o.s,o.x-8,o.y-8,o.bgc,1,o.f) end end function draw() cls() drawMap() drawPlr() drawObj() end function collide(a,b) local al = a.x - 8 local ar = a.x - 1 local at = a.y - 8 local ab = a.y - 1 local bl = b.x - 8 local br = b.x - 1 local bt = b.y - 8 local bb = b.y - 1 if ar < bl or br < al or at > bb or bt > ab then return false end return true end function cPK(i) p.k = p.k + 1 sfx(0,60,32,0,8,0) table.remove(o,i) return false end function cPD(i) if p.k > 0 then sfx(1,24,32,0,8,0) table.remove(o,i) p.k = p.k - 1 return false end return true end function cPE(i) start() return true end function pS(i) return false end function cED(i) return true end function collideObj(p,nP) for i,o in pairs(o) do if collide(nP,o) then local cf = o.c[p.t] return cf(i) end end end color = 2 width = print("PRESS 'X' TO START!",0,-6) isRed = true isGreen = false isBlue = false timeToChangeColor = 0 function updColor() timeToChangeColor = timeToChangeColor - 1 if timeToChangeColor <= 0 then if isRed then color = 5 timeToChangeColor = 10 isGreen = true isRed = false isBlue = false elseif isGreen then color = 10 timeToChangeColor = 10 isBlue = true isRed = false isGreen = false elseif isBlue then color = 2 timeToChangeColor = 10 isRed = true isBlue = false isGreen = false end end end function printMenu() cls() spr(st,(xt + 8)//2,yt//2,0,2,0,0,wt,ht) spr(336,120 - 12,98,0,4) updColor() print("PRESS 'X' TO START!",(240-width)//2,(136-6)//2,color) end function updateMenu() if btn(5) then scr = "game" end end function TIC() if scr == "game" then update() draw() elseif scr == "start" then printMenu() updateMenu() end end function cK(c,l) local k = { s = 270, x = c * 8 + 8, y = l * 8 + 8, bgc = 2, f = 0, c = { p = cPK, e = pS } } return k end function cD(c,l) local d = { s = 271, x = c * 8 + 8, y = l * 8 + 8, bgc = 2, f = 0, c = { p = cPD, e = cED } } return d end function cE(c,l) local e = { t = "e", s = 259, x = c * 8 + 8, y = l * 8 + 8, qdf = 0, bgc = 0, f = 0, c = { p = cPE, e = pS } } return e end function start() p = { t = "p", s = 256, x = 16, y = 72, f = 0, qdf = 1, k = 0 } o = {} local k = cK(12,6) table.insert(o,k) local d = cD(15,13) table.insert(o,d) local e = cE(28,9) table.insert(o,e) scr = "start" end start()