         guard !state.gameIsOver else {
             return
         }
+        updateEventQueue()
         updateObstaclePositions()
         handleCollisions()
         updatePlayerStates()

    
    private var timeStep = 0
    private var lastObstacleTimeStep: Int?
    
    init(playerNumber: Int, seed: Int? = nil, isMultiplayer: Bool, peers: [MCPeerID]) {
        obstacleGenerator = ObstacleGenerator(seed: seed)

        timeStep += 1
    }

    func handleEvent(event: GameEvent, player: Int?, occurringTimeStep: Int = timeStep) {
        if let player = state.players.filter({ $0.playerNumber == player }).first {
            switch event {
                case .PlayerDidJump:
                    player.jump(occurringTimeStep)
                    if state.isMultiplayer && player! == state.myPlayer.playerNumber {
                        var jumpData = [String: AnyObject]()
                        jumpData["time_step"] = occurringTimeStep
                        gameNetworkPortal.send(.PlayerDidJump, data: jumpData)
                    }
                case .PlayerDidDuck:
                    player.duck(occurringTimeStep)
                    if state.isMultiplayer && player! == state.myPlayer.playerNumber {
                        var duckData = [String: AnyObject]()
                        duckData["time_step"] = occurringTimeStep
                        gameNetworkPortal.send(.PlayerDidJump, data: duckData)
                    }
                default:
                    break
            }
        }
    }
    
    private func updateEventQueue() {
        while eventQueue.last?.timeStep <= timeStep {
            guard let front = eventQueue.popLast() else {
                break
            }
            handleEvent(front.event, player: front.playerNumber, occurringTimeStep: front.timeStep)
        }
    }
    
