示例#1
0
    void SetGameStateBasedOnCharState()
    {
        if (!GameStateUtils.IsPlaying(gameState))
        {
            return;
        }

        if (state.Value == CharacterState.Idle)
        {
            gameState.Value = GameStateConstants.PLAYING_RUNNING;
        }
        else if (CharacterStateUtils.IsJumping(state.Value))
        {
            gameState.Value = GameStateConstants.PLAYING_JUMPING;
        }
        else if (CharacterStateUtils.IsFalling(state.Value))
        {
            gameState.Value = GameStateConstants.PLAYING_FALLING;
        }
        else if (CharacterStateUtils.HasLanded(state.Value))
        {
            gameState.Value = GameStateConstants.PLAYING_LANDED;
        }
        else
        {
            gameState.Value = GameStateConstants.PLAYING;
        }
    }
示例#2
0
    void OnCollisionEnter2D(Collision2D collision)
    {
        if (!GameStateUtils.IsPlaying(gameState))
        {
            return;
        }

        if ((collision.gameObject.tag == TagConstants.FLOOR || collision.gameObject.tag == TagConstants.MATTRESS) && state.Value == CharacterState.Falling)
        {
            smoke.Play();
            Camera.main.GetComponent <CameraShake>().Shake(0.3f);

            // Prevent character from moving sideways when landing
            actionsNextFixedUpdate.Add(StopXVelocity);

            if (collision.gameObject.tag == TagConstants.MATTRESS)
            {
                SoundManager.instance.PlayFX(LANDING);
                scoreManager.DidLandOnMattress();
                state.Value = CharacterState.Landed;
                StartCoroutine(LandedOnMattress());
            }
            else if (collision.gameObject.tag == TagConstants.FLOOR)
            {
                Die();
            }
        }
    }
示例#3
0
        private async Task <dynamic> GameInfo(dynamic args, CancellationToken cancellation_token)
        {
            string             game_id = Request.Query["gameId"];
            QuantumChessEngine engine  = await WebAppManagers.DatabaseManager.RequestEngine(game_id);

            var response = new Model.InfoResponse();

            response.ActivePlayer = PlayerUtils.ToString(engine.ActivePlayer);
            response.GameState    = GameStateUtils.ToString(engine.GameState);
            response.Squares      = new Dictionary <String, Model.InfoResponse.SquareEncoded>();
            for (int i = 0; i < 64; i++)
            {
                Position     pos    = Position.FromIndex(i);
                QuantumPiece qpiece = engine.QuantumChessboard.GetQuantumPiece(pos);
                if (qpiece.Piece.HasValue)
                {
                    response.Squares[pos.ToString()] = new Model.InfoResponse.SquareEncoded()
                    {
                        Player      = PlayerUtils.ToString(qpiece.Piece.Value.Player),
                        Piece       = PieceTypeUtils.ToString(qpiece.Piece.Value.PieceType),
                        Probability = qpiece.Probability
                    };
                }
                else
                {
                    response.Squares[pos.ToString()] = null;
                }
            }

            response.LastMovePositions = engine.LastMovePositions.Select((pos) => pos.ToString().ToLower()).ToArray();

            return(Response.AsJson(response));
        }
示例#4
0
    private void FixedUpdate()
    {
        if (ship == null || ship.engine == null)
        {
            return;
        }

        var engine = ship.engine;

        switch (mouseState)
        {
        case MouseState.Off:
            engine.LerpYawToNeutral();
            break;

        case MouseState.Toggled:
        case MouseState.Held:
            engine.AddPitch(GameStateUtils.GetMousePositionOnScreen().y);
            engine.AddYaw(GameStateUtils.GetMousePositionOnScreen().x);
            break;

        default:
            Debug.LogWarning("MouseState has incorrect value...");
            break;
        }
    }
示例#5
0
    void Update()
    {
        if (!GameStateUtils.IsPlaying(gameState))
        {
            return;
        }

        animator.SetInteger(STATE, (int)state.Value);
        Shader.SetGlobalFloat(_Y_POSITION, this.transform.position.y * 0.03f);
        rb.gravityScale = rb.velocity.y < -1f ? 3.5f : 1f;

        // For animation
        if (state.Value == CharacterState.Idle && (Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.RightArrow)))
        {
            state.Value = CharacterState.Running;
        }

        if (state.Value == CharacterState.CanJump && Input.GetKeyDown(KeyCode.Space) && jumpingTriggerTransform != null)
        {
            SoundManager.instance.PlayFX(JUMP);
            state.Value = CharacterState.PreJumping;
            actionsNextFixedUpdate.Add(DoPreJump);
            StartCoroutine(DelayAndJump());

            percentJumpAreaReached = (transform.position.x - (jumpingTriggerTransform.position.x - jumpingTriggerTransform.localScale.x / 2)) / jumpingTriggerTransform.localScale.x;
        }
        else if (state.Value == CharacterState.Running || state.Value == CharacterState.CanJump)
        {
            if ((lastKey == KeyCode.None || lastKey == KeyCode.RightArrow) && Input.GetKeyDown(KeyCode.LeftArrow))
            {
                SoundManager.instance.PlayFX(RUNNING);
                actionsNextFixedUpdate.Add(AddRunSpeed);
                lastKey = KeyCode.LeftArrow;
                smoke.Play();
            }
            else if ((lastKey == KeyCode.None || lastKey == KeyCode.LeftArrow) && Input.GetKeyDown(KeyCode.RightArrow))
            {
                SoundManager.instance.PlayFX(RUNNING);
                actionsNextFixedUpdate.Add(AddRunSpeed);
                lastKey = KeyCode.RightArrow;
                smoke.Play();
            }
        }
        else if (state.Value == CharacterState.Falling)
        {
            if (Input.GetKey(KeyCode.LeftArrow))
            {
                actionsNextFixedUpdate.Add(AddTorqueNForceFallingLeft);
            }
            else if (Input.GetKey(KeyCode.RightArrow))
            {
                actionsNextFixedUpdate.Add(AddTorqueNForceFallingRight);
            }

            CountRotation();

            scoreManager.AddWhenFalling(Time.deltaTime);
        }
    }
示例#6
0
        public static BsonDocument Serialize(Game game)
        {
            var document = new BsonDocument();

            document.Set("_id", new BsonObjectId(game.Id));
            document.Set("active_player", PlayerUtils.ToString(game.Engine.ActivePlayer));
            document.Set("game_state", GameStateUtils.ToString(game.Engine.QuantumChessboard.GameState));
            document.Set("creation_time", game.Engine.CreationTime);
            document.Set("last_modification_time", DateTime.Now);

            var bson_harmonics = new BsonArray();

            foreach (QuantumHarmonic harmonic in game.Engine.QuantumChessboard.Harmonics)
            {
                var bson_harmonic = new BsonDocument();
                bson_harmonic.Set("harmonic_state", GameStateUtils.ToString(harmonic.Board.GameState));
                bson_harmonic.Set("degeneracy", Convert.ToInt64(harmonic.Degeneracy));

                var bson_chessboard = new BsonArray();
                for (int i = 0; i < 64; i++)
                {
                    Piece?piece = harmonic.Board[i];
                    if (piece.HasValue)
                    {
                        var bson_piece = new BsonDocument();
                        bson_piece.Set("player", PlayerUtils.ToString(piece.Value.Player));
                        bson_piece.Set("piece", PieceTypeUtils.ToString(piece.Value.PieceType));
                        bson_chessboard.Add(bson_piece);
                    }
                    else
                    {
                        bson_chessboard.Add(BsonNull.Value);
                    }
                }

                bson_harmonic.Set("chessboard", bson_chessboard);
                bson_harmonics.Add(bson_harmonic);
            }
            document.Set("harmonics", bson_harmonics);

            var last_move_positions = new BsonArray();

            foreach (Position pos in game.Engine.LastMovePositions)
            {
                last_move_positions.Add(pos.ToString());
            }
            document.Set("last_move_positions", last_move_positions);

            return(document);
        }
示例#7
0
        public static Game Deserialize(BsonDocument document)
        {
            ObjectId  id            = document["_id"].AsObjectId;
            Player    active_player = PlayerUtils.FromString(document["active_player"].AsString);
            GameState game_state    = GameStateUtils.FromString(document["game_state"].AsString);
            DateTime  creation_time = document["creation_time"].ToLocalTime();

            var harmonics = new List <QuantumHarmonic>();

            foreach (BsonValue bson_harmonic_val in document["harmonics"].AsBsonArray)
            {
                BsonDocument bson_harmonic   = bson_harmonic_val.AsBsonDocument;
                GameState    harmonic_state  = GameStateUtils.FromString(bson_harmonic["harmonic_state"].AsString);
                ulong        degeneracy      = Convert.ToUInt64(bson_harmonic["degeneracy"].AsInt64);
                BsonArray    bson_chessboard = bson_harmonic["chessboard"].AsBsonArray;
                var          chessboard      = Chessboard.EmptyChessboard(harmonic_state);
                for (int i = 0; i < 64; i++)
                {
                    BsonValue bson_square_val = bson_chessboard[i];
                    if (bson_square_val.IsBsonNull)
                    {
                        chessboard[i] = null;
                    }
                    else
                    {
                        BsonDocument bson_square   = bson_square_val.AsBsonDocument;
                        Player       square_player = PlayerUtils.FromString(bson_square["player"].AsString);
                        PieceType    square_piece  = PieceTypeUtils.FromString(bson_square["piece"].AsString);
                        chessboard[i] = new Piece(square_player, square_piece);
                    }
                }
                harmonics.Add(new QuantumHarmonic(chessboard, degeneracy));
            }
            var quantum_chessboard = new QuantumChessboard(harmonics, game_state);

            var last_move_positions = new List <Position>();

            foreach (BsonValue pos_val in document["last_move_positions"].AsBsonArray)
            {
                last_move_positions.Add(Position.Parse(pos_val.AsString));
            }

            var engine = new QuantumChessEngine(quantum_chessboard, active_player, creation_time, last_move_positions.ToArray());

            return(new Game(id, engine));
        }
示例#8
0
    void FixedUpdate()
    {
        if (!GameStateUtils.IsPlaying(gameState))
        {
            return;
        }

        rb.gravityScale = rb.velocity.y < -1f ? 3.5f : 1f;

        for (int i = 0; i < actionsNextFixedUpdate.Count; ++i)
        {
            actionsNextFixedUpdate[i]();
        }
        actionsNextFixedUpdate.Clear();

        ClampAngularVelocity();
    }
示例#9
0
    void OnTriggerExit2D(Collider2D collider)
    {
        if (!GameStateUtils.IsPlaying(gameState))
        {
            return;
        }

        if (collider.tag == TagConstants.JUMPING_TRIGGER)
        {
            jumpingTriggerTransform = null;

            if (state.Value == CharacterState.CanJump)
            {
                Die();
            }
        }
    }
示例#10
0
    private void CalculateOffsets()
    {
        var mouseCoords = GameStateUtils.GetMousePositionOnScreen();

        distanceOffset = Mathf.Clamp(Speed / speedDivisor, 0, maxDistance);

        if (calculateRotationOffsets)
        {
            pitchOffset = Mathf.Clamp(mouseCoords.y * pitchModifier, maxLowerPitch, maxUpperPitch);
            yawOffset   = Mathf.Clamp(mouseCoords.x * yawModifier, -maxYaw, maxYaw);
        }

        else
        {
            pitchOffset = 0;
            yawOffset   = 0;
        }
    }
示例#11
0
    void OnTriggerEnter2D(Collider2D collider)
    {
        if (!GameStateUtils.IsPlaying(gameState))
        {
            return;
        }

        if (collider.tag == TagConstants.JUMPING_TRIGGER)
        {
            jumpingTriggerTransform = collider.transform;
            state.Value             = CharacterState.CanJump;
        }
        else if ((state.Value != CharacterState.Running && (collider.tag == TagConstants.POLE && collider.transform.parent == null) ||
                  collider.tag == TagConstants.HINDER))
        {
            Die();
        }
    }
示例#12
0
        protected override PlayerState ExtractFeatures(GameState state, string myPlayerId)
        {
            var player = state.Players[myPlayerId];
            var x      = player.X;
            var y      = player.Y;

            return(new PlayerState
            {
                TwoTopTile = (uint)GameStateUtils.GetBoardTile(state, x, y - 2, myPlayerId),
                TopTile = (uint)GameStateUtils.GetBoardTile(state, x, y - 1, myPlayerId),
                TwoLeftTile = (uint)GameStateUtils.GetBoardTile(state, x - 2, y, myPlayerId),
                LeftTile = (uint)GameStateUtils.GetBoardTile(state, x - 1, y, myPlayerId),
                RightTile = (uint)GameStateUtils.GetBoardTile(state, x + 1, y, myPlayerId),
                TwoRightTile = (uint)GameStateUtils.GetBoardTile(state, x + 2, y, myPlayerId),
                BottomCenterTile = (uint)GameStateUtils.GetBoardTile(state, x, y + 1, myPlayerId),
                TwoBottomTile = (uint)GameStateUtils.GetBoardTile(state, x, y + 2, myPlayerId),
                Alive = (uint)(player.Alive ? 1 : 0),
                Respawning = (uint)player.Respawning,
                BombsLeft = (uint)player.BombsLeft,
            });
        }
示例#13
0
        public async Task <List <GameInfo> > RequestActiveGames()
        {
            var res = new List <GameInfo>();

            using (var cursor = await ActiveGames_.FindAsync(EmptyFilter_)) {
                while (await cursor.MoveNextAsync())
                {
                    var batch = cursor.Current;
                    foreach (var document in batch)
                    {
                        res.Add(new GameInfo()
                        {
                            GameId           = document["_id"].AsObjectId.ToString(),
                            LastModification = DateTime.Now - document["last_modification_time"].ToLocalTime(),
                            CreationTime     = DateTime.Now - document["creation_time"].ToLocalTime(),
                            GameState        = GameStateUtils.FromString(document["game_state"].AsString),
                        });
                    }
                }
            }
            res.Sort((x, y) => x.LastModification.CompareTo(y.LastModification));
            return(res);
        }
示例#14
0
        /// <summary>
        /// Checks the current gamestate and checks if the animation layer should be triggered.
        /// Note will also have the side-effect of updating _previousTriggerValue so this should not be called
        /// more than once per frame.
        /// </summary>
        private void CheckTriggers(IGameState gamestate)
        {
            if (Properties.TriggerMode == AnimationTriggerMode.AlwaysOn)
            {
                // Should return true if it has not already been played OR it is allowed to repeat indefinately
                // Should also not try to get a value from the state
                if (Properties.AnimationRepeat == 0)
                {
                    StartAnimation(); // Always true if infinite repeats
                }
                else if (!_alwaysOnHasPlayed)
                {
                    _alwaysOnHasPlayed = true; // True if it has not been played
                    StartAnimation();
                }

                // Handling for key-based triggers
            }
            else if (Properties.TriggerMode == AnimationTriggerMode.WhileKeyHeld)
            {
                // If we are in "while held down" mode, check to see if any of the keys pressed do not currently
                // have an animation with them as the assigned key. If not, create trigger it
                foreach (var key in _pressedKeys.Where(k => !runningAnimations.Any(a => a.assignedKey == k)))
                {
                    StartAnimation(key);
                }

                // Handling for numeric value change based triggers
            }
            else if (IsTriggerNumericValueBased(Properties.TriggerMode))
            {
                // Check to see if a gamestate value change should trigger the animation
                double resolvedTriggerValue = GameStateUtils.TryGetDoubleFromState(gamestate, Properties.TriggerPath);
                switch (Properties.TriggerMode)
                {
                case AnimationTriggerMode.OnChange:
                    if (resolvedTriggerValue != _previousTriggerDoubleValue)
                    {
                        StartAnimation();
                    }
                    break;

                case AnimationTriggerMode.OnHigh:
                    if (resolvedTriggerValue > _previousTriggerDoubleValue)
                    {
                        StartAnimation();
                    }
                    break;

                case AnimationTriggerMode.OnLow:
                    if (resolvedTriggerValue < _previousTriggerDoubleValue)
                    {
                        StartAnimation();
                    }
                    break;
                }
                _previousTriggerDoubleValue = resolvedTriggerValue;

                // Handling for boolean value based triggers
            }
            else
            {
                bool resolvedTriggerValue = GameStateUtils.TryGetBoolFromState(gamestate, Properties.TriggerPath);
                switch (Properties.TriggerMode)
                {
                case AnimationTriggerMode.OnTrue:
                    if (resolvedTriggerValue && !_previousTriggerBoolValue)
                    {
                        StartAnimation();
                    }
                    break;

                case AnimationTriggerMode.OnFalse:
                    if (!resolvedTriggerValue && _previousTriggerBoolValue)
                    {
                        StartAnimation();
                    }
                    break;

                case AnimationTriggerMode.WhileTrue:
                    if (resolvedTriggerValue && runningAnimations.Count == 0)
                    {
                        StartAnimation();
                    }
                    break;
                }
                _previousTriggerBoolValue = resolvedTriggerValue;
            }
        }
示例#15
0
        /// <summary>Parses the numbers, compares the result, and returns the result.</summary>
        public bool Evaluate(IGameState gameState)
        {
            var @enum = GameStateUtils.TryGetEnumFromState(gameState, StatePath);

            return(@enum != null && @enum.Equals(EnumValue));
        }
示例#16
0
        public void Check(IGameState gs, ILayerHandler handler)
        {
            if (Action == null || ReferenceComparisons == null)
            {
                return;
            }

            foreach (Tuple <string, Tuple <LogicOperator, object> > kvp in ReferenceComparisons)
            {
                dynamic var = GameStateUtils.RetrieveGameStateParameter(gs, kvp.Item1);

                if (var == null)
                {
                    return;
                }

                Console.WriteLine("Got him");

                dynamic comparison = kvp.Item2.Item2;
                bool    valid      = false;

                switch (kvp.Item2.Item1)
                {
                case LogicOperator.GreaterThan:
                    valid = Operator.GreaterThan(var, comparison);
                    break;

                case LogicOperator.GreaterThanOrEqual:
                    valid = Operator.GreaterThanOrEqual(var, comparison);
                    break;

                case LogicOperator.LessThan:
                    valid = Operator.LessThan(var, comparison);
                    break;

                case LogicOperator.LessThanOrEqual:
                    valid = Operator.LessThanOrEqual(var, comparison);
                    break;

                case LogicOperator.Equal:
                    valid = Operator.Equal(var, comparison);
                    break;

                case LogicOperator.NotEqual:
                    valid = Operator.NotEqual(var, comparison);
                    break;

                default:
                    break;
                }

                if (!valid)
                {
                    return;
                }
            }

            switch (Action.Item1)
            {
            case ActionType.SetProperty:
                Tuple <string, object> vars = (Tuple <string, object>)Action.Item2;
                string str = vars.Item1;
                if (!str.StartsWith("_"))
                {
                    str = "_" + str;
                }
                object var = vars.Item2;
                if (var is RealColor)
                {
                    var = ((RealColor)var).Color;
                }
                ((ILogic)handler.Properties).Logic.SetValueFromString(str, var);
                //handler.Properties._PrimaryColor = (Color)Action.Item2;
                break;

            default:
                break;
            }
        }
示例#17
0
 /// <summary>Parses the numbers, compares the result, and returns the result.</summary>
 public double Evaluate(IGameState gameState) => GameStateUtils.TryGetDoubleFromState(gameState, VariablePath);
示例#18
0
    private void Update()
    {
        CurrentAimPosition = GetCurrentAimPosition();

        if (Input.GetKeyDown(InputManager.PauseGameKey) && canPause)
        {
            GameStateUtils.TogglePause();
            return;
        }

        if (!inputAllowed || ship == null)
        {
            return;
        }

        #region movement
        if (Input.GetKey(InputManager.ThrottleUpKey) || Input.GetAxis("Mouse ScrollWheel") > 0f)
        {
            ship.engine.ThrottleUp();
        }

        else if (Input.GetKeyUp(InputManager.ThrottleUpKey))
        {
            Action <bool> action = ship.engine.Blink;
            StartCoroutine(DoubleTap(InputManager.ThrottleUpKey, action, true));
        }

        if (Input.GetKey(InputManager.ThrottleDownKey) || Input.GetAxis("Mouse ScrollWheel") < 0f)
        {
            ship.engine.ThrottleDown();
        }

        if (Input.GetKey(InputManager.StrafeLeftKey))
        {
            ship.engine.Strafe = -1;
        }
        else if (Input.GetKeyUp(InputManager.StrafeLeftKey))
        {
            Action action = ship.engine.SidestepLeft;
            StartCoroutine(DoubleTap(InputManager.StrafeLeftKey, action));
        }

        if (Input.GetKey(InputManager.StrafeRightKey))
        {
            ship.engine.Strafe = 1;
        }
        else if (Input.GetKeyUp(InputManager.StrafeRightKey))
        {
            Action action = ship.engine.SidestepRight;
            StartCoroutine(DoubleTap(InputManager.StrafeRightKey, action));
        }

        // If neither strafe key is pressed, reset the ship's strafing
        if (!Input.GetKey(InputManager.StrafeRightKey) && !Input.GetKey(InputManager.StrafeLeftKey))
        {
            ship.engine.Strafe = 0;
        }

        if (Input.GetKeyDown(InputManager.ToggleMouseFlightKey))
        {
            ToggleMouseFlight();
        }

        if (Input.GetKeyDown(InputManager.AfterburnerKey))
        {
            ship.ToggleAfterburner(true);
        }

        else if (Input.GetKeyUp(InputManager.AfterburnerKey))
        {
            ship.ToggleAfterburner(false);
        }

        if (Input.GetKeyDown(InputManager.ManualMouseFlightKey))
        {
            if (MouseState == MouseState.Off)
            {
                StartCoroutine("ManualMouseFlightCoroutine");
            }
        }

        if (Input.GetKeyUp(InputManager.ManualMouseFlightKey))
        {
            StopAllCoroutines();

            if (MouseState == MouseState.Held)
            {
                MouseState = MouseState.Off;
            }
        }

        if (Input.GetKey(KeyCode.LeftShift) && Input.GetKeyDown(InputManager.ThrottleUpKey))
        {
            ship.cruiseEngine.ToggleCruiseEngines();
        }

        if (Input.GetKeyDown(InputManager.KillEnginesKey))
        {
            ship.engine.Drifting = !ship.engine.Drifting;
        }

        #endregion

        #region hardpoints
        if (Input.GetKey(InputManager.Hardpoint1Key))
        {
            ship.guns[0].Fire(CurrentAimPosition);
        }

        if (Input.GetKey(InputManager.Hardpoint2Key))
        {
            ship.guns[1].Fire(CurrentAimPosition);
        }

        if (Input.GetKey(InputManager.Hardpoint3Key))
        {
            ship.guns[2].Fire(CurrentAimPosition);
        }

        if (Input.GetKey(InputManager.Hardpoint4Key))
        {
            ship.guns[3].Fire(CurrentAimPosition);
        }

        if (Input.GetKey(InputManager.Hardpoint5Key))
        {
            ship.guns[4].Fire(CurrentAimPosition);
        }

        if (Input.GetKey(InputManager.Hardpoint6Key))
        {
            ship.guns[5].Fire(CurrentAimPosition);
        }

        if (Input.GetKey(InputManager.Hardpoint7Key))
        {
            ship.guns[6].Fire(CurrentAimPosition);
        }

        if (Input.GetKey(InputManager.Hardpoint8Key))
        {
            ship.guns[7].Fire(CurrentAimPosition);
        }

        if (Input.GetKey(InputManager.Hardpoint9Key))
        {
            ship.guns[8].Fire(CurrentAimPosition);
        }

        if (Input.GetKey(InputManager.Hardpoint10Key))
        {
            ship.guns[9].Fire(CurrentAimPosition);
        }

        if (Input.GetKey(InputManager.FireKey))
        {
            ship.FireActiveWeapons(CurrentAimPosition);
        }

        #endregion
    }
示例#19
0
 static void Pause(CommandArg[] args)
 {
     GameStateUtils.TogglePause();
 }