Exemple #1
0
        public void Draw(GameTime gt, SpriteBatch sb, int gs, Camera2D camera)
        {
            //Draw background
            for (int i = 0; i < 30; i++) {
                for (int j = 0; j < 30; j++) {
                    sb.Draw(bgList[i,j],
                        new Vector2(i * 512 - (512*15), j * 512 - (512*15)),
                        Color.White);
                }
            }

            foreach (Meteorite meteorite in meteoriteList) {
                meteorite.Draw(gt, sb, camera);
            }

            //Draw newest objective, if it's the right obj status
            if (ObjectiveStatus == 0 || ObjectiveStatus == 2 || ObjectiveStatus == 4) {
                Collectible c = Objectives.Peek();
                c.Draw(sb);
            }

            Ship.Draw(gt, sb, camera);

            Player1.Draw(gt, sb, camera);
        }
Exemple #2
0
        protected override void Initialize()
        {
            hud = new HUD();
            level = new Level(this, hud);
            hud.CurrentLevel = level;
            camera = new Camera2D(level.Player1.Position);

            base.Initialize();
        }
        public void Draw(GameTime gt, SpriteBatch sb, Camera2D camera)
        {
            Sprite.Draw(gt, sb, Position, 0f);

            //Draw both
            if (ShipStatus == 0 || ShipStatus == 1) {
                sb.Draw(brokenShip1, brokenShipRect1, Color.White);
                sb.Draw(brokenShip2, brokenShipRect2, Color.White);
            }
            //Just the broken engine
            else if (ShipStatus == 2) {
                sb.Draw(brokenShip2, brokenShipRect2, Color.White);
            }
        }
Exemple #4
0
        private void DrawMessages(SpriteBatch sb, Camera2D camera)
        {
            if (messages.Count > 0)
            {
                for (int i = 0; i < messages.Count; i++)
                {
                    DisplayMessage msg = messages[i];

                    sb.DrawString(HUDFont, msg.CurrentDrawnMessage, msg.Position + camera.Position, msg.DrawColor,
                                  -CurrentLevel.Player1.playerRotation, new Vector2(msg.CurrentDrawnMessage.Length * 14 / 2, 10),
                                  1f, SpriteEffects.None, 0f);
                    if (msg.CurrentIndex == msg.Message.Length)
                    {
                        continue;
                    }

                    msg.CurrentDrawnMessage += msg.Message[msg.CurrentIndex].ToString();
                    msg.CurrentIndex++;
                    messages[i] = msg;
                }
            }
        }
 public void Draw(GameTime gt, SpriteBatch sb, Camera2D camera)
 {
     Sprite.Draw(gt, sb, Position, camera.Rotation);
 }
        public void Update(GameTime gt, KeyboardState kb, KeyboardState kbOld, Camera2D camera)
        {
            Vector2 oldMovementSpeed = MovementSpeed;

            float decelerationX = MovementSpeed.X * (float)gt.ElapsedGameTime.TotalSeconds * 0.3f;
            float decelerationY = MovementSpeed.Y * (float)gt.ElapsedGameTime.TotalSeconds * 0.3f;
            float acceleration  = ACCELERATION * (float)gt.ElapsedGameTime.TotalSeconds;

            //Slow down the space man
            if (MovementSpeed.X > 0)
            {
                MovementSpeed += new Vector2(-decelerationX, 0);
            }
            else if (MovementSpeed.X < 0)
            {
                MovementSpeed += new Vector2(-decelerationX, 0);
            }

            if (MovementSpeed.Y > 0)
            {
                MovementSpeed += new Vector2(0, -decelerationY);
            }
            else if (MovementSpeed.Y < 0)
            {
                MovementSpeed += new Vector2(0, -decelerationY);
            }

            BoundingBox = new Rectangle((int)Position.X - 22,
                                        (int)Position.Y - 22,
                                        45,
                                        45);

            //Add speed based on kb input
            if (kb.IsKeyDown(Keys.Left) || kb.IsKeyDown(Keys.A))
            {
                MovementSpeed += Utility.CalculateDiagonalMovement(acceleration, camera.Rotation, "left");
                moveEffect.Play();
            }

            if (kb.IsKeyDown(Keys.Right) || kb.IsKeyDown(Keys.D))
            {
                MovementSpeed += Utility.CalculateDiagonalMovement(acceleration, camera.Rotation, "right");
                moveEffect.Play();
            }

            if (kb.IsKeyDown(Keys.Up) || kb.IsKeyDown(Keys.W))
            {
                MovementSpeed += Utility.CalculateDiagonalMovement(-acceleration, camera.Rotation, "up");
                moveEffect.Play();
            }

            if (kb.IsKeyDown(Keys.Down) || kb.IsKeyDown(Keys.S))
            {
                MovementSpeed += Utility.CalculateDiagonalMovement(-acceleration, camera.Rotation, "down");
                moveEffect.Play();
            }
            //Kill sound effect if all keys are up
            if (kb.IsKeyUp(Keys.W) && kb.IsKeyUp(Keys.A) && kb.IsKeyUp(Keys.S) && kb.IsKeyUp(Keys.D))
            {
                moveEffect.Stop();
            }

            //Adding gametime was something I forgot to do, so *85 is just a number that felt similar
            //to running the game at 60fps with no gametime multiplication
            Position += Vector2.Multiply(MovementSpeed, (float)gt.ElapsedGameTime.TotalSeconds * 85);
            //Position += MovementSpeed;

            //Determine player rotation to try to orient with the camera
            if (playerRotation < camera.Rotation && !kb.IsKeyDown(Keys.Q))
            {
                playerRotationAcceleration += 0.0002f;
                playerRotation             += MathHelper.Clamp(playerRotationAcceleration, playerRotationAcceleration, MAX_ROTATION_ACCELERATION);
                if (playerRotation > camera.Rotation)
                {
                    playerRotation = camera.Rotation;
                }
            }
            else if (playerRotation > camera.Rotation && !kb.IsKeyDown(Keys.E))
            {
                playerRotationAcceleration += 0.0002f;
                playerRotation             -= MathHelper.Clamp(playerRotationAcceleration, playerRotationAcceleration, MAX_ROTATION_ACCELERATION);
                if (playerRotation < camera.Rotation)
                {
                    playerRotation = camera.Rotation;
                }
            }
            //When there's no rotation, reset the speed so we get that acceleration again.
            else
            {
                playerRotationAcceleration = 0f;
            }


            base.Update(gt);
        }
 public void Draw(GameTime gt, SpriteBatch sb, Camera2D camera)
 {
     //Negate the rotation, the camera takes in the float backwards
     Sprite.Draw(gt, sb, Position, -playerRotation);
 }
Exemple #8
0
        private void DrawMessages(SpriteBatch sb, Camera2D camera)
        {
            if (messages.Count > 0) {
                for (int i = 0; i < messages.Count; i++) {
                    DisplayMessage msg = messages[i];

                    sb.DrawString(HUDFont, msg.CurrentDrawnMessage, msg.Position + camera.Position, msg.DrawColor,
                        -CurrentLevel.Player1.playerRotation, new Vector2(msg.CurrentDrawnMessage.Length*14 /2, 10),
                        1f, SpriteEffects.None, 0f);
                    if (msg.CurrentIndex == msg.Message.Length) {
                        continue;
                    }

                    msg.CurrentDrawnMessage += msg.Message[msg.CurrentIndex].ToString();
                    msg.CurrentIndex++;
                    messages[i] = msg;
                }
            }
        }
Exemple #9
0
        public void Draw(GameTime gt, SpriteBatch sb, Camera2D camera)
        {
            DrawMessages(sb, camera);

            if (CurrentLevel.ObjectiveStatus < 5) {
                Collectible col = CurrentLevel.Objectives.Peek();

                if (HudState == 2) {
                    if (CurrentLevel.ObjectiveStatus == 0 || CurrentLevel.ObjectiveStatus == 2 || CurrentLevel.ObjectiveStatus == 4) {
                        sb.Draw(CurrentLevel.Resources.ObjectiveArrow, CurrentLevel.Player1.Position, null,
                            Color.White, GetWaypointRotationAngle(CurrentLevel.Player1.Position, col.Position),
                            new Vector2(CurrentLevel.Resources.ObjectiveArrow.Width / 2, CurrentLevel.Resources.ObjectiveArrow.Height / 2),
                            1f, SpriteEffects.None, 0.5f);
                    }
                }
            }

            if (HudState == 2) {
                if (CurrentLevel.ObjectiveStatus == 1 || CurrentLevel.ObjectiveStatus == 3 || CurrentLevel.ObjectiveStatus == 5) {
                    //This draws arrow to ship
                    sb.Draw(CurrentLevel.Resources.ObjectiveArrow, CurrentLevel.Player1.Position, null,
                        Color.White, GetWaypointRotationAngle(CurrentLevel.Player1.Position, CurrentLevel.Ship.Position),
                        new Vector2(CurrentLevel.Resources.ObjectiveArrow.Width / 2, CurrentLevel.Resources.ObjectiveArrow.Height / 2),
                        1f, SpriteEffects.None, 0.5f);
                }
            }

            //If the controls message is up, show the controls image
            if (CurrentLevel.ObjectiveStatus == 0) {
                sb.Draw(CurrentLevel.Resources.Controls, CONTROLS_POSITION + camera.Position, null, Color.White,
                    -CurrentLevel.Player1.playerRotation,
                    new Vector2(CurrentLevel.Resources.Controls.Width/2, CurrentLevel.Resources.Controls.Height/2),
                    1f, SpriteEffects.None, 0f);
            }
        }
 public void Update(GameTime gt, KeyboardState kb, KeyboardState kbOld, Camera2D camera)
 {
     base.Update(gt);
 }
Exemple #11
0
        public void Update(GameTime gt, KeyboardState kb, KeyboardState kbOld, int gs, Camera2D camera)
        {
            Player1.Update(gt, kb, kbOld, camera);
            Ship.Update(gt, kb, kbOld, camera);

            /*if (Math.Abs(Player1.MovementSpeed.X) + Math.Abs(Player1.MovementSpeed.Y) > 2) {
             *  if ((int)gt.TotalGameTime.TotalSeconds % 5 == 0) {
             *      Meteorite meteorite = new Meteorite(Resources.Meteor, Resources.MeteorMask,
             *          Player1.Position, Player1.MovementSpeed);
             *      meteoriteList.Add(meteorite);
             *  }
             * }*/

            //Check through game states for collision logic
            if (ObjectiveStatus == 1 || ObjectiveStatus == 3 || ObjectiveStatus == 5)
            {
                if (Player1.BoundingBox.Intersects(Ship.BoundingBox))
                {
                    ObjectiveStatus++;
                    Ship.ShipStatus++;
                    Player1.Inventory.RemoveAt(Player1.Inventory.Count - 1);
                    Resources.Repair.Play();
                    Hud.AddMessage(ObjectiveStatus);
                }
            }
            else if (ObjectiveStatus == 0 || ObjectiveStatus == 2 || ObjectiveStatus == 4)
            {
                Collectible col = Objectives.Peek();
                if (Player1.BoundingBox.Intersects(col.BoundingBox))
                {
                    Player1.Inventory.Add(Objectives.Pop());
                    ObjectiveStatus++;
                    Resources.Pickup.Play();
                    Hud.AddMessage(ObjectiveStatus);
                }
            }

            /*foreach (Meteorite meteorite in meteoriteList) {
             *  meteorite.Update(gt);
             * }*/

            base.Update(gt);
        }
Exemple #12
0
        public void Update(GameTime gt, KeyboardState kb, KeyboardState kbOld, int gs, Camera2D camera)
        {
            Player1.Update(gt, kb, kbOld, camera);
            Ship.Update(gt, kb, kbOld, camera);

            /*if (Math.Abs(Player1.MovementSpeed.X) + Math.Abs(Player1.MovementSpeed.Y) > 2) {
                if ((int)gt.TotalGameTime.TotalSeconds % 5 == 0) {
                    Meteorite meteorite = new Meteorite(Resources.Meteor, Resources.MeteorMask,
                        Player1.Position, Player1.MovementSpeed);
                    meteoriteList.Add(meteorite);
                }
            }*/

            //Check through game states for collision logic
            if(ObjectiveStatus == 1 || ObjectiveStatus == 3 || ObjectiveStatus == 5){
                if(Player1.BoundingBox.Intersects(Ship.BoundingBox)){
                    ObjectiveStatus++;
                    Ship.ShipStatus++;
                    Player1.Inventory.RemoveAt(Player1.Inventory.Count - 1);
                    Resources.Repair.Play();
                    Hud.AddMessage(ObjectiveStatus);
                }
            }
            else if(ObjectiveStatus == 0 || ObjectiveStatus == 2 || ObjectiveStatus == 4){
                Collectible col = Objectives.Peek();
                if(Player1.BoundingBox.Intersects(col.BoundingBox)){
                    Player1.Inventory.Add(Objectives.Pop());
                    ObjectiveStatus++;
                    Resources.Pickup.Play();
                    Hud.AddMessage(ObjectiveStatus);
                }
            }

            /*foreach (Meteorite meteorite in meteoriteList) {
                meteorite.Update(gt);
            }*/

            base.Update(gt);
        }
Exemple #13
0
        public void Update(GameTime gt, KeyboardState kb, KeyboardState kbOld, Camera2D camera)
        {
            Vector2 oldMovementSpeed = MovementSpeed;

            float decelerationX = MovementSpeed.X * (float)gt.ElapsedGameTime.TotalSeconds * 0.3f;
            float decelerationY = MovementSpeed.Y * (float)gt.ElapsedGameTime.TotalSeconds * 0.3f;
            float acceleration = ACCELERATION * (float)gt.ElapsedGameTime.TotalSeconds;

            //Slow down the space man
            if (MovementSpeed.X > 0) {
                MovementSpeed += new Vector2(-decelerationX, 0);
            }
            else if (MovementSpeed.X < 0) {
                MovementSpeed += new Vector2(-decelerationX, 0);
            }

            if (MovementSpeed.Y > 0) {
                MovementSpeed += new Vector2(0, -decelerationY);
            }
            else if (MovementSpeed.Y < 0) {
                MovementSpeed += new Vector2(0, -decelerationY);
            }

            BoundingBox = new Rectangle((int)Position.X - 22,
                (int)Position.Y - 22,
                45,
                45);

            //Add speed based on kb input
            if (kb.IsKeyDown(Keys.Left) || kb.IsKeyDown(Keys.A)) {
                MovementSpeed += Utility.CalculateDiagonalMovement(acceleration, camera.Rotation, "left");
                moveEffect.Play();
            }

            if (kb.IsKeyDown(Keys.Right) || kb.IsKeyDown(Keys.D)) {
                MovementSpeed += Utility.CalculateDiagonalMovement(acceleration, camera.Rotation, "right");
                moveEffect.Play();
            }

            if (kb.IsKeyDown(Keys.Up) || kb.IsKeyDown(Keys.W)) {
                MovementSpeed += Utility.CalculateDiagonalMovement(-acceleration, camera.Rotation, "up");
                moveEffect.Play();
            }

            if (kb.IsKeyDown(Keys.Down) || kb.IsKeyDown(Keys.S)) {
                MovementSpeed += Utility.CalculateDiagonalMovement(-acceleration, camera.Rotation, "down");
                moveEffect.Play();
            }
            //Kill sound effect if all keys are up
            if (kb.IsKeyUp(Keys.W) && kb.IsKeyUp(Keys.A) && kb.IsKeyUp(Keys.S) && kb.IsKeyUp(Keys.D))
                moveEffect.Stop();

            //Adding gametime was something I forgot to do, so *85 is just a number that felt similar
            //to running the game at 60fps with no gametime multiplication
            Position += Vector2.Multiply(MovementSpeed, (float)gt.ElapsedGameTime.TotalSeconds * 85);
            //Position += MovementSpeed;

            //Determine player rotation to try to orient with the camera
            if (playerRotation < camera.Rotation && !kb.IsKeyDown(Keys.Q)) {
                playerRotationAcceleration += 0.0002f;
                playerRotation += MathHelper.Clamp(playerRotationAcceleration, playerRotationAcceleration, MAX_ROTATION_ACCELERATION);
                if (playerRotation > camera.Rotation) {
                    playerRotation = camera.Rotation;
                }
            }
            else if (playerRotation > camera.Rotation && !kb.IsKeyDown(Keys.E)) {
                playerRotationAcceleration += 0.0002f;
                playerRotation -= MathHelper.Clamp(playerRotationAcceleration, playerRotationAcceleration, MAX_ROTATION_ACCELERATION);
                if (playerRotation < camera.Rotation) {
                    playerRotation = camera.Rotation;
                }
            }
            //When there's no rotation, reset the speed so we get that acceleration again.
            else {
                playerRotationAcceleration = 0f;
            }

            base.Update(gt);
        }
Exemple #14
0
 public void Draw(GameTime gt, SpriteBatch sb, Camera2D camera)
 {
     //Negate the rotation, the camera takes in the float backwards
     Sprite.Draw(gt, sb, Position, -playerRotation);
 }
Exemple #15
0
 public void Update(GameTime gt, KeyboardState kb, KeyboardState kbOld, Camera2D camera)
 {
     base.Update(gt);
 }
 public void Draw(GameTime gt, SpriteBatch sb, Camera2D camera)
 {
     Sprite.Draw(gt, sb, Position, camera.Rotation);
 }