private void ActionSuperJumpUp(BackgroundAccess Foreground)
        {
            // jump up 8 to 12
            if (this.VelocityY < 0.0f)
            {
                this._State = PlayerState.FallMoving;
            }
            else
            {
                this._State = PlayerState.SuperJumpUp;
            }

            if (this.Frame < 8 || this.Frame > 12)
            {
                this.Frame     = 8;
                this.VelocityY = SpaceAndTime.LengthFrom2DTo3D(50);
                this.VelocityX = 0.0f;
            }
            else if (this.Frame != 12)
            {
                this.Frame++;
            }

            this.ApplyNormalGravity();
        }
        private void ActionSuperJumpMoving(BackgroundAccess Foreground)
        {
            // 13 to 16
            if (this.VelocityY < 0.0f)
            {
                this._State = PlayerState.FallMoving;
            }
            else
            {
                this._State = PlayerState.SuperJumpMoving;
            }

            if (this.Frame < 13 || this.Frame > 16)
            {
                this.Frame     = 13;
                this.VelocityY = SpaceAndTime.LengthFrom2DTo3D(50);
                if (this.FaceLeft)
                {
                    this.VelocityX = SpaceAndTime.LengthFrom2DTo3D(16);
                }
                else
                {
                    this.VelocityX = -SpaceAndTime.LengthFrom2DTo3D(16);
                }
            }
            else if (this.Frame != 16)
            {
                this.Frame++;
            }

            this.ApplyNormalGravity();
        }
        private void ActionRollBack(BackgroundAccess Foreground)
        {
            //roll 8 to 5

            this._State = PlayerState.RollBack;

            if (this.Frame < 5 || this.Frame > 8)
            {
                this.Frame = 8;
            }
            else if (this.Frame == 5)
            {
                if (this.FaceLeft == true)
                {
                    this._State = PlayerState.StandLeft;
                }
                else
                {
                    this._State = PlayerState.StandRight;
                }
            }
            else
            {
                this.Frame--;
            }

            this.ApplyNormalGravity();
        }
        public override void Move(BackgroundAccess Foreground)
        {
            float NewX = 0;
            float NewY = 0;

            if (this._FaceLeft)
            {
                this.VelocityX = 0.1f;
            }
            else
            {
                this.VelocityX = -0.1f;
            }

            if (Foreground.CheckPlatformCollisionAndKillPlatforms(this, this.VelocityX, this.VelocityY, ref NewX, ref NewY) == false)
            {
                this.X = NewX;
                this.Y = NewY;
            }
            else
            {
                this._IsDead = true;
            }

            //Decrease velocity acording to gravity
            if (this.VelocityY > -0.3f)
            {
                this.VelocityY -= 0.02f;
            }
        }
        private void ActionParachute(BackgroundAccess Foreground)
        {
            //parachute 17
            this._State = PlayerState.Parachute;
            this.Frame  = 17;

            if (this.IsOnGround == true)
            {
                this._State = PlayerState.Land;
            }

            //Set velocity from gravity
            this.VelocityY -= SpaceAndTime.LengthFrom2DTo3D(2);
            if (this.VelocityY < SpaceAndTime.LengthFrom2DTo3D(8))
            {
                this.VelocityY = -SpaceAndTime.LengthFrom2DTo3D(8);
            }

            if (this.FaceLeft == true)
            {
                this.VelocityX = SpaceAndTime.LengthFrom2DTo3D(16);
            }
            else
            {
                this.VelocityX = -SpaceAndTime.LengthFrom2DTo3D(16);
            }
        }
        private void ActionHook(BackgroundAccess Foreground)
        {
            //Hook 24 to 25
            this._State = PlayerState.Hook;

            if (this.Frame < 24 || this.Frame > 25)
            {
                this.Frame = 24;
            }
            else if (this.Frame == 25)
            {
                if (this.FaceLeft == true)
                {
                    this._State = PlayerState.JumpLeftUp;
                }
                else
                {
                    this._State = PlayerState.JumpRightUp;
                }
            }
            else
            {
                this.Frame++;
            }

            this.ApplyNormalGravity();
        }
        public void ChangeState(BackgroundAccess ForeGround)
        {
            if (this.Location == SpriteAccess.LocationMode.Local)
            {
                this.ChangeStateLocal(ForeGround);
            }

            this.UpdateSpriteInfo();
        }
        private void ActionClimbIdle(BackgroundAccess Foreground)
        {
            //climb 26 to 28
            this._State = PlayerState.ClimbIdle;

            this.VelocityY = 0;
            this.VelocityX = 0;

            this.Frame = 27;
        }
        private void MoveUp(BackgroundAccess Foreground)
        {
//			float NewX = 0;
//			float NewY = 0;
//
//			Foreground.CheckPlatformCollision(this, 0.0f, this.VelocityY, ref NewX, ref NewY);
//			this.X = NewX;
//			this.Y = NewY;

            this.IsOnGround = false;
            this.Y         += this.VelocityY;
        }
        public static void MoveWeapons(BackgroundAccess Foreground)
        {
            for (int i = 0; i < WeaponManagerAccess.AllWeapons.Count; i++)
            {
                //move
                ((WeaponAccess)WeaponManagerAccess.AllWeapons[i]).Move(Foreground);

                //kill item if it hit a platform
                if (((WeaponAccess)WeaponManagerAccess.AllWeapons[i]).IsDead == true)
                {
                    WeaponManagerAccess.AllWeapons.RemoveAt(i);
                }
            }
        }
        private void ActionHurt(BackgroundAccess Foreground)
        {
            //hurt 7

            float BigMovement = SpaceAndTime.LengthFrom2DTo3D(30);

            if (this.Frame != 7)
            {
                this.Frame = 7;

                //First cancel all movement
                this.VelocityX = 0;
                this.VelocityY = 0;

                //Now get the new movement
                switch (this._HurtSide)
                {
                case (CollisionRectAccess.HitSide.TopRight):
                    this.VelocityX = BigMovement;
                    this.VelocityY = -BigMovement;
                    break;

                case (CollisionRectAccess.HitSide.TopLeft):
                    this.VelocityX = -BigMovement;
                    this.VelocityY = -BigMovement;
                    break;

                case (CollisionRectAccess.HitSide.BottomRight):
                    this.VelocityX = BigMovement;
                    this.VelocityY = BigMovement;
                    break;

                case (CollisionRectAccess.HitSide.BottomLeft):
                    this.VelocityX = -BigMovement;
                    this.VelocityY = BigMovement;
                    break;
                }
            }
            else if (this.VelocityX == 0 || this.IsOnGround)
            {
                this._HurtSide = CollisionRectAccess.HitSide.None;
                this._State    = PlayerState.RollBack;
            }

            this.ApplyNormalGravity();
        }
        private void ActionFallDown(BackgroundAccess Foreground)
        {
            //Fall 12
            if (this.IsOnGround == true)
            {
                this._State = PlayerState.Land;
            }
            else
            {
                this._State = PlayerState.FallDown;
                this.Frame  = 12;
            }

            this.VelocityX = 0.0f;

            this.ApplyNormalGravity();
        }
        public override void Move(BackgroundAccess Foreground)
        {
            if (this._FaceLeft)
            {
                this.VelocityX = 1.0f;
            }
            else
            {
                this.VelocityX = -1.0f;
            }

            this.X += this.VelocityX;

            if (this.X > 5 || this.X < -5)
            {
                this._IsDead = true;
            }
        }
        private void ActionClimbDown(BackgroundAccess Foreground)
        {
            //climb 26 to 28
            this._State = PlayerState.ClimbDown;

            this.X         = Foreground.GetPollCenter(this);
            this.VelocityY = -0.1f;
            this.VelocityX = 0;

            if (this.Frame < 26 || this.Frame >= 28)
            {
                this.Frame = 26;
            }
            else
            {
                this.Frame++;
            }
        }
        public override void Move(BackgroundAccess Foreground)
        {
            float NewX = 0;
            float NewY = 0;

            if (Foreground.CheckPlatformCollision(this, 0, this.VelocityY, ref NewX, ref NewY) == false)
            {
                this.Y = NewY;
            }
            else
            {
                this.VelocityY = 0.0f;
            }

            //Decrease velocity acording to gravity
            if (this.VelocityY > -0.3f)
            {
                this.VelocityY -= 0.02f;
            }
        }
        private void ActionRollForward(BackgroundAccess Foreground)
        {
            //roll 5 to 8

            this._State = PlayerState.RollForward;

            if (this.Frame < 5 || this.Frame > 8)
            {
                this.Frame = 5;
            }
            else if (this.Frame == 8)
            {
                if (this.FaceLeft == true)
                {
                    this._State = PlayerState.StandLeft;
                }
                else
                {
                    this._State = PlayerState.StandRight;
                }
            }
            else
            {
                this.Frame++;
            }

            if (this.FaceLeft == true)
            {
                this.VelocityX = SpaceAndTime.LengthFrom2DTo3D(16);
            }
            else
            {
                this.VelocityX = -SpaceAndTime.LengthFrom2DTo3D(16);
            }

            this.ApplyNormalGravity();
        }
Esempio n. 17
0
        private void LoadScript()
        {
            this.IsRunningScript = true;

            //Setup the screen
            this.Screen.StartDrawing(640, 480, (float)Math.PI / 4, 1.0f, 1000f);

            //Setup players
            this.PlayableCharacters    = new PlayableCharacterAccess[2];
            this.PlayableCharacters[0] = new PlayableCharacterAccess(this.Screen.device, GameConfig.Files.SpriteA, -2.3f, -1.0f, SpaceAndTime.SpriteZLocation, 128, 128, 1024, 1024, Color.FromArgb(0xFF, 0x00, 0xFF, 0x00), 20, 0);
            this.PlayableCharacters[1] = new PlayableCharacterAccess(this.Screen.device, GameConfig.Files.SpriteB, 2.6f, -1.0f, SpaceAndTime.SpriteZLocation, 128, 128, 1024, 1024, Color.FromArgb(0xFF, 0x00, 0xFF, 0x00), 20, 0);

            this.PlayableCharacters[0].Location = GameConfig.Locations.PlayerOne;
            this.PlayableCharacters[1].Location = GameConfig.Locations.PlayerTwo;

            this.PlayableCharacters[0].Sounds = this.sound;
            this.PlayableCharacters[1].Sounds = this.sound;

            //Get a device for the user
            // tell the manager what type of device and the key map.
            // the ControllerId uniquly matches the user to a device or
            // part of a device.
            InputDeviceManagerAccess.ControllerIdType ControllerId;
            ControllerId = this.InputDeviceManager.GetNewKeyboardInstance(DI.Key.I, DI.Key.K, DI.Key.J, DI.Key.L, DI.Key.U);
            //ControllerId = this.InputDeviceManager.GetNewGamepadInstance(InputDeviceAccess.Buttons.AnyUp, InputDeviceAccess.Buttons.AnyDown, InputDeviceAccess.Buttons.AnyLeft, InputDeviceAccess.Buttons.AnyRight, InputDeviceAccess.Buttons.One);
            this.PlayableCharacters[0].SetInputDevices(this.InputDeviceManager, ControllerId);

            ControllerId = this.InputDeviceManager.GetNewKeyboardInstance(DI.Key.W, DI.Key.S, DI.Key.A, DI.Key.D, DI.Key.E);
            //ControllerId = this.InputDeviceManager.GetNewGamepadInstance(InputDeviceAccess.Buttons.AnyUp, InputDeviceAccess.Buttons.AnyDown, InputDeviceAccess.Buttons.AnyLeft, InputDeviceAccess.Buttons.AnyRight, InputDeviceAccess.Buttons.One);
            this.PlayableCharacters[1].SetInputDevices(this.InputDeviceManager, ControllerId);


            this.Background = new BackgroundAccess(this.Screen.device);

            //Create Bubbles
            this.BubbleManager = new BubbleManagerAccess(this.Screen.device);
        }
        private void ActionRunLeft(BackgroundAccess Foreground)
        {
            //walk 32 to 37

            this._State   = PlayerState.RunLeft;
            this.FaceLeft = true;

            if (this.Frame == 34 || this.Frame == 37)
            {
                Sounds.PlayStep();
            }

            //Reset to first frame if this animation has not started
            if (this.Frame < 32 || this.Frame >= 37)
            {
                this.Frame = 32;
            }
            else
            {
                this.Frame++;                 //Move to next frame
            }
            this.VelocityX = SpaceAndTime.LengthFrom2DTo3D(16);
            this.ApplyNormalGravity();
        }
        private void ActionJumpUp(BackgroundAccess Foreground)
        {
            // jump up 8 to 12
            if (this.FaceLeft == true)
            {
                this._State = PlayerState.JumpLeftUp;
            }
            else
            {
                this._State = PlayerState.JumpRightUp;
            }

            if (this.Frame < 8 || this.Frame > 12)
            {
                this.Frame     = 8;
                this.VelocityY = SpaceAndTime.LengthFrom2DTo3D(32);
            }
            else if (this.Frame != 12)
            {
                this.Frame++;
            }

            this.ApplyNormalGravity();
        }
        private void MoveDown(BackgroundAccess Foreground)
        {
            float NewX = 0;
            float NewY = 0;

            if (this._State != PlayerState.ClimbDown)
            {
                if (Foreground.CheckPlatformCollision(this, 0.0f, this.VelocityY, ref NewX, ref NewY))
                {
                    this.IsOnGround = true;
                    this.VelocityY  = 0.0f;
                }
                else
                {
                    this.IsOnGround = false;
                }
                this.X = NewX;
                this.Y = NewY;
            }
            else
            {
                this.Y += this.VelocityY;
            }
        }
        private void ActionFallMoving(BackgroundAccess Foreground)
        {
            //Fall 12
            if (this.IsOnGround == true)
            {
                this._State = PlayerState.Land;
            }
            else
            {
                this._State = PlayerState.FallMoving;
                this.Frame  = 12;
            }

            if (this.FaceLeft)
            {
                this.VelocityX = SpaceAndTime.LengthFrom2DTo3D(16);
            }
            else
            {
                this.VelocityX = -SpaceAndTime.LengthFrom2DTo3D(16);
            }

            this.ApplyNormalGravity();
        }
 private void MoveHorizontal(BackgroundAccess Foreground)
 {
     this.X += this.VelocityX;
 }
 //this weapon doesn't move but it's children will
 public virtual void Move(BackgroundAccess Foreground)
 {
 }
        private void ChangeStateLocal(BackgroundAccess Foreground)
        {
            //Have the device manager give me a ref to the device
            // that way I can poll and get keys from it directly
            InputDeviceAccess CurrInputDevice = this.ParentInputDeviceManager.GetInputDeviceRef(this.ControllerId);

            CurrInputDevice.PollInput();


            //Make player fall if he is jumping and moving down
            if (this.VelocityY < 0 && this._State != PlayerState.Parachute &&
                this._State != PlayerState.ClimbDown && this._State != PlayerState.ClimbUp &&
                this._State != PlayerState.ClimbIdle && this._State != PlayerState.Drown &&
                this._HurtSide == CollisionRectAccess.HitSide.None)
            {
                if (this._State == PlayerState.JumpLeftMoving || this._State == PlayerState.JumpRightMoving || this._State == PlayerState.FallMoving)
                {
                    this._State = PlayerState.FallMoving;
                }
                else
                {
                    this._State = PlayerState.FallDown;
                }
            }

            //Make player fall off laders if they move right or left
            if (
                (this._State == PlayerState.ClimbDown || this._State == PlayerState.ClimbUp || this._State == PlayerState.ClimbIdle) &&
                (CurrInputDevice.GetKey(InputDeviceAccess.GameKeys.Left, this.ControllerId) || CurrInputDevice.GetKey(InputDeviceAccess.GameKeys.Right, this.ControllerId))
                )
            {
                this.FaceLeft = CurrInputDevice.GetKey(InputDeviceAccess.GameKeys.Left, this.ControllerId);
                this._State   = PlayerState.FallMoving;
            }


            //Synchronous animations
            // Respawn if the player sank into the goo or died
            if (this.Y < -2.2f || this._State == PlayerState.Dead)
            {
                this.ActionRespawn();
            }
            // Die
            else if (this._State == PlayerState.Dying || this._Item == ItemType.Death)
            {
                this.ActionDie();
            }
            // Drown
            else if (this.Y <= -1.6815 || this._State == PlayerState.Drown)
            {
                this.ActionDrown();
            }
            // Explode
            else if (this._State == PlayerState.Explode)
            {
                this.ActionExplode();
            }
            //Hurt
            else if (this._HurtSide != CollisionRectAccess.HitSide.None)
            {
                //TODO:
                //if ishurt and standing and they are pressing they key twords the
                // enemy then do is ramming and turn off hurt
                // otherwise do hurt
                this.ActionHurt(Foreground);
            }
            //				//Hook
            //			else if(this._Item == ItemType.Hook &&
            //				(
            //				this._State == PlayerState.Hook ||
            //				CurrInputDevice.GetKey(InputDeviceAccess.GameKeys.Attack, this.ControllerId)==true &&
            //				(this._State == PlayerState.FallDown || this._State == PlayerState.FallMoving ||
            //				this._State == PlayerState.JumpLeftMoving || this._State == PlayerState.JumpRightMoving ||
            //				this._State == PlayerState.JumpLeftUp || this._State == PlayerState.JumpRightUp)
            //				)
            //				)
            //			{
            //				this.ActionHook(Foreground);
            //			}
            //Parachute
            else if (
                this._Item == ItemType.parachute &&
                (CurrInputDevice.GetKey(InputDeviceAccess.GameKeys.Attack, this.ControllerId) == true || this._State == PlayerState.Parachute) &&
                (this._State == PlayerState.FallDown || this._State == PlayerState.FallMoving || this._State == PlayerState.Parachute)
                )
            {
                if (CurrInputDevice.GetKey(InputDeviceAccess.GameKeys.Right, this.ControllerId))
                {
                    this.FaceLeft = false;
                }
                else if (CurrInputDevice.GetKey(InputDeviceAccess.GameKeys.Left, this.ControllerId))
                {
                    this.FaceLeft = true;
                }
                this.ActionParachute(Foreground);
            }
            //Landing
            else if (this.IsOnGround && (this._State == PlayerState.Land || this._State == PlayerState.FallDown || this._State == PlayerState.FallMoving))
            {
                this.ActionLand();
            }
            //Climbing up poll
            else if (CurrInputDevice.GetKey(InputDeviceAccess.GameKeys.Up, this.ControllerId) &&
                     Foreground.CanGrabPoll(this) && (this.IsOnGround || this._State == PlayerState.ClimbUp || this._State == PlayerState.ClimbDown || this._State == PlayerState.ClimbIdle))
            {
                this.ActionClimbUp(Foreground);
            }
            //Climbing down poll
            else if (CurrInputDevice.GetKey(InputDeviceAccess.GameKeys.Down, this.ControllerId) &&
                     Foreground.CanGrabPoll(this) && (this.IsOnGround || this._State == PlayerState.ClimbUp || this._State == PlayerState.ClimbDown || this._State == PlayerState.ClimbIdle))
            {
                this.ActionClimbDown(Foreground);
            }
            //Idle on poll
            else if (this._State == PlayerState.ClimbUp || this._State == PlayerState.ClimbDown || this._State == PlayerState.ClimbIdle)
            {
                this.ActionClimbIdle(Foreground);
            }
            //Falling Moving and Falling Down
            else if (this.IsOnGround == false && this._State != PlayerState.Parachute &&
                     this._State != PlayerState.JumpLeftMoving && this._State != PlayerState.JumpRightMoving &&
                     this._State != PlayerState.JumpLeftUp && this._State != PlayerState.JumpRightUp &&
                     this._State != PlayerState.SuperJumpMoving && this._State != PlayerState.SuperJumpUp)
            {
                if (this._State != PlayerState.FallDown)
                {
                    this.ActionFallMoving(Foreground);
                }
                else
                {
                    this.ActionFallDown(Foreground);
                }
            }
            //Jumping moving
            else if (
                (this._State == PlayerState.JumpRightMoving || this._State == PlayerState.JumpLeftMoving) ||
                (CurrInputDevice.GetKey(InputDeviceAccess.GameKeys.Up, this.ControllerId) == true &&
                 (CurrInputDevice.GetKey(InputDeviceAccess.GameKeys.Left, this.ControllerId) == true || CurrInputDevice.GetKey(InputDeviceAccess.GameKeys.Right, this.ControllerId) == true) &&
                 this.IsOnGround == true)
                )
            {
                //Set a direction for the initial frame
                if (this._State != PlayerState.JumpRightMoving && this._State != PlayerState.JumpLeftMoving)
                {
                    this.FaceLeft = CurrInputDevice.GetKey(InputDeviceAccess.GameKeys.Left, this.ControllerId);
                }
                this.ActionJumpMoving(Foreground);
            }
            //Jumping up
            else if (
                (this._State == PlayerState.JumpRightUp || this._State == PlayerState.JumpLeftUp) ||
                CurrInputDevice.GetKey(InputDeviceAccess.GameKeys.Up, this.ControllerId) == true &&
                this.IsOnGround == true
                )
            {
                this.ActionJumpUp(Foreground);
            }
            //Super Jump moving
            else if (
                this._State == PlayerState.SuperJumpMoving ||
                (CurrInputDevice.GetKey(InputDeviceAccess.GameKeys.Attack, this.ControllerId) == true &&
                 this._Item == ItemType.SuperJump &&
                 (CurrInputDevice.GetKey(InputDeviceAccess.GameKeys.Left, this.ControllerId) == true || CurrInputDevice.GetKey(InputDeviceAccess.GameKeys.Right, this.ControllerId) == true) &&
                 this.IsOnGround == true)
                )
            {
                //Set a direction for the initial frame
                if (this._State != PlayerState.JumpRightMoving && this._State != PlayerState.JumpLeftMoving)
                {
                    this.FaceLeft = CurrInputDevice.GetKey(InputDeviceAccess.GameKeys.Left, this.ControllerId);
                }
                this.ActionSuperJumpMoving(Foreground);
            }
            //Super Jump up
            else if (
                this._State == PlayerState.SuperJumpUp ||
                (this._Item == ItemType.SuperJump &&
                 CurrInputDevice.GetKey(InputDeviceAccess.GameKeys.Attack, this.ControllerId) == true &&
                 this.IsOnGround == true)
                )
            {
                this.ActionSuperJumpUp(Foreground);
            }
            //Rolling backwords
            else if (this._State == PlayerState.RollBack)
            {
                this.ActionRollBack(Foreground);
            }
            //Rolling Forward
            else if (
                this._State == PlayerState.RollForward ||
                (
                    (this._State == PlayerState.RunRight || this._State == PlayerState.RunLeft) &&
                    CurrInputDevice.GetKey(InputDeviceAccess.GameKeys.Down, this.ControllerId) == true &&
                    (CurrInputDevice.GetKey(InputDeviceAccess.GameKeys.Left, this.ControllerId) == true || CurrInputDevice.GetKey(InputDeviceAccess.GameKeys.Right, this.ControllerId) == true)
                )
                )
            {
                this.ActionRollForward(Foreground);
            }
            //Use weapon
            else if ((CurrInputDevice.GetKey(InputDeviceAccess.GameKeys.Attack, this.ControllerId) == true || this._State == PlayerState.Shoot || this._State == PlayerState.Grenade || this._State == PlayerState.Mine || this._State == PlayerState.SlideMine) && this.ItemCount > 0)
            {
                if (this._Item == ItemType.Gun)
                {
                    this.ActionGun();
                }
                else if (this._Item == ItemType.Grenade)
                {
                    this.ActionGrenade();
                }
                else if (this._Item == ItemType.SlideMine)
                {
                    this.ActionSlideMine();
                }
                else if (this._Item == ItemType.Mine)
                {
                    this.ActionMine();
                }
            }
            //Asynchronous animations
            //Ducking
            else if (CurrInputDevice.GetKey(InputDeviceAccess.GameKeys.Down, this.ControllerId) == true)
            {
                this.ActionDuck();
            }
            //Running Right
            else if (CurrInputDevice.GetKey(InputDeviceAccess.GameKeys.Right, this.ControllerId) == true)
            {
                this.ActionRunRight(Foreground);
            }
            //Running Left
            else if (CurrInputDevice.GetKey(InputDeviceAccess.GameKeys.Left, this.ControllerId) == true)
            {
                this.ActionRunLeft(Foreground);
            }
            //Idle animations
            else if (this._State == PlayerState.Duck)
            {
                this.ActionLand();
            }
            else
            {
                if (this.FaceLeft == false)
                {
                    this.ActionStandRight();
                }
                else
                {
                    this.ActionStandLeft();
                }
            }

            //Move player
            if (this.VelocityX != 0.0f)
            {
                this.MoveHorizontal(Foreground);
            }
            if (this.VelocityY > 0.0f)
            {
                this.MoveUp(Foreground);
            }
            else if (this.VelocityY < 0.0f)
            {
                this.MoveDown(Foreground);
            }
        }