Beispiel #1
0
 public void Draw(SpriteBatch spriteBatch, Camera camera)
 {
     foreach (TileLayer layer in layers)
     {
         layer.Draw(spriteBatch, camera);
     }
 }
Beispiel #2
0
        public void Draw(SpriteBatch spriteBatch, Camera camera, int layerIndex, Texture2D treasureChestTexture, Texture2D doorTexture)
        {
            Point min = Engine.ConvertPositionToCell(camera.Position);
            Point max = Engine.ConvertPositionToCell(
                camera.Position + new Vector2(
                    spriteBatch.GraphicsDevice.Viewport.Width + Engine.TileWidth,
                    spriteBatch.GraphicsDevice.Viewport.Height + Engine.TileHeight));

            if (layerIndex > 50)
            {
                int lI = layerIndex - 50;
                Layers[lI].Draw(spriteBatch, camera, min, max, treasureChestTexture, doorTexture);
            }

            else
            {
                foreach (TileLayer layer in Layers)
                    layer.Draw(spriteBatch, camera, min, max, treasureChestTexture, doorTexture);
            }
        }
Beispiel #3
0
        // Draw the Animation Strip
        public void Draw(SpriteBatch spriteBatch, Vector2 position, Camera cam)
        {
            Position = position;
            Position -= cam.Position;
            Position.X -= FrameWidth*scale/2;
            Position.Y -= FrameHeight*scale;

            // Only draw the animation when we are active
            if (Active)
            {
                if (Flip)
                {
                    spriteBatch.Draw(
                      spriteStrip,			    // Texture
                      Position,	        	    // Position
                      sourceRect,				// Source Rectangle (null = full texture)
                      color,			        // Tint colour
                      0,						// Rotation
                      Vector2.Zero,			    // Origin
                      scale,						// Scale
                      SpriteEffects.FlipHorizontally,		// Special effect
                      drawDepth		    	// Depth
                   );
                }
                else
                {
                        // spriteBatch.Draw(spriteStrip, destinationRect, sourceRect, color);
                   spriteBatch.Draw(
                       spriteStrip,			    // Texture
                       Position,	        	// Position
                       sourceRect,				// Source Rectangle (null = full texture)
                       color,			        // Tint colour
                       0,						// Rotation
                       Vector2.Zero,			// Origin
                        scale,						// Scale
                       SpriteEffects.None,		// Special effect
                       drawDepth				// Depth
                    );
                }
            }
        }
Beispiel #4
0
 /// <summary>
 /// Sets the Camera object representing the player's view of the world.
 /// </summary>
 /// <param name="camera">The Camera object to use to represent the player's view of the world.</param>
 public void SetCamera( Camera camera )
 {
     Camera = camera;
 }
Beispiel #5
0
        protected override void LoadContent()
        {
            // Load the font for drawing text
            dbg.DbgFont = Content.Load<SpriteFont>( "Fonts/font" );

            ////////////////////////////////////////////
            // Init the tile engine components
            ////////////////////////////////////////////

            // Camera
            camera = new Camera(this);
            camera.Speed = camSpeed;
            camera.Autonomous = false;
            Components.Add( camera );

            // TileMap
            tileMap = new IsoTileMap( camera );
            //tileMap = new SquareTileMap( camera );
            //tileMap = new HexTileMap( camera );
            tileMap.Scale = mapScale;

            // Cursor - Cursors are currently only implemented for iso maps!
            tileMap.Cursor.Active = true;
            tileMap.Cursor.Colour = Color.Blue;

            // Load the tile map
            tileMap.LoadFromFile( Content, "Content/Maps/IsoTestMap.map" );
            //tileMap.LoadFromFile( Content, "Content/Maps/WallsIsoTestMap.map" );
            //tileMap.LoadFromFile( Content, "Content/Maps/SnowIsoTestMap.map" );
            //tileMap.LoadFromFile( Content, "Content/Maps/SmallIsoTestMap.map" );
            //tileMap.LoadFromFile( Content, "Content/Maps/SquareTestMap.map" );
            //tileMap.LoadFromFile( Content, "Content/Maps/HexTestMap.map" );

            // Set the camera to fit the world
            tileMap.SetCameraToWorldBounds();
            //camera.SetBounds( Point.Zero, new Point( 5000, 5000 ) ); // Ok I lied :P let the camera be for now!

            ////////////////////////////////////////////
            // Spells!
            ////////////////////////////////////////////

            // Fun with spells!
            spell = new Spell();
            spell.Initialize( GraphicsDevice.Viewport, Content.Load<Texture2D>( "Spells/spell1" ) );
        }
Beispiel #6
0
        public override void Activate(bool instancePreserved)
        {
            IsoTileMap world;
            Camera camera;

            if (!instancePreserved)
            {
                Color myColor = Color.FromNonPremultiplied(255, 10, 10, 128);
                Console.WriteLine(myColor);
                ContentManager content = ScreenManager.Game.Content;
                manager = GameManager.Instance;
                manager.InMultiplayer = false;

                escapePressed = new InputAction(null, new Keys[] { Keys.Escape }, true);
                uPressed = new InputAction(null, new Keys[] { Keys.U }, true);

                // Called when the screen is first activated.. can initialize here
                camera = new Camera(ScreenManager.Game);
                camera.Autonomous = false;
                manager.Camera = camera;

                world = new IsoTileMap(camera);
                world.Cursor.Active = true;
                world.Cursor.Colour = Color.Blue;
                world.LoadFromFile(content, "Content/Maps/MPMap.map");
                scorebg = content.Load<Texture2D>("UITextures/scorebg");
                scoreFont = content.Load<SpriteFont>("Fonts/GUIFont");
                gameOverFont = content.Load<SpriteFont>("Fonts/GameOverFont");
                world.SetCameraToWorldBounds();
                manager.TileMap = world;

                                // Set up a fresh game state
                GameManager.Instance.GameState = new GameState(GameManager.Instance);

                manager.GameState.Characters = new Character[26];

                Character playerChar = new Character(manager);
                manager.GameState.Characters[0] = playerChar;
                playerChar.Initialize(1, new Vector2(350, 350));
                playerChar.IsPlayer = true;
                player = playerChar;
                characters.Add(playerChar);
                actionBar = new ActionBar(player);
                playerFrame = new PlayerFrame(player);
                playerChar.Team = Team.BLUE;
                player.CurrentFocus = 25;
                player.CurrentHealth = 100;
                player.CrystalCount = 500;

                manager.MyID = 0;

                for (int i = 1; i < 26; i++)
                {
                    NPC c = new NPC(manager);
                    manager.GameState.Characters[i] = c;
                    bool canPlace = false;
                    Vector2 pos = Vector2.Zero;
                    while (!canPlace)
                    {
                        int xPos = randomizer.Next(32, manager.TileMap.GetWidthInPixels() - 32);
                        int yPos = randomizer.Next(32, manager.TileMap.GetHeightInPixels() - 32);
                        pos = new Vector2(xPos, yPos);
                        if ((pos - manager.GameState.Characters[0].WorldPosition).Length() > 1000)
                        {
                            canPlace = true;
                        }
                    }
                    c.Initialize(randomizer.Next(0, 4), pos);
                }

                /*
                NPC char1 = new NPC(manager);
                char1.Initialize(0, new Vector2(450, 350));
                characters.Add(char1);
                char1.Name = "Player1";

                NPC char2 = new NPC(manager);
                char2.Initialize(1, new Vector2(550, 350));
                characters.Add(char2);
                char2.Name = "Player2";
                char2.Team = Team.RED;
                char2.CurrentHealth = char2.MaxHealth / 2;

                NPC char3 = new NPC(manager);
                char3.Initialize(2, new Vector2(650, 350));
                characters.Add(char3);
                char3.Name = "Player3";

                NPC char4 = new NPC(manager);
                char4.Initialize(3, new Vector2(750, 350));
                characters.Add(char4);
                char4.Name = "Player4";
                char4.Team = Team.RED;
                char4.CurrentHealth = char2.MaxHealth / 2;
                */
                /*
                Random randomizer = new Random();
                for (int i = 0; i < 20; i++)
                {

                    Character chari = new Character(manager);
                    chari.Initialize(3, new Vector2(randomizer.Next(0,4000),randomizer.Next(0, 4000)));
                    characters.Add(chari);
                    chari.Name = "Player4";
                    chari.Team = Team.RED;
                    chari.CurrentHealth = char2.MaxHealth;
                    Console.WriteLine("ok");
                }
                */

                //manager.GameState.Characters = new[] { playerChar, char1, char2, char3, char4 };
                namePlates = new List<NamePlate>();
                radar = new Radar(playerChar);
                radar.Scale = 0.5f;
                radar.Alpha = 0.8f;
                radar.SnapToCorner(Radar.Corner.TopRight);

                foreach (Character c in manager.GameState.Characters)
                {
                    if (c != player)
                    {
                        NamePlate np = new NamePlate(c);
                        namePlates.Add(np);
                    }
                }

                for (int i = 0; i < 120; i++)
                {
                    PickUp pu = new PickUp(manager);
                    pickUps.Add(pu);
                    pu.Initialize(0);
                }

                bgMusic = ScreenManager.Game.Content.Load<Song>("Audio/Demo_FinalFight");
                MediaPlayer.IsRepeating = true;
                MediaPlayer.Play( bgMusic );
                MediaPlayer.Volume = 0.4f;
                cPress = new InputAction(null, new Keys[] { Keys.C }, true);
                bPress = new InputAction(null, new Keys[] { Keys.B }, true);
            }
        }
Beispiel #7
0
 public IsoTileMap( Camera camera )
     : base(camera)
 {
     this.type = TileMapType.Isometric;
 }
Beispiel #8
0
        public void Draw(SpriteBatch batch, Camera camera, Point min, Point max, Texture2D treasureChestTexture, Texture2D doorTexture)
        {
            batch.Begin(
                SpriteSortMode.Texture,
                BlendState.AlphaBlend,
                null, null, null, null,
                camera.TransformMatrix);

            min.X = (int)Math.Max(min.X, 0);
            min.Y = (int)Math.Max(min.Y, 0);
            max.X = (int)Math.Min(max.X, Width);
            max.Y = (int)Math.Min(max.Y, Height);

            for (int x = min.X; x < max.X; x++)
            {
                for (int y = min.Y; y < max.Y; y++)
                {
                    int textureIndex = map[y, x];

                    if (textureIndex == -1)
                        continue;

                    Texture2D texture = tileTextures[textureIndex];

                    batch.Draw(
                        texture,
                        new Rectangle(
                            x * Engine.TileWidth,
                            y * Engine.TileHeight,
                            Engine.TileWidth,
                            Engine.TileHeight),
                        new Color(new Vector4(1f, 1f, 1f, Alpha)));
                }
            }

            batch.End();

            batch.Begin(SpriteSortMode.Texture,
                        BlendState.AlphaBlend,
                        null, null, null, null,
                        camera.TransformMatrix);

            foreach (TreasureChest treasurechest in chests)
            {
                FrameAnimation animation = treasurechest.CurrentAnimation;

                if (animation != null)
                    batch.Draw(
                        treasureChestTexture,
                        new Rectangle(
                        (int)treasurechest.Postition.X * Engine.TileWidth,
                        (int)treasurechest.Postition.Y * Engine.TileHeight,
                        Engine.TileWidth,
                        Engine.TileHeight),
                        animation.CurrentRect,
                        Color.White);

            }

            foreach (Door door in doors)
            {
                FrameAnimation animation = door.CurrentAnimation;

                if (animation != null)
                    batch.Draw(
                        doorTexture,
                        new Rectangle(
                        (int)door.Postition.X * Engine.TileWidth,
                        (int)door.Postition.Y * Engine.TileHeight,
                        Engine.TileWidth,
                        Engine.TileHeight),
                        animation.CurrentRect,
                        Color.White);

            }

            batch.End();
        }
Beispiel #9
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            camera = new Camera(myMap, squaresDown, squaresAcross);

            base.Initialize();
        }
Beispiel #10
0
 public SquareTileMap( Camera camera )
     : base(camera)
 {
     type = TileMapType.Square;
 }
Beispiel #11
0
        public void Draw(SpriteBatch spriteBatch, Camera camera, Texture2D collisionTexture)
        {
            spriteBatch.Begin();
            for (int y = 0; y < Height; y++)
            {
                for (int x = 0; x < Width; x++)
                {
                    if (GetCellIndex(x, y) == 0)
                    {
                        spriteBatch.Draw(
                            collisionTexture,
                            new Rectangle(
                                x * Engine.TileWidth - (int)camera.Position.X,
                                y * Engine.TileHeight - (int)camera.Position.Y,
                                Engine.TileWidth,
                                Engine.TileHeight),
                            new Color(new Vector4(1f, 0f, 0f, 0f)));
                    }

                    if (GetCellIndex(x, y) >= 50)
                    {
                        spriteBatch.Draw(
                            collisionTexture,
                            new Rectangle(
                                x * Engine.TileWidth - (int)camera.Position.X,
                                y * Engine.TileHeight - (int)camera.Position.Y,
                                Engine.TileWidth,
                                Engine.TileHeight),
                            new Color(new Vector4(0f, 1f, 0f, 0f)));
                    }
                }
            }
            spriteBatch.End();
        }
 public Camera()
 {
     position = new Vector2(0, 0);
     Instance = this;
     zoom = 1f;
 }
Beispiel #13
0
        public void Draw(SpriteBatch batch, Camera camera)
        {
            int tileMapWidth = Width;
            int tileMapHeight = Height;

            batch.Begin(SpriteSortMode.Texture,
                BlendState.NonPremultiplied,
                SamplerState.PointWrap,
                DepthStencilState.Default,
                RasterizerState.CullNone,
                null, camera.TransformMatrix);

            for (int x = 0; x < tileMapWidth; x++)
            {
                for (int y = 0; y < tileMapHeight; y++)
                {
                    int tileIndex = _map[y, x];

                    if (tileIndex != -1)
                    {
                        Texture2D texture = _tileTextures[tileIndex];

                        batch.Draw(
                            texture,
                            new Rectangle(
                                (x * Engine.TileWidth),
                                (y * Engine.TileHeight),
                                Engine.TileWidth,
                                Engine.TileHeight),
                            new Color(new Vector4(1f, 1f, 1f, alpha )));
                    }
                }
            }

            batch.End();
        }
Beispiel #14
0
        public void Draw(SpriteBatch batch, Camera camera)
        {
            batch.Begin();
            int tileMapWidth = shipBlocks.GetLength(1);
            int tileMapHeight = shipBlocks.GetLength(0);

            for (int x = 0; x < tileMapWidth; x++)
            {
                for (int y = 0; y < tileMapHeight; y++)
                {
                    int textureIndex = shipBlocks[y, x];
                    if (textureIndex == -1)
                    {
                        continue;
                    }
                    Texture2D texture = tileTextures[textureIndex];

                    batch.Draw(texture, new Rectangle(
                            x * TileWidth - (int)camera.Position.X,
                            y * TileHeight - (int)camera.Position.Y,
                            TileWidth,
                            TileHeight),
                        Color.White); // subtract to set camera position if cam goes down (larger) subtract so tile map shifts up
                }

            }
            batch.End();
        }
Beispiel #15
0
        /// <summary>
        /// Default constructor for GameLobby objects.
        /// </summary>
        /// <param name="wizServer">A reference to the Game Server object.</param>
        public GameLobby( WizardryGameServer wizServer, int id )
        {
            messageQueue = new ConcurrentQueue<NetIncomingMessage>();

            this.game = wizServer;
            this.wizServer = wizServer;
            myID = id;

            numConnected = 0;
            players = new NetConnection[GameSettings.MAX_LOBBY_CAPACITY];
            for ( int i = 0; i < GameSettings.MAX_LOBBY_CAPACITY; ++i )
            {
                players[i] = null;
            }
            gameState = new GameState( this );

            camera = new TileEngine.Camera( wizServer );
            tilemap = new IsoTileMap( camera );
            tilemap.LoadFromFile( wizServer.Content, "Content/Maps/MPMap.map" );

            prevUpdateTime = DateTime.MinValue;
        }
Beispiel #16
0
 /// <summary>
 /// Standard TileMap Constructor.
 /// </summary>
 /// <param name="camera">The Camera object representing the player's view of the world.</param>
 public TileMap( Camera camera )
 {
     this.camera = camera;
     this.cursor = new MapCursor( this );
 }
Beispiel #17
0
 public HexTileMap( Camera camera )
     : base(camera)
 {
     type = TileMapType.Hex;
 }
Beispiel #18
0
        public override void Activate( bool instancePreserved )
        {
            if ( !instancePreserved )
            {
                ContentManager content = ScreenManager.Game.Content;

                // The escape button handler to open the pause menu
                escapePressed = new InputAction( null, new Keys[] { Keys.Escape }, true );

                // The u button handler to open the upgrades screen
                uPressed = new InputAction( null, new Keys[] { Keys.U }, true );

                // Create world/camera
                Camera camera = new Camera( ScreenManager.Game );
                camera.Autonomous = false;
                GameManager.Instance.Camera = camera;
                IsoTileMap world = new IsoTileMap( camera );
                //world.Cursor.Active = true;
                //world.Cursor.Colour = Color.Blue;
                world.LoadFromFile( content, "Content/Maps/MPMap.map" );
                world.SetCameraToWorldBounds();
                GameManager.Instance.TileMap = world;

                // Set up the game UI
                playerChar = GameManager.Instance.GameState.Characters[GameManager.Instance.MyID];
                playerChar.IsPlayer = true;
                playerFrame = new PlayerFrame( playerChar );
                actionBar = new ActionBar( playerChar );
                radar = new Radar( playerChar );
                radar.Scale = 0.6f;
                radar.Alpha = 0.8f;
                radar.SnapToCorner( Radar.Corner.TopRight );

                // NamePlates
                namePlates = new NamePlate[GameManager.Instance.GameState.Characters.Length];
                for ( int i = 0; i < namePlates.Length; ++i )
                {
                    namePlates[i] = new NamePlate( GameManager.Instance.GameState.Characters[i] );
                }

                // Load fonts
                scoreBoardFont = content.Load<SpriteFont>( "Fonts/ScoreBoardFont" );
                msgFont = content.Load<SpriteFont>( "Fonts/ScoreBoardFont" );

                // Start listening for packets from the server
                GameManager.Instance.RegisterForPackets( this );
            }
        }
Beispiel #19
0
        public void Draw(SpriteBatch batch, Camera camera)
        {
            batch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
            int tileMapWidth = map.GetLength(1);
            int tileMapHeight = map.GetLength(0);

            for (int x = 0; x < tileMapWidth; x++)
            {
                for (int y = 0; y < tileMapHeight; y++)
                {
                    int textureIndex = map[y, x];
                    if (textureIndex == -1)
                    {
                        continue;
                    }
                    Texture2D texture = tileTextures[textureIndex];

                    batch.Draw(texture, new Rectangle(
                            x * TileWidth - (int)camera.Position.X,
                            y * TileHeight - (int)camera.Position.Y,
                            TileWidth,
                            TileHeight),
                        new Color(new Vector4(1f,1f,1f,Alpha))); // subtract to set camera position if cam goes down (larger) subtract so tile map shifts up
                }

            }
            batch.End();
        }
        public void Draw(SpriteBatch batch, Camera camera)
        {
            batch.Begin(SpriteSortMode.Texture, BlendState.AlphaBlend, null, null, null, null, camera.TransformMatrix);

            int tileMapWidth = map.GetLength(1);
            int tileMapHeight = map.GetLength(0);

            for (int x = 0; x < tileMapWidth; x++)
            {
                for (int y = 0; y < tileMapHeight; y++)
                {
                    int tileTextureIndex = map[y, x];

                    if (tileTextureIndex == -1)
                        continue;

                    Texture2D texture = tileTextures[tileTextureIndex];

                    batch.Draw(texture
                                    , new Rectangle(
                                        x * Engine.TileWidth,
                                        y * Engine.TileHeight,
                                        Engine.TileWidth,
                                        Engine.TileHeight)
                                    , new Color(new Vector4(1f, 1f, 1f, Alpha)));//R, G, B, Alpha
                }
            }
            batch.End();
        }