Advertisement
Guest User

Untitled

a guest
Apr 20th, 2015
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.81 KB | None | 0 0
  1. pico-8 cartridge // http://www.pico-8.com
  2. version 4
  3. __lua__
  4. --flier: test of tranus
  5. --      chris scott, 2015
  6.  
  7.  
  8. --btn(0) = left
  9. --btn(1) = right
  10. --btn(2) = up
  11. --btn(3) = down
  12. --btn(4) = z
  13. --btn(5) = x
  14.  
  15. function makewall(s, h)
  16.                                             -- size, height, id
  17.     wall = {}
  18.     wall.s = s
  19.     wall.h = h
  20.     wall.x = 127 -- screen pos
  21.     add(w, wall)
  22. end
  23.  
  24. function _init()
  25.     debug = true -- set to false later
  26.     size = 3
  27.     height = 0
  28.     pause = 200
  29.     nextwall = 20 -- next wall time
  30.     t = 0 -- time
  31.     w = {} -- walls
  32.     p1 = {} -- init player 1
  33.     p1.x = 0 -- x pos
  34.     p1.y = 0 -- y pos
  35.     p1.f = 0 -- frame
  36.     p1.fs = 0 -- first frame
  37.     p1.fe = 5 -- last frame
  38.     p1.roll = false -- are we rollin'?
  39.     wsindex = {16,32,48} -- top, mid, bottom
  40.     wid = 0 -- initial wall id
  41.    
  42. end
  43.  
  44. function _update()
  45.     t += 1 -- increase time
  46.    
  47.     -- roll animation
  48.     if p1.roll then
  49.         if (p1.f < p1.fe) then
  50.             p1.f += 1 -- animate the player
  51.         else
  52.             p1.f = p1.fs -- reset the sprite
  53.             p1.roll = false --stop rollin'
  54.         end
  55.     end
  56.    
  57.     -- input
  58.     if (btn(0)) then p1.x -= 1 end
  59.     if (btn(1)) then p1.x += 1 end
  60.     if (btn(2)) then p1.y -= 1 end
  61.     if (btn(3)) then p1.y += 1 end
  62.     if (btn(4)) then p1.roll = true end
  63.    
  64.     -- wall making
  65.     if (t == nextwall)  then
  66.         wid += 1
  67.         height += flr(rnd(20))-10
  68.         makewall(size, height)
  69.         nextwall += pause
  70.     end
  71.    
  72.     -- wall moving
  73.     if w then
  74.         for i in all(w) do
  75.            
  76.         end
  77.     end
  78. end
  79.  
  80. function _draw()
  81.     -- gotta clear the screen
  82.     cls()
  83.     -- draw player
  84.     spr(p1.f, p1.x, p1.y)
  85.    
  86.     -- draw walls
  87.     for i in all(w) do
  88.         -- draw top edge
  89.         spr(wsindex[3], w[i]["x"], w[i]["h"]-8)
  90.         -- draw bottom edge
  91.         spr(wsindex[1], w[i].x, w[i].h+w[i].s*8)
  92.     end
  93.     if debug then
  94.         --wallx = w.wid.x
  95.         print("tick "..t)
  96.         print("wallid "..wid)
  97.         print("walls")
  98.         for i in all(w) do
  99.             print(w[1].x)
  100.         end
  101.  end
  102.  
  103. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement