HELP! GameStates from scratch. (Intro > Menu > Game)

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Shepherd()
Prole
Posts: 5
Joined: Wed Apr 23, 2014 7:34 pm

HELP! GameStates from scratch. (Intro > Menu > Game)

Post by Shepherd() »

I'm a bit of a newbie. I;m having difficulty getting my gamestates to run properly. When I run I get a black screen. The issue seems to be from the Introstate based on my own assessment. Any help to get this to run would be much appreciated, my mental state is degrading.

Code: Select all

--main.lua

require "conf"
require "introstate"
require "menustate"
require "gamestate"
require "statesystems"
require "menubuttons"

function love.load()

	switchState("Intro")
	
	TitleScreen:start()
	
	GameTitle = love.graphics.newImage ("images/hologram18.jpg")
	CompanyLogo = love.graphics.newImage ("images/Shepherd001.jpg")
	
	if currentState == "Intro" then
		love.graphics.setBackgroundColor(0,0,0)
	end
	
	if currentState == "Menu" then
	button_spawn(375, 175, "Start", "start")
	button_spawn(375, 475, "Quit", "quit")
	end

	small = love.graphics.newFont(25)
	medium = love.graphics.newFont(50)
	large = love.graphics.newFont(80)	
	


end

function love.update(dt)
	
	mousex = love.mouse.getX()
	mousey = love.mouse.getY()
	
	if currentState == "Intro" then
		TitleScreen.update(dt)
	end
	
	if currentState == "Menu" then
		button_check()
	end
	

--		stateDrawCurrentState()
--		stateGetCurrentStateInput()		

end

function love.draw()
	
	if currentState == "Intro" then
		TitleScreen.draw()
	end

	if currentState == "Menu" then
		button_draw()
	end
	
	if currentState == "Game" then
		love.graphics.setFont(small)
		love.graphics.print("Temp Game State", 325, 275)
	end
end

function love.mousepressed(x,y,button)
	
	if currentState == "Menu" then
		button_click(x,y)
	end
end

Code: Select all

--introstate.lua

TitleScreen = {}

local self = TitleScreen;

function TitleScreen.start()
  self.objects = {}
  self.co = coroutine.wrap(function()
    wait(1)
    self.objects[1] = love.graphics.draw(CompanyLogo, 200, 200)
    wait(2)
    self.objects[1] = nil
    wait(1)
    self.objects[1] = love.graphics.draw(GameTitle, 200, 200)
--    wait(0.5)
--    self.objects[2] = GameSubtitle.new()
    wait(10)
    switchState("Menu")
	end)
end

function TitleScreen.update(dt)
  self.co(dt)
end

function TitleScreen.draw()
  for i = 1, #self.objects do
    self.objects[i].draw()
  end
end

function wait(seconds)
  while seconds > 0 do
	local dt = coroutine.yield(true)
    seconds = seconds - dt
  end
end
User avatar
HugoBDesigner
Party member
Posts: 403
Joined: Mon Feb 24, 2014 6:54 pm
Location: Above the Pocket Dimension
Contact:

Re: HELP! GameStates from scratch. (Intro > Menu > Game)

Post by HugoBDesigner »

You haven't even added a "currentState" variable at love.load :P

And I see no switchState function, but it might be in another file. Just add this variable BEFORE the first "switchState" call :)
@HugoBDesigner - Twitter
HugoBDesigner - Blog
Shepherd()
Prole
Posts: 5
Joined: Wed Apr 23, 2014 7:34 pm

Re: HELP! GameStates from scratch. (Intro > Menu > Game)

Post by Shepherd() »

Yes, currentState and switchState do exist in other files. I had this running fine between Menu and Game state, but only started experiencing problems with Intro.
User avatar
SneakySnake
Citizen
Posts: 94
Joined: Fri May 31, 2013 2:01 pm
Contact:

Re: HELP! GameStates from scratch. (Intro > Menu > Game)

Post by SneakySnake »

Upload a .love file so we can see all of your code.
User avatar
JaquesEdrillavo
Prole
Posts: 7
Joined: Tue Apr 08, 2014 2:12 am
Location: Mexico

Re: HELP! GameStates from scratch. (Intro > Menu > Game)

Post by JaquesEdrillavo »

Hey!
Hope someone can help him, since it is something it's been bothering me for a while.

Also, I don't know about this but, you used TitleScreen in your introstate.lua, but you tried to call it "Intro" in main.lua, which is not defined nowhere in the introstate.lua

Again, Im new, but I'm just trying to help.

Hope someone with more knowledge helps you better!
Cheers!
Shepherd()
Prole
Posts: 5
Joined: Wed Apr 23, 2014 7:34 pm

Re: HELP! GameStates from scratch. (Intro > Menu > Game)

Post by Shepherd() »

I'll post more info tonight. Thanks for ALL of the replies.
Shepherd()
Prole
Posts: 5
Joined: Wed Apr 23, 2014 7:34 pm

Re: HELP! GameStates from scratch. (Intro > Menu > Game)

Post by Shepherd() »

Here is the .love file, not sure if it works? Didn't seem to work for me. So I included the bulk of the states system I have pre-coded. This is surely a frustrating black screen for a n00b like myself.

Code: Select all

--statesystems.lua

oldState = "none"
currentState = "none"

function stateDrawCurrentState()
	if currentState == "Game" then
		GameDraw()
	elseif currentState == "Menu" then
		MenuDraw()
	end
end

function stateGetCurrentStateInput()
	if currentState == "Game" then
		GameDoInput()
	elseif currentState == "Menu" then
		MenuDoInput()
	end
end

function switchState(state)
	if currentState ~= state then
		oldState = currentState

		if oldState == "Game" then
			GameShutdown()

		elseif oldState == "Menu" then
			MenuShutdown()
		end

		currentState = state

--		if currentState == "Game" then
--			GameSetup()
--		elseif currentState == "Menu" then
--			MenuSetup()
--		end
	end
end
Attachments
Lua Project 2.love
(171.32 KiB) Downloaded 96 times
Shepherd()
Prole
Posts: 5
Joined: Wed Apr 23, 2014 7:34 pm

Re: HELP! GameStates from scratch. (Intro > Menu > Game)

Post by Shepherd() »

*bump*
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 9 guests