Example #1
0
 public override void Update()
 {
     base.Update();
     if (this.AnimationData.CurrentFrame == 8)
     {
         this.IsDead = true;
     }
     if (playerAffected == true)
     {
         HelperObject ho = (HelperObject)ObjectManager.GetObjectByName("HelperObject");
         ho.xVel = 0;
         ho.yVel = 0;
     }
 }
Example #2
0
        public override void CollisionReaction(CollisionInfo collisionInfo_)
        {
            base.CollisionReaction(collisionInfo_);
            GameObject with = collisionInfo_.collidedWithGameObject;

            if (with.Name == "PlayerBody" && playerAffected == false)
            {
                float xdiff = with.Position.X - Position.X;
                float ydiff = with.Position.Y - Position.Y;

                float xsquared = xdiff * xdiff;
                float ysquared = ydiff * ydiff;

                float length = (float)Math.Sqrt(xsquared + ysquared);
                xdiff /= length;
                ydiff /= length;
                HelperObject ho = (HelperObject)ObjectManager.GetObjectByName("HelperObject");
                ho.xVel        = xdiff * (1000 / (length + 200));
                ho.yVel        = ydiff * (1000 / (length + 200));
                playerAffected = true;
            }
        }
Example #3
0
 public override void Update()
 {
     base.Update();
     prevPosX         = Position.X;
     prevPosY         = Position.Y;
     this.Position.X += velocityX;
     this.Position.Y += velocityY;
     velocityY       -= 0.16f;
     ConstructLevel();
     timer -= FrameRateController.FrameTime;
     if (willDie == true)
     {
         HelperObject ho = (HelperObject)ObjectManager.GetObjectByName("HelperObject");
         ho.xVel     = 0;
         ho.yVel     = 0;
         this.IsDead = true;
         CollisionData.CollisionEnabled = false;
     }
     if (timer <= 0 && willDie == false)
     {
         Explode();
     }
 }
Example #4
0
        public override void CollisionReaction(CollisionInfo collisionInfo_)
        {
            base.CollisionReaction(collisionInfo_);
            GameObject with = collisionInfo_.collidedWithGameObject;

            if (with.Name == "PlayerBody")
            {
                PersistentData.Health -= damage;
                this.IsDead            = true;
                Random rand = new Random();
                PersistentData.Health -= damage;

                HelperObject ho = (HelperObject)ObjectManager.GetObjectByName("HelperObject");
                ho.bleedTicks = (int)(rand.NextDouble() * 10) + 8;
            }
            if (with.Name == "EnemyBody")
            {
                this.IsDead = true;
            }
            if (with.Name == "bullet1")
            {
                this.IsDead = true;
            }
            if (with.Name == "bullet2")
            {
                this.IsDead = true;
            }
            if (with.Name == "bullet3")
            {
                this.IsDead = true;
            }
            if (with.Name == "bullet4")
            {
                this.IsDead = true;
            }
        }
Example #5
0
        void PlayerMovement()
        {
            HelperObject ho = (HelperObject)ObjectManager.GetObjectByName("HelperObject");

            if (ho.xVel != 0)
            {
                playerVelX      += ho.xVel;
                playerIsOnGround = false;
            }
            if (ho.yVel != 0)
            {
                playerVelY += ho.yVel;
            }
            if (playerIsOnGround == true)
            {
                playerVelY  = 0;
                playerVelX *= 0.9f;
                if (InputManager.IsPressed(Keys.A) && canGoLeft == true && head.IsDead == false)
                {
                    playerVelX -= movementSpeed;
                }
                if (InputManager.IsPressed(Keys.D) && canGoRight == true && head.IsDead == false)
                {
                    playerVelX += movementSpeed;
                }
                if (InputManager.IsTriggered(Keys.W) && head.IsDead == false)
                {
                    playerVelY = PersistentData.jumpPower;
                }
                if (Math.Abs(playerVelX) > 0.5f)
                {
                    isWalking = true;
                }
                else
                {
                    isWalking = false;
                }
            }
            else
            {
                playerVelY -= 0.16f;
                if (InputManager.IsPressed(Keys.A) && canGoLeft == true && head.IsDead == false)
                {
                    playerVelX -= 0.02f;
                    playerPosX -= 0.7f;
                }
                if (InputManager.IsPressed(Keys.D) && canGoRight == true && head.IsDead == false)
                {
                    playerVelX += 0.02f;
                    playerPosX += 0.7f;
                }
            }
            if (playerIsOnGround == true)
            {
                if (isWalking == true)
                {
                    playerBodyFrameTime -= FrameRateController.FrameTime;
                    if (playerBodyFrameTime <= 0)
                    {
                        playerBodyFrameNum++;
                        playerBodyFrameTime = 0.1f;
                    }
                    if (playerBodyFrameNum >= 8)
                    {
                        playerBodyFrameNum = 0;
                    }
                }
                else
                {
                    playerBodyFrameNum = 0;
                }
            }
            else
            {
                playerBodyFrameNum = 2;
            }
            body.Position.X = playerPosX;
            body.Position.Y = playerPosY + 46;
            head.Position.X = playerPosX;
            head.Position.Y = playerPosY + 76;
            gun.Position.X  = playerPosX;
            gun.Position.Y  = playerPosY + 66;
            playerPosX     += playerVelX;
            playerPosY     += playerVelY;

            //float mousePosX = Cursor.Position.X - 965 + Camera.Position.X ;
            //float mousePosY = (Cursor.Position.Y * -1) + 500 + Camera.Position.Y;

            float mousePosX = Cursor.Position.X - 960 + gun.Position.X;
            float mousePosY = (Cursor.Position.Y * -1) + 540 + gun.Position.Y;

            float xdiff = mousePosX - gun.Position.X;
            float ydiff = mousePosY - gun.Position.Y;

            float xsquared = xdiff * xdiff;
            float ysquared = ydiff * ydiff;

            float length = (float)Math.Sqrt(xsquared + ysquared);

            xdiff /= length;
            ydiff /= length;

            //firing
            if (weapon1Cooldown > 0)
            {
                weapon1Cooldown   -= FrameRateController.FrameTime;
                ho.bullet1CoolDown = weapon1Cooldown;
            }
            if (weapon2Cooldown > 0)
            {
                weapon2Cooldown   -= FrameRateController.FrameTime;
                ho.bullet2CoolDown = weapon2Cooldown;
            }
            if (weapon3Cooldown > 0)
            {
                weapon3Cooldown   -= FrameRateController.FrameTime;
                ho.bullet3CoolDown = weapon3Cooldown;
            }
            if (weapon4Cooldown > 0)
            {
                weapon4Cooldown   -= FrameRateController.FrameTime;
                ho.bullet4CoolDown = weapon4Cooldown;
            }
            if (grenade1Cooldown > 0)
            {
                grenade1Cooldown   -= FrameRateController.FrameTime;
                ho.grenade1CoolDown = grenade1Cooldown;
            }
            if (grenade2Cooldown > 0)
            {
                grenade2Cooldown   -= FrameRateController.FrameTime;
                ho.grenade2CoolDown = grenade2Cooldown;
            }
            if (grenade3Cooldown > 0)
            {
                grenade3Cooldown   -= FrameRateController.FrameTime;
                ho.grenade3CoolDown = grenade3Cooldown;
            }
            if (grenade4Cooldown > 0)
            {
                grenade4Cooldown   -= FrameRateController.FrameTime;
                ho.grenade4CoolDown = grenade4Cooldown;
            }
            if (InputManager.IsTriggered(Keys.LButton) && head.IsDead == false)
            {
                if (PersistentData.weaponType == 1 && weapon1Cooldown <= 0)
                {
                    GameObject b = new bullet1(xdiff * 10, ydiff * 10);
                    b.Position.X    = gun.Position.X + xdiff * 30;
                    b.Position.Y    = gun.Position.Y + ydiff * 30;
                    weapon1Cooldown = PersistentData.weapon1DefaultCooldown;
                }
                if (PersistentData.weaponType == 2 && weapon2Cooldown <= 0)
                {
                    GameObject b = new bullet2(xdiff * 10, ydiff * 10);
                    b.Position.X    = gun.Position.X + xdiff * 30;
                    b.Position.Y    = gun.Position.Y + ydiff * 30;
                    weapon2Cooldown = PersistentData.weapon2DefaultCooldown;
                }
                if (PersistentData.weaponType == 3 && weapon3Cooldown <= 0)
                {
                    GameObject b = new bullet3(xdiff * 10, ydiff * 10);
                    b.Position.X    = gun.Position.X + xdiff * 30;
                    b.Position.Y    = gun.Position.Y + ydiff * 30;
                    weapon3Cooldown = PersistentData.weapon3DefaultCooldown;
                }
                if (PersistentData.weaponType == 4 && weapon4Cooldown <= 0)
                {
                    GameObject b = new bullet4(xdiff * 10, ydiff * 10);
                    b.Position.X    = gun.Position.X + xdiff * 30;
                    b.Position.Y    = gun.Position.Y + ydiff * 30;
                    weapon4Cooldown = PersistentData.weapon4DefaultCooldown;
                }
            }
            if (head.IsDead == false)
            {
                if (InputManager.IsTriggered(Keys.Z) && grenade1Cooldown <= 0 && PersistentData.grenade1 == true)
                {
                    GameObject g = new grenade1(xdiff * 5, ydiff * 5);
                    g.Position.X     = gun.Position.X + xdiff * 5;
                    g.Position.Y     = gun.Position.Y + ydiff * 5;
                    grenade1Cooldown = PersistentData.grenade1DefaultCooldown;
                }
                if (InputManager.IsTriggered(Keys.X) && grenade2Cooldown <= 0 && PersistentData.grenade2 == true)
                {
                    GameObject g = new grenade2(xdiff * 5, ydiff * 5);
                    g.Position.X     = gun.Position.X + xdiff * 5;
                    g.Position.Y     = gun.Position.Y + ydiff * 5;
                    grenade2Cooldown = PersistentData.grenade2DefaultCooldown;
                }
                if (InputManager.IsTriggered(Keys.C) && grenade3Cooldown <= 0 && PersistentData.grenade3 == true)
                {
                    GameObject g = new grenade3(xdiff * 7, ydiff * 7);
                    g.Position.X     = gun.Position.X + xdiff * 5;
                    g.Position.Y     = gun.Position.Y + ydiff * 5;
                    grenade3Cooldown = PersistentData.grenade3DefaultCooldown;
                }
                if (InputManager.IsTriggered(Keys.V) && grenade4Cooldown <= 0 && PersistentData.grenade4 == true)
                {
                    GameObject g = new grenade4(xdiff * 7, ydiff * 7);
                    g.Position.X     = gun.Position.X + xdiff * 5;
                    g.Position.Y     = gun.Position.Y + ydiff * 5;
                    grenade4Cooldown = PersistentData.grenade4DefaultCooldown;
                }
            }

            float radians = (float)(Math.Atan2(ydiff, xdiff));
            float degrees = (float)(radians * 180 / Math.PI);

            gun.Rotation = degrees;
            int FrameOffset = 0;

            if (degrees < 90 && degrees > -90 && head.IsDead == false)
            {
                gun.AnimationData.GoToFrame(0);
                head.AnimationData.GoToFrame(0);
                body.Rotation       = 0;
                FrameOffset         = 0;
                deadBodyFrameOffset = 0;
            }
            else if (head.IsDead == false)
            {
                gun.AnimationData.GoToFrame(1);
                head.AnimationData.GoToFrame(1);
                body.Rotation       = 180;
                FrameOffset         = 8;
                deadBodyFrameOffset = 12;
            }
            if (degrees > -60 || degrees < -120)
            {
                head.Rotation = degrees;
            }
            else if (degrees > -90)
            {
                head.Rotation = -60;
            }
            else
            {
                head.Rotation = -120;
            }
            body.AnimationData.GoToFrame((uint)(playerBodyFrameNum + FrameOffset));
        }
Example #6
0
        void IconUpdate()
        {
            HelperObject ho = (HelperObject)ObjectManager.GetObjectByName("HelperObject");

            if (PersistentData.bullet1 == true)
            {
                float percent = ho.bullet1CoolDown / PersistentData.weapon1DefaultCooldown;
                bullet1Cooldown.Scale.Y     = percent;
                bullet1Cooldown.Position.Y -= bullet1Cooldown.Height * (1 - percent) / 2;
                if (ho.bullet1CoolDown > 0)
                {
                    bullet1Icon.Opacity = 0.4f;
                }
                else
                {
                    bullet1Icon.Opacity = 1;
                }
            }
            else
            {
                bullet1Icon.Opacity = 0.2f;
            }
            if (PersistentData.bullet2 == true)
            {
                float percent = ho.bullet2CoolDown / PersistentData.weapon2DefaultCooldown;
                bullet2Cooldown.Scale.Y     = percent;
                bullet2Cooldown.Position.Y -= bullet2Cooldown.Height * (1 - percent) / 2;
                if (ho.bullet2CoolDown > 0)
                {
                    bullet2Icon.Opacity = 0.4f;
                }
                else
                {
                    bullet2Icon.Opacity = 1;
                }
            }
            else
            {
                bullet2Icon.Opacity = 0.2f;
            }
            if (PersistentData.bullet3 == true)
            {
                float percent = ho.bullet3CoolDown / PersistentData.weapon3DefaultCooldown;
                bullet3Cooldown.Scale.Y     = percent;
                bullet3Cooldown.Position.Y -= bullet3Cooldown.Height * (1 - percent) / 2;
                if (ho.bullet3CoolDown > 0)
                {
                    bullet3Icon.Opacity = 0.4f;
                }
                else
                {
                    bullet3Icon.Opacity = 1;
                }
            }
            else
            {
                bullet3Icon.Opacity = 0.2f;
            }
            if (PersistentData.bullet4 == true)
            {
                float percent = ho.bullet4CoolDown / PersistentData.weapon4DefaultCooldown;
                bullet4Cooldown.Scale.Y     = percent;
                bullet4Cooldown.Position.Y -= bullet4Cooldown.Height * (1 - percent) / 2;
                if (ho.bullet4CoolDown > 0)
                {
                    bullet4Icon.Opacity = 0.4f;
                }
                else
                {
                    bullet4Icon.Opacity = 1;
                }
            }
            else
            {
                bullet4Icon.Opacity = 0.2f;
            }
            if (PersistentData.grenade1 == true)
            {
                float percent = ho.grenade1CoolDown / PersistentData.grenade1DefaultCooldown;
                grenade1Cooldown.Scale.Y     = percent;
                grenade1Cooldown.Position.Y -= grenade1Cooldown.Height * (1 - percent) / 2;
                if (ho.grenade1CoolDown > 0)
                {
                    grenade1Icon.Opacity = 0.4f;
                }
                else
                {
                    grenade1Icon.Opacity = 1;
                }
            }
            else
            {
                grenade1Icon.Opacity = 0.2f;
            }
            if (PersistentData.grenade2 == true)
            {
                float percent = ho.grenade2CoolDown / PersistentData.grenade2DefaultCooldown;
                grenade2Cooldown.Scale.Y     = percent;
                grenade2Cooldown.Position.Y -= grenade2Cooldown.Height * (1 - percent) / 2;
                if (ho.grenade2CoolDown > 0)
                {
                    grenade2Icon.Opacity = 0.4f;
                }
                else
                {
                    grenade2Icon.Opacity = 1;
                }
            }
            else
            {
                grenade2Icon.Opacity = 0.2f;
            }
            if (PersistentData.grenade3 == true)
            {
                float percent = ho.grenade3CoolDown / PersistentData.grenade3DefaultCooldown;
                grenade3Cooldown.Scale.Y     = percent;
                grenade3Cooldown.Position.Y -= grenade3Cooldown.Height * (1 - percent) / 2;
                if (ho.grenade3CoolDown > 0)
                {
                    grenade3Icon.Opacity = 0.4f;
                }
                else
                {
                    grenade3Icon.Opacity = 1;
                }
            }
            else
            {
                grenade3Icon.Opacity = 0.2f;
            }
            if (PersistentData.grenade4 == true)
            {
                float percent = ho.grenade4CoolDown / PersistentData.grenade4DefaultCooldown;
                grenade4Cooldown.Scale.Y     = percent;
                grenade4Cooldown.Position.Y -= grenade4Cooldown.Height * (1 - percent) / 2;
                if (ho.grenade4CoolDown > 0)
                {
                    grenade4Icon.Opacity = 0.4f;
                }
                else
                {
                    grenade4Icon.Opacity = 1;
                }
            }
            else
            {
                grenade4Icon.Opacity = 0.2f;
            }
        }