Exemplo n.º 1
0
 public override void ApplyLevel(TiledMap level)
 {
     base.ApplyLevel(level);
     foreach (TiledMap.TileSet tileSets in MyMap.TileSets)
     {
         List<Sprite> sprites = TileSheet.GrabSprites(ExternalResources.GTexture(tileSets.ImageSource),
                                                      tileSets.TileSize, new Vector2i(0, 0));
         tiles.AddRange(sprites);
     }
 }
Exemplo n.º 2
0
        protected GameModeBase(GameServer server)
        {
            map = new TileMap();
            TiledMap = new TiledMap();

            players = new List<Player>();
            entityWorldIdToGive = 0;
            Server = server;
            entities = new Dictionary<ushort, EntityBase>();

            entityToUpdate = 0;
            entityPositionUpdateTimer = new Stopwatch();
            entityPositionUpdateTimer.Restart();
        }
Exemplo n.º 3
0
 protected override STileBase GetTileFromGID(TiledMap.TileLayer layer, uint id)
 {
     return new TileBase();
 }
Exemplo n.º 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;
            }
        }