Browse Source

Added button animations

tags/earlygalaxy
Madiwka3 4 years ago
parent
commit
6d13a08486
4 changed files with 70 additions and 18 deletions
  1. +21
    -0
      button.lua
  2. +19
    -1
      main.lua
  3. +20
    -12
      mainMenu.lua
  4. +10
    -5
      src/baseGame.lua

+ 21
- 0
button.lua View File

@@ -0,0 +1,21 @@
button = Class{}

function button:init(x, y, width, height, color)
self.x = x
self.y = y
self.w = width
self.h = height
self.color = color
end

function button:update(dt)

end



function button:render()
love.graphics.setColor(unpack(color))
love.graphics.rectangle("fill", self.x,self.y, self.w, self.h)
love.graphics.setColor(0, 0, 0, 255)
end

+ 19
- 1
main.lua View File

@@ -109,14 +109,25 @@ function newTouch(id, x, y)
originalY = y originalY = y
} }
end end
function newButton(text, fn)
function newButton(text, fn, sp)
if sp ~= nil then
return {
x = (VIRTUAL_WIDTH * 0.5) - VIRTUAL_WIDTH * (1/3)*0.5,
text = text,
fn = fn,
now = false,
last = false
}
else
return { return {
x = 1290,
text = text, text = text,
fn = fn, fn = fn,
now = false, now = false,
last = false last = false
} }
end end
end
function love.keyboard.mouseWasReleased() function love.keyboard.mouseWasReleased()
return love.keyboard.mouseisReleased return love.keyboard.mouseisReleased
end end
@@ -195,6 +206,7 @@ function love.load()
if globalState == "base" and gameState ~= "done" then if globalState == "base" and gameState ~= "done" then
paused = true paused = true
else else
resetButtonX(buttons)
TEXT = "Nuclear Pong" TEXT = "Nuclear Pong"
resettinggenius() resettinggenius()
paused = false paused = false
@@ -2378,4 +2390,10 @@ for i, touch in ipairs(touches) do
end end
end end
return false return false
end

function resetButtonX(arr)
for i, buttons in ipairs(arr) do
buttons.x = 1290
end
end end

+ 20
- 12
mainMenu.lua View File

@@ -71,7 +71,9 @@ function mainMenu:butt(gameState, VIRTUAL_WIDTH, VIRTUAL_HEIGHT, buttons, sounds
local total_height = (ev_BUTTON_HEIGHT + margin) * #buttons local total_height = (ev_BUTTON_HEIGHT + margin) * #buttons
local ev_bx, ev_by local ev_bx, ev_by
for i, button in ipairs(buttons) do for i, button in ipairs(buttons) do
print("Button")
button.last = button.now button.last = button.now
ev_bx = button.x
if (location == 'control') then if (location == 'control') then
if string.sub(button.text, 1, 1) == '2' then if string.sub(button.text, 1, 1) == '2' then
@@ -87,10 +89,12 @@ function mainMenu:butt(gameState, VIRTUAL_WIDTH, VIRTUAL_HEIGHT, buttons, sounds
elseif button.text == 'NUCLEAR MODE' and easternum < 11 then elseif button.text == 'NUCLEAR MODE' and easternum < 11 then
ev_bx = -400 ev_bx = -400
ev_by = -400 ev_by = -400
else
ev_bx = locationx - (ev_button_width * 0.5)
elseif button.x > locationx - (ev_button_width * 0.5) then
button.x = button.x - 15
ev_by = locationy - (total_height * 0.5) + cursor_y
else
ev_by = locationy - (total_height * 0.5) + cursor_y ev_by = locationy - (total_height * 0.5) + cursor_y
end
end
if (button.text == 'Play') and location == 'playercount' then color = {0/255, 255/255, 0/255, 255} else if (button.text == 'Play') and location == 'playercount' then color = {0/255, 255/255, 0/255, 255} else
color = {10, 10, 0, 255} color = {10, 10, 0, 255}
end end
@@ -119,7 +123,10 @@ function mainMenu:butt(gameState, VIRTUAL_WIDTH, VIRTUAL_HEIGHT, buttons, sounds
love.keyboard.mouseisReleased = false love.keyboard.mouseisReleased = false
love.graphics.setColor(0,0,0,1) love.graphics.setColor(0,0,0,1)
love.graphics.rectangle("fill", 0, 0, VIRTUAL_WIDTH, VIRTUAL_HEIGHT) love.graphics.rectangle("fill", 0, 0, VIRTUAL_WIDTH, VIRTUAL_HEIGHT)
sounds['wallhit']:play()
sounds['wallhit']:play()
for i, buttons in ipairs(buttons) do
buttons.x = 1280
end
button.fn() button.fn()
end end
love.graphics.setColor(unpack(color)) love.graphics.setColor(unpack(color))
@@ -156,7 +163,7 @@ function mainMenu:butt(gameState, VIRTUAL_WIDTH, VIRTUAL_HEIGHT, buttons, sounds
cursor_y = cursor_y + (ev_BUTTON_HEIGHT + margin) cursor_y = cursor_y + (ev_BUTTON_HEIGHT + margin)
else else
if (button.text == '1v1') then if (button.text == '1v1') then
love.graphics.print(playertext, smallfont, VIRTUAL_WIDTH*0.5 - textW*0.5, by+textH*0.5)
love.graphics.print(playertext, smallfont, ev_bx + ev_button_width*0.5 - textW*0.5, by+textH*0.5)
elseif button.text == 'snc' then elseif button.text == 'snc' then
if (nuckemodactive == 1) then if (nuckemodactive == 1) then
love.graphics.setColor(1,0,0,1) love.graphics.setColor(1,0,0,1)
@@ -165,28 +172,28 @@ function mainMenu:butt(gameState, VIRTUAL_WIDTH, VIRTUAL_HEIGHT, buttons, sounds
love.graphics.print(synctext, smallfont, VIRTUAL_WIDTH*0.5 - textW*0.7, ev_by+textH*0.5) love.graphics.print(synctext, smallfont, VIRTUAL_WIDTH*0.5 - textW*0.7, ev_by+textH*0.5)
love.graphics.setColor(0,0,0,1) love.graphics.setColor(0,0,0,1)
else else
love.graphics.print(synctext, smallfont, VIRTUAL_WIDTH*0.45 - textW*0.5, ev_by+textH*0.5)
love.graphics.print(synctext, smallfont, ev_bx + ev_button_width*0.5 - textW*0.5, ev_by+textH*0.5)
end end
elseif (button.text == 'ballCount') then elseif (button.text == 'ballCount') then
love.graphics.print("Ball Count: " .. maxBalls, smallfont, VIRTUAL_WIDTH*0.5 - textW*0.7, ev_by+textH*0.5)
love.graphics.print("Ball Count: " .. maxBalls, smallfont, ev_bx + ev_button_width*0.5 - textW*0.5, ev_by+textH*0.5)
elseif (button.text == "Ball Speed: ") then elseif (button.text == "Ball Speed: ") then
if (nuckemodactive == 1) then if (nuckemodactive == 1) then
love.graphics.setColor(1,0,0,1) love.graphics.setColor(1,0,0,1)
love.graphics.print("shaitan machina", smallfont, VIRTUAL_WIDTH*0.5 - textW*0.5, ev_by+textH*0.5)
love.graphics.print("shaitan machina", smallfont, ev_bx + ev_button_width*0.5 - textW*0.5, ev_by+textH*0.5)
love.graphics.setColor(1,1,1,1) love.graphics.setColor(1,1,1,1)
love.graphics.print("shaitan machina", smallfont, VIRTUAL_WIDTH*0.5 - textW*0.5, ev_by+textH*0.5)
love.graphics.print("shaitan machina", smallfont, ev_bx + ev_button_width*0.5 - textW*0.5, ev_by+textH*0.5)
love.graphics.setColor(0,0,0,1) love.graphics.setColor(0,0,0,1)
else else
love.graphics.print(button.text .. ballSet, smallfont, VIRTUAL_WIDTH*0.5 - textW*0.6, ev_by+textH*0.5)
love.graphics.print(button.text .. ballSet, smallfont, ev_bx + ev_button_width*0.5 - textW*0.5, ev_by+textH*0.5)
end end
elseif button.text == 'ptw' then elseif button.text == 'ptw' then
love.graphics.print("Points to Win: " .. ptw, smallfont,VIRTUAL_WIDTH*0.5 - textW * 2.8, ev_by+textH*0.5)
love.graphics.print("Points to Win: " .. ptw, smallfont, ev_bx + ev_button_width*0.5 - textW * 2.8, ev_by+textH*0.5)
elseif (button.text == 'Silverblade') then elseif (button.text == 'Silverblade') then
love.graphics.print("Difficulty: " .. prtext, smallfont, VIRTUAL_WIDTH*0.5 - textW , ev_by+textH*0.5) love.graphics.print("Difficulty: " .. prtext, smallfont, VIRTUAL_WIDTH*0.5 - textW , ev_by+textH*0.5)
else else
love.graphics.print(button.text, smallfont, locationx - textW*0.5, ev_by+textH*0.5)
love.graphics.print(button.text, smallfont, ev_bx + ev_button_width*0.5 - textW*0.5, ev_by+textH*0.5)
end end
love.graphics.setColor(255, 255, 255, 255) love.graphics.setColor(255, 255, 255, 255)
cursor_y = cursor_y + (ev_BUTTON_HEIGHT + margin) cursor_y = cursor_y + (ev_BUTTON_HEIGHT + margin)
@@ -197,6 +204,7 @@ function mainMenu:butt(gameState, VIRTUAL_WIDTH, VIRTUAL_HEIGHT, buttons, sounds
end end
function mainMenu:addButton(text, fn) function mainMenu:addButton(text, fn)
return { return {
x = 1290,
text = text, text = text,
fn = fn, fn = fn,
now = false, now = false,


+ 10
- 5
src/baseGame.lua View File

@@ -749,7 +749,8 @@ function menuDraw()
IPnew, IPnew,
function() function()
love.keyboard.setTextInput( true, 0, VIRTUAL_HEIGHT, VIRTUAL_WIDTH, VIRTUAL_HEIGHT/3) love.keyboard.setTextInput( true, 0, VIRTUAL_HEIGHT, VIRTUAL_WIDTH, VIRTUAL_HEIGHT/3)
end
end,
"stationary"
) )
) )
end end
@@ -763,7 +764,8 @@ function menuDraw()
gameState = "1serve" gameState = "1serve"
ball[1]:reset(1, 1) ball[1]:reset(1, 1)
player2.dy = 0 player2.dy = 0
end
end,
"stationary"
) )
) )
table.insert( table.insert(
@@ -773,7 +775,8 @@ function menuDraw()
function() function()
IP = IPnew IP = IPnew
counter = 0 counter = 0
end
end,
"stationary"
) )
) )
if status == "offline" then if status == "offline" then
@@ -790,7 +793,8 @@ function menuDraw()
gameState = "1serve" gameState = "1serve"
ball[1]:reset(1, 1) ball[1]:reset(1, 1)
player2.dy = 0 player2.dy = 0
end
end,
"stationary"
) )
) )
@@ -806,7 +810,8 @@ function menuDraw()
gameState = "1serve" gameState = "1serve"
ball[1]:reset(1, 1) ball[1]:reset(1, 1)
player2.dy = 0 player2.dy = 0
end
end,
"stationary"
) )
) )
elseif status == "full" then elseif status == "full" then


Loading…
Cancel
Save