Example #1
0
        public MiniMap(Level.TileMap tileMap, FogOfWar fog, Dictionary<ushort, Entities.EntityBase> entities )
        {
            Team = 0;
            Entities = entities;
            TileMap = tileMap;
            Fog = fog;

            CameraPosition = new Vector2f(0, 0);
            renderTexture = new RenderTexture(SIZEX, SIZEY);

            MapSprite = new Sprite(renderTexture.Texture);
        }
Example #2
0
        public GameModeBase()
        {
            myId = 0;
            idSet = false;

            map = new TileMap();

            alerts = new List<HUDAlert>();
            entities = new Dictionary<ushort, EntityBase>();
            players = new Dictionary<byte, Player>();

            Effects = new List<EffectBase>();

            pathFinding = null;

            Fog = null;

            deathSound_Cliff = new Sound(ExternalResources.GSoundBuffer("Resources/Audio/Death/0.wav"));
            unitCompleteSound_Worker = new Sound(ExternalResources.GSoundBuffer("Resources/Audio/UnitCompleted/0.wav"));
            useSound_Cliff = new Sound(ExternalResources.GSoundBuffer("Resources/Audio/UseCommand/0.wav"));
            gatherResourceSound_Cliff = new Sound(ExternalResources.GSoundBuffer("Resources/Audio/GetResources/0.wav"));
            attackSound_Cliff = new Sound(ExternalResources.GSoundBuffer("Resources/Audio/OnAttack/0.wav"));
        }
Example #3
0
        public void Render(RenderTarget target, FloatRect screenBounds, FogOfWar fog = null)
        {
            /*
            var spriteSheet =
                TileSheet.GrabSprites(ExternalResources.GTexture("Resources/Sprites/Map/terrain_atlas.png"),
                                      new Vector2i(32, 32), new Vector2i(0, 0));
            Sprite sprite = new Sprite();
            sprite.Texture = ExternalResources.GTexture("Resources/Sprites/TestTile.png");

            for(int x = 0;  x < MapSize.X; x++)
            {
                for(int y = 0; y < MapSize.Y; y++)
                {
                    STileBase tile = Tiles[x, y];
                    switch(tile.Type)
                    {
                        case STileBase.TileType.Grass:
                            sprite = spriteSheet[160];
                            break;
                        case STileBase.TileType.Water:
                            sprite = spriteSheet[179];
                            break;
                        case STileBase.TileType.Stone:
                            sprite = spriteSheet[50];
                            break;
                        default:
                            break;
                    }
                    sprite.Position = new Vector2f(x*TileSize.X, y*TileSize.Y);
                    target.Draw(sprite);
                }
            }
             * */

            if (MyMap == null) return;

            int startX = (int)(screenBounds.Left/TileSize.X);
            int startY = (int)(screenBounds.Top/TileSize.Y);
            int endX = (int)((screenBounds.Left + screenBounds.Width) / TileSize.X);
            int endY = (int)((screenBounds.Top + screenBounds.Height) / TileSize.Y);
            endX++;
            endY++;

            startX = Math.Max(startX, 0);
            startY = Math.Max(startY, 0);
            endX = Math.Min(endX, Tiles.GetLength(0));
            endY = Math.Min(endY, Tiles.GetLength(1));

            foreach (TiledMap.TileLayer layers in MyMap.TileLayers)
            {
                for (int y = startY; y < endY; y++)
                {
                    for (int x = startX; x < endX; x++)
                    {
                        if (layers.GIds[x, y] == 0 || layers.GIds[x, y] - 1 >= tiles.Count) continue;

                        Sprite sprite = tiles[(int) layers.GIds[x, y] - 1];
                        sprite.Position = new Vector2f(x*TileSize.X, y*TileSize.Y);
                        if(fog != null)
                        {
                            switch (fog.Grid[x,y].CurrentState)
                            {
                                case FOWTile.TileStates.NeverSeen:
                                    sprite.Color = new Color(50, 50, 50);
                                    break;
                                case FOWTile.TileStates.PreviouslySeen:
                                    sprite.Color = new Color(150, 150, 150);
                                    break;
                                case FOWTile.TileStates.CurrentlyViewed:
                                    sprite.Color = new Color(255, 255, 255);
                                    break;
                                default:
                                    break;
                            }
                        }
                        target.Draw(sprite);
                    }
                }
            }
        }
Example #4
0
        public void ParseData(MemoryStream stream)
        {
            var reader = new BinaryReader(stream);
            var signature = (Gamemode.Signature) reader.ReadByte();

            switch (signature)
            {
                case Gamemode.Signature.Custom:
                    ParseCustom(stream);
                    break;
                case Gamemode.Signature.Entity:
                    {
                        ushort id = reader.ReadUInt16();
                        if (entities.ContainsKey(id))
                            entities[id].ParseData(stream);
                    }
                    break;
                case Gamemode.Signature.MapLoad:
                    ParseMap(stream);
                    break;
                case Gamemode.Signature.TiledMapLoad:
                    {
                        var tiledMap = new TiledMap();
                        tiledMap.Load(stream);
                        map.ApplyLevel(tiledMap);
                        pathFinding = new SpatialAStar<PathNode, object>(map.GetPathNodeMap());
                        Fog = new FogOfWar(map.MapSize.X, map.MapSize.Y);
                        for (int x = 0; x < map.MapSize.X; x++)
                        {
                            for (int y = 0; y < map.MapSize.Y; y++)
                            {
                                Fog.Grid[x, y].Blocker = map.Tiles[x, y].Solid;
                            }
                        }
                    }
                    break;
                case Gamemode.Signature.Handshake:
                    ParseHandshake(stream);
                    break;
                case Gamemode.Signature.EntityAdd:
                    {
                        ushort id = reader.ReadUInt16();
                        byte entityType = reader.ReadByte();
                        EntityBase entity = EntityBase.EntityFactory(entityType);
                        entity.Type = (Entity.EntityType) entityType;
                        entity.WorldEntities = entities;
                        entity.WorldId = id;
                        entity.MyGameMode = this;
                        entity.LoadFromBytes(stream);
                        AddEntity(entity, id);
                        entity.SetTeam(reader.ReadByte());
                    }
                    break;
                case Gamemode.Signature.EntityLoad:
                    {
                        ushort count = reader.ReadUInt16();
                        for (int i = 0; i < count; i++)
                        {
                            ushort entId = reader.ReadUInt16();
                            byte entType = reader.ReadByte();
                            EntityBase entAdd = EntityBase.EntityFactory(entType);
                            entAdd.Type = (Entity.EntityType) entType;
                            entAdd.WorldEntities = entities;
                            entAdd.LoadFromBytes(stream);
                            entAdd.WorldId = entId;
                            entAdd.MyGameMode = this;
                            AddEntity(entAdd, entId);
                            entAdd.SetTeam(reader.ReadByte());
                        }
                    }
                    break;
                case Gamemode.Signature.PlayerData:
                    {
                        byte playerId = reader.ReadByte();
                        if (players.ContainsKey(playerId))
                        {
                            players[playerId].Load(stream);
                        }
                    }
                    break;
                case Gamemode.Signature.PlayersLoad:
                    {
                        byte count = reader.ReadByte();
                        for (int i = 0; i < count; i++)
                        {
                            var playerAdd = new Player();
                            playerAdd.Load(stream);
                            if (players.ContainsKey(playerAdd.ClientId) == false)
                            {
                                players.Add(playerAdd.ClientId, playerAdd);
                            }
                        }
                    }
                    break;
                case Gamemode.Signature.RemoveEntity:
                    {
                        ushort id = reader.ReadUInt16();
                        if (entities.ContainsKey(id))
                        {
                            entities[id].OnDeath();
                            entities.Remove(id);
                        }
                    }
                    break;
                case Gamemode.Signature.GroupMovement:
                    {
                        float x = reader.ReadSingle();
                        float y = reader.ReadSingle();
                        bool reset = reader.ReadBoolean();
                        bool attack = reader.ReadBoolean();
                        byte count = reader.ReadByte();

                        for (int i = 0; i < count; i++)
                        {
                            ushort id = reader.ReadUInt16();
                            if (!entities.ContainsKey(id)) continue;
                            if (reset)
                                entities[id].ClearRally();

                            Vector2f startPos = entities[id].Position;
                            if (!reset && entities[id].rallyPoints.Count > 0)
                            {
                                startPos = new Vector2f(entities[id].rallyPoints[entities[id].rallyPoints.Count - 1].X,
                                                        entities[id].rallyPoints[entities[id].rallyPoints.Count - 1].Y);
                            }

                            PathFindReturn path = PathFindNodes(startPos.X, startPos.Y, x, y);

                            if (path.List == null) continue;

                            foreach (PathNode pathNode in path.List)
                            {
                                if (pathNode == path.List.First.Value) continue;
                                var pos =
                                    new Vector2f(pathNode.X*path.MapSize.X + (path.MapSize.X/2),
                                                 pathNode.Y*path.MapSize.Y + (path.MapSize.Y/2));
                                entities[id].Move(pos.X, pos.Y, attack);
                            }
                        }
                    }
                    break;
                case Gamemode.Signature.SetCamera:
                    {
                        SetCamera(reader.ReadByte(), new Vector2f(reader.ReadSingle(), reader.ReadSingle()));
                    }
                    break;
                case Gamemode.Signature.UpdatePosition:
                    {
                        ushort unitId = reader.ReadUInt16();
                        float posX = reader.ReadSingle();
                        float posY = reader.ReadSingle();

                        if (entities.ContainsKey(unitId))
                        {
                            entities[unitId].Position = new Vector2f(posX, posY);
                        }
                    }
                    break;
            }
        }