I can't guarantee any code here will work. This is just to explain what is wrong and give you an idea of how to fix it.
And please, for the love of god, use consistent indentation. I don't care about the specifics, but make sure everything is indented when it's inside a block of code (if statements, loops, functions, etc. should all have the code inside them indented, and indented the same amount.)
You don't seem to understand how the love.load, love.update, and love.draw functions work. I'm going to try to give you examples of how to fix your stuff, but
PLEASE go read some tutorials on game states and game loops. It's very clear from reading your code that you don't understand how they work (or how love works exactly). It's possible to write a game without understanding this stuff properly, but if you try to make something a bit more complicated than a really really basic game, it will be
much easier if you've got a good understanding of game loops and game states. I'd also suggest looking at how other people handle game states in their games, because that can be very informative.
love.load is called once, in the very beginning of your game. If you define it twice, like you did (line 16, and then line 43) only one of those will ever run. In this case, because your if statement on line 14 is true, it will call the love.load on line 16, and NEVER call the love.load on line 43, where you define background, Bleft and Bright. None of those will exist, because that code will never run.
What you need to do is put ALL your loading code in one single love.load() function which should look something like this:
Code: Select all
function love.load()
-- All this is from your first love.load
local newGame = loveframes.Create("button")
newGame:SetSize(TITLE.size.w, TITLE.size.h)
newGame:SetPos(TITLE.optionsX, TITLE.optionsY)
newGame:SetText("New Game")
newGame.OnClick = TITLE.newGame
local loadGame = loveframes.Create("button")
loadGame:SetSize(TITLE.size.w, TITLE.size.h)
loadGame:SetPos(TITLE.optionsX, TITLE.optionsY + TITLE.spacing)
loadGame:SetText("Load Game")
loadGame.OnClick = TITLE.loadGame
local exit = loveframes.Create("button")
exit:SetSize(TITLE.size.w, TITLE.size.h)
exit:SetPos(TITLE.optionsX, TITLE.optionsY + TITLE.spacing * 2)
exit:SetText("Exit")
exit.OnClick = TITLE.exit
TITLE.newGame = newGame
TITLE.loadGame = loadGame
TITLE.exit = exit
--all this is from your second love.load()
local background = love.graphics.newImage("Graphics/seven.jpg")
Bleft = love.graphics.newImage("Graphics/Bleft.png")
Bright = love.graphics.newImage("Graphics/Bright.png")
end
You also can't define love.update twice like you did (lines 66 and 107). The reason your loveframes buttons work is because the second love.update definition is the only one being called. It replaced the first one. Delete the second definition of love.update, and move the loveframes.update call onto the bottom of your first love.update. It should look like this:
Code: Select all
function love.update(dt)
-- you should probably put these inside an if statement to check if you're actually playing the game
if love.keyboard.isDown("down") then
y = y + (speed * dt)
end
if love.keyboard.isDown("up") then
y = y - (speed * dt)
end
if love.keyboard.isDown("right") then
x = x + (speed * dt)
Bunchie = Bleft
end
if love.keyboard.isDown("left") then
x = x - (speed * dt)
Bunchie = Bright
end
if love.keyboard.isDown("escape") then
love.event.push('quit')
end
loveframes.update(dt)
end
Please note that you should add an if statement around the section of ifs here to check your game state. You don't want to let a player change stuff when you're in the main menu!
love.update() is where most of your game logic should probably be.
Next, you define love.draw twice. This is also a problem. love.draw is also only called once every frame, and defining it again replaces the first definition with the second. This means that the code from line 102 will never run.
To fix your drawing code, you need to do 2 things:
You need to move all your drawing code into a single definition for love.draw()
And you're going to need to check what game state you're in.
It should look something like this:
Code: Select all
function love.draw() -- friendly reminder: things are drawn in the order you actually tell it to, be careful, you can hide things by drawing on top of them.
if gamestate == "menu" then
love.graphics.draw(TITLE.background)
loveframes.draw() --if you only use loveframes in the title menu, this is ok, if you're going to use it in the rest of the game, you need to move it outside this if statement.
end
if gamestate == "game" then
love.graphics.draw(background)
love.graphics.draw(Bunchie, x, y)
end
end
The basic idea of how love.draw() should work is that you have sections of code for every game state, using if statements to check which state you're in to determine what code should run.
You can also call other functions inside love.draw() In fact, my love.draw in something I've been working on looks like this right now:
Code: Select all
function love.draw()
mapRenderer:update()
-- spriteRenderer:update()
-- hudRenderer:update()
end
I won't go into detail, but there's a whole lot more code that goes into drawing the map that you don't see here. This keeps things cleaner and easier to understand, and means I don't need to look at the code for drawing the map unless I actually need to.