Beispiel #1
0
    public static void ReadFromJson(this Game.RocketConfig self, JsonTextReader reader)
    {
        while (reader.Read())
        {
            if (reader.TokenType == JsonToken.PropertyName)
            {
                var name = (string)reader.Value;
                reader.Read();
                switch (name)
                {
                case "name":
                    self.name = (string)reader.Value;
                    break;

                case "startingSpeed":
                    self.startingSpeed = (System.Single)(double) reader.Value;
                    break;

                case "acceleration":
                    self.acceleration = (System.Single)(double) reader.Value;
                    break;

                case "damage":
                    self.damage = (System.Single)(double) reader.Value;
                    break;

                case "cooldown":
                    self.cooldown = (System.Single)(double) reader.Value;
                    break;

                case "gravityInfluence":
                    self.gravityInfluence = (System.Single)(double) reader.Value;
                    break;

                case "description":
                    self.description = (string)reader.Value;
                    break;

                case "invulTime":
                    self.invulTime = (System.Single)(double) reader.Value;
                    break;
                }
            }
            else if (reader.TokenType == JsonToken.EndObject)
            {
                break;
            }
        }
    }
Beispiel #2
0
 public static void WriteJson(this Game.RocketConfig self, JsonTextWriter writer)
 {
     writer.WriteStartObject();
     writer.WritePropertyName("name");
     writer.WriteValue(self.name);
     writer.WritePropertyName("startingSpeed");
     writer.WriteValue(self.startingSpeed);
     writer.WritePropertyName("acceleration");
     writer.WriteValue(self.acceleration);
     writer.WritePropertyName("damage");
     writer.WriteValue(self.damage);
     writer.WritePropertyName("cooldown");
     writer.WriteValue(self.cooldown);
     writer.WritePropertyName("gravityInfluence");
     writer.WriteValue(self.gravityInfluence);
     writer.WritePropertyName("description");
     writer.WriteValue(self.description);
     writer.WritePropertyName("invulTime");
     writer.WriteValue(self.invulTime);
     writer.WriteEndObject();
 }
Beispiel #3
0
        public static GameModel New(RocketConfig playerRocket)
        {
            // this is kind of 'whatever' code
            // usually code like this is replaced as soon as possible with valid GD data and configs

            var c     = GameConfig.instance;
            var model = new GameModel();

            // sun as planet impl )) right now it seems almost ok, but I surely wont do that in real project
            model.planets.Add(NewPlanet(Sun, 0));

            int   planetCount     = random.Range(c.minAiPlayers + 1, c.maxAiPlayers + 1);
            float basePlanetOrbit = 1;

            for (int i = 1; i <= planetCount; i++)
            {
                var orbit  = 0.5f + basePlanetOrbit * i;
                var config = new PlanetConfig
                {
                    radius        = random.Range(0.4f, 0.5f),
                    rotationSpeed = random.Sign() * 5 * random.Range(0.1f, 0.16f) / (orbit),
                    name          = PlanetNames.RandomElement(random),
                    gravityPower  = 1,
                    maxHp         = 50,
                    orbitDistance = orbit
                };
                model.planets.Add(NewPlanet(config, i));
            }
            model.playerPlanetId = random.Range(1, planetCount + 1);
            if (playerRocket != null)
            {
                model.PlanetWithId(model.playerPlanetId).rocketUsed = playerRocket;
            }
            model.Update(0); // settings planet positions
            return(model);
        }