hchello, i am new there and to the programing at all.
I'd like to start from gamedev and from lua and now from LOVE -_-
first wat i need is to make FSM code for my 1st game, kinda state for main menu, play|pause screens, and some UI.
I need any help.
For now i'm readyng wiki and looking the code of games. Maybe someone know there exactly i should look? any help will be usefull
Hmm... Maybe we should gather a list of Lua and Love documentation and tutorials and stuff, and make a stickied thread?
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit! Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
I am currently using boolean flags. For everything. Everytime I am going to draw I ask if it's the gamestart menu, the settings menu, the playing scene or whatever. And the same for the input. I should definately take a look at this FMS thing xD
Ellohir wrote:I am currently using boolean flags. For everything. Everytime I am going to draw I ask if it's the gamestart menu, the settings menu, the playing scene or whatever. And the same for the input. I should definately take a look at this FMS thing xD
I decided not use any 3rd party State Library since I found that this simple routine used for love.draw and love.update worked so well enough. Why complicate more?
(love draw variation here)
if(game_state == 'nullState') then drawNull()
elseif(game_state == 'introState') then drawIntro()
elseif(game_state == 'selectState') then drawSelect()
elseif(game_state == 'playState') then drawPlay()
elseif(game_state == 'editState') then drawEdit()
elseif(game_state == 'deadState' or game_state == "goalState") then drawDebriefing()
elseif(game_state == 'helpState') then drawHelp()
elseif(game_state == 'pauseState') then drawPause()
elseif(game_state == 'quitState') then drawQuit()
else error('game_state is not valid')
end
Dilli wrote:For gamestate management I love Pölygamy
Did you worked in LUA variant? Last time I checked the Lua docs for Polygamy were rare (or non-existent)
coffee wrote:I decided not use any 3rd party State Library since I found that this simple routine used for love.draw and love.update worked so well enough. Why complicate more?
coffee wrote:I decided not use any 3rd party State Library since I found that this simple routine used for love.draw and love.update worked so well enough. Why complicate more?
Thank you for the clever suggestion Robin. It would be a pleasure implant that but this way rises a problem because it screws the update routine since that I can't redirect the game_state to both sides at same time (draw/update).
function love.update()
if(game_state == 'nullState') then updateNull()
elseif(game_state == 'introState') then updateIntro()
elseif(game_state == 'selectState') then updateSelect()
elseif(game_state == 'playState') then updatePlay()
elseif(game_state == 'editState') then updateEdit()
elseif(game_state == 'deadState' or game_state == 'goalState') then updateDebriefing()
elseif(game_state == 'helpState') then updateHelp()
elseif(game_state == 'pauseState') then updatePause()
elseif(game_state == 'quitState') then updateQuit()
else error('game_state is not valid')
end -- end if --
end
but perhaps I can do something close like this? (didn't tested yet for syntax validation sorry)
local current_state
local game_states = {
introState = {
draw = function() love.graphics.print("INTRO!!",0,0) end,
update = function(dt) end,
keypressed = function(key) if key == " " then current_state = "selectState" end end },
selectState = {
draw = function() love.graphics.print("SELECT!",0,0) end,
update = function(dt) end,
keypressed = function(key) end}
}
function love.load()
current_state = "introState" --or 1,2,...,#game_states
end
function love.update(dt)
game_states[current_state].update(dt)
end
function love.draw()
game_states[current_state].draw()
end
function love.keypressed(key)
game_states[current_state].keypressed(key)
end
Added a metatable default state to clean it up a bit. Only override the functions you want to this way.
local current_state
local game_states = {}
local defaultState = {
update = function(dt) end,
draw = function() end,
keypressed = function(key) end
}
local introState = {
draw = function() love.graphics.print("INTRO!!",0,0) end,
keypressed = function(key) if key == " " then current_state = "selectState" end end
}
setmetatable(introState, {__index = defaultState})
game_states["introState"] = introState
local selectState = {
draw = function() love.graphics.print("SELECT!",0,0) end
}
setmetatable(selectState, {__index = defaultState})
game_states["selectState"] = selectState
function love.load()
current_state = "introState" --or 1,2,...,#game_states
end
function love.update(dt)
game_states[current_state].update(dt)
end
function love.draw()
game_states[current_state].draw()
end
function love.keypressed(key)
game_states[current_state].keypressed(key)
end