Advertisement
xerpi

RBM HOR

Jul 17th, 2011
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.17 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 = 2
  38. prism.y = 2
  39. prism.status = "down"
  40. list={"vertical","up","down","right","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 == "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 == "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 == "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 == "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 xy(y,x)
  119.     if x >0 and y > 0 and x <= map.width and y<=map.height then
  120.         return map[y][x]
  121.     else
  122.         return "c"
  123.     end
  124. end
  125. prism.status = "vertical"
  126.  
  127. function prism.move()
  128. if controls.press("down") then
  129.     if prism.status == "vertical" then
  130.         if xy(prism.y +1,prism.x) != "c" and xy(prism.y +2,prism.x) != "c" then
  131.             prism.y = prism.y+1
  132.             prism.status = "down"  
  133.         end
  134.     elseif prism.status == "up" then
  135.         if xy(prism.y +1,prism.x) != "c" and xy(prism.y +2,prism.x) != "c" then
  136.             prism.y = prism.y+1
  137.             prism.status = "vertical"  
  138.         end
  139.     elseif prism.status == "down" then
  140.         if xy(prism.y +1,prism.x) != "c" then
  141.             prism.y = prism.y+2
  142.             prism.status = "vertical"  
  143.         end
  144.     elseif prism.status == "right" then
  145.         if xy(prism.y +1,prism.x) != "c" and xy(prism.y +1,prism.x+1) != "c" then
  146.             prism.y = prism.y+1
  147.         end
  148.     elseif prism.status == "left" then
  149.         if xy(prism.y +1,prism.x) != "c" and xy(prism.y +1,prism.x-1) != "c" then
  150.             prism.y = prism.y+1
  151.         end
  152.     end
  153. end
  154. if controls.press("up") then
  155.     if prism.status == "vertical" then
  156.         if xy(prism.y -1,prism.x) != "c" and xy(prism.y -2,prism.x) != "c" then
  157.             prism.y = prism.y-1
  158.             prism.status = "up"
  159.         end
  160.     elseif prism.status == "up" then
  161.         if xy(prism.y -1,prism.x) != "c" and xy(prism.y -2,prism.x) != "c" then
  162.             prism.y = prism.y-2
  163.             prism.status = "vertical"  
  164.         end
  165.     elseif prism.status == "down" then
  166.         if xy(prism.y -1,prism.x) != "c" then
  167.             prism.y = prism.y-1
  168.             prism.status = "vertical"  
  169.         end
  170.     elseif prism.status == "right" then
  171.         if xy(prism.y -1,prism.x) != "c" and xy(prism.y -1,prism.x+1) != "c" then
  172.             prism.y = prism.y-1
  173.         end
  174.     elseif prism.status == "left" then
  175.         if xy(prism.y -1,prism.x) != "c" and xy(prism.y -1,prism.x-1) != "c" then
  176.             prism.y = prism.y-1
  177.         end
  178.     end
  179. end
  180. if controls.press("right") then
  181.    
  182. end
  183. if controls.press("left") then
  184.  
  185. end
  186. end
  187.  
  188.  
  189. while true do
  190. --prism.status=list[c]
  191. controls.read()
  192.  
  193. if controls.start() then
  194.     --POS
  195.     if controls.up() then pos.y = pos.y+0.5 end
  196.     if controls.down() then pos.y = pos.y-0.5 end
  197.     if controls.left() then pos.x = pos.x-0.5 end
  198.     if controls.right() then pos.x = pos.x+0.5 end
  199.     if controls.l() then pos.z = pos.z-0.5 end
  200.     if controls.r() then pos.z = pos.z+0.5 end
  201.     --ROT
  202.     if controls.triangle() then rot.y = rot.y+0.05 end
  203.     if controls.cross() then rot.y = rot.y-0.05 end
  204.     if controls.square() then rot.x = rot.x-0.05 end
  205.     if controls.circle() then rot.x = rot.x+0.05 end
  206.     if math.abs(controls.analogy())> 50 then rot.x = rot.x+controls.analogy()/2000 end
  207. else
  208. prism.move()
  209. if controls.press("l") then c= c-1 if c<1 then c = #list end end
  210. if controls.press("r") then c= c+1 if c>#list then c = 1 end end
  211. end
  212.  
  213.  
  214. blit_map()
  215.  
  216.  
  217. screen.print(5,5,"ROT: ".." x:"..rot.x.." y:"..rot.y.." z:"..rot.z)
  218. screen.print(5,25,"POS: ".." x:"..pos.x.." y:"..pos.y.." z:"..pos.z)
  219. screen.print(5,45,"Prism: ".." x:"..prism.x.." y:"..prism.y.." status:"..prism.status)
  220. screen.print(425,5,"@"..screen.fps())
  221.  
  222. if controls.select() then a() end
  223. screen.flip()
  224. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement