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
FSM - Finite State Machine
Re: FSM - Finite State Machine
http://www.lua.org/pil/
for all your Lua ;D!
for all your Lua ;D!
Re: FSM - Finite State Machine
vrld's HUMP has a gamestate module, maybe that is what you're looking for?
- Taehl
- Dreaming in associative arrays
- Posts: 1025
- Joined: Mon Jan 11, 2010 5:07 am
- Location: CA, USA
- Contact:
Re: FSM - Finite State Machine
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+.
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Re: FSM - Finite State Machine
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
Re: FSM - Finite State Machine
For gamestate management I love Pölygamy
Re: FSM - Finite State Machine
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?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
(love draw variation here)
Code: Select all
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
Did you worked in LUA variant? Last time I checked the Lua docs for Polygamy were rare (or non-existent)Dilli wrote:For gamestate management I love Pölygamy
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: FSM - Finite State Machine
I'd use a table here, it's simpler to extend: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?
Code: Select all
game_states = {nullState = drawNull, introState = drawIntro, selectState = drawSelect, ... }
-- in love.draw
game_states[game_state]()
Help us help you: attach a .love.
Re: FSM - Finite State Machine
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).Robin wrote:I'd use a table here, it's simpler to extend: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?Code: Select all
game_states = {nullState = drawNull, introState = drawIntro, selectState = drawSelect, ... } -- in love.draw game_states[game_state]()
Code: Select all
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
Code: Select all
game_states = {nullState = Null, introState = Intro, selectState = Select, ... }
-- in love.draw
redirect_function = "draw"..game_state
game_states[redirect_function]()
-- in love.update
redirect_state = "update"..game_state
game_states[redirect_function]()
- TechnoCat
- Inner party member
- Posts: 1611
- Joined: Thu Jul 30, 2009 12:31 am
- Location: Milwaukee, WI
- Contact:
Re: FSM - Finite State Machine
Seems like you are overcomplicating things. This is good news though. right?
Press space to change gamestate.
Added a metatable default state to clean it up a bit. Only override the functions you want to this way.
Press space to change gamestate.
Code: Select all
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
Code: Select all
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
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 2 guests