Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ScriptStateMachineComponent = {
- states = {
- IdleState = {
- enter = function(self, entity)
- setAnimation(entity, "idle")
- startTimer(entity, "idleTimer")
- end,
- execute = function(self, entity)
- if(timerTicked(entity, "idleTimer")) then -- open the book after some time
- setScriptState(entity, "OpeningBookState")
- end
- end,
- exit = function(self, entity)
- stopTimer(entity, "idleTimer")
- end
- },
- OpeningBookState = {
- enter = function(self, entity)
- setAnimation(entity, "openingBook")
- end,
- execute = function(self, entity)
- if(currentAnimationFinished(entity)) then -- finished opening the book
- setScriptState(entity, "ReadingBookState")
- end
- end
- },
- ReadingBookState = {
- init = function(self)
- self.flippingPage = false
- self.flippedPages = 0
- end,
- enter = function(self, entity)
- setAnimation(entity, "reading")
- startTimer(entity, "pageFlipTimer")
- end,
- execute = function(self, entity)
- if(timerTicked(entity, "pageFlipTimer") and not self.flippingPage) then -- time to flip the page
- if(self.flippedPages == 5) then -- flipped enough times already, go to idle state
- setScriptState(entity, "IdleState")
- else -- flip the page!
- self.flippingPage = true
- setAnimation(entity, "flippingPage")
- stopTimer(entity, "pageFlipTimer")
- end
- end
- if(self.flippingPage and currentAnimationFinished(entity)) then -- finished flipping the page, go to reading state
- setAnimation(entity, "reading")
- startTimer(entity, "pageFlipTimer")
- self.flippingPage = false
- self.flippedPages = self.flippedPages + 1
- end
- end
- }
- }
- },
- TimerComponent = {
- timers = {
- idleTimer = {
- tickTime = 1500,
- },
- pageFlipTimer = {
- tickTime = 2500,
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement