Page 1 of 1

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

Posted: Wed Apr 30, 2014 5:23 am
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

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

Posted: Wed Apr 30, 2014 7:59 am
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 :)

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

Posted: Wed Apr 30, 2014 5:06 pm
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.

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

Posted: Wed Apr 30, 2014 6:02 pm
by SneakySnake
Upload a .love file so we can see all of your code.

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

Posted: Wed Apr 30, 2014 10:49 pm
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!

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

Posted: Thu May 01, 2014 12:54 am
by Shepherd()
I'll post more info tonight. Thanks for ALL of the replies.

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

Posted: Fri May 02, 2014 4:43 am
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

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

Posted: Sat May 03, 2014 5:38 am
by Shepherd()
*bump*