Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ----CUBE MODE
- --Draw board
- mode["Classic"].draw_board = function()
- -----Blit the board --------
- --timers.rot = timers.rot + 0.02 --Increase this variable for rotating models
- local pos={}; local rot={}; local depth = 0
- --The distance between "layers" of the cube
- depth = (1-board.nd)*board.depth_space
- for y = 1, board.height do
- for x = 1, board.width do
- --Calculate the position of empty models
- pos.x = board.pos.x +((x-board.nx)*board.width_space)
- pos.y = board.pos.y + math.sin(-board.rot.x)*(y-board.ny)*board.height_space +math.sin(1.57-board.rot.x)*depth
- pos.z = board.pos.z + math.cos(-board.rot.x)*(y-board.ny)*board.height_space +math.cos(1.57-board.rot.x)*depth
- --Blit the empty models if board.blit_empty is true
- if board.blit_empty then
- models.empty_cube.model:rotation(board.rot.x ,board.rot.y, board.rot.z)
- models.empty_cube.model:position(pos.x, pos.y, pos.z)
- models.empty_cube.model:blit()
- end
- if board.table[1][y][x] == "" then continue end
- --If the current "chip" is not empty then
- --Blit the model depending the player
- if board.table[1][y][x] == board.player[1].st then --Player 1
- -- Model rotation
- rot.x = board.rot.x + board.player[1].model.turning.x * timers.rot
- rot.y = board.rot.y + board.player[1].model.turning.y * timers.rot
- rot.z = board.rot.z + board.player[1].model.turning.z * timers.rot
- board.player[1].model.model:position(pos.x, pos.y, pos.z)
- board.player[1].model.model:rotation(rot.x, rot.y, rot.z)
- board.player[1].model.model:blit()
- else --Player 2
- -- Model rotation
- rot.x = board.rot.x + board.player[2].model.turning.x * timers.rot
- rot.y = board.rot.y + board.player[2].model.turning.y * timers.rot
- rot.z = board.rot.z + board.player[2].model.turning.z * timers.rot
- board.player[2].model.model:position(pos.x, pos.y, pos.z)
- board.player[2].model.model:rotation(rot.x, rot.y, rot.z)
- board.player[2].model.model:blit()
- end
- end
- end
- end
- --Move selector
- mode["Classic"].move_selector = function()
- --Move up
- if controls.press("up") then
- board.sel.y = board.sel.y - 1
- if board.sel.y < 1 then board.sel.y = board.height end
- end
- --Move down
- if controls.press("down") then
- board.sel.y = board.sel.y + 1
- if board.sel.y > board.height then board.sel.y = 1 end
- end
- --Move left
- if controls.press("left") then
- board.sel.x = board.sel.x - 1
- if board.sel.x < 1 then board.sel.x = board.width end
- end
- --Move right
- if controls.press("right") then
- board.sel.x = board.sel.x + 1
- if board.sel.x > board.width then board.sel.x = 1 end
- end
- end
- --Show (draw/blit) selector
- mode["Classic"].draw_selector = function()
- local pos={}
- local rot={}
- ---Position
- local depth = (board.sel.d-board.nd)*board.depth_space
- pos.x = board.pos.x +(((board.sel.x-board.nx))*board.width_space)
- 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
- 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
- --
- ---Rotation
- rot.x = board.rot.x
- rot.y = board.rot.y
- rot.z = board.rot.z
- ---Blit the selector ( yellow if free, red if filled)
- if board.table[board.sel.d][board.sel.y][board.sel.x] == "" then
- models.sel.model:position(pos.x, pos.y, pos.z)
- models.sel.model:rotation(rot.x, rot.y, rot.z)
- models.sel.model:blit()
- else
- models.sel2.model:position(pos.x, pos.y, pos.z)
- models.sel2.model:rotation(rot.x, rot.y, rot.z)
- models.sel2.model:blit()
- end
- --Blit blue cube is selected
- for i =1, #board.player do
- if board.player[i].selected then
- pos.x = board.pos.x +(((board.player[i].sel_pos.x-board.nx))*board.width_space)
- 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
- 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
- models.sel4.model:position(pos.x, pos.y, pos.z)
- models.sel4.model:rotation(rot.x, rot.y, rot.z)
- models.sel4.model:blit()
- end
- end
- end
- --Show (draw/blit) selector
- mode["Classic"].play_human = function()
- board.has_to_check=false
- screen.print(5,40, "1: "..board.player[1].putted.." 2:"..board.player[2].putted.." row:"..board.row)
- if controls.press("cross") then
- if board.player[board.turn].putted < board.row then
- if board.table[board.sel.d][board.sel.y][board.sel.x] == "" then
- board.table[board.sel.d][board.sel.y][board.sel.x] = board.player[board.turn].st
- board.player[board.turn].putted = board.player[board.turn].putted +1
- board.has_to_check=true
- mode.next_turn()
- end
- elseif board.player[board.turn].putted >= board.row then
- 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
- board.player[board.turn].sel_pos.x = board.sel.x
- board.player[board.turn].sel_pos.y = board.sel.y
- board.player[board.turn].selected =true
- elseif board.table[board.sel.d][board.sel.y][board.sel.x] == "" and board.player[board.turn].selected then
- board.table[board.sel.d][board.player[board.turn].sel_pos.y][board.player[board.turn].sel_pos.x] = ""
- board.player[board.turn].selected = false
- board.table[board.sel.d][board.sel.y][board.sel.x] = board.player[board.turn].st
- board.has_to_check=true
- mode.next_turn()
- 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
- board.player[board.turn].selected = false
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement