Esempio n. 1
0
        public IGameObject BuildGameObject(GameObjectSerialized gameObjectSerialized)
        {
            if (gameObjectSerialized.GameObjectType != SerializedName)
            {
                throw new ArgumentException("Wrong serialized object");
            }

            var playerInputComponent  = new PlayerInputComponent();
            var playerPhysicComponent = new PhysicComponent(_playerData.Speed);
            var playerLogicComponent  = new PlayerLogicComponent(_fireCommand, _consoleWriter,
                                                                 _geometryMathService);

            var playerGraphicComponent = new PlayerGraphicComponent(_consoleWriter,
                                                                    _geometryMathService, _playerData);

            var user = new GameObject(playerInputComponent,
                                      playerPhysicComponent, playerLogicComponent, playerGraphicComponent);

            user.X = gameObjectSerialized.X;
            user.Y = gameObjectSerialized.Y;

            user.Width  = _playerData.Width;
            user.Height = _playerData.Height;

            return(user);
        }
        // PUBLIC STATIC

        // PRIVATE

        // PRIVATE STATIC

        // PRIVATE COROUTINE

        // PRIVATE INVOKE

        //--------------------------------------
        //  Events
        //--------------------------------------
        /// <summary>
        /// Raises the trigger enter2 d event.
        /// </summary>
        /// <param name="collider2D">Collider2 d.</param>
        public void OnTriggerEnter2D(Collider2D collider2D)
        {
            //NOTE: CURRENTLY ALL WALL TYPES 'KILL' YOU.
            //TODO: Perhaps make only BOTTOM kill and the rest just do nothing (bounce player via physics
            if (_boundaryType == BoundaryType.TOP ||
                _boundaryType == BoundaryType.BOTTOM ||
                _boundaryType == BoundaryType.LEFT ||
                _boundaryType == BoundaryType.RIGHT)
            {
                //
                if (collider2D.gameObject.tag == MainConstants.PLAYER_TAG)
                {
                    if (!_wasTriggered)
                    {
                        _wasTriggered = true;
                        Invoke("doRefreshBoundary", 1f);
                        PlayerInputComponent playerInputComponent = collider2D.gameObject.GetComponent <PlayerInputComponent>();
                        playerInputComponent.onBoundaryHit();
                    }
                }
                else if (collider2D.gameObject.tag == MainConstants.ENEMY_TAG)
                {
                    EnemyAIComponent enemyAIComponent = collider2D.gameObject.GetComponent <EnemyAIComponent>();
                    enemyAIComponent.onBoundaryHit();
                }
            }
        }
Esempio n. 3
0
        public void finishGrapple(Entity grapple)
        {
            if (!level.getPlayer().hasComponent(GlobalVars.PLAYER_INPUT_COMPONENT_NAME))
            {
                PlayerInputComponent plInComp = ( PlayerInputComponent )level.getPlayer().addComponent(new PlayerInputComponent(level.getPlayer()));
                plInComp.passedAirjumps = 0;
            }
            if (!level.getPlayer().hasComponent(GlobalVars.GRAVITY_COMPONENT_NAME))
            {
                level.getPlayer().addComponent(new GravityComponent(0, GlobalVars.STANDARD_GRAVITY));
            }


            if (stopPlayer)
            {
                VelocityComponent velComp = ( VelocityComponent )level.getPlayer().getComponent(GlobalVars.VELOCITY_COMPONENT_NAME);

                velComp.x = 0;
                velComp.y = 0;

                stopPlayer = false;
            }
            if (level.curGrap == grapple)
            {
                level.curGrap = null;
            }
            level.removeEntity(grapple);
            return;
        }
Esempio n. 4
0
        //--------------------------------------------------------------------------------



        //------------------------------------- Actions ----------------------------------
        public void playerJump(PositionComponent posComp, VelocityComponent velComp, PlayerInputComponent pelInComp)
        {
            //If it's landed on something, jump
            float checkY = posComp.y + (posComp.height / 2) + GlobalVars.MIN_TILE_SIZE / 2;

            //float buffer = 2;

            if (pelInComp.passedAirjumps < GlobalVars.numAirJumps)
            {
                velComp.setVelocity(velComp.x, pelInComp.jumpStrength);
                pelInComp.passedAirjumps++;
                pelInComp.justJumped = true;
            }

            /*
             * if ( level.getCollisionSystem().findObjectsBetweenPoints( posComp.x - posComp.width / 2 + buffer, checkY, posComp.x + posComp.width / 2 - buffer, checkY ).Count > 0 ) {
             *  velComp.setVelocity( velComp.x, pelInComp.jumpStrength );
             *  pelInComp.passedAirjumps = 0;
             * } else {
             *  if ( pelInComp.passedAirjumps < GlobalVars.numAirJumps ) {
             *      velComp.setVelocity( velComp.x, pelInComp.jumpStrength );
             *      pelInComp.passedAirjumps++;
             *  }
             * }
             * */
        }
Esempio n. 5
0
        public bool getUnlocked(int pupNum)
        {
            switch (pupNum)
            {
            case (GlobalVars.BOUNCE_NUM):
                return(bouncyUnlocked);

            case (GlobalVars.SPEED_NUM):
                return(speedyUnlocked);

            case (GlobalVars.JMP_NUM):
                PlayerInputComponent inpComp = ( PlayerInputComponent )level.getPlayer().getComponent(GlobalVars.PLAYER_INPUT_COMPONENT_NAME);
                return(GlobalVars.numAirJumps == GlobalVars.doubleJumpNumAirJumps);

            case (GlobalVars.SPAWN_NUM):
                return(spawnUnlocked);

            case (GlobalVars.GLIDE_NUM):
                return(glideUnlocked);

            case (GlobalVars.GRAP_NUM):
                return(grappleUnlocked);
            }
            return(false);
        }
    public void Run(float delta)
    {
        float y = Convert.ToSingle(Input.IsActionPressed("action_down")) - Convert.ToSingle(Input.IsActionPressed("action_up"));
        float x = Convert.ToSingle(Input.IsActionPressed("action_right")) - Convert.ToSingle(Input.IsActionPressed("action_left"));

        foreach (int i in _filter)
        {
            ref PlayerInputComponent component = ref _filter.Get1(i);
            component.MoveDirection = new Vector2(x, y).Normalized();
        }
Esempio n. 7
0
        /// <summary>
        /// Does set brittle references.
        ///
        /// NOTE: For simplicity, this brittle approach is used instead of alternatives;
        ///         * public transform references, set via dragging from hierarchy items
        ///         * Inversion Of Control (StrangeIoC) where less GameObject-to-GameObject references are needed.
        ///         * Manager dynamically spawning via Instantiate()
        ///         * Etc...
        ///
        ///
        /// NOTE: We could shift this code to a newly created GUIManager. For now its fine.
        ///
        ///
        /// </summary>
        private void _doSetBrittleReferences()
        {
            //
            _startWaypoint_gameobject = _doThrowErrorIfNull(GameObject.Find(MainConstants.StartWaypoint)) as GameObject;
            _player_gameobject        = _doThrowErrorIfNull(GameObject.Find(MainConstants.PlayerUnPrefab)) as GameObject;

            //
            _playerInputComponent  = _player_gameobject.GetComponent <PlayerInputComponent>();
            _characterController2D = _player_gameobject.GetComponent <CharacterController2D>();
        }
Esempio n. 8
0
        // PRIVATE STATIC

        // PRIVATE COROUTINE

        // PRIVATE INVOKE

        //--------------------------------------
        //  Events
        //--------------------------------------
        /// <summary>
        /// Raises the trigger enter2 d event.
        /// </summary>
        /// <param name="collider2D">Collider2 d.</param>
        public void OnTriggerEnter2D(Collider2D collider2D)
        {
            if (collider2D.gameObject.tag == MainConstants.PLAYER_TAG)
            {
                if (!_wasTriggered)
                {
                    PlayerInputComponent playerInputComponent = collider2D.gameObject.GetComponent <PlayerInputComponent>();
                    _doTriggerCollisionWithPlayer(playerInputComponent);
                }
            }
        }
Esempio n. 9
0
    public void ManualAwake()
    {
        _player         = GetComponent <Player>();
        _inputComponent = _player.inputComponent;
        _flagComponent  = _player.flagComponent;

        if (!photonView.isMine)
        {
            return;
        }

        _movementSlower = new MovementSlower(_player, _maxMovementSlowFactor, _slowFalloffExponent, _slowFalloffSpeed);
    }
Esempio n. 10
0
    public void ManualAwake()
    {
        _player             = GetComponent <Player>();
        _collisionComponent = _player.collisionComponent;
        _inputComponent     = _player.inputComponent;

        if (!photonView.isMine)
        {
            return;
        }

        _player.healthComponent.OnDeath += () => TryDropWeapon();

        FindObjectOfType <AmmoCounterUI>().Initialize(this);
    }
Esempio n. 11
0
        public async void AddCharacter(string hubId, Guid characterId)
        {
            var    player         = GetCharacter(Context.ConnectionId, characterId);
            Entity playerEntity   = _world.CreateEntity(); // you can pass an unique ID as first parameter.
            var    playerInput    = new PlayerInputComponent();
            var    playerLocation = new LocationComponent();

            playerLocation.RoomId    = 0;
            playerInput.connectionId = player.ConnectionId;
            playerInput.userId       = player.AccountId;
            //TODO:  Create character load to store/load components
            playerEntity.AddComponent(playerInput);
            playerEntity.AddComponent(playerLocation);
            AddCharacterToCache(Context.ConnectionId, player, playerEntity);
            await SendToClient($"Welcome {player.Name}. Your adventure awaits you.", Context.ConnectionId);

            GetRoom(Context.ConnectionId, player);
        }
Esempio n. 12
0
        public async Task <Entity> CreatePlayerEntity()
        {
            var playerInput    = new PlayerInputComponent(this);
            var playerGraphics = new PlayerGraphicsComponent(_spriteSheetLoader, _entitySpriteBatch, playerInput);
            await playerGraphics.LoadAsync();

            var playerPhysics = new PlayerPhysicsComponent(_mapManager);
            var playerAttack  = new PlayerAttackComponent(_spriteSheetLoader, _entitySpriteBatch);
            await playerAttack.LoadAsync();

            var player = new Entity(playerInput, playerPhysics, playerGraphics, playerAttack);

            player.Position = new Vector2(75, 75);
            EntityRegistry.Add(player);
            PlayerEntity = player;

            return(player);
        }
Esempio n. 13
0
        //Draw everything!
        public virtual void Draw(Graphics g)
        {
            sysManager.Draw(g);
            //this part is the check for the flash
            //if flashtime is greater than 0, then it means that flash needs to be done
            string towrite = "";

            if (getPlayer() != null)
            {
                if (getPlayer().hasComponent(GlobalVars.PLAYER_INPUT_COMPONENT_NAME))
                {
                    PlayerInputComponent pelInComp = ( PlayerInputComponent )getPlayer().getComponent(GlobalVars.PLAYER_INPUT_COMPONENT_NAME);
                    towrite = pelInComp.passedAirjumps.ToString();
                }
            }
            //g.DrawString( towrite, SystemFonts.DefaultFont, Brushes.Black, new RectangleF( 10, 30, cameraWidth - 20, cameraHeight - 20 ) );
            //g.DrawString( fps.ToString( "F" ) + "", SystemFonts.DefaultFont, Brushes.Black, new RectangleF( 10, 10, cameraWidth - 20, cameraHeight - 20 ) );
        }
Esempio n. 14
0
        // PUBLIC STATIC

        // PRIVATE
        /// <summary>
        /// Does trigger waypoing.
        ///
        /// NOTE: We crudely evaluate victory here. Todo: More checks could be added (player velocity.y)
        ///
        /// </summary>
        private void _doTriggerCollisionWithPlayer(PlayerInputComponent aPlayerInputComponent)
        {
            //FLAG THE COLLISION
            _wasTriggered = true;
            //
            if (aPlayerInputComponent.isVulnerableToEnemy)
            {
                SimpleGameManager.Instance.audioManager.doPlaySound(AudioClipType.ENEMY_KILLS_PLAYER);
                aPlayerInputComponent.doKnockOut();
                //BUT REFRESH QUICKLY COLLISION FLAG FOR ANY SUBSEQUENT INTERACTION
                Invoke("doRefreshEnemy", 1f);
            }
            else
            {
                SimpleGameManager.Instance.audioManager.doPlaySound(AudioClipType.PLAYER_KILLS_ENEMY);
                _enemyAIComponent.doKnockOut();
            }
        }
Esempio n. 15
0
        public override void revertToStartingState()
        {
            PositionComponent posComp = ( PositionComponent )this.getComponent(GlobalVars.POSITION_COMPONENT_NAME);

            level.getMovementSystem().teleportToNoCollisionCheck(posComp, posComp.startingX, posComp.startingY);
            level.getMovementSystem().changeSize(posComp, posComp.startingWidth, posComp.startingHeight);

            if (hasComponent(GlobalVars.PLAYER_INPUT_COMPONENT_NAME))
            {
                PlayerInputComponent plInComp = ( PlayerInputComponent )this.getComponent(GlobalVars.PLAYER_INPUT_COMPONENT_NAME);
                plInComp.passedAirjumps = 0;
            }

            VelocityComponent velComp = ( VelocityComponent )this.getComponent(GlobalVars.VELOCITY_COMPONENT_NAME);

            velComp.x = 0;
            velComp.y = 0;

            AnimationComponent animComp = ( AnimationComponent )this.getComponent(GlobalVars.ANIMATION_COMPONENT_NAME);

            animComp.animationOn = false;
            setNormalImage();
            level.sysManager.spSystem.toNoPowerups();

            HealthComponent healthComp = ( HealthComponent )this.getComponent(GlobalVars.HEALTH_COMPONENT_NAME);

            healthComp.restoreHealth();

            removeComponent(GlobalVars.PLAYER_INPUT_COMPONENT_NAME);
            addComponent(new PlayerInputComponent(this));

            if (!hasComponent(GlobalVars.GRAVITY_COMPONENT_NAME))
            {
                addComponent(new GravityComponent(0, GlobalVars.STANDARD_GRAVITY));
            }
        }
Esempio n. 16
0
 void Awake()
 {
     settings    = GetComponent <PlayerSettings>();
     playerInput = GetComponent <PlayerInputComponent>();
 }
Esempio n. 17
0
 public void PickUp(PlayerInputComponent inInputComponent)
 {
     _inputComponent = inInputComponent;
     OnPickedUp?.Invoke();
 }
Esempio n. 18
0
 public void Drop()
 {
     _inputComponent = null;
     OnDropped?.Invoke();
 }
Esempio n. 19
0
 void Awake()
 {
     playerInputLibrary = GetComponent <PlayerInputComponent>();
     movementComponent  = GetComponent <ShipMovementComponent>();
     targetPos          = transform.position;
 }
Esempio n. 20
0
 public void Run(float delta)
 {
     foreach (int i in _filter)
     {
         ref PlayerInputComponent playerInputComponent = ref _filter.Get1(i);
         ref MoveableComponent    moveableComponent    = ref _filter.Get2(i);
Esempio n. 21
0
 public Player(MinerGame game, GameObjectInitializer initializer)
     : base(game, initializer)
 {
     Input    = new PlayerInputComponent(this, 700f);
     Airborne = true;
 }
Esempio n. 22
0
        //-----------------------------------------------------------------------------

        //------------------------------- Helper Methods -------------------------------

        /*
         * This method checks to see if a left/right key is down and there's no movement.
         * If that's the case - it makes sure there's something blocking the movement, or it restarts it.
         *
         * This is used for situations like when the player is running against a wall and jumps, if the jump
         * clears the wall then the horizontal movement should restart without the need for a second key press.
         */
        public void restartHorizontalMovementIfNoBlock(VelocityComponent velComp, PositionComponent posComp, PlayerInputComponent pelInComp, AnimationComponent animComp)
        {
            if (Math.Abs(velComp.x) < Math.Abs(pelInComp.playerHorizMoveSpeed))
            {
                float allowedOverlap  = 3.0f;
                float extraHDistCheck = GlobalVars.MIN_TILE_SIZE / 2;
                float upperY          = (posComp.y - posComp.height / 2);
                float lowerY          = (posComp.y + posComp.height / 2 - allowedOverlap);

                if (level.getInputSystem().myKeys[GlobalVars.KEY_RIGHT].pressed && velComp.x == 0)
                {
                    float rightX = (posComp.x + posComp.width / 2 + extraHDistCheck);

                    bool tmpPrecice = GlobalVars.preciseCollisionChecking;
                    GlobalVars.preciseCollisionChecking = false; //turn off precise collision detection to prevent jitters.

                    List <Entity> cols = level.getCollisionSystem().findObjectsBetweenPoints(rightX, upperY, rightX, lowerY);
                    if (cols.Count <= 0)
                    {
                        beginMoveRight(posComp, velComp, pelInComp, animComp);
                    }

                    GlobalVars.preciseCollisionChecking = tmpPrecice; //put collision detection back to its normal setting
                }
                if (level.getInputSystem().myKeys[GlobalVars.KEY_LEFT].pressed && velComp.x == 0)
                {
                    float leftX      = (posComp.x - posComp.width / 2 - extraHDistCheck);
                    bool  tmpPrecice = GlobalVars.preciseCollisionChecking;
                    GlobalVars.preciseCollisionChecking = false; //turn off precise collision detection to prevent jitters.

                    List <Entity> cols = level.getCollisionSystem().findObjectsBetweenPoints(leftX, upperY, leftX, lowerY);

                    if (cols.Count <= 0)
                    {
                        beginMoveLeft(posComp, velComp, pelInComp, animComp);
                    }

                    GlobalVars.preciseCollisionChecking = tmpPrecice; //Put it back on asap!
                }
            }
        }
Esempio n. 23
0
        public override void Update(float deltaTime)
        {
            foreach (Entity e in getApplicableEntities())
            {
                PositionComponent    posComp   = ( PositionComponent )e.getComponent(GlobalVars.POSITION_COMPONENT_NAME);
                VelocityComponent    velComp   = ( VelocityComponent )e.getComponent(GlobalVars.VELOCITY_COMPONENT_NAME);
                PlayerInputComponent pelInComp = ( PlayerInputComponent )e.getComponent(GlobalVars.PLAYER_INPUT_COMPONENT_NAME);
                AnimationComponent   animComp  = ( AnimationComponent )e.getComponent(GlobalVars.ANIMATION_COMPONENT_NAME);
                checkForInput(posComp, velComp, pelInComp, animComp);
                ColliderComponent colComp = (ColliderComponent)e.getComponent(GlobalVars.COLLIDER_COMPONENT_NAME);

                List <Entity> collisions = level.getCollisionSystem().findObjectsBetweenPoints(
                    colComp.getX(posComp) - colComp.width / 2 + 1, colComp.getY(posComp) + (colComp.height / 2) + 1, colComp.getX(posComp) + colComp.width / 2 - 1, colComp.getY(posComp) +
                    (colComp.height / 2) + 1);

                //Reset passedAirJumps if needed
                if (pelInComp.passedAirjumps != 0 && collisions.Count > 0)
                {
                    if (!pelInComp.justJumped)
                    {
                        pelInComp.passedAirjumps = 0;
                    }
                    else
                    {
                        pelInComp.justJumped = false;
                    }
                }

                //If there's a key down and the player isn't moving horizontally, check to make sure there's a collision
                restartHorizontalMovementIfNoBlock(velComp, posComp, pelInComp, animComp);
                if (level != null && level.getPlayer() != null)
                {
                    if (level.getInputSystem().myKeys[GlobalVars.KEY_RIGHT].pressed || level.getInputSystem().myKeys[GlobalVars.KEY_LEFT].pressed)
                    {
                        level.getPlayer().startAnimation();
                    }
                    else
                    {
                        if (level.getPlayer() != null)
                        {
                            level.getPlayer().stopAnimation();
                        }
                    }
                }

                //Slow horizontal if no left/right key down
                if (velComp.x != 0 && !level.getInputSystem().myKeys[GlobalVars.KEY_LEFT].pressed && !level.getInputSystem().myKeys[GlobalVars.KEY_RIGHT].pressed)
                {
                    if (velComp.x < 0)
                    {
                        velComp.x += playerHorizSlowSpeed;
                        if (velComp.x > 0)
                        {
                            velComp.x = 0;
                        }
                    }
                    else
                    {
                        velComp.x -= playerHorizSlowSpeed;
                        if (velComp.x < 0)
                        {
                            velComp.x = 0;
                        }
                    }
                }
            }
        }
Esempio n. 24
0
 public void beginMoveRight(PositionComponent posComp, VelocityComponent velComp, PlayerInputComponent pelInComp, AnimationComponent animComp)
 {
     if (pelInComp != null && pelInComp.player != null)
     {
         velComp.setVelocity(pelInComp.playerHorizMoveSpeed, velComp.y);
         if (!pelInComp.player.isLookingRight())
         {
             pelInComp.player.faceRight();
         }
         level.getPlayer().startAnimation();
     }
 }
Esempio n. 25
0
 //----------------------------------- Input -----------------------------------
 public void checkForInput(PositionComponent posComp, VelocityComponent velComp, PlayerInputComponent pelInComp, AnimationComponent animComp)
 {
     if (level.getInputSystem().myKeys[GlobalVars.KEY_JUMP].down)
     {
         playerJump(posComp, velComp, pelInComp);
     }
     if (level.getInputSystem().myKeys[GlobalVars.KEY_LEFT].down)
     {
         beginMoveLeft(posComp, velComp, pelInComp, animComp);
     }
     if (level.getInputSystem().myKeys[GlobalVars.KEY_RIGHT].down)
     {
         beginMoveRight(posComp, velComp, pelInComp, animComp);
     }
     if (level.getInputSystem().myKeys[GlobalVars.KEY_RIGHT].up)
     {
         endRightHorizontalMove(posComp, velComp, animComp);
     }
     if (level.getInputSystem().myKeys[GlobalVars.KEY_LEFT].up)
     {
         endLeftHorizontalMove(posComp, velComp, animComp);
     }
 }