示例#1
0
 public void collision(LostPlayer player, Sprite sprite)
 {
     if (player.position.X + (player.spriteSheet.currentSegment.frameSize.X * player.spriteSheet.scale) <= sprite.position.X + (SpriteManager.speed.X + 4) && player.position.X + (player.spriteSheet.currentSegment.frameSize.X * player.spriteSheet.scale) > sprite.position.X)
     {
         float difference = player.position.X + (player.spriteSheet.currentSegment.frameSize.X * player.spriteSheet.scale) - sprite.position.X;
         foreach (Sprite spr in sprites)
         {
             spr.position.X += difference;
         }
     }
     if (player.position.Y + (player.spriteSheet.currentSegment.frameSize.Y * player.spriteSheet.scale) <= sprite.position.Y + (SpriteManager.speed.Y + 4) && player.position.Y + (player.spriteSheet.currentSegment.frameSize.Y * player.spriteSheet.scale) > sprite.position.Y)
     {
         float difference = player.position.Y + (player.spriteSheet.currentSegment.frameSize.Y * player.spriteSheet.scale) - sprite.position.Y;
         foreach (Sprite spr in sprites)
         {
             spr.position.Y += difference;
         }
     }
     if (player.position.X < sprite.position.X + (sprite.spriteSheet.currentSegment.frameSize.X * sprite.spriteSheet.scale) && player.position.X >= sprite.position.X + (sprite.spriteSheet.currentSegment.frameSize.X * sprite.spriteSheet.scale) - (SpriteManager.speed.X + 4))
     {
         float difference = sprite.position.X + (sprite.spriteSheet.currentSegment.frameSize.X * sprite.spriteSheet.scale) - player.position.X;
         foreach (Sprite spr in sprites)
         {
             spr.position.X -= difference;
         }
     }
     if (player.position.Y < sprite.position.Y + (sprite.spriteSheet.currentSegment.frameSize.Y * sprite.spriteSheet.scale) && player.position.Y >= sprite.position.Y + (sprite.spriteSheet.currentSegment.frameSize.Y * sprite.spriteSheet.scale) - (SpriteManager.speed.Y + 4))
     {
         float difference = sprite.position.Y + (sprite.spriteSheet.currentSegment.frameSize.Y * sprite.spriteSheet.scale) - player.position.Y;
         foreach (Sprite spr in sprites)
         {
             spr.position.Y -= difference;
         }
     }
 }
示例#2
0
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(Game.GraphicsDevice);

            for (int i = (mapSize / 2) * -1; i <= mapSize / 2; i++)
            {
                for (int j = (mapSize / 2) * -1; j <= mapSize / 2; j++)
                {
                    backgrounds.Add(new BackgroundSprite(Game.Content.Load <Texture2D>(@"Images/background_2048"), new Vector2((Game.GraphicsDevice.Viewport.Width / 2 - frameSize.X / 2) + (j * frameSize.X), (Game.GraphicsDevice.Viewport.Height / 2 - frameSize.Y / 2) + (i * frameSize.Y)), state));
                }
            }

            Random random = new Random();

            for (int i = 0; i < stumpCount; i++)
            {
                objects.Add(new StumpSprite(Game.Content.Load <Texture2D>(@"Images/truestump"), new Vector2(random.Next(Game.GraphicsDevice.Viewport.Width / 2 + (((frameSize.X * (mapSize / 2)) + (frameSize.X / 2)) * -1), Game.GraphicsDevice.Viewport.Width / 2 + (frameSize.X * (mapSize / 2)) + (frameSize.X / 2)), random.Next(Game.GraphicsDevice.Viewport.Height / 2 + (((frameSize.Y * (mapSize / 2)) + (frameSize.Y / 2)) * -1), Game.GraphicsDevice.Viewport.Height / 2 + (frameSize.Y * (mapSize / 2)) + (frameSize.Y / 2))), state));
            }

            for (int i = 0; i < zombieCount; i++)
            {
                zombies.Add(new ZombieSprite(Game.Content.Load <Texture2D>(@"Images/ZombieSpriteSheet"), new Vector2(random.Next(Game.GraphicsDevice.Viewport.Width / 2 + (((frameSize.X * (mapSize / 2)) + (frameSize.X / 2)) * -1), Game.GraphicsDevice.Viewport.Width / 2 + (frameSize.X * (mapSize / 2)) + (frameSize.X / 2)), random.Next(Game.GraphicsDevice.Viewport.Height / 2 + (((frameSize.Y * (mapSize / 2)) + (frameSize.Y / 2)) * -1), Game.GraphicsDevice.Viewport.Height / 2 + (frameSize.Y * (mapSize / 2)) + (frameSize.Y / 2))), state));
            }

            for (int i = 0; i < batteryCount; i++)
            {
                batteries.Add(new BatterySprite(Game.Content.Load <Texture2D>(@"Images/battery"), new Vector2(random.Next(Game.GraphicsDevice.Viewport.Width / 2 + (((frameSize.X * (mapSize / 2)) + (frameSize.X / 2)) * -1), Game.GraphicsDevice.Viewport.Width / 2 + (frameSize.X * (mapSize / 2)) + (frameSize.X / 2)), random.Next(Game.GraphicsDevice.Viewport.Height / 2 + (((frameSize.Y * (mapSize / 2)) + (frameSize.Y / 2)) * -1), Game.GraphicsDevice.Viewport.Height / 2 + (frameSize.Y * (mapSize / 2)) + (frameSize.Y / 2))), state));
            }

            foreach (ZombieSprite zombie in zombies)
            {
                map.add(zombie);
            }

            foreach (BackgroundSprite back in backgrounds)
            {
                map.add(back);
            }

            foreach (BatterySprite battery in batteries)
            {
                map.add(battery);
            }

            foreach (MapBoundSprite sprite in objects)
            {
                map.add(sprite);
            }


            //add zombies
            gps = new GpsSprite(Game.Content.Load <Texture2D>(@"Images/gps_locator (1)"), new Vector2(random.Next(Game.GraphicsDevice.Viewport.Width / 2 + (((frameSize.X * (mapSize / 2)) + (frameSize.X / 2)) * -1), Game.GraphicsDevice.Viewport.Width / 2 + (frameSize.X * (mapSize / 2)) + (frameSize.X / 2)), random.Next(Game.GraphicsDevice.Viewport.Height / 2 + (((frameSize.Y * (mapSize / 2)) + (frameSize.Y / 2)) * -1), Game.GraphicsDevice.Viewport.Height / 2 + (frameSize.Y * (mapSize / 2)) + (frameSize.Y / 2))), state);
            map.add(gps);
            player         = new LostPlayer(Game.Content.Load <Texture2D>(@"Images/PersonSpriteSheet"), new Vector2(Game.GraphicsDevice.Viewport.Width / 2 - playerSize.X / 2, Game.GraphicsDevice.Viewport.Height / 2 - playerSize.Y / 2), state);
            overlay        = new OverlaySprite(Game.Content.Load <Texture2D>(@"Images/overlay"), new Vector2((Game.GraphicsDevice.Viewport.Width / 2 - frameSize.X / 2) + (0 * frameSize.X), (Game.GraphicsDevice.Viewport.Height / 2 - frameSize.Y / 2) + (0 * frameSize.Y)), state);
            batteryOverlay = new BatteryOverlaySprite(Game.Content.Load <Texture2D>(@"Images/battery_game2"), new Vector2(Game.GraphicsDevice.Viewport.Width - 50, 20), state);

            base.LoadContent();
        }