Sha256: e459f75977579a3c6dcf95cc5a70ef9ac97128ee04429d1b4abcc55e0ef4e886

Contents?: true

Size: 748 Bytes

Versions: 1

Compression:

Stored size: 748 Bytes

Contents

module Gosuplus
  class StateManager
    def initialize(window)
      @states = []
      @index = 0
    end

    def update
      @states[@index].update if @states.size > 0
      self.next if @states[@index].finished
    end

    def draw
      @states[@index].draw if @states.size > 0
    end

    def handle_input(key, type)
      @states[@index].handle_input(key, type) if @states.size > 0
    end

    def next
      @states[@index].on_exit
      @states[@index].on_load
      @index += 1
    end

    def previous
      @states[@index].on_exit
      @states[@index].on_load
      @index -= 1
    end

    def add(state)
      state.on_load unless @states.size > 0

      @states << state
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
Gosuplus-1.0.25 lib/Gosuplus/statemanager.rb