forked from xiroV/awesome-chess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
84 lines (73 loc) · 2.7 KB
/
main.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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
82
83
84
require "lib/tove"
require "lib/gooi"
require "chess/init"
require "chess/moves"
require "chess/utils"
require "chess/hud/menu"
function love.mousepressed(x, y, button, istouch)
if menuActive then
gooi.pressed()
else
if aiType == nil or aiType == "random" and colorTurn == "white" then
if button == 1 then
for i=8,1,-1 do
for j=1,8,1 do
pos=files[j]..ranks[i]
if x >= positions[pos].x and x < positions[pos].x + 96
and y >= positions[pos].y and y < positions[pos].y + 96 then
if positions[pos].piece ~= nil and positions[pos].piece.color == colorTurn then
selectedPos = pos
selectedPiece = positions[pos].piece.kind
selectedFile = positions[pos].file
selectedRank = positions[pos].rank
possibleMoves = getPosMoves(selectedPiece, selectedFile, selectedRank, colorTurn)
elseif positions[pos].piece == nil or positions[pos].piece.color == getEnemyColor(colorTurn) then
for k=1,#possibleMoves,1 do
if pos == possibleMoves[k] then
movePiece(selectedFile, selectedRank, j, i)
break
end
end
end
end
end
end
end
end
end
end
function love.draw()
love.graphics.translate(400, 400)
theBoard:draw()
love.graphics.origin()
-- Draw pieces
for i=8,1,-1 do
for j=1,8,1 do
pos=files[j]..ranks[i]
-- Mark possible moves
if table.len(possibleMoves) > 0 then
for k=1,table.len(possibleMoves),1 do
if possibleMoves[k] == pos then
markPosition(pos)
end
end
end
-- Mark selected move
if selectedPos == pos then
markPosition(pos)
end
-- Draw pieces
if positions[pos].piece ~= nil then
love.graphics.translate(positions[pos].center_x, positions[pos].center_y)
positions[pos].piece.asset:draw()
love.graphics.origin()
end
end
end
if menuActive then
drawMenu()
end
end
love.mousereleased = function(x, y, button)
gooi.released()
end