Beispiel #1
0
        private void Move()
        {
            //Trailing smoke particles
            if (tiLifetimeCounter.ElapsedSoFar > 0.5 - GM.r.FloatBetween(0.1f, 0.3f))
            {
                Vector2 offset = new Vector2(20 * RotationHelper.MyDirection(this, 180).X, 20 * RotationHelper.MyDirection(this, 180).Y);
                new SmokeParticle(Position2D + offset, Vector3.Zero, Vector2.Zero, 0.2f);
                GM.eventM.AddTimer(tiSmokeCounter = new Event(0.5f, "Smoke Counter"));
            }

            if (target.Dead)
            {
                RotationHelper.VelocityInCurrentDirection(this, speed, 0);
            }
            else
            {
                //turnDir = -1, anticlockwise; 0, none; 1, clockwise
                int turnDir = (int)RotationHelper.AngularDirectionTo(this, target.Position, 0, false);

                //Direction to add velocity to, additional angle is 90 * turnDir so -90 for anticlockwise, 90 for clockwise, straight ahead for none
                Vector3 velDir = RotationHelper.MyDirection(this, 90 * turnDir);

                Velocity  = RotationHelper.MyDirection(this, 0) * speed;
                Velocity += velDir * (turnAmount / 5);
                RotationHelper.FaceVelocity(this, DirectionAccuracy.free, false, 0);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Constructor for bullet class
        /// </summary>
        /// <param name="player">The object that fired the bullet</param>
        /// <param name="fireAngle">2D vector to travel towards</param>
        /// <param name="bulletSpeed">Speed of bullet</param>
        /// <param name="bulletDamage">Damage on hit</param>
        public Bullet(Sprite player, Vector2 fireAngle, float bulletSpeed, int bulletDamage)
        {
            damage = bulletDamage;

            this.player = player;
            GM.engineM.AddSprite(this);
            Frame.Define(Tex.SingleWhitePixel);
            SX = 4;
            SY = 24;

            //Sound effects
            GM.audioM.PlayEffect("shoot");

            //get player attributes
            Wash = player.Wash;

            //set postion of bullet and give velocity
            X = player.Centre.X;
            Y = player.Centre.Y;

            //Set rotation at player
            Position2D = RotationHelper.RotateAround(player.Centre2D, player.Centre2D, 0);

            //Create direction vector and normalise
            Vector2 direction = fireAngle - Position2D;

            direction = Vector2.Normalize(direction);

            //Face direction vector
            RotationHelper.FaceDirection(this, direction, DirectionAccuracy.free, 0);
            RotationHelper.VelocityInCurrentDirection(this, bulletSpeed, 0);
            Position += RotationHelper.MyDirection(this, 0) * 32;

            //collision setup
            CollisionActive   = true;
            CollisionPrimary  = true;
            PrologueCallBack += Hit;
            EpilogueCallBack += AfterHit;
            Moving            = true;

            //kill after 5 seconds
            TimerInitialise();
            Timer.KillAfter(5f);
        }
Beispiel #3
0
        /// <summary>
        /// Code to run each tick
        /// </summary>
        private void Tick()
        {
            if (Visible && velApplied == false)
            {
                RotationHelper.VelocityInCurrentDirection(this, 750, 0);

                Velocity += new Vector3(GM.r.FloatBetween(-20, 20), GM.r.FloatBetween(-20, 20), 0);

                GM.audioM.PlayEffect("shoot");

                //Release smoke
                int rAmount = (int)GM.r.FloatBetween(1, 2);
                for (int i = 0; i < rAmount; i++)
                {
                    new FadingParticle(Position2D, Velocity * 0.01f, RotationAngle, 5);
                }

                velApplied = true;
            }
        }
Beispiel #4
0
        private void Move()
        {
            //For gunSprite
            Vector2 playerPos = GameSetup.PlayerChar.Position2D;
            Vector2 direction = playerPos - Position2D;

            direction = Vector2.Normalize(direction);
            RotationHelper.FaceDirection(gunSprite, direction, DirectionAccuracy.free, 0);
            gunSprite.Position2D = Position2D + (direction * 15);
            Vector2 currentPosition = Position2D;

            //For movement:
            float distanceFromPlayer = Vector2.Distance(Position2D, playerPos);

            if (distanceFromPlayer > 200)
            {
                //Move towards player
                RotationHelper.FacePosition(this, GameSetup.PlayerChar.Position, DirectionAccuracy.free, 0, false);
                RotationHelper.VelocityInCurrentDirection(this, 500, 0);
            }
            if (distanceFromPlayer < 400)
            {
                //Switch strafe direction after 2 seconds
                int dirMultiplier = 1;
                if (tiSwitchDirection.ElapsedSoFar > 2)
                {
                    dirMultiplier = -1;
                }
                RotationHelper.VelocityInThisDirection(this, RotationHelper.MyDirection(this, dirMultiplier * 60), 250);

                //For firing
                if (GM.eventM.Elapsed(tiShootCooldown))
                {
                    //create bullet and pass reference to player and angle
                    new Bullet(this, playerPos, 1000f, 10);
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// act on key sets to move player and shoot
        /// </summary>
        private void Move()
        {
            //For gunSprite
            Vector2 aimPos    = GM.inputM.MouseLocation;
            Vector2 direction = aimPos - Position2D;

            direction = Vector2.Normalize(direction);
            RotationHelper.FaceDirection(gunSprite, direction, DirectionAccuracy.free, 0);
            gunSprite.Position2D = Position2D + (direction * 15);
            Vector2 currentPosition = Position2D;

            //For console
            if (GM.inputM.KeyPressed(Keys.C))
            {
                debugMode = true;
            }
            if (debugMode == true)
            {
                GM.textM.Draw(FontBank.arcadePixel, "Debug", GM.screenSize.Left + 175, GM.screenSize.Top + 40, TextAtt.TopLeft);

                if (GM.inputM.KeyPressed(Keys.F5))
                {
                    LaserEnemy laserEnemy = new LaserEnemy(GM.inputM.MouseLocation, false);
                }
                if (GM.inputM.KeyPressed(Keys.F12))
                {
                    GameSetup.EnemySpawnSystem.Kill();
                }
            }

            //For dodging
            Vector3 d = new Vector3(0, 0, 0);

            if (tiBoostDelay == null || tiBoostDelay.ElapsedSoFar > 0.25f)
            {
                if (GM.inputM.KeyDown(MoveLeft))
                {
                    d += Vector3.Left;
                }
                if (GM.inputM.KeyDown(MoveRight))
                {
                    d += Vector3.Right;
                }
                if (GM.inputM.KeyDown(Forward))
                {
                    d += Vector3.Down;
                }
                if (GM.inputM.KeyDown(Backward))
                {
                    d += Vector3.Up;
                }
                if (d == new Vector3(0, 0, 0))
                {
                    RotationHelper.FaceDirection(this, Vector3.Down, DirectionAccuracy.free, 0);
                }
                else
                {
                    RotationHelper.FaceDirection(this, d, DirectionAccuracy.free, 0);
                    RotationHelper.VelocityInCurrentDirection(this, 500, 0);
                }
            }

            //For directionSprite
            Vector3 dNorm = d;

            dNorm.Normalize();
            RotationHelper.FaceDirection(directionSprite, dNorm, DirectionAccuracy.free, 0);
            directionSprite.Position = Position + (dNorm * 20);

            //For firing
            if ((GM.inputM.KeyDown(Fire) || GM.inputM.MouseLeftButtonHeld()) && GM.eventM.Elapsed(tiFireCooldown))
            {
                //create bullet and pass reference to player and angle
                new Bullet(this, aimPos, 1500f, 10);
            }

            if (GM.inputM.KeyDown(SpecialFire) && (tiSpecialFireCooldown == null || GM.eventM.Elapsed(tiSpecialFireCooldown)))
            {
                for (int i = 0; i < 360; i += 5)
                {
                    Vector3 v3ShootAngle = RotationHelper.MyDirection(this, i);
                    Vector2 v2ShootAngle = new Vector2(v3ShootAngle.X, v3ShootAngle.Y);

                    RotationHelper.Direction2DFromAngle(i, 0);

                    //create bullet and pass reference to player and angle
                    new Bullet(this, Position2D + v2ShootAngle, 750, 50);
                }

                for (int i = 0; i < 360; i += 10)
                {
                    Vector3 v3ShootAngle = RotationHelper.MyDirection(this, i);
                    Vector2 v2ShootAngle = new Vector2(v3ShootAngle.X, v3ShootAngle.Y);

                    RotationHelper.Direction2DFromAngle(i, 0);

                    //create bullet and pass reference to player and angle
                    new Bullet(this, Position2D + v2ShootAngle, 500, 50);
                }

                if (tiSpecialFireCooldown == null)
                {
                    GM.eventM.AddTimer(tiSpecialFireCooldown = new Event(10f, "Special Fire Cooldown"));
                }
            }

            //For boosting
            if (GM.inputM.KeyPressed(Boost) && (tiBoostDelay == null || GM.eventM.Elapsed(tiBoostDelay)) && d != Vector3.Zero)
            {
                if (tiBoostDelay == null)
                {
                    GM.eventM.AddTimer(tiBoostDelay = new Event(0.5f, "dodge delay"));
                }

                //Raycasting to check for collisions and offset to avoid collision
                //Position += d * 100;
                //Ray findHits = new Ray(Position, d);

                Friction     = 0f;
                Velocity    += dNorm * 800;
                invulnerable = true;
                Wash         = Color.LightGreen;
            }

            //Resetting dodge delay for displaying
            if (tiBoostDelay != null && tiBoostDelay.ElapsedSoFar > 0.25f)
            {
                Friction     = 10f;
                invulnerable = false;
                Wash         = Color.LimeGreen;
            }

            //Locking sequence
            if (GM.inputM.MouseRightButtonPressed())
            {
                lockSprite.Visible = true;

                attack = null;
                float bestDistance = int.MaxValue;

                foreach (Sprite s in GM.engineM.SpriteList)
                {
                    if (s is Enemy)
                    {
                        if (attack == null || Vector2.DistanceSquared(aimPos, s.Centre2D) < bestDistance)
                        {
                            attack       = s;
                            bestDistance = Vector2.DistanceSquared(aimPos, s.Centre2D);
                        }
                    }
                }
                if (attack != null)
                {
                    lockSprite.Position2D = attack.Position2D;
                }
            }

            if (GM.inputM.MouseRightButtonHeld() && GM.eventM.Elapsed(tiLockingDelay) && attack != null)
            {
                GM.eventM.AddEventRaiseOnce(beepCountDown = new Event(0.25f, "Beep Countdown"));
                float graphicsLockAmount = lockAmount / 4;
                Color color = new Color();
                if (lockAmount < 1)
                {
                    lockAmount += tiLockingDelay.Interval * 4;
                    lockSprite.RotationAngle = 360 * graphicsLockAmount;
                    color.R = (byte)(250 * lockAmount);
                    color.B = (byte)(255 - color.R);
                }
                else
                {
                    lockSprite.RotationAngle = 0;
                    color.R = (byte)(255);
                    color.B = (byte)(0);
                }
                if (GM.eventM.Elapsed(beepCountDown))
                {
                    //Beep sound effect
                }

                lockSprite.Position2D = attack.Position2D;
                lockSprite.ScaleBoth  = 1.5f + (1 - lockAmount);
                lockSprite.Wash       = color;
            }

            if (GM.inputM.MouseRightButtonReleased())
            {
                if (lockAmount >= 1 && (tiAltFireCooldown == null || GM.eventM.Elapsed(tiAltFireCooldown)))
                {
                    FireMissile(attack);
                }
                lockSprite.Visible = false;
                lockAmount         = 0;
            }
        }
Beispiel #6
0
        private void Move()
        {
            //Do this for first 0.5 seconds of life
            if (tiBirth.ElapsedSoFar < 0.5)
            {
                RotationHelper.FaceDirection(this, direction, DirectionAccuracy.free, 10);
                RotationHelper.VelocityInCurrentDirection(this, 500, 0);
            }
            //Then do this
            else
            {
                if (tiBirth.ElapsedSoFar < 10)
                {
                    if (fourLasers)
                    {
                        RotationVelocity = 22.5f;
                    }
                    else
                    {
                        RotationVelocity = 45f;
                    }
                }
            }

            //For shooting
            //Every 5 seconds
            if (tiBirth.ElapsedSoFar > 5)
            {
                //1 laser
                laserTop.Position2D    = Position2D;
                laserTop.RotationAngle = RotationAngle;
                laserTop.Visible       = true;

                //4 lasers
                if (fourLasers)
                {
                    laserLeft.Position2D    = Position2D;
                    laserLeft.RotationAngle = RotationAngle + 90;
                    laserLeft.Visible       = true;
                }
            }

            //Every 5+1 seconds
            if (tiBirth.ElapsedSoFar > 6)
            {
                //1 laser
                laserTop.Wash = Color.Red;
                laserTop.SX   = 0.2f;

                //Checking for collisions
                Ray rayTop    = new Ray(Position, RotationHelper.MyDirection(this, 0));
                Ray rayBottom = new Ray(Position, RotationHelper.MyDirection(this, 180));

                BoundingSphere playerSphere = new BoundingSphere(GameSetup.PlayerChar.Position, (GameSetup.PlayerChar.Right - GameSetup.PlayerChar.Left));

                if ((rayTop.Intersects(playerSphere) != null || rayBottom.Intersects(playerSphere) != null) && GM.eventM.Elapsed(tiDamageCooldown))
                {
                    GameSetup.PlayerChar.Health -= 2;
                    if (GameSetup.PlayerChar.Health <= 0)
                    {
                        GameSetup.PlayerChar.Kill();
                    }
                }
                //4 lasers
                if (fourLasers)
                {
                    laserLeft.Wash = Color.Red;
                    laserLeft.SX   = 0.2f;

                    Ray rayLeft  = new Ray(Position, RotationHelper.MyDirection(this, 90));
                    Ray rayRight = new Ray(Position, RotationHelper.MyDirection(this, 270));

                    if ((rayLeft.Intersects(playerSphere) != null || rayRight.Intersects(playerSphere) != null) && GM.eventM.Elapsed(tiDamageCooldown))
                    {
                        GameSetup.PlayerChar.Health -= 2;
                        if (GameSetup.PlayerChar.Health <= 0)
                        {
                            GameSetup.PlayerChar.Kill();
                        }
                    }
                }
            }

            //Every 10 seconds
            if (tiBirth.ElapsedSoFar >= 10)
            {
                GM.eventM.AddEventRaiseOnce(tiBirth = new Event(10f, "Birth timer"));

                direction = Vector3.Zero;

                if (Position.X <= GM.screenSize.Center.X)
                {
                    direction.X += 1;
                }
                else
                {
                    direction.X -= 1;
                }
                if (Position.Y <= GM.screenSize.Center.Y)
                {
                    direction.Y += 1;
                }
                else
                {
                    direction.Y -= 1;
                }
                direction.Normalize();

                //1 laser
                laserTop.Wash    = Color.OrangeRed;
                laserTop.Visible = false;
                laserTop.SX      = 0.1f;

                //4 lasers
                if (fourLasers)
                {
                    laserLeft.Wash    = Color.OrangeRed;
                    laserLeft.Visible = false;
                    laserLeft.SX      = 0.1f;
                }
            }
        }
Beispiel #7
0
 private void Move()
 {
     //Move towards player
     RotationHelper.FacePosition(this, GameSetup.PlayerChar.Position, DirectionAccuracy.free, 0, false);
     RotationHelper.VelocityInCurrentDirection(this, 400, 0);
 }
Beispiel #8
0
 /// <summary>
 /// Moves the player in the angle specified
 /// </summary>
 /// <param name="additionalAngle">0 is directly infront of the player 90 is to the right of the player</param>
 /// <param name="speed">velocity in direction</param>
 private void Move(int speed, int additionalAngle)
 {
     RotationHelper.VelocityInCurrentDirection(this, speed, additionalAngle);
 }