Advertisement
xerpi

classic mode done

Jul 22nd, 2011
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.29 KB | None | 0 0
  1. ----CUBE MODE
  2.     --Draw board
  3.         mode["Classic"].draw_board = function()
  4.             -----Blit the board --------
  5.                         --timers.rot = timers.rot + 0.02 --Increase this variable for rotating models
  6.                         local pos={}; local rot={}; local depth = 0
  7.                             --The distance between "layers" of the cube
  8.                             depth = (1-board.nd)*board.depth_space                 
  9.                             for y = 1, board.height do
  10.                                 for x = 1, board.width do
  11.                                     --Calculate the position of empty models
  12.                                         pos.x = board.pos.x +((x-board.nx)*board.width_space)
  13.                                         pos.y = board.pos.y + math.sin(-board.rot.x)*(y-board.ny)*board.height_space +math.sin(1.57-board.rot.x)*depth
  14.                                         pos.z = board.pos.z + math.cos(-board.rot.x)*(y-board.ny)*board.height_space +math.cos(1.57-board.rot.x)*depth
  15.                                     --Blit the empty models if board.blit_empty is true
  16.                                         if board.blit_empty then
  17.                                             models.empty_cube.model:rotation(board.rot.x ,board.rot.y, board.rot.z)
  18.                                             models.empty_cube.model:position(pos.x, pos.y, pos.z)                              
  19.                                             models.empty_cube.model:blit() 
  20.                                         end
  21.                                     if board.table[1][y][x] == "" then continue end
  22.                                     --If the current "chip" is not empty then
  23.                                    
  24.                                         --Blit the model depending the player
  25.                                         if board.table[1][y][x] == board.player[1].st then  --Player 1
  26.                                             -- Model rotation
  27.                                                 rot.x = board.rot.x + board.player[1].model.turning.x * timers.rot
  28.                                                 rot.y = board.rot.y + board.player[1].model.turning.y * timers.rot
  29.                                                 rot.z = board.rot.z + board.player[1].model.turning.z * timers.rot
  30.                                                 board.player[1].model.model:position(pos.x, pos.y, pos.z)
  31.                                                 board.player[1].model.model:rotation(rot.x, rot.y, rot.z)
  32.                                                 board.player[1].model.model:blit()         
  33.                                         else                                            --Player 2 
  34.                                             -- Model rotation
  35.                                                 rot.x = board.rot.x + board.player[2].model.turning.x * timers.rot
  36.                                                 rot.y = board.rot.y + board.player[2].model.turning.y * timers.rot
  37.                                                 rot.z = board.rot.z + board.player[2].model.turning.z * timers.rot
  38.                                                 board.player[2].model.model:position(pos.x, pos.y, pos.z)
  39.                                                 board.player[2].model.model:rotation(rot.x, rot.y, rot.z)
  40.                                                 board.player[2].model.model:blit()             
  41.                                         end
  42.                                 end
  43.                             end
  44.         end
  45.        
  46.     --Move selector
  47.         mode["Classic"].move_selector = function()
  48.             --Move up
  49.                 if controls.press("up") then
  50.                     board.sel.y = board.sel.y - 1
  51.                     if board.sel.y < 1 then board.sel.y = board.height end
  52.                 end
  53.             --Move down
  54.                 if controls.press("down") then
  55.                     board.sel.y = board.sel.y + 1
  56.                     if board.sel.y > board.height then board.sel.y = 1 end
  57.                 end
  58.             --Move left
  59.                 if controls.press("left") then
  60.                     board.sel.x = board.sel.x - 1
  61.                     if board.sel.x < 1 then board.sel.x = board.width end
  62.                 end
  63.             --Move right
  64.                 if controls.press("right") then
  65.                     board.sel.x = board.sel.x + 1
  66.                     if board.sel.x > board.width then board.sel.x = 1 end
  67.                 end                    
  68.         end
  69.        
  70.     --Show (draw/blit) selector
  71.         mode["Classic"].draw_selector = function()
  72.             local pos={}
  73.             local rot={}
  74.                
  75.             ---Position
  76.                 local depth = (board.sel.d-board.nd)*board.depth_space         
  77.                 pos.x = board.pos.x +(((board.sel.x-board.nx))*board.width_space)
  78.                 pos.y = board.pos.y + math.sin(-board.rot.x)*(board.sel.y-board.ny)*board.height_space +math.sin(1.57-board.rot.x)*depth
  79.                 pos.z = board.pos.z + math.cos(-board.rot.x)*(board.sel.y-board.ny)*board.height_space +math.cos(1.57-board.rot.x)*depth
  80.                 --
  81.             ---Rotation
  82.                 rot.x = board.rot.x
  83.                 rot.y = board.rot.y
  84.                 rot.z = board.rot.z
  85.             ---Blit the selector ( yellow if free, red if filled)
  86.                 if board.table[board.sel.d][board.sel.y][board.sel.x] == "" then
  87.                     models.sel.model:position(pos.x, pos.y, pos.z)
  88.                     models.sel.model:rotation(rot.x, rot.y, rot.z)
  89.                     models.sel.model:blit()
  90.                 else
  91.                     models.sel2.model:position(pos.x, pos.y, pos.z)
  92.                     models.sel2.model:rotation(rot.x, rot.y, rot.z)
  93.                     models.sel2.model:blit()
  94.                 end
  95.             --Blit blue cube is selected
  96.                 for i =1, #board.player do
  97.                     if board.player[i].selected then
  98.                         pos.x = board.pos.x +(((board.player[i].sel_pos.x-board.nx))*board.width_space)
  99.                         pos.y = board.pos.y + math.sin(-board.rot.x)*(board.player[i].sel_pos.y-board.ny)*board.height_space +math.sin(1.57-board.rot.x)*depth
  100.                         pos.z = board.pos.z + math.cos(-board.rot.x)*(board.player[i].sel_pos.y-board.ny)*board.height_space +math.cos(1.57-board.rot.x)*depth
  101.                         models.sel4.model:position(pos.x, pos.y, pos.z)
  102.                         models.sel4.model:rotation(rot.x, rot.y, rot.z)
  103.                         models.sel4.model:blit()                   
  104.                     end
  105.                 end
  106.                                    
  107.            
  108.         end
  109.        
  110.     --Show (draw/blit) selector
  111.         mode["Classic"].play_human = function()
  112.             board.has_to_check=false
  113.             screen.print(5,40, "1: "..board.player[1].putted.."    2:"..board.player[2].putted.."   row:"..board.row)
  114.             if controls.press("cross") then
  115.                 if board.player[board.turn].putted < board.row then
  116.                     if board.table[board.sel.d][board.sel.y][board.sel.x] == "" then
  117.                         board.table[board.sel.d][board.sel.y][board.sel.x] = board.player[board.turn].st
  118.                          board.player[board.turn].putted =  board.player[board.turn].putted +1
  119.                         board.has_to_check=true
  120.                         mode.next_turn()
  121.                     end
  122.                 elseif board.player[board.turn].putted >= board.row then               
  123.                         if not board.player[board.turn].selected and board.table[board.sel.d][board.sel.y][board.sel.x] == board.player[board.turn].st then
  124.                             board.player[board.turn].sel_pos.x = board.sel.x
  125.                             board.player[board.turn].sel_pos.y = board.sel.y
  126.                             board.player[board.turn].selected =true
  127.                         elseif board.table[board.sel.d][board.sel.y][board.sel.x] == "" and board.player[board.turn].selected then
  128.                             board.table[board.sel.d][board.player[board.turn].sel_pos.y][board.player[board.turn].sel_pos.x] = ""
  129.                             board.player[board.turn].selected = false
  130.                             board.table[board.sel.d][board.sel.y][board.sel.x] = board.player[board.turn].st
  131.                             board.has_to_check=true
  132.                             mode.next_turn()
  133.                         elseif board.player[board.turn].selected and board.sel.y == board.player[board.turn].sel_pos.y and board.sel.x== board.player[board.turn].sel_pos.x then
  134.                             board.player[board.turn].selected = false                      
  135.                         end                
  136.                 end
  137.             end
  138.         end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement