private void Map_MapCompleted(object sender, EventArgs e) { int id = map.ID, oldScore = map.Score; id++; Camera.Focus = new Actor() { Position = Vector2.Zero }; map.UnloadContent(); map.MapCompleted -= Map_MapCompleted; map.PlayerKilled -= Map_PlayerKilled; try { using (ContentManager c = new ContentManager(content.ServiceProvider, content.RootDirectory)) map = c.Load <ActorMap>($"Maps/{id}"); } catch { if (SceneManager.Instance.CurrentScene == this) { SceneManager.Instance.ChangeScene(new EndingScene(game, oldScore)); } } map.LoadContent(content); map.Score = oldScore; Camera.Focus = map.Player; map.MapCompleted += Map_MapCompleted; map.PlayerKilled += Map_PlayerKilled; }
public static int GetActors(SqliteDataReader reader) { while(reader.Read()) { ActorMap a = new ActorMap(); a.ActorID = reader.GetInt32(0); a.SessionID = reader.GetInt32(1); a.Type = (ActorType)reader.GetInt32(2); AllActors.Add(a); } return 0; }
public void LoadContent(ContentManager content) { this.content = content; InputManager.Instance.OnBackButtonClicked += InputManager_OnBackButtonClicked; using (ContentManager c = new ContentManager(content.ServiceProvider, content.RootDirectory)) try { map = c.Load <ActorMap>($"Maps/{firstMap}"); } catch { map = c.Load <ActorMap>($"Maps/1"); } map.LoadContent(content); map.PlayerKilled += Map_PlayerKilled; map.MapCompleted += Map_MapCompleted; Camera = new Camera2D(game, new Vector2(game.GetScaledResolution().X, game.GetScaledResolution().Y *(1 - guiSize))); Camera.Initialize(); Camera.CalculateDeadZone(map.Size, map.TileDimensions); Camera.Focus = map.Player; guiText = new Text(new Vector2(game.GetScaledResolution().X *0.06f, game.GetScaledResolution().Y *guiSize / 4), $"[{map.DiamondsRequired}]/{map.DiamondValue} [{map.DiamondsCollected}] {map.Time} {map.Score}", Color.White); guiText.LoadContent(content); }
void LoadActors() { for (var a = 0; a < numberOfActors; a++) { var id = stream.ReadInt32(); var type = stream.ReadInt32(); var x = (int)Math.Round((float)stream.ReadInt32() / map.Grid.TileSize.Width); var y = (int)Math.Round((float)stream.ReadInt32() / map.Grid.TileSize.Height); var invalidLocation = false; if (x < 0 || x > mapSize.Width || y < 0 || y > mapSize.Height) { Console.WriteLine("Invalid coordinates {0},{1} for actor type {2}.".F(x, y, type)); invalidLocation = true; } stream.Seek(4, SeekOrigin.Current); var numberOfProperties = stream.ReadInt32(); stream.Seek(4, SeekOrigin.Current); if (numberOfProperties > 0) { for (var p = 0; p < numberOfProperties; p++) { var key = stream.ReadASCII(128); var value = stream.ReadInt32(); Console.WriteLine(key + ": " + value); } } if (!ActorMap.ContainsKey(type)) { Console.WriteLine("Ignoring unknown actor type: `{0}` @ {1},{2}".F(type, x, y)); continue; } if (invalidLocation) { continue; } var actorInfo = ActorMap[type]; var actorType = actorInfo.ActorType.ToLowerInvariant(); var actor = new ActorReference(actorType) { new LocationInit(new CPos(x + MapCordonWidth, y + MapCordonWidth)), }; if (actorInfo.Color == Color.White) { actor.Add(new OwnerInit("Neutral")); } if (actorInfo.Color == Color.Green) { actor.Add(new OwnerInit("Ants")); } if (actorInfo.Color == Color.Blue) { actor.Add(new OwnerInit("Beetles")); } if (actorInfo.Color == Color.Red) { actor.Add(new OwnerInit("Spiders")); } if (actorInfo.Color == Color.Yellow) { actor.Add(new OwnerInit("Wasps")); } if (actorInfo.Color == Color.Black) { actor.Add(new OwnerInit("Creeps")); } AddPlayer(actorInfo.Color); var actorCount = map.ActorDefinitions.Count; if (!map.Rules.Actors.ContainsKey(actorType)) { Console.WriteLine("Ignoring unknown actor type: `{0}`".F(actorType)); } else { map.ActorDefinitions.Add(new MiniYamlNode("Actor" + actorCount++, actor.Save())); } } }