Code: Select all
-- Using the keyword 'local' here is not required, but personally I
-- believe it is a good habit. It restricts the variable 'gamestate'
-- to just this file. It helps hide data in that way so that you avoid
-- conflicts with other files (e.g. accidentally re-using a name).
local gamestate = "intro"
-- You had originally wrapped these function definitions in an if-statement.
-- That is unnecessary.
function love.load()
WindowWidth = love.graphics.getWidth()
WindowHeight = love.graphics.getHeight()
love.graphics.setBackgroundColor(0, 50, 0)
darktree = love.graphics.newImage("dark tree.png")
stars = love.graphics.newImage("stars.png")
mage = love.graphics.newImage("mage.png")
warrior = love.graphics.newImage("warrior.png")
end
-- You should define drawinto() before you assign it anything.
function drawintro()
love.graphics.setColor(0, 0, 70)
love.graphics.rectangle("fill", 0, 0, WindowWidth, WindowHeight / 4)
love.graphics.setColor(255, 255, 255)
love.graphics.draw(stars , 0, 0, 0, 1, 0.75, 0, 0)
love.graphics.draw(darktree, WindowWidth / 2 - 300, WindowHeight / 2 - 200, 0, 1, 1, 0, 0)
love.graphics.draw(darktree, WindowWidth / 2 + 150, WindowHeight / 2 - 300, 0, 1, 1, 0, 0)
love.graphics.draw(darktree, WindowWidth / 2 + 100, WindowHeight / 2 - 100, 0, 1, 1, 0, 0)
love.graphics.setNewFont(12)
love.graphics.print("Welcome to the world of Dahamar, you now have to choose your path. Move with the arrows keys.", 100, 200, 0, 1, 1, 0, 0)
love.graphics.setColor(255, 10, 10)
love.graphics.setNewFont(30)
love.graphics.print("WARRIOR", 350, 30, 0, 1, 1, 0, 0)
love.graphics.setColor(10, 10, 255)
love.graphics.print("MAGE", 30 , 300, 0, 1, 1, 0, 0)
love.graphics.setColor(0, 0, 0)
love.graphics.print("THIEF/ASSASSIN", 540, 300, 0, 1, 1, 0, 0)
end
-- Defining this earlier for the same reason as drawintro().
function drawwarrior1()
love.graphics.draw(warrior, WindowWidth / 2 - 75, WindowHeight / 2 - 110, 0, 1, 1, 0, 0)
end
-- This is the most important part: LÖVE calls love.update() over and
-- over and over, for every 'tick' in the game. That means that
-- love.draw() will always use the drawinto() function (for all
-- intents and purposes) since love.update() does nothing but assign
-- drawinto() to the love.draw() function. Because the engine calls
-- love.update() so often that means you realistically do not have the
-- time to make the engine use any other drawing function.
--
-- So for that reason you want to change love.draw() here based on the
-- value of the 'gamestate' variable.
function love.update(dt)
if gamestate == "intro" then
love.draw = drawintro
elseif gamestate == "warrior1" then
love.draw = drawwarrior1
end
end
function love.keypressed(key)
if key == "up" then
gamestate = "warrior1"
end
end