Exemplo n.º 1
0
 public Bullet(ContentManager content, Ship ship)
 {
     texture = content.Load<Texture2D>(@"Sprites/shipBullet");
     Rotation = ship.turret.rotation;
     direction = 2 * ship.turret.direction;
     Position = new Vector2(ship.turret.bulletPosition.X, ship.turret.bulletPosition.Y);
     size = new Rectangle(0, 0, texture.Width, texture.Height);
     origin = new Vector2(texture.Width / 2, texture.Height / 2);
 }
Exemplo n.º 2
0
 public Console(ContentManager content, Ship aShip, int anXShift, int aYShift, Texture2D img)
 {
     xShift = anXShift;
     yShift = aYShift;
     position.X = aShip.GetPosition().X + (float)xShift;
     position.Y = aShip.GetPosition().Y + (float)yShift;
     texture = img;
     consoleRec = new Rectangle((int)position.X, (int)position.Y, texture.Width, texture.Height);
 }
 public Turret(ContentManager content, Ship aShip, int anXShift, int aYShift)
 {
     xShift = anXShift;
     yShift = aYShift;
     position.X = aShip.GetPosition().X + (float)xShift;
     position.Y = aShip.GetPosition().Y + (float)yShift;
     Texture = content.Load<Texture2D>(@"Sprites/turret");
     conTexture = content.Load<Texture2D>(@"Sprites/console");
     rec = new Rectangle((int)position.X, (int)position.Y, conTexture.Width, conTexture.Height);
     shipPos.X = aShip.GetPosition().X;
     shipPos.Y = aShip.GetPosition().Y;
     rotation = 0.0f;
     origin = new Vector2(Texture.Width / 2, Texture.Height / 2);
     prevMouseState = Mouse.GetState();
     localVector = new Vector2(0, position.Y - shipPos.Y);
 }
Exemplo n.º 4
0
        public Laser(ContentManager content, Ship aShip, int anXShift, int aYShift)
        {
            xShift = anXShift;
            yShift = aYShift;
            position.X = aShip.GetPosition().X + (float)xShift;
            position.Y = aShip.GetPosition().Y + (float)yShift;

            Texture = content.Load<Texture2D>(@"Sprites/lazer");
            conTexture = content.Load<Texture2D>(@"Sprites/console");
            rec = new Rectangle((int)position.X, (int)position.Y, conTexture.Width, conTexture.Height);
            laserRect = new Rectangle((int)position.X, (int)position.Y, Texture.Width, Texture.Height);
            shipPos.X = aShip.GetPosition().X;
            shipPos.Y = aShip.GetPosition().Y;
            rotation = 0f;
            origin = new Vector2(Texture.Width / 2, Texture.Height / 2);
            prevMouseState = Mouse.GetState();
            localVector = new Vector2(0, position.Y - shipPos.Y - 55);
            shouldUpdate = false;
            clockWise = false;
        }
Exemplo n.º 5
0
        public Shield(ContentManager content, Ship aShip, int anXShift, int aYShift)
        {
            xShift = anXShift;
            yShift = aYShift;
            consolePosition.X = aShip.GetPosition().X + (float)xShift;
            consolePosition.Y = aShip.GetPosition().Y + (float)yShift;
            shipPos.X = aShip.GetPosition().X;
            shipPos.Y = aShip.GetPosition().Y;

            consoleTexture = content.Load<Texture2D>(@"Sprites/shieldConsole");
            consoleRec = new Rectangle((int)consolePosition.X, (int)consolePosition.Y, consoleTexture.Width, consoleTexture.Height);

            position.X = aShip.GetPosition().X + 0f;
            position.Y = aShip.GetPosition().Y - 165f;
            shieldTexture = content.Load<Texture2D>(@"Sprites/shield");
            rotation = 0f;
            origin = new Vector2(shieldTexture.Width / 2, shieldTexture.Height / 2);
            shouldUpdate = false;
            clockWise = false;
            localVector = new Vector2(0, position.Y - shipPos.Y );
        }
        public void Update(Ship ship)
        {
            float ChaseThreshold = ChaseDistance;
            float CaughtThreshold = CaughtDistance;

            float distanceFromShip = Vector2.Distance(Position, ship.GetPosition());

            if (Orientation < TurnToFace(Position, ship.GetPosition(), Orientation, TurnSpeed) && Orientation > TurnToFace(Position, ship.GetPosition(), Orientation, TurnSpeed))
            {
                state = State.Shooting;
                fakeTime++;
            }

            if(state == State.Shooting && fakeTime == 10)
            {
                Shoot();
                fakeTime = 0;
            }

            if (distanceFromShip > EvadeDistance + Hysteresis)
            {
                state = State.Wander;
            }

            else if (distanceFromShip < EvadeDistance - Hysteresis)
            {
                state = State.Evading;
            }

            if (state == State.Evading)
            {
                Vector2 seekPosition = 2.5f * Position - ship.GetPosition();

                Orientation = TurnToFace(Position, seekPosition, Orientation, TurnSpeed);

                currentSpeed = MathHelper.Min(currentSpeed++, MaxSpeed);
            }

            if (state == State.Chasing)
            {
                ChaseThreshold += Hysteresis / 2;
                CaughtThreshold -= Hysteresis / 2;
            }

            else
            {
                Wander(Position, ref WanderDirection, ref Orientation, TurnSpeed);

                currentSpeed = .35f * MaxSpeed;
            }

            for (int i = 0; i < bullets.Count; i++)
                bullets[i].Update();

            for (int i = 0; i < bullets.Count; i++)
            {
                if (bullets[i].Outside())
                    bullets.RemoveAt(i);
            }

            Rectangle shiprec = new Rectangle((int)ship.GetPosition().X - 190, (int)ship.GetPosition().Y - 190, ship.shipRing.Width, ship.shipRing.Height);

            for (int i = 0; i < bullets.Count; i++)
            {
                if (shiprec.Intersects(new Rectangle((int)bullets[i].Position.X, (int)bullets[i].Position.Y, bullets[i].texture.Width, bullets[i].texture.Height)))
                {
                    bullets.RemoveAt(i);
                    ship.Hurt();
                }
            }

            heading = new Vector2((float)Math.Cos(Orientation), (float)Math.Sin(Orientation));
            Position += heading * currentSpeed;
        }
 private void Teleport(Ship ship)
 {
     Position = new Vector2(random.Next(1850), random.Next(950));
     while (Vector2.Distance(Position, ship.GetPosition()) < 240f)
     {
         Position = new Vector2(random.Next(1850), random.Next(950));
     }
 }
        public void Update(Ship ship)
        {
            if (state == State.Shooting)
            {
                timeInShoot++;
                timeInTele = 0;
                Orientation = TurnToFace(Position, ship.GetPosition(), Orientation, TurnSpeed);
                if (timeInShoot == 50)
                    Shoot();
                if (timeInShoot > 150)
                    state = State.Telport;
            }
            else if (state == State.Telport)
            {
                timeInShoot = 0;
                timeInTele++;
                if (timeInTele == 30)
                {
                    Teleport(ship);
                    state = State.Shooting;
                }
            }

            heading = new Vector2((float)Math.Cos(Orientation), (float)Math.Sin(Orientation));

            for (int i = 0; i < bullets.Count; i++)
                bullets[i].Update();

            for (int i = 0; i < bullets.Count; i++)
                if (bullets[i].Outside())
                    bullets.RemoveAt(i);
            Rectangle shiprec = new Rectangle((int)ship.GetPosition().X - 190, (int)ship.GetPosition().Y - 190, ship.shipRing.Width, ship.shipRing.Height);
            for (int i = 0; i < bullets.Count; i++)
            {
                if (shiprec.Intersects(new Rectangle((int)bullets[i].Position.X, (int)bullets[i].Position.Y, bullets[i].texture.Width, bullets[i].texture.Height)))
                    bullets.RemoveAt(i);
            }
        }
 private void GameSetUp()
 {
     lives = 3;
     ship = new Ship(Content, graphics);
     playerCnt = 1;
     shift = new Vector2(0, 0);
     player = new Player(new Vector2(ship.GetPosition().X, ship.GetPosition().Y - 100), Content, 1);
     bluePlanet = new Planet(Content);
     gasPlanet = new Planet(Content, 1);
     aquaGasPlanet = new Planet(Content, 2);
     marblePlanet = new Planet(Content, 3);
     ps.Add(bluePlanet);
     ps.Add(gasPlanet);
     ps.Add(aquaGasPlanet);
     ps.Add(marblePlanet);
     ees.Clear();
     ecs.Clear();
     ets.Clear();
     ees.Add(new EnemyEvader(Content, new Vector2(1900, 950), -1800, -400, marblePlanet));
     ees.Add(new EnemyEvader(Content, new Vector2(1900, 950), -1700, 100, marblePlanet));
     ees.Add(new EnemyEvader(Content, new Vector2(1900, 950), -1800, -50, marblePlanet));
     ees.Add(new EnemyEvader(Content, new Vector2(1900, 950), -1650, 280, marblePlanet));
     ees.Add(new EnemyEvader(Content, new Vector2(1900, 950), -1450, 500, marblePlanet));
     ees.Add(new EnemyEvader(Content, new Vector2(1900, 950), -1820, 450, marblePlanet));
     ees.Add(new EnemyEvader(Content, new Vector2(1900, 950), 3600, 1800, aquaGasPlanet));
     ees.Add(new EnemyEvader(Content, new Vector2(1900, 950), 3000, 1800, aquaGasPlanet));
     ees.Add(new EnemyEvader(Content, new Vector2(1900, 950), 3600, 1500, aquaGasPlanet));
     ees.Add(new EnemyEvader(Content, new Vector2(1900, 950), 2500, -400, gasPlanet));
     ees.Add(new EnemyEvader(Content, new Vector2(1900, 950), 2300, -500, gasPlanet));
     ees.Add(new EnemyEvader(Content, new Vector2(1900, 950), 2000, -600, gasPlanet));
     ees.Add(new EnemyEvader(Content, new Vector2(1900, 950), 2500, -700, gasPlanet));
     ets.Add(new EnemyTeleport(Content, new Vector2(1900, 950)));
     ets.Add(new EnemyTeleport(Content, new Vector2(1900, 950)));
     //ets.Add(new EnemyTeleport(Content, new Vector2(1900, 950)));
 }
 private void GameSetUp(int playerAmnt)
 {
     ship = new Ship(Content, graphics);
     player = new Player(new Vector2(ship.GetPosition().X, ship.GetPosition().Y - 100), Content, 1);
     playerCnt = playerAmnt;
     if(playerAmnt > 1)
         player2 = new Player(new Vector2(ship.GetPosition().X-70, ship.GetPosition().Y - 110), Content, 2);
     ees.Clear();
     ecs.Clear();
     ets.Clear();
     //ees.Add(new EnemyEvader(Content, new Vector2(1900, 950), 20, 30));
     ees.Add(new EnemyEvader(Content, new Vector2(1900, 950), 800, 30));
     ecs.Add(new EnemyChaser(Content, new Vector2(1900, 950)));
     ets.Add(new EnemyTeleport(Content, new Vector2(1900, 950)));
 }
 private void GameSetUp()
 {
     lives = 3;
     ship = new Ship(Content, graphics);
     playerCnt = 1;
     player = new Player(new Vector2(ship.GetPosition().X, ship.GetPosition().Y - 100), Content, 1);
     ees.Clear();
     ecs.Clear();
     ets.Clear();
     //ees.Add(new EnemyEvader(Content, new Vector2(1900, 950), 20, 30));
     ees.Add(new EnemyEvader(Content, new Vector2(1900, 950), 800, 30));
     ecs.Add(new EnemyChaser(Content, new Vector2(1900, 950)));
     ecs.Add(new EnemyChaser(Content, new Vector2(1900, 950)));
     ecs.Add(new EnemyChaser(Content, new Vector2(1900, 950)));
     ecs.Add(new EnemyChaser(Content, new Vector2(1900, 950)));
     ets.Add(new EnemyTeleport(Content, new Vector2(1900, 950)));
 }
        public void Update(Ship ship)
        {
            float ChaseThreshold = ChaseDistance;
            float CaughtThreshold = CaughtDistance;

            if (state == State.Wander)
            {
                ChaseThreshold -= Hysteresis / 2;
            }

            else if (state == State.Chasing)
            {
                ChaseThreshold += Hysteresis / 2;
                CaughtThreshold -= Hysteresis / 2;
            }

            else if (state == State.Caught)
            {
                CaughtThreshold += Hysteresis / 2;
            }

            float distanceFromCat = Vector2.Distance(Position, ship.GetPosition());
            if (distanceFromCat > ChaseThreshold)
            {
                state = State.Wander;
            }
            else if (distanceFromCat > CaughtThreshold)
            {
                state = State.Chasing;
            }
            else
            {
                state = State.Caught;
            }
            float currentSpeed;
            if (state == State.Chasing)
            {
                // the  wants to chase the cat, so it will just use the TurnToFace
                // function to turn towards the cat's position. Then, when the
                // moves forward, he will chase the cat.
                Orientation = TurnToFace(Position, ship.GetPosition(), Orientation,
                    TurnSpeed);
                currentSpeed = MaxSpeed;
            }
            else if (state == State.Wander)
            {
                // wander works just like the mouse's.
                Wander(Position, ref WanderDirection, ref Orientation,
                    TurnSpeed);
                currentSpeed = .25f * MaxSpeed;
            }
            else
            {
                currentSpeed = 0.0f;
            }
            Vector2 heading = new Vector2(
                (float)Math.Cos(Orientation), (float)Math.Sin(Orientation));
            Position += heading * currentSpeed;
        }
 private void GameSetUp()
 {
     ship = new Ship(Content, new Vector2(1900, 950));
     player = new Player(new Vector2(ship.GetPosition().X, ship.GetPosition().Y + ship.GetHeight()), Content);
 }