public void Update() { if (nextLevelQueued) { nextLevelQueued = false; NextLevel(); } foreach (var obj in objects) { obj.Update(); } foreach (var proj in projectiles) { proj.Update(); } for (int i = objects.Count - 1; i >= 0; --i) { if (objects[i].Dead) { objects.RemoveAt(i); } } for (int i = projectiles.Count - 1; i >= 0; --i) { if (projectiles[i].Dead) { projectiles.RemoveAt(i); } } foreach (var obj in queuedObjects) { objects.Add(obj); } queuedObjects.Clear(); if (objects.OfType <Enemy>().Count() == 0) { if (warp == null) { map.Floor[(int)warpPos.X, (int)warpPos.Y] = FloorTile.Stone; objects.Add(warp = new LevelWarp(this) { Position = new Vector3(warpPos.X, 0, warpPos.Y) }); Game1.playSound("detector"); } } /* * camAngle = ( camAngle + 0.025f ) % 360; * cam.pos = baseCamPos + new Vector3( ( float ) Math.Cos( camAngle ) * map.Size.X, 0, (float) Math.Sin( camAngle ) * map.Size.Y ); * cam.target = baseCamPos; */ }
private void InitLevel(string path) { string[] lines = File.ReadAllLines(Path.Combine(Mod.instance.Helper.DirectoryPath, "assets", "levels", path + ".txt")); string[] toks = lines[0].Split(' '); warp = null; objects.Clear(); projectiles.Clear(); Vector2 playerPos = Vector2.Zero; map = new Map(new Vector2(int.Parse(toks[0]), int.Parse(toks[1]))); if (toks.Length > 2 && toks[2] == "sky") { map.Sky = Color.SkyBlue; } for (int i = 1; i <= map.Size.Y; ++i) { int iy = i - 1; for (int ix = 0; ix < map.Size.X; ++ix) { map.Floor[ix, iy] = FloorTile.Stone; map.Walls[ix, iy] = WallTile.Empty; switch (lines[i][ix]) { case ' ': break; case '#': case 'M': map.Walls[ix, iy] = WallTile.Stone; if (lines[i][ix] == 'M') { objects.Add(new MuralThing(this) { Position = new Vector3(ix, 0, iy - 0.01f) }); } break; case 'L': map.Floor[ix, iy] = FloorTile.Lava; break; case 'F': // TODO: Forge break; case 'P': playerPos = new Vector2(ix, iy); break; case 's': objects.Add(new TigerSlimeEnemy(this) { Position = new Vector3(ix + 0.5f, 0, iy + 0.5f) }); break; case 'b': objects.Add(new BatEnemy(this) { Position = new Vector3(ix + 0.5f, 0.5f, iy + 0.5f) }); break; case 'W': case 'G': warpPos = new Vector2(ix, iy); if (lines[i][ix] == 'G') { map.Floor[ix, iy] = FloorTile.Lava; objects.Add(new GolemEnemy(this) { Position = new Vector3(ix + 0.5f, -0.65f, iy + 0.5f) }); } break; default: Log.warn("Unknown tile type " + lines[i][ix] + "!"); break; } } } objects.Insert(0, new Floor(this, path == "ending")); objects.Insert(1, new Walls(this, path == "ending")); objects.Add(player = new Player(this) { Position = new Vector3(playerPos.X, 0.5f, playerPos.Y) }); if (path == "0" || path == "ending") { objects.Add(warp = new LevelWarp(this) { Position = new Vector3(warpPos.X, 0, warpPos.Y) }); } }