Commit a2192ffb by anshve

Upload New File

parent 542dde54
Showing with 176 additions and 0 deletions
MenuState = Class{__includes = BaseState}
function MenuState:enter(params)
self.currentMenuItem = 0
self.paddleColors = {
[0] = {255, 255, 255, 255},
[1] = {171/255, 0, 0, 255},
[2] = {0, 171/255, 0, 255},
[3] = {0, 0, 171/255, 255},
[4] = {186/255, 128/255, 65/255, 255/255}
}
self.menuItems = {
[0] = {
text = "Mode type: ",
selected = 0,
options = {
[0] = "Singleplayer",
[1] = "Multiplayer",
}
},
[1] = {
text = "1 Paddle color: ",
selected = 0,
options = {
[0] = "White",
[1] = "Red",
[2] = "Green",
[3] = "Blue",
[4] = "Brown",
}
},
[2] = {
text = "2 Paddle color: ",
selected = 0,
options = {
[0] = "White",
[1] = "Red",
[2] = "Green",
[3] = "Blue",
[4] = "Brown",
}
},
[3] = {
text = "Background: ",
selected = 0,
options = {
[0] = "Default",
[1] = "Football pitch",
[2] = "Ice pitch",
[3] = "TalTech pitch",
}
},
[4] = {
text = "Max Score: ",
selected = 0,
options = {
[0] = 5,
[1] = 7,
[2] = 10,
[3] = 15,
}
},
[5] = {
text = "Start Game"
}
}
paddle1 = Paddle(5, 20, PADDLE_WIDTH, PADDLE_HEIGHT)
paddle2 = Paddle(VIRTUAL_WIDTH - 10, VIRTUAL_HEIGHT - PADDLE_HEIGHT - 15, PADDLE_WIDTH, PADDLE_HEIGHT)
end
function MenuState:update(dt)
if love.keyboard.wasPressed('up') and self.currentMenuItem > 0 then
self.currentMenuItem = self.currentMenuItem - 1
gSounds['select']:play()
end
if love.keyboard.wasPressed('down') and self.currentMenuItem < #self.menuItems then
self.currentMenuItem = self.currentMenuItem + 1
gSounds['select']:play()
end
if love.keyboard.wasPressed('enter') or love.keyboard.wasPressed('return') then
if self.currentMenuItem == 5 then
gStateMachine:change('serve', {
mode = self.menuItems[0].selected,
background = self.menuItems[3].selected,
maxScore = self.menuItems[4].options[self.menuItems[4].selected],
paddle1 = paddle1,
paddle2 = paddle2
})
end
if self.currentMenuItem ~= 5 then
if self.menuItems[self.currentMenuItem].selected == #self.menuItems[self.currentMenuItem].options then
self.menuItems[self.currentMenuItem].selected = 0
else
self.menuItems[self.currentMenuItem].selected = self.menuItems[self.currentMenuItem].selected + 1
end
end
if self.currentMenuItem == 1 then
paddle1:changeColor(self.paddleColors[self.menuItems[self.currentMenuItem].selected])
elseif self.currentMenuItem == 2 then
paddle2:changeColor(self.paddleColors[self.menuItems[self.currentMenuItem].selected])
end
gSounds['select']:play()
end
end
function MenuState:render()
if self.menuItems[3].selected == 0 then
love.graphics.clear(40 / 255, 45 / 255, 52 / 255, 1)
else
local backgroundName = 'background-' .. self.menuItems[3].selected
local backgroundWidth = gTextures[backgroundName]:getWidth()
local backgroundHeight = gTextures[backgroundName]:getHeight()
love.graphics.draw(gTextures[backgroundName], 0, 0, 0, VIRTUAL_WIDTH / (backgroundWidth - 1), VIRTUAL_HEIGHT / (backgroundHeight - 1))
end
love.graphics.setFont(gFonts['large'])
self:drawTextShadow("PONG", 0, VIRTUAL_HEIGHT / 10)
love.graphics.setColor(1, 1, 1, 1)
love.graphics.printf("PONG", 0, VIRTUAL_HEIGHT / 10 , VIRTUAL_WIDTH, 'center')
love.graphics.setFont(gFonts['small'])
paddle1:render()
paddle2:render()
self:drawOptions()
end
function MenuState:drawOptions(y)
for i = 0, #self.menuItems do
local yGap = 16
local xGap = 36
local textYPos = VIRTUAL_HEIGHT / 3 + yGap * i
local selectedOption = self.menuItems[i].selected
if i == #self.menuItems then
textYPos = VIRTUAL_HEIGHT / 2 + 64
xGap = 0
end
self:drawTextShadow(self.menuItems[i].text, -xGap, textYPos)
if self.currentMenuItem == i then
love.graphics.setColor(252/255, 186/255, 3/255, 255/255)
else
love.graphics.setColor(1, 1, 1, 1)
end
love.graphics.printf(self.menuItems[i].text, -xGap, textYPos, VIRTUAL_WIDTH, 'center')
if i ~= #self.menuItems then
self:drawTextShadow(self.menuItems[i].options[selectedOption], xGap, textYPos)
love.graphics.setColor(1, 1, 1, 1)
love.graphics.printf(self.menuItems[i].options[selectedOption], xGap, textYPos, VIRTUAL_WIDTH, 'center')
end
love.graphics.setColor(1, 1, 1, 1)
end
end
function MenuState:drawTextShadow(text, x, y)
love.graphics.setColor(34/255, 32/255, 52/255, 255/255)
love.graphics.printf(text, x + 2, y + 1, VIRTUAL_WIDTH, 'center')
love.graphics.printf(text, x + 1, y + 1, VIRTUAL_WIDTH, 'center')
love.graphics.printf(text, x + 0, y + 1, VIRTUAL_WIDTH, 'center')
love.graphics.printf(text, x + 1, y + 2, VIRTUAL_WIDTH, 'center')
end
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment