Beispiel #1
0
 /// <summary>
 /// Add a sprite to the queue
 /// </summary>
 /// <param name="next"></param>
 public void Enqueue(Vector2 next)
 {
     if (count < queue.Length)
     {
         count++;
         queue[e]            = new Arrow(queue[e - 1].Target, next);
         endArrow.Position2D = next;
         RotationHelper.FaceDirection(endArrow, Vector2.Normalize(next - queue[e - 1].Target), DirectionAccuracy.free, 0);
         e = (e + 1) % queue.Length;
     }
 }
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>
        /// Constructor for smoke particle
        /// </summary>
        /// <param name="spawnPos"></param>
        /// <param name="spawnVel"></param>
        /// <param name="spawnAngle"></param>
        /// <param name="lifetime">Minimum lifetime for particle in seconds</param>
        public FadingParticle(Vector2 spawnPos, Vector3 spawnVel, float spawnAngle, float lifetime)
        {
            //Init values
            GM.eventM.AddEvent(tiLifetime = new Event(lifetime + GM.r.FloatBetween(0, 0.1f), "Lifetime Counter"));
            GM.engineM.AddSprite(this);
            Frame.Define(Tex.SingleWhitePixel);
            ScaleBoth = 10;
            Wash      = Color.WhiteSmoke;
            Velocity  = spawnVel;
            float   rotRan   = GM.r.FloatBetween(-10f, 10f);
            Vector3 spawnRot = RotationHelper.Direction3DFromAngle(spawnAngle, 0);

            RotationHelper.FaceDirection(this, spawnRot, DirectionAccuracy.free, rotRan);
            Position2D = spawnPos;
            float xRan = GM.r.FloatBetween(-10f, 10f);
            float yRan = GM.r.FloatBetween(-10f, 10f);

            Position2D += new Vector2(xRan, yRan);

            UpdateCallBack += LifeCountdown;
        }
Beispiel #4
0
        public SmokeParticle(Vector2 spawnPos, Vector3 spawnVel, Vector2 spawnRot, float lifetime)
        {
            GM.eventM.AddEvent(tiLifetime = new Event(lifetime, "Lifetime Counter"));

            GM.engineM.AddSprite(this);
            Frame.Define(Tex.SingleWhitePixel);
            ScaleBoth = 10;
            Wash      = Color.WhiteSmoke;

            float xRan = GM.r.FloatBetween(-10, 10);
            float yRan = GM.r.FloatBetween(-10, 10);

            RotationHelper.VelocityInThisDirection(this, new Vector3(spawnVel.X + xRan, spawnVel.Y + yRan, 0), 100);

            float rotRan = GM.r.FloatBetween(-10, 10);

            RotationHelper.FaceDirection(this, spawnRot, DirectionAccuracy.free, rotRan);

            Position2D = spawnPos;

            UpdateCallBack += LifeCountdown;
        }
Beispiel #5
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 #6
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 #7
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 #8
0
        /// <summary>
        /// Constructor for CannonBall class
        /// </summary>
        /// <param name="owner">The ship that fired the CannonBall</param>
        /// <param name="fireFrom">2D position to fire from</param>
        /// <param name="fireDir">2D position to fire towards</param>
        /// <param name="type">Type of shot to use - 0 ball shot, 1 bar shot, 2 carcass shot, 3 grape shot, 4 grapple shot</param>
        public CannonBall(Sprite owner, Vector3 fireFrom, Vector3 fireDir, int type)
        {
            //Init values
            Position   = fireFrom;
            shotType   = type;
            this.owner = owner;
            GM.engineM.AddSprite(this);
            Friction = 0.25f;

            switch (type)
            {
            case 0:
                Frame.Define(GM.txSprite, new Rectangle(111, 160, 5, 5));
                break;

            case 1:
                Frame.Define(GM.txSprite, new Rectangle(121, 161, 7, 3));
                ScaleBoth = 1.25f;
                break;

            case 2:
                Frame.Define(GM.txSprite, new Rectangle(133, 160, 5, 7));
                break;

            case 3:
                Frame.Define(GM.txSprite, new Rectangle(143, 159, 2, 2));
                ScaleBoth = 3;
                break;

            case 4:
                Frame.Define(GM.txSprite, new Rectangle(133, 170, 5, 5));
                ScaleBoth = 1.5f;
                break;

            default:
                Frame.Define(Tex.Circle4by4);
                Wash = Color.DarkGray;
                break;
            }

            RotationHelper.FaceDirection(this, fireDir, DirectionAccuracy.free, 0);
            Position += RotationHelper.MyDirection(this, 0) * 50;

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

            //kill after a random time and delay firing
            TimerInitialise();
            fireDelay = GM.r.FloatBetween(0, 0.5f);
            if (type != 3 && type != 4)
            {
                Timer.ShowAfterKillAfter(fireDelay, GM.r.FloatBetween(0.5f, 0.7f));
            }
            else
            {
                Timer.ShowAfterKillAfter(fireDelay, GM.r.FloatBetween(0.2f, 0.4f));
            }

            velApplied      = false;
            UpdateCallBack += Tick;

            splash           = true;
            FuneralCallBack += Death;
        }