Advertisement
xerpi

cube 3d

Jul 17th, 2011
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.33 KB | None | 0 0
  1. mode={}
  2.     mode["Cube"] ={}
  3.     mode["3D"] ={}
  4.     mode["Classic"] ={}
  5.     mode["Connect-4"] ={}
  6. ----CUBE MODE
  7.     mode["Cube"].draw_board = function()
  8.         -----Blit the board --------
  9.                     --timers.rot = timers.rot + 0.02 --Increase this variable for rotating models
  10.                     local pos={}; local rot={}; local depth = 0
  11.                     for d = 1, board.depth do
  12.                         --The distance between "layers" of the cube
  13.                             depth = (d-2)*10                       
  14.                         for y = 1, board.height do
  15.                             for x = 1, board.width do  
  16.                                 --Calculate the position of empty models
  17.                                     pos.x = board.pos.x +((x-1)*board.w)
  18.                                     pos.y = board.pos.y + math.sin(-board.rot.x)*(y-2)*board.w +math.sin(1.57-board.rot.x)*depth
  19.                                     pos.z = board.pos.z + math.cos(-board.rot.x)*(y-2)*board.w +math.cos(1.57-board.rot.x)*depth
  20.                                 --Blit the empty models
  21.                                     models.empty_cube.model:rotation(board.rot.x ,board.rot.y, board.rot.z)
  22.                                     models.empty_cube.model:position(pos.x, pos.y, pos.z)                              
  23.                                     models.empty_cube.model:blit() 
  24.                                 if board.table[d][y][x] == "" then continue end
  25.                                 --If the current "chip" is not empty then
  26.                                
  27.                                     --Blit the model depending the player
  28.                                     if board.table[d][y][x] == board.player[1].st then  --Player 1
  29.                                         -- Model rotation
  30.                                             rot.x = board.rot.x + board.player[1].model.turning.x * timers.rot
  31.                                             rot.y = board.rot.y + board.player[1].model.turning.y * timers.rot
  32.                                             rot.z = board.rot.z + board.player[1].model.turning.z * timers.rot
  33.                                             board.player[1].model.model:position(pos.x, pos.y, pos.z)
  34.                                             board.player[1].model.model:rotation(rot.x, rot.y, rot.z)
  35.                                             board.player[1].model.model:blit()         
  36.                                     else                                            --Player 2 
  37.                                         -- Model rotation
  38.                                             rot.x = board.rot.x + board.player[2].model.turning.x * timers.rot
  39.                                             rot.y = board.rot.y + board.player[2].model.turning.y * timers.rot
  40.                                             rot.z = board.rot.z + board.player[2].model.turning.z * timers.rot
  41.                                             board.player[2].model.model:position(pos.x, pos.y, pos.z)
  42.                                             board.player[2].model.model:rotation(rot.x, rot.y, rot.z)
  43.                                             board.player[2].model.model:blit()             
  44.                                     end    
  45.                             end
  46.                         end
  47.                     end
  48.     end
  49.    
  50.  
  51.    
  52.    
  53.    
  54.    
  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. dofile("src/game.lua")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement