Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pico-8 cartridge // http://www.pico-8.com
- version 4
- __lua__
- --flier: test of tranus
- -- chris scott, 2015
- --btn(0) = left
- --btn(1) = right
- --btn(2) = up
- --btn(3) = down
- --btn(4) = z
- --btn(5) = x
- function makewall(s, h)
- -- size, height, id
- wall = {}
- wall.s = s
- wall.h = h
- wall.x = 127 -- screen pos
- add(w, wall)
- end
- function _init()
- debug = true -- set to false later
- size = 3
- height = 0
- pause = 200
- nextwall = 20 -- next wall time
- t = 0 -- time
- w = {} -- walls
- p1 = {} -- init player 1
- p1.x = 0 -- x pos
- p1.y = 0 -- y pos
- p1.f = 0 -- frame
- p1.fs = 0 -- first frame
- p1.fe = 5 -- last frame
- p1.roll = false -- are we rollin'?
- wsindex = {16,32,48} -- top, mid, bottom
- wid = 0 -- initial wall id
- end
- function _update()
- t += 1 -- increase time
- -- roll animation
- if p1.roll then
- if (p1.f < p1.fe) then
- p1.f += 1 -- animate the player
- else
- p1.f = p1.fs -- reset the sprite
- p1.roll = false --stop rollin'
- end
- end
- -- input
- if (btn(0)) then p1.x -= 1 end
- if (btn(1)) then p1.x += 1 end
- if (btn(2)) then p1.y -= 1 end
- if (btn(3)) then p1.y += 1 end
- if (btn(4)) then p1.roll = true end
- -- wall making
- if (t == nextwall) then
- wid += 1
- height += flr(rnd(20))-10
- makewall(size, height)
- nextwall += pause
- end
- -- wall moving
- if w then
- for i in all(w) do
- end
- end
- end
- function _draw()
- -- gotta clear the screen
- cls()
- -- draw player
- spr(p1.f, p1.x, p1.y)
- -- draw walls
- for i in all(w) do
- -- draw top edge
- spr(wsindex[3], w[i]["x"], w[i]["h"]-8)
- -- draw bottom edge
- spr(wsindex[1], w[i].x, w[i].h+w[i].s*8)
- end
- if debug then
- --wallx = w.wid.x
- print("tick "..t)
- print("wallid "..wid)
- print("walls")
- for i in all(w) do
- print(w[1].x)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement