Advertisement
xerpi

RBM ALL DIRECTIONS!

Jul 17th, 2011
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.66 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. {"","","","",""},
  18. {"","","e","","c"},
  19. {"c","","","",""},
  20. {"","","","",""},
  21. {"","","","",""},
  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 = 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" 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" and xy(prism.y +2,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.  
  155. if controls.press("up") then
  156.     if prism.status == "vertical" then
  157.         if xy(prism.y -1,prism.x) != "c" and xy(prism.y -2,prism.x) != "c" then
  158.             prism.y = prism.y-1
  159.             prism.status = "up"
  160.         end
  161.     elseif prism.status == "up" then
  162.         if xy(prism.y -1,prism.x) != "c" and xy(prism.y -2,prism.x) != "c" then
  163.             prism.y = prism.y-2
  164.             prism.status = "vertical"  
  165.         end
  166.     elseif prism.status == "down" then
  167.         if xy(prism.y -1,prism.x) != "c" then
  168.             prism.y = prism.y-1
  169.             prism.status = "vertical"  
  170.         end
  171.     elseif prism.status == "right" then
  172.         if xy(prism.y -1,prism.x) != "c" and xy(prism.y -1,prism.x+1) != "c" then
  173.             prism.y = prism.y-1
  174.         end
  175.     elseif prism.status == "left" then
  176.         if xy(prism.y -1,prism.x) != "c" and xy(prism.y -1,prism.x-1) != "c" then
  177.             prism.y = prism.y-1
  178.         end
  179.     end
  180. end
  181.  
  182. if controls.press("right") then
  183.     if prism.status == "vertical" then
  184.         if xy(prism.y ,prism.x+1) != "c" and xy(prism.y ,prism.x+2) != "c" then
  185.             prism.x = prism.x+1
  186.             prism.status = "right" 
  187.         end
  188.     elseif prism.status == "up" then
  189.         if xy(prism.y ,prism.x+1) != "c" and xy(prism.y-1 ,prism.x+1) != "c" then
  190.             prism.x = prism.x+1
  191.         end
  192.     elseif prism.status == "down" then
  193.         if xy(prism.y ,prism.x+1) != "c" and xy(prism.y+1 ,prism.x+1) != "c" then
  194.             prism.x = prism.x+1
  195.         end
  196.     elseif prism.status == "right" then
  197.         if xy(prism.y ,prism.x+1) != "c" and xy(prism.y ,prism.x+2) != "c" then
  198.             prism.x = prism.x+2
  199.             prism.status = "vertical"
  200.         end
  201.     elseif prism.status == "left" then
  202.         if xy(prism.y ,prism.x+1) != "c" then
  203.             prism.x = prism.x+1
  204.             prism.status = "vertical"
  205.         end
  206.     end
  207. end
  208.  
  209. if controls.press("left") then
  210.     if prism.status == "vertical" then
  211.         if xy(prism.y ,prism.x-1) != "c" and xy(prism.y ,prism.x-2) != "c" then
  212.             prism.x = prism.x-1
  213.             prism.status = "left"  
  214.         end
  215.     elseif prism.status == "up" then
  216.         if xy(prism.y ,prism.x-1) != "c" and xy(prism.y-1 ,prism.x-1) != "c" then
  217.             prism.x = prism.x-1
  218.         end
  219.     elseif prism.status == "down" then
  220.         if xy(prism.y ,prism.x-1) != "c" and xy(prism.y+1 ,prism.x-1) != "c" then
  221.             prism.x = prism.x-1
  222.         end
  223.     elseif prism.status == "right" then
  224.         if xy(prism.y ,prism.x-1) != "c" then
  225.             prism.x = prism.x-1
  226.             prism.status = "vertical"
  227.         end
  228.     elseif prism.status == "left" then
  229.         if xy(prism.y ,prism.x-1) != "c" then
  230.             prism.x = prism.x-2
  231.             prism.status = "vertical"
  232.         end
  233.     end
  234. end
  235. end
  236.  
  237.  
  238. while true do
  239. --prism.status=list[c]
  240. controls.read()
  241.  
  242. if controls.start() then
  243.     --POS
  244.     if controls.up() then pos.y = pos.y+0.5 end
  245.     if controls.down() then pos.y = pos.y-0.5 end
  246.     if controls.left() then pos.x = pos.x-0.5 end
  247.     if controls.right() then pos.x = pos.x+0.5 end
  248.     if controls.l() then pos.z = pos.z-0.5 end
  249.     if controls.r() then pos.z = pos.z+0.5 end
  250.     --ROT
  251.     if controls.triangle() then rot.y = rot.y+0.05 end
  252.     if controls.cross() then rot.y = rot.y-0.05 end
  253.     if controls.square() then rot.x = rot.x-0.05 end
  254.     if controls.circle() then rot.x = rot.x+0.05 end
  255.     if math.abs(controls.analogy())> 50 then rot.x = rot.x+controls.analogy()/2000 end
  256. else
  257. prism.move()
  258. if controls.press("l") then c= c-1 if c<1 then c = #list end end
  259. if controls.press("r") then c= c+1 if c>#list then c = 1 end end
  260. end
  261.  
  262.  
  263. blit_map()
  264.  
  265.  
  266. screen.print(5,5,"ROT: ".." x:"..rot.x.." y:"..rot.y.." z:"..rot.z)
  267. screen.print(5,25,"POS: ".." x:"..pos.x.." y:"..pos.y.." z:"..pos.z)
  268. screen.print(5,45,"Prism: ".." x:"..prism.x.." y:"..prism.y.." status:"..prism.status)
  269. screen.print(425,5,"@"..screen.fps())
  270.  
  271. if controls.select() then a() end
  272. screen.flip()
  273. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement