/// <summary> /// Lataa seuraavan levelin /// </summary> protected void LoadNextLevel() { // putsataan aivan kaikki, myös näppäimet ClearAll(); // tyhjätään collected Collected = new List<int>(); CollectedUpdatedFlag = false; // luodaan display CreateDisplay(); // ladataan kenttä CurrentLevel = levels[0]; GridLogic = CurrentLevel.Load(); // päivitetään display UpdateDisplay(); // asetetaan ohjaimet SetControls(); // elossaolo-timer Timer timer = new Timer(); timer.Interval = 4; timer.Timeout += PelaajaElossa; playerAliveCheckTimer = timer; timer.Start(); // kamera Camera.StayInLevel = true; Camera.Zoom(1); Camera.Follow(Player); }
/// <summary> /// Käy kentän kaikki merkit läpi ja kutsuu <c>SetTileMethod</c>-metodilla annettuja /// aliohjelmia kunkin merkin kohdalla. Palauttaa täytetyn GridLogic-olion. /// </summary> /// <remarks> /// Aliohjelmassa voi esimerkiksi luoda olion ruudun kohdalle. /// </remarks> /// <param name="tileWidth">Yhden ruudun leveys.</param> /// <param name="tileHeight">Yhden ruudun korkeus.</param> /// <returns>Olioilla täytetty GridLogic-olio</returns> public GridLogic Execute(Grid grid) { Game game = Peli.Instance; int width = tiles.GetLength(1); int height = tiles.GetLength(0); GridLogic gridLogic = new GridLogic(grid, width, height); double tileWidth = grid.CellSize.X; double tileHeight = grid.CellSize.Y; // Tehdään kenttä sen kokoiseksi että luodut oliot ladotaan gridiin nätisti // ... ja Grid.SnapToCenter toimii fiksusti // Aina parillinen määrä kertoimena. if (width % 2 == 0) game.Level.Width = width * tileWidth + (2 * tileWidth); else game.Level.Width = (width * tileWidth) + (3 * tileWidth); if (height % 2 == 0) game.Level.Height = height * tileHeight + (2 * tileHeight); else game.Level.Height = (height * tileHeight) + (3 * tileHeight); for (int y = height - 1; y >= 0; y--) { for (int x = 0; x < width; x++) { char symbol = tiles[y, x]; if (legend.ContainsKey(symbol)) { TileMethod f = legend[symbol]; double realX = game.Level.Left + (x * tileWidth) + (tileWidth / 2); double realY = game.Level.Top - (y * tileHeight) - (tileHeight / 2); GameObject o = f(new Vector(realX, realY), tileWidth, tileHeight, args[symbol]); (o as Block).GridLocation = new Vector(x, y); gridLogic.Add(y, x, o); } } } return gridLogic; }