I seem to have an issue with gamestates. Again, it's probably stupid, but I really don't know.
I attempted to convert my gamestates into individual .lua files, so that they could easily be called back upon via HUMP. Now, although the menu screen loads up just fine, when I select the "Start" button, it appears to not load anything at all, despite me calling for it to load to "room1". I'm wondering how I can fix this so that it loads up the actual game, rather than a black screen.
The .luas in question:
main.lua
Code: Select all
require "player"
require "middleclass"
require "enemy"
gamestate = require("gamestate")
--States
menu = require("menu")
door = require("door")
room1 = require("room1")
room2 = require("room2")
room3 = require("room3")
battle = require("battle")
function love.load()
--Cleaning...
gr = love.graphics
kb = love.keyboard
gs = gamestate
gs.switch(menu)
--Loading Fonts
medium = gr.newFont("âëâmâxPOP.otf", 45)
--Loading Classes...
player.load()
enemy.new()
door.new()
-- Loading Background...
function BG()
gr.setBackgroundColor(0,155,0)
end
--Loading Barriers...
function DRAW_BAR()
gr.setColor(225,25,255)
gr.rectangle("fill",0,0,1280,250)
end
function DRAW_BAR2()
gr.setColor(210,25,155)
gr.rectangle("fill",0,0,1280,250)
end
function DRAW_BAR3()
gr.setColor(55,25,125)
gr.rectangle("fill",0,0,1280,250)
end
--Loading Battle screen
function DRAW_BSCREEN()
gr.setBackgroundColor(0,0,19)
end
-- Loading Objects
doors = {};
doors[1] = door.new(200, 160, 80, 90, 'room1');
doors[2] = door.new(500, 160, 80, 90, 'room2');
doors[3] = door.new(700, 160, 80, 90, 'room3');
enemies = {};
enemies[1] = enemy.new(900, 600, 'battle');
end
function love.update(dt)
mousex = love.mouse.getX()
mousey = love.mouse.getY()
gs.update(dt)
end
function love.keypressed(key)
end
function love.keyreleased(key)
end
function love.mousepressed(x,y)
gs.mousepressed(x,y)
button_click(x,y)
end
function love.mousereleased(x,y)
end
function love.draw()
gs.draw()
end
menu.lua
Code: Select all
button = {}
menu = {}
menu.gamestate = gamestate.new()
function menu:init()
--Loading Buttons
button_spawn(550, 200, "Start", "start")
button_spawn(550, 550, "Quit", "quit")
end
function button_spawn(x,y,text, id)
table.insert(button,{x = x, y = y, text = text, id = id, mouseover = false})
end
button.width = love.graphics.getWidth(text)
button.height = love.graphics.getHeight(text)
function button_draw()
for i, v in ipairs(button) do
if v.mouseover == false then
love.graphics.setColor(255,255,255)
end
if v.mouseover == true then
love.graphics.setColor(0,255,0)
end
love.graphics.setFont(medium)
love.graphics.print(v.text,v.x,v.y)
love.graphics.rectangle("line",v.x,v.y,button.width, button.height)
end
end
function button_click(x,y)
for i, v in ipairs(button) do
if x > v.x and
x < v.x + medium:getWidth(v.text) and
y > v.y and
y < v.y + medium:getHeight() then
if v.id == "quit" then
love.event.push("quit")
end
if v.id == "start" then
gs.switch(room1)
end
end
end
end
function button_check()
for i, v in ipairs(button) do
if mousex > v.x and
mousex < v.x + medium:getWidth(v.text) and
mousey > v.y and
mousey < v.y + medium: getHeight() then
v.mouseover = true
else
v.mouseover = false
end
end
end
function menu:update(dt)
button_check()
end
function love:mousepressed(x,y)
button_click(x,y)
end
function menu:draw()
button_draw()
end
return menu
room1.lua
Code: Select all
require "player"
require "door"
room1 = {}
local self = {}
room1.gamestate = gamestate.new()
function self:init()
end
function self:update(dt)
doors[2]:update(dt, player)
UPDATE_PLAYER(dt)
end
function self:draw()
BG()
DRAW_BAR()
DRAW_PLAYER()
doors[2]:draw()
end
return room1