Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
anshve
/
PongGame
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
759077e1
authored
Apr 28, 2022
by
anshve
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
2a6a020e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
0 deletions
PongSource/src/StateMachine.lua
PongSource/src/StateMachine.lua
0 → 100644
View file @
759077e1
StateMachine
=
Class
{}
function
StateMachine
:
init
(
states
)
self
.
empty
=
{
render
=
function
()
end
,
update
=
function
()
end
,
enter
=
function
()
end
,
exit
=
function
()
end
}
self
.
states
=
states
or
{}
-- [name] -> [function that returns states]
self
.
current
=
self
.
empty
end
function
StateMachine
:
change
(
stateName
,
enterParams
)
assert
(
self
.
states
[
stateName
])
-- state must exist!
self
.
current
:
exit
()
self
.
current
=
self
.
states
[
stateName
]()
self
.
current
:
enter
(
enterParams
)
end
function
StateMachine
:
update
(
dt
)
self
.
current
:
update
(
dt
)
end
function
StateMachine
:
render
()
self
.
current
:
render
()
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment