Advertisement
xerpi

RBM ALL POSITIONS

Jul 17th, 2011
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.83 KB | None | 0 0
  1. math.randomseed(os.time()) 
  2. os.cpu(333) --A little powah for loading all
  3. lcb = 0
  4. function loadcallback()
  5. screen.print(370,255,"Cargandeh"..string.sub("...",1,math.floor(lcb)))
  6. screen.flip()
  7. lcb = lcb + 0.05 if lcb > 4 then lcb = 0 end
  8. end
  9.  
  10.  
  11. prism = {obj=model.load("models/prism.obj")}
  12. exit = {obj=model.load("models/exit.obj")}
  13. cube = {obj=model.load("models/cube.obj")}
  14. floor = {obj=model.load("models/floor.obj")}
  15.  
  16. map = {
  17. {"","","","c",""},
  18. {"","","e","",""},
  19. {"","","","c",""},
  20. {"","","","",""},
  21. {"c","","","",""},
  22. }
  23. map.height = #map
  24. map.width = #map[1]
  25. map.w=10
  26. map.h=5
  27. map.d=10
  28.  
  29.  
  30. --Y->z
  31. --X->x
  32. --Z->y 
  33.  
  34. pos={x=-map.width*5+5,y=0,z=-75}
  35. rot={x=1,y=0,z=0}
  36.  
  37. prism.x = 1
  38. prism.y = 1
  39. prism.status = "horizontal_up"
  40. list={"vertical","horizontal_up","horizontal_down","horizontal_right","horizontal_left"}
  41. c=1
  42.  
  43. function blit_map()
  44.     local depth = 0
  45.     local p={x=0,y=0,z=0}
  46.     local r={x=0,y=0,z=0}
  47.     local sp = {x=0,y=0,z=0}
  48.     local sr = {x=0,y=0,z=0}
  49.     local ny = map.height/2
  50.         for y = 1, map.height do
  51.             for x = 1, map.width do
  52.                 --Calculate the position of empty models
  53.                     p.x = pos.x +((x-1)*map.w)
  54.                     p.y = pos.y + math.sin(-rot.x)*(y-ny)*map.w
  55.                     p.z = pos.z + math.cos(-rot.x)*(y-ny)*map.w
  56.                 --Blit the empty models
  57.                     floor.obj:rotation(rot.x ,rot.y, rot.z)
  58.                     floor.obj:position(p.x, p.y, p.z)                              
  59.                     floor.obj:blit()   
  60.                     if x== prism.x and y == prism.y then                   
  61.                         if prism.status == "horizontal_up" then
  62.                             sp.x = p.x
  63.                             sp.y = p.y+math.sin(1.57-rot.x)*15
  64.                             sp.z = p.z+math.cos(1.57-rot.x)*15
  65.                             sr.x = rot.x-1.57
  66.                             sr.y = rot.y
  67.                             sr.z = rot.z
  68.                         elseif prism.status == "horizontal_down" then
  69.                             sp.x = p.x
  70.                             sp.y = pos.y + math.sin(-rot.x)*((y-1)-ny)*map.w+math.sin(1.57-rot.x)*5
  71.                             sp.z = pos.z + math.cos(-rot.x)*((y-1)-ny)*map.w+math.cos(1.57-rot.x)*5
  72.                             sr.x = rot.x+1.57
  73.                             sr.y = rot.y
  74.                             sr.z = rot.z
  75.                         elseif prism.status == "horizontal_right" then
  76.                             sp.x = p.x
  77.                             sp.y = pos.y+ math.sin(-rot.x)*((y-1)-ny)*map.w+math.sin(1.57-rot.x)*15
  78.                             sp.z = pos.z + math.cos(-rot.x)*((y-1)-ny)*map.w+math.cos(1.57-rot.x)*15
  79.                             sr.x = rot.x-1.57
  80.                             sr.y = rot.y
  81.                             sr.z = rot.z-1.57
  82.                         elseif prism.status == "horizontal_left" then
  83.                             sp.x = pos.x +(x*map.w)
  84.                             sp.y = p.y+math.sin(1.57-rot.x)*15
  85.                             sp.z = p.z+math.cos(1.57-rot.x)*15
  86.                             sr.x = rot.x-1.57
  87.                             sr.y = rot.y
  88.                             sr.z = rot.z+1.57                  
  89.                         elseif prism.status == "vertical" then
  90.                             sp.x = p.x
  91.                             sp.y = p.y+math.sin(1.57-rot.x)*5
  92.                             sp.z = p.z+math.cos(1.57-rot.x)*5
  93.                             sr.x = rot.x
  94.                             sr.y = rot.y
  95.                             sr.z = rot.z
  96.                         end
  97.                         prism.obj:rotation(sr.x,sr.y,sr.z)
  98.                         prism.obj:position(sp.x,sp.y,sp.z)
  99.                         prism.obj:blit()
  100.                        
  101.                     end
  102.                     if map[y][x] != "" then
  103.                         if map[y][x] == "c" then
  104.                             cube.obj:position(p.x,p.y+math.sin(1.57-rot.x)*5,p.z+math.cos(1.57-rot.x)*5)
  105.                             cube.obj:rotation(rot.x,rot.y,rot.z)
  106.                             cube.obj:blit()
  107.                         elseif map[y][x] == "e" then
  108.                             exit.obj:position(p.x,p.y+math.sin(1.57-rot.x)*5,p.z+math.cos(1.57-rot.x)*5)
  109.                             exit.obj:rotation(rot.x,rot.y,rot.z)
  110.                             exit.obj:blit()    
  111.                         end
  112.                     end
  113.             end
  114.     end
  115.  
  116. end
  117.  
  118. function prism.move()
  119. if controls.press("down") then
  120.     prism.y = prism.y+1 if prism.y > map.height then prism.y = 1 end
  121. end
  122. if controls.press("up") then
  123.  
  124.     prism.y = prism.y-1 if prism.y < 1 then prism.y = map.height end
  125. end
  126. if controls.press("right") then
  127.     prism.x = prism.x+1 if prism.x > map.width then prism.x = 1 end
  128. end
  129. if controls.press("left") then
  130.     prism.x = prism.x-1 if prism.x < 1 then prism.x = map.width end
  131. end
  132. end
  133.  
  134.  
  135. while true do
  136. prism.status=list[c]
  137. controls.read()
  138.  
  139. if controls.start() then
  140.     --POS
  141.     if controls.up() then pos.y = pos.y+0.5 end
  142.     if controls.down() then pos.y = pos.y-0.5 end
  143.     if controls.left() then pos.x = pos.x-0.5 end
  144.     if controls.right() then pos.x = pos.x+0.5 end
  145.     if controls.l() then pos.z = pos.z-0.5 end
  146.     if controls.r() then pos.z = pos.z+0.5 end
  147.     --ROT
  148.     if controls.triangle() then rot.y = rot.y+0.05 end
  149.     if controls.cross() then rot.y = rot.y-0.05 end
  150.     if controls.square() then rot.x = rot.x-0.05 end
  151.     if controls.circle() then rot.x = rot.x+0.05 end
  152.     if math.abs(controls.analogy())> 50 then rot.x = rot.x+controls.analogy()/2000 end
  153. else
  154. prism.move()
  155. if controls.press("l") then c= c-1 if c<1 then c = #list end end
  156. if controls.press("r") then c= c+1 if c>#list then c = 1 end end
  157. end
  158.  
  159.  
  160. blit_map()
  161.  
  162.  
  163. screen.print(5,5,"ROT: ".." x:"..rot.x.." y:"..rot.y.." z:"..rot.z)
  164. screen.print(5,25,"POS: ".." x:"..pos.x.." y:"..pos.y.." z:"..pos.z)
  165. screen.print(5,45,"Prism: ".." x:"..prism.x.." y:"..prism.y.." status:"..prism.status)
  166. screen.print(425,5,"@"..screen.fps())
  167.  
  168. if controls.select() then a() end
  169. screen.flip()
  170. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement