Advertisement
xerpi

3D CUBE+POSITIONS

Jul 17th, 2011
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.50 KB | None | 0 0
  1. board.pos.x = -board.width*5+5
  2. board.pos.y = 0
  3. board.pos.z = -35
  4.  
  5. mode={}
  6.     mode["Cube"] ={}
  7.     mode["3D"] ={}
  8.     mode["Classic"] ={}
  9.     mode["Connect-4"] ={}
  10. ----CUBE MODE
  11.     mode["Cube"].draw_board = function()
  12.         -----Blit the board --------
  13.                     --timers.rot = timers.rot + 0.02 --Increase this variable for rotating models
  14.                     local pos={}; local rot={}; local depth = 0
  15.                     local nd = board.depth-board.depth/2+0.5
  16.                     local ny = board.height -board.height/2+0.5
  17.                     for d = 1, board.depth do
  18.                         --The distance between "layers" of the cube
  19.                             depth = (d-nd)*10                      
  20.                         for y = 1, board.height do
  21.                             for x = 1, board.width do  
  22.                                 --Calculate the position of empty models
  23.                                     pos.x = board.pos.x +((x-1)*board.w)
  24.                                     pos.y = board.pos.y + math.sin(-board.rot.x)*(y-ny)*board.w +math.sin(1.57-board.rot.x)*depth
  25.                                     pos.z = board.pos.z + math.cos(-board.rot.x)*(y-ny)*board.w +math.cos(1.57-board.rot.x)*depth
  26.                                 --Blit the empty models
  27.                                     models.empty_cube.model:rotation(board.rot.x ,board.rot.y, board.rot.z)
  28.                                     models.empty_cube.model:position(pos.x, pos.y, pos.z)                              
  29.                                     models.empty_cube.model:blit() 
  30.                                 if board.table[d][y][x] == "" then continue end
  31.                                 --If the current "chip" is not empty then
  32.                                
  33.                                     --Blit the model depending the player
  34.                                     if board.table[d][y][x] == board.player[1].st then  --Player 1
  35.                                         -- Model rotation
  36.                                             rot.x = board.rot.x + board.player[1].model.turning.x * timers.rot
  37.                                             rot.y = board.rot.y + board.player[1].model.turning.y * timers.rot
  38.                                             rot.z = board.rot.z + board.player[1].model.turning.z * timers.rot
  39.                                             board.player[1].model.model:position(pos.x, pos.y, pos.z)
  40.                                             board.player[1].model.model:rotation(rot.x, rot.y, rot.z)
  41.                                             board.player[1].model.model:blit()         
  42.                                     else                                            --Player 2 
  43.                                         -- Model rotation
  44.                                             rot.x = board.rot.x + board.player[2].model.turning.x * timers.rot
  45.                                             rot.y = board.rot.y + board.player[2].model.turning.y * timers.rot
  46.                                             rot.z = board.rot.z + board.player[2].model.turning.z * timers.rot
  47.                                             board.player[2].model.model:position(pos.x, pos.y, pos.z)
  48.                                             board.player[2].model.model:rotation(rot.x, rot.y, rot.z)
  49.                                             board.player[2].model.model:blit()             
  50.                                     end    
  51.                             end
  52.                         end
  53.                     end
  54.     end
  55.    
  56.  
  57.    
  58.    
  59.    
  60.    
  61.    
  62.    
  63.    
  64.    
  65.    
  66.    
  67.    
  68.    
  69.    
  70.    
  71.    
  72.    
  73.    
  74.    
  75.    
  76.    
  77.    
  78.    
  79.    
  80.    
  81.    
  82.    
  83.    
  84.    
  85.    
  86.    
  87. dofile("src/game.lua")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement