Пример #1
0
 public virtual void Init()
 {
     for (int level = 1; level <= 3; level++)
     {
         currentGunLevel = gunLevels [level - 1];
         ObjectPooler.Pool pool = new ObjectPooler.Pool(GetGunTag(level), currentGunLevel.bullet, currentGunLevel.bulletCount);
         ObjectPooler.instance.AddToPool(pool);
     }
 }
 /// <summary>
 /// Initalizes the Player object
 /// </summary>
 public void Initialize()                           //the vertical texture, the horizontal texture and the starting position of the player
 {
     this.HitBox      = setHitBox();                // Generates the hitbox
     this.Active      = this.Animation.Active;      //the player starts active
     this.Health      = 100;
     this.Angle       = (float)(Math.PI * 0 / 180); // The animation will be drawn at its default rotation
     this.Firing      = false;
     this.hit         = false;
     this.elapsedTime = 0;
     this.fireRate    = 150;
     type             = BulletType.Player;
     this.Score       = 0;
     modifier         = 1;
     this.Level       = GunLevel.one;
 }
Пример #3
0
    public int GetLevel(float XP)
    {
        float exp = XP;

        int ret = 0;

        while (exp >= 0 && ret <= 2)
        {
            ret++;
            GunLevel gl = gunLevels [ret - 1];
            exp -= gl.XPToNextLevel;
        }

        return(Mathf.Clamp(ret, 1, 3));
    }
Пример #4
0
 public void Respawn(int xPos, int yPos, bool spawnRight, Bullet bullet)
 {
     pBullet = bullet;
     if (spawnRight)
     {
         pTexture    = pTextureR;
         pGunTexture = pGunTextureR;
         pGunOffset  = pPosition.Width / 2;
     }
     else
     {
         pTexture    = pTextureL;
         pGunTexture = pGunTextureL;
         pGunOffset  = -(pPosition.Width / 2);
     }
     pPosition.X                  = xPos;
     pPosition.Y                  = yPos;
     newPosition                  = pPosition;
     pCollisionPosition           = pPosition;
     pCollisionPosition.X        -= (int)(pCollisionPosition.Width / 2);
     pCollisionPosition.Y        -= (int)(pCollisionPosition.Height / 2);
     pGunPosition.X               = pPosition.X + pGunOffset;
     pGunPosition.Y               = pPosition.Y - (pPosition.Height / 4);
     pGunCollisionPosition        = pGunPosition;
     pGunCollisionPosition.Height = (3 * (pGunPosition.Height / 2));
     pGunCollisionPosition.Width  = (int)(pGunPosition.Width * 1.2);
     pGunCollisionPosition.X     -= pGunPosition.Width / 2;
     pGunCollisionPosition.Y     -= pGunPosition.Height / 2;
     pVelocity.X                  = 0;
     pVelocity.Y                  = 0;
     onGround          = true;
     jumping           = false;
     loaded            = true;
     dead              = false;
     pLevelOffset      = 0;
     collisionPlatform = -1;
     level             = GunLevel.Mid;
     pTimeElapsed      = 0;
 }
Пример #5
0
        public void Update(KeyboardState kState, KeyboardState oldKState, GamePadState cState, GamePadState oldCState, GraphicsDevice graphics, GameTime gameTime)
        {
            if (!dead)
            {
                if (playerNum == 1)
                {
                    shoot    = Keys.F;
                    left     = Keys.A;
                    right    = Keys.D;
                    jump     = Keys.G;
                    lowerGun = Keys.S;
                    raiseGun = Keys.W;
                }
                else if (playerNum == 2)
                {
                    shoot    = Keys.NumPad1;
                    left     = Keys.Left;
                    right    = Keys.Right;
                    jump     = Keys.NumPad2;
                    lowerGun = Keys.Down;
                    raiseGun = Keys.Up;
                }

                if (cState.IsConnected)
                {
                    if ((cState.Triggers.Right > 0.2 || kState.IsKeyDown(shoot)) && oldCState.Triggers.Right <= 0.2 && loaded && oldKState.IsKeyUp(shoot))                     // Shoot bullet
                    {
                        if (Level.curLevel.PlatformCollision(pGunCollisionPosition) == -1)
                        {
                            if (pTexture == pTextureR)
                            {
                                if (level == GunLevel.Mid)
                                {
                                    pBullet.Fire(new Vector2(1, 0), pGunPosition);
                                }
                                else if (level == GunLevel.High)
                                {
                                    pBullet.Fire(new Vector2(1, 1), pGunPosition);
                                }
                                else
                                {
                                    pBullet.Fire(new Vector2(1, -1), pGunPosition);
                                }
                            }
                            else
                            {
                                if (level == GunLevel.Mid)
                                {
                                    pBullet.Fire(new Vector2(-1, 0), pGunPosition);
                                }
                                else if (level == GunLevel.High)
                                {
                                    pBullet.Fire(new Vector2(-1, 1), pGunPosition);
                                }
                                else
                                {
                                    pBullet.Fire(new Vector2(-1, -1), pGunPosition);
                                }
                            }
                            Fire();
                        }
                    }

                    if (cState.ThumbSticks.Left.X < -0.2 || kState.IsKeyDown(left))                     // Move left
                    {
                        pVelocity.X -= ((float)graphics.Viewport.Width / 128);
                        if (pTexture == pTextureR)
                        {
                            Turn(-(int)pPosition.Width / 2);
                        }
                        WalkAnimate(gameTime);
                    }

                    if (cState.ThumbSticks.Left.X > 0.2 || kState.IsKeyDown(right))                     // Move right
                    {
                        pVelocity.X += ((float)graphics.Viewport.Width / 128);
                        if (pTexture == pTextureL)
                        {
                            Turn((int)pPosition.Width / 2);
                        }
                        WalkAnimate(gameTime);
                    }

                    if (!kState.IsKeyDown(right) && !kState.IsKeyDown(left) && cState.ThumbSticks.Left.X < 0.2 && cState.ThumbSticks.Left.X > -0.2)                     // if not moving, play still shot
                    {
                        spriteSheet.X = 214 * 0;
                        spriteSheet.Y = 317 * 0;
                    }

                    if (cState.Buttons.A == ButtonState.Pressed || cState.Triggers.Left > 0.2 || kState.IsKeyDown(jump))                     // Jump
                    {
                        if (onGround && !jumping)
                        {
                            pVelocity.Y -= 30 * ((float)graphics.Viewport.Height / 720);
                            jumping      = true;
                            onGround     = false;
                        }
                        else if (!onGround && jumping && pVelocity.Y < 0)
                        {
                            pVelocity.Y -= ((float)graphics.Viewport.Height / 720);
                        }
                    }
                    if (kState.IsKeyUp(jump) && cState.Buttons.A == ButtonState.Released && cState.Triggers.Left <= 0.2 && (oldCState.Buttons.A == ButtonState.Pressed || oldCState.Triggers.Left > 0.2 || oldKState.IsKeyDown(jump)))
                    {
                        jumping = false;
                    }
                    // if ((cState.ThumbSticks.Right.Y > 0.2 || cState.ThumbSticks.Left.Y > 0.2 || kState.IsKeyDown(raiseGun)) && oldKState.IsKeyUp(raiseGun) && oldCState.ThumbSticks.Right.Y < 0.2 && oldCState.ThumbSticks.Left.Y < 0.2)
                    if ((cState.ThumbSticks.Right.Y > 0.2 || kState.IsKeyDown(raiseGun)) && oldKState.IsKeyUp(raiseGun) && oldCState.ThumbSticks.Right.Y < 0.2)                     // Change gun level
                    {
                        if (level == Player.GunLevel.Low)
                        {
                            level        = Player.GunLevel.Mid;
                            pLevelOffset = 0;
                        }
                        else if (level == Player.GunLevel.Mid)
                        {
                            level        = Player.GunLevel.High;
                            pLevelOffset = -((int)pPosition.Height / 4);
                        }
                    }
                    // if ((cState.ThumbSticks.Right.Y < -0.2 || cState.ThumbSticks.Left.Y < -0.2 || kState.IsKeyDown(lowerGun)) && oldKState.IsKeyUp(lowerGun) && oldCState.ThumbSticks.Right.Y > -0.2 && oldCState.ThumbSticks.Left.Y > -0.2)
                    if ((cState.ThumbSticks.Right.Y < -0.2 || kState.IsKeyDown(lowerGun)) && oldKState.IsKeyUp(lowerGun) && oldCState.ThumbSticks.Right.Y > -0.2)                     // Change gun level
                    {
                        if (level == Player.GunLevel.High)
                        {
                            level        = Player.GunLevel.Mid;
                            pLevelOffset = 0;
                        }
                        else if (level == Player.GunLevel.Mid)
                        {
                            level        = Player.GunLevel.Low;
                            pLevelOffset = (int)pPosition.Height / 4;
                        }
                    }
                }
                else
                {
                    if (kState.IsKeyDown(shoot) && loaded && oldKState.IsKeyUp(shoot))                     // Shoot bullet
                    {
                        if (Level.curLevel.PlatformCollision(pGunCollisionPosition) == -1)
                        {
                            if (pTexture == pTextureR)
                            {
                                if (level == GunLevel.Mid)
                                {
                                    pBullet.Fire(new Vector2(1, 0), pGunPosition);
                                }
                                else if (level == GunLevel.High)
                                {
                                    pBullet.Fire(new Vector2(1, 1), pGunPosition);
                                }
                                else
                                {
                                    pBullet.Fire(new Vector2(1, -1), pGunPosition);
                                }
                            }
                            else
                            {
                                if (level == GunLevel.Mid)
                                {
                                    pBullet.Fire(new Vector2(-1, 0), pGunPosition);
                                }
                                else if (level == GunLevel.High)
                                {
                                    pBullet.Fire(new Vector2(-1, 1), pGunPosition);
                                }
                                else
                                {
                                    pBullet.Fire(new Vector2(-1, -1), pGunPosition);
                                }
                            }
                            Fire();
                        }
                    }

                    if (kState.IsKeyDown(left))                     // Move left
                    {
                        pVelocity.X -= ((float)graphics.Viewport.Width / 128);
                        if (pTexture == pTextureR)
                        {
                            Turn(-(int)pPosition.Width / 2);
                        }
                        WalkAnimate(gameTime);
                    }

                    if (kState.IsKeyDown(right))                     // Move right
                    {
                        pVelocity.X += ((float)graphics.Viewport.Width / 128);
                        if (pTexture == pTextureL)
                        {
                            Turn((int)pPosition.Width / 2);
                        }
                        WalkAnimate(gameTime);
                    }

                    if (!kState.IsKeyDown(right) && !kState.IsKeyDown(left))                     // if not moving, play still shot
                    {
                        spriteSheet.X = 214 * 0;
                        spriteSheet.Y = 317 * 0;
                    }

                    if (kState.IsKeyDown(jump))                     // Jump
                    {
                        if (onGround && !jumping)
                        {
                            pVelocity.Y -= 30 * ((float)graphics.Viewport.Height / 720);
                            jumping      = true;
                            onGround     = false;
                        }
                        else if (!onGround && jumping && pVelocity.Y < 0)
                        {
                            pVelocity.Y -= ((float)graphics.Viewport.Height / 720);
                        }
                    }
                    if (kState.IsKeyUp(jump) && oldKState.IsKeyDown(jump))
                    {
                        jumping = false;
                    }
                    if (kState.IsKeyDown(raiseGun) && oldKState.IsKeyUp(raiseGun))                     // Change gun level
                    {
                        if (level == Player.GunLevel.Low)
                        {
                            level        = Player.GunLevel.Mid;
                            pLevelOffset = 0;
                        }
                        else if (level == Player.GunLevel.Mid)
                        {
                            level        = Player.GunLevel.High;
                            pLevelOffset = -((int)pPosition.Height / 4);
                        }
                    }
                    if (kState.IsKeyDown(lowerGun) && oldKState.IsKeyUp(lowerGun))                     // Change gun level
                    {
                        if (level == Player.GunLevel.High)
                        {
                            level        = Player.GunLevel.Mid;
                            pLevelOffset = 0;
                        }
                        else if (level == Player.GunLevel.Mid)
                        {
                            level        = Player.GunLevel.Low;
                            pLevelOffset = (int)pPosition.Height / 4;
                        }
                    }
                }

                // ------------------------------------------ Calculating velocity
                CalcVelocity(gameTime);
                CalcVelocity(gameTime);

                pPosition.X += (int)(pVelocity.X * (float)gameTime.ElapsedGameTime.TotalMilliseconds / 16);
                pPosition.Y += (int)(pVelocity.Y * (float)gameTime.ElapsedGameTime.TotalMilliseconds / 16);

                pCollisionPosition    = pPosition;
                pCollisionPosition.X -= (int)(pCollisionPosition.Width / 2);
                pCollisionPosition.Y -= (int)(pCollisionPosition.Height / 2);

                pGunPosition.X        = pPosition.X + pGunOffset;
                pGunPosition.Y        = pPosition.Y + pLevelOffset;
                pGunCollisionPosition = pGunPosition;
                if (pTexture == pTextureL)
                {
                    pGunCollisionPosition.X -= (int)(pGunPosition.Width * 0.2);
                }
                if (level == GunLevel.Mid)
                {
                    pGunCollisionPosition.X     -= pGunPosition.Width / 2;
                    pGunCollisionPosition.Y     -= pGunPosition.Height / 2;
                    pGunCollisionPosition.Height = (3 * (pGunPosition.Height / 2));
                    pGunCollisionPosition.Width  = (int)(1.2 * pGunPosition.Width);
                }
                else if (level == GunLevel.Low)
                {
                    if (pTexture == pTextureR)
                    {
                        pGunCollisionPosition.X -= pGunPosition.Width / 2;
                    }
                    else
                    {
                        pGunCollisionPosition.X -= pGunPosition.Width / 4;
                    }
                    pGunCollisionPosition.Y     -= pGunPosition.Height / 4;
                    pGunCollisionPosition.Width  = 3 * (pGunPosition.Width / 4);
                    pGunCollisionPosition.Height = (3 * (pGunPosition.Height / 2));
                }
                else
                {
                    if (pTexture == pTextureR)
                    {
                        pGunCollisionPosition.X -= pGunPosition.Width / 2;
                    }
                    else
                    {
                        pGunCollisionPosition.X -= pGunPosition.Width / 4;
                    }
                    pGunCollisionPosition.Y     -= pGunPosition.Height;
                    pGunCollisionPosition.Width  = 3 * (pGunPosition.Width / 4);
                    pGunCollisionPosition.Height = (3 * (pGunPosition.Height / 2));
                }

                if (pVelocity.Y != 0)
                {
                    onGround = false;
                }

                if (!jumping)
                {
                    pVelocity.Y += pAcceleration - ((float)graphics.Viewport.Height / 720);
                }
                else
                {
                    pVelocity.Y += pAcceleration;
                }

                // ------------------------------------------ Resetting values
                pVelocity.X = 0;
            }
            // ------------------------------------------ Death handle
            else if (dead && loaded)
            {
                if (pTexture == pTextureR)
                {
                    pBullet.Dead(new Vector2(1, 0), pGunPosition);
                }
                else
                {
                    pBullet.Dead(new Vector2(-1, 0), pGunPosition);
                }
                Fire();
            }
        }