Browse Source

Added button animations

tags/earlygalaxy
Madiwka3 3 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
}
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 {
x = 1290,
text = text,
fn = fn,
now = false,
last = false
}
end
end
function love.keyboard.mouseWasReleased()
return love.keyboard.mouseisReleased
end
@@ -195,6 +206,7 @@ function love.load()
if globalState == "base" and gameState ~= "done" then
paused = true
else
resetButtonX(buttons)
TEXT = "Nuclear Pong"
resettinggenius()
paused = false
@@ -2378,4 +2390,10 @@ for i, touch in ipairs(touches) do
end
end
return false
end

function resetButtonX(arr)
for i, buttons in ipairs(arr) do
buttons.x = 1290
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 ev_bx, ev_by
for i, button in ipairs(buttons) do
print("Button")
button.last = button.now
ev_bx = button.x
if (location == 'control') 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
ev_bx = -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
end
end
if (button.text == 'Play') and location == 'playercount' then color = {0/255, 255/255, 0/255, 255} else
color = {10, 10, 0, 255}
end
@@ -119,7 +123,10 @@ function mainMenu:butt(gameState, VIRTUAL_WIDTH, VIRTUAL_HEIGHT, buttons, sounds
love.keyboard.mouseisReleased = false
love.graphics.setColor(0,0,0,1)
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()
end
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)
else
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
if (nuckemodactive == 1) then
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.setColor(0,0,0,1)
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
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
if (nuckemodactive == 1) then
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.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)
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
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
love.graphics.print("Difficulty: " .. prtext, smallfont, VIRTUAL_WIDTH*0.5 - textW , ev_by+textH*0.5)
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
love.graphics.setColor(255, 255, 255, 255)
cursor_y = cursor_y + (ev_BUTTON_HEIGHT + margin)
@@ -197,6 +204,7 @@ function mainMenu:butt(gameState, VIRTUAL_WIDTH, VIRTUAL_HEIGHT, buttons, sounds
end
function mainMenu:addButton(text, fn)
return {
x = 1290,
text = text,
fn = fn,
now = false,


+ 10
- 5
src/baseGame.lua View File

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


Loading…
Cancel
Save