Beispiel #1
0
 public void Draw(SpriteBatch spriteBatch, Camera camera, bool wrap)
 {
     Rectangle? rect = null;
     int screenWidth = Game1.graphics.PreferredBackBufferWidth;
     if (wrap)
     {
         if (camera.Position.X / (1 / layer) - offset.X > texture.Bounds.Width)
             offset.X += texture.Bounds.Width;
         if (camera.Position.X / (1 / layer) - offset.X < 0)
             offset.X -= texture.Bounds.Width;
         rect = new Rectangle(0, 0, screenWidth + texture.Bounds.Width, Game1.graphics.PreferredBackBufferHeight);
     }
     spriteBatch.Draw(texture, new Vector2(-camera.Position.X / (1 / layer), 0) + offset, rect, Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, layer);
 }
Beispiel #2
0
 /// <summary>
 /// Draws clouds and moon according to camera position
 /// </summary>
 private void DrawParallax(SpriteBatch spriteBatch, Camera camera)
 {
     spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend, SamplerState.LinearWrap, null, null);
     parallaxMoon.Draw(spriteBatch, camera, false);
     parallaxClouds.Draw(spriteBatch, camera, true);
     spriteBatch.End();
 }
Beispiel #3
0
        /// <summary>
        /// Draws the game over text over the parallax
        /// </summary>
        private void DrawGameOverScreen(SpriteBatch spriteBatch, Camera camera)
        {
            DrawParallax(spriteBatch, camera);

            spriteBatch.Begin();
            Texture2D gameOverTexture = Library.textures["GameOver"];
            Vector2 drawPosition = new Vector2(graphics.PreferredBackBufferWidth / 2 - gameOverTexture.Width / 2, graphics.PreferredBackBufferHeight / 2 - gameOverTexture.Height / 2);
            spriteBatch.Draw(gameOverTexture, drawPosition, Color.White);
            spriteBatch.End();
        }
Beispiel #4
0
 protected override void LoadContent()
 {
     gameIsStarted = false;
     spriteBatch = new SpriteBatch(GraphicsDevice);
     Library.LoadContent(Content);
     random = new Random();
     cursor = new Cursor();
     level = new Level();
     levelEditor = new LevelEditor();
     saver = new SaveFileManager();
     saver.LoadLevel("level1");
     camera = new Camera(new Vector2(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height));
     HUDCamera = new Camera(new Vector2(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height));
     camera.CenterOn(level.startPos);
     HUDCamera.CenterOn(level.startPos);
     camera.Update();
     HUDCamera.Update();
     menu = new Menu();
     currentState = GameState.MainMenu;
     parallaxClouds = new ParallaxBackground(Vector2.Zero, Library.textures["Clouds"], 0.5f);
     parallaxMoon = new ParallaxBackground(new Vector2(700, 20), Library.textures["Moon"], 0.4f);
     //graphics.PreferredBackBufferHeight = (int)(graphics.PreferredBackBufferWidth / GraphicsDevice.DisplayMode.AspectRatio);
     if(GraphicsDevice.DisplayMode.AspectRatio == (8/6))
         graphics.IsFullScreen = true;
     graphics.ApplyChanges();
     song = Library.sounds["BaineSong"];
     songLoop = song.CreateInstance();
     songLoop.IsLooped = true;
     songLoop.Play();
 }
Beispiel #5
0
 public void Draw(SpriteBatch spriteBatch, Camera camera)
 {
     // Draw every sprite inside camera bounds
     for (int i = 0; i < sprites.Count; i++)
     {
         if (sprites[i].IsDead)
         {
             sprites.RemoveAt(i--);
             continue;
         }
         if (sprites[i].Bounds.Intersects(camera.Bounds))
             sprites[i].Draw(spriteBatch);
     }
     // Draw every moving sprite inside camera bounds
     for (int i = 0; i < movingSprites.Count; i++)
     {
         if (movingSprites[i].IsDead)
         {
             movingSprites.RemoveAt(i--);
             continue;
         }
         if (movingSprites[i].Bounds.Intersects(camera.Bounds))
             movingSprites[i].Draw(spriteBatch);
     }
     spriteBatch.Draw(Library.textures["GoalFlag"], goalPos, null, Color.White, 0, new Vector2(5, 40), 1, SpriteEffects.None, 1);
 }