-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.lua
196 lines (167 loc) · 6.45 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
love.math.setRandomSeed( os.time() )
require('logic')
require('game')
require('test')
require('drawdice')
require('button')
require('bot')
require('ui')
require('net_server')
mainFont = love.graphics.newFont('font/Limelight-Regular.ttf',15)
bigFont = love.graphics.newFont('font/Limelight-Regular.ttf',128)
currentGame = nil
clientIndex = 1
clientBet = {face=2,count=1}
history = {}
previousRoundWinner = 0
previousRoundLoser = 0
globalState = "MENU"
-- Netcode related fields
online = false
notHost = false
local prev_state = ''
local timeAccumulate = 0
local rustleSound = love.audio.newSource( 'sound/rustle_dice.mp3','static' )
local callSound = love.audio.newSource( 'sound/call.mp3','static' )
local saySounds = {
love.audio.newSource( 'sound/say1.mp3','static' ),
love.audio.newSource( 'sound/say2.mp3','static' ),
love.audio.newSource( 'sound/say3.mp3','static' ),
love.audio.newSource( 'sound/say4.mp3','static' ),
love.audio.newSource( 'sound/say5.mp3','static' )
}
function love.load(arg)
love.window.setTitle("Liar's Dice by NotExplosive")
love.window.setMode(1024, 576, {
minwidth = 1024,
minheight = 576,
fullscreen = false,
resizable = true
})
end
love.graphics.setBackgroundColor(38, 43, 68)
function love.update(dt)
--networkUpdate(dt)
if currentGame then
if prev_state ~= currentGame.state then
prev_state = currentGame.state
end
if currentGame.state == 'game_over' then
currentGame = nil
globalState = "MENU"
end
if currentGame.state ~= 'game_over' then
if currentGame.currentPlayerIndex ~= clientIndex and currentGame.state ~= 'round_over' then
local estimate = estimateBoard(
currentGame.players[
currentGame.currentPlayerIndex]
.hand,
currentGame:totalDice())
timeAccumulate = timeAccumulate + dt
if timeAccumulate > love.math.random(3)/2 then
saySounds[love.math.random(5)]:play()
local output = botTurn(currentGame.players[currentGame.currentPlayerIndex].hand,currentGame:totalDice(),currentGame.currentBet)
if output.command == 'call' then
callSound:stop()
callSound:play()
local tbl = currentGame:call()
previousRoundWinner = tbl[1]
previousRoundLoser = tbl[2]
else
local bet = output.bet
local p = currentGame.currentPlayerIndex
if currentGame:submitBet(bet) then
history[#history+1] = {face=bet.face,count=bet.count,player=p}
end
end
timeAccumulate = 0
end
clientBet.face = currentGame.currentBet.face
clientBet.count = currentGame.currentBet.count
end
end
end
end
playerHandTimers = {}
function love.draw()
love.graphics.setColor(255,255,255)
-- Debug scaffolding
-- love.graphics.print(constructOutput())
love.graphics.setColor(255,255,255,10)
love.graphics.ellipse('fill', love.graphics.getWidth()/2, love.graphics.getHeight()/2, 500, 200)
love.graphics.setFont( bigFont )
love.graphics.print('Liar\'s Dice',love.graphics.getWidth()/2-love.graphics.getFont():getWidth('Liar\'s Dice')/2, love.graphics.getHeight()/2-64)
love.graphics.setFont( mainFont )
love.graphics.setColor(255,255,255,50)
love.graphics.print('by NotExplosive',love.graphics.getWidth()/2-love.graphics.getFont():getWidth('Liar\'s Dice')/2, love.graphics.getHeight()/2+64)
love.graphics.setColor(255,255,255)
startGameButton.visible = globalState == "MENU" and not (online and notHost)
--hostButton.visible = globalState == "MENU" and not online
--joinButton.visible = globalState == "MENU" and not online
exitButton.visible = globalState ~= "MENU"
for i = 1, #Buttons do
Buttons[i]:draw()
end
if currentGame then
-- offset for hands UI
-- TODO: change this whole architecture so each module has a root x,y
local x = love.graphics.getWidth()/2
local y = 16
if currentGame.state ~= 'game_over' then
if #history > 3 then
table.remove(history,1)
end
drawHistory(0,500)
local clientsTurn = clientIndex == currentGame.currentPlayerIndex
local roundStart = currentGame.state == 'round_start'
local roundMid = currentGame.state == 'round_mid'
local roundEnd = currentGame.state == 'round_over'
callButton.visible = clientsTurn and not roundStart and not roundEnd and not isValidBet(currentGame.currentBet,clientBet)
nextRoundButton.visible = roundEnd
betButton.visible = clientsTurn and not roundEnd and isValidBet(currentGame.currentBet,clientBet)
countUpButton.visible = clientsTurn and not roundEnd
countDownButton.visible = clientsTurn and not roundEnd
twoButton.visible = clientsTurn and not roundEnd
threeButton.visible = clientsTurn and not roundEnd
fourButton.visible = clientsTurn and not roundEnd
fiveButton.visible = clientsTurn and not roundEnd
sixButton.visible = clientsTurn and not roundEnd
if clientsTurn and (roundMid or roundStart) then
drawBet(clientBet,UI_ROOT.x-108,UI_ROOT.y,.5)
end
for i = 1, #currentGame.players do
local name = currentGame.players[i].name
if i == currentGame.currentPlayerIndex then
name = name .. '*'
end
local highlightFace = nil
if currentGame.state == 'round_over' then
highlightFace = currentGame.currentBet.face
if previousRoundWinner == i then
name = name .. ' winner!'
end
if previousRoundLoser == i then
name = name .. ' loser!'
end
end
love.graphics.setFont(mainFont)
love.graphics.setColor(255,255,255)
if i == clientIndex then
drawHand(currentGame.players[i],UI_ROOT.x-8,UI_ROOT.y-46,32,highlightFace,playerHandTimers,false)
else
local angle = i/#currentGame.players * math.pi + math.pi/2 + math.pi/4
local distance = 200
local ax,ay = love.graphics.getWidth()/2+math.cos(angle)*distance*2,love.graphics.getHeight()/2+math.sin(angle)*distance
if currentGame.state == 'round_over' then
drawHand(currentGame.players[i],ax,ay,32,highlightFace)
else
drawHiddenHand(currentGame.players[i],ax,ay,32)
end
end
love.graphics.setColor(255,255,255)
y = y + 46
end
drawBet(currentGame.currentBet,love.graphics.getWidth()/2-32-64,love.graphics.getHeight()/2-64)
end
end
end