using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Otter; namespace OtterApp { class TileEntity: Entity { // The Tilemap Graphic to use for rendering tiles. public Tilemap TileMap; // The grid size to use for the Tilemap. public static int GridSize = 32; // The current selected tile to place. public bool TilemapShown = false; BoxCollider tileCollider = new BoxCollider(32, 32, Tags.World); public TileEntity() : base() { // Create the Tilemap the size of the game window using the defined grid size. TileMap = new Tilemap("tileset.png", Game.Instance.Width, Game.Instance.Height, GridSize, GridSize); // Add the Tilemap to the list of Graphics to render. AddGraphic(TileMap); // Add the collider so that it can check for collisions. AddCollider(tileCollider); // Center the origin of the collider so it aligns with the image. tileCollider.CenterOrigin(); // Place some tiles. (y = 31 => Unterer Bildschirmrand[tiefer = außerhalb des Screens]) //Prebuild Testingground Level TileMap.SetTile(3, 29, 640); TileMap.SetTile(4, 29, 641); TileMap.SetTile(5, 29, 642); TileMap.SetTile(6, 29, 643); TileMap.SetTile(7, 29, 642); TileMap.SetTile(8, 29, 643); TileMap.SetTile(9, 29, 642); TileMap.SetTile(10, 29, 643); TileMap.SetTile(11, 29, 642); TileMap.SetTile(12, 29, 643); TileMap.SetTile(13, 29, 670); TileMap.SetTile(14, 29, 671); TileMap.SetTile(15, 29, 672); //Gap TileMap.SetTile(18, 29, 640); TileMap.SetTile(19, 29, 641); TileMap.SetTile(20, 29, 642); TileMap.SetTile(21, 29, 642); TileMap.SetTile(22, 29, 642); TileMap.SetTile(23, 29, 642); TileMap.SetTile(24, 29, 642); TileMap.SetTile(25, 29, 642); TileMap.SetTile(26, 29, 642); TileMap.SetTile(27, 29, 642); TileMap.SetTile(28, 29, 670); TileMap.SetTile(29, 29, 671); TileMap.SetTile(30, 29, 672); TileMap.SetTile(3, 30, 698); TileMap.SetTile(4, 30, 699); TileMap.SetTile(5, 30, 700); TileMap.SetTile(6, 30, 701); TileMap.SetTile(7, 30, 700); TileMap.SetTile(8, 30, 701); TileMap.SetTile(9, 30, 700); TileMap.SetTile(10,30, 701); TileMap.SetTile(11, 30, 700); TileMap.SetTile(12, 30, 701); TileMap.SetTile(13, 30, 728); TileMap.SetTile(14, 30, 729); TileMap.SetTile(15, 30, 730); //Gap TileMap.SetTile(18, 30, 698); TileMap.SetTile(19, 30, 699); TileMap.SetTile(20, 30, 700); TileMap.SetTile(21, 30, 700); TileMap.SetTile(22, 30, 700); TileMap.SetTile(23, 30, 700); TileMap.SetTile(24, 30, 700); TileMap.SetTile(25, 30, 700); TileMap.SetTile(26, 30, 700); TileMap.SetTile(27, 30, 700); TileMap.SetTile(28, 30, 728); TileMap.SetTile(29, 30, 729); TileMap.SetTile(30, 30, 730); TileMap.SetTile(3, 31, 756); TileMap.SetTile(4, 31, 757); TileMap.SetTile(5, 31, 992); TileMap.SetTile(6, 31, 992); TileMap.SetTile(7, 31, 992); TileMap.SetTile(8, 31, 992); TileMap.SetTile(9, 31, 992); TileMap.SetTile(10, 31, 992); TileMap.SetTile(11, 31, 992); TileMap.SetTile(12, 31, 992); TileMap.SetTile(13, 31, 786); TileMap.SetTile(14, 31, 787); TileMap.SetTile(15, 31, 788); //Gap TileMap.SetTile(18, 31, 756); TileMap.SetTile(19, 31, 757); TileMap.SetTile(20, 31, 992); TileMap.SetTile(21, 31, 992); TileMap.SetTile(22, 31, 992); TileMap.SetTile(23, 31, 992); TileMap.SetTile(24, 31, 992); TileMap.SetTile(25, 31, 992); TileMap.SetTile(26, 31, 992); TileMap.SetTile(27, 31, 992); TileMap.SetTile(28, 31, 786); TileMap.SetTile(29, 31, 787); TileMap.SetTile(30, 31, 788); } public override void Update() { base.Update(); // Determine the grid position of the mouse. // var gridX = (int)Util.SnapToGrid(Input.MouseX, GridSize) / GridSize; // var gridY = (int)Util.SnapToGrid(Input.MouseY, GridSize) / GridSize; if (Input.KeyReleased(Key.M)) { // Log the current tile value. Console.WriteLine("TileMap is shown"); if (TilemapShown == true) TilemapShown = false; else TilemapShown = true; showTileMap(TilemapShown); } } public override void Render() { base.Render(); if (TilemapShown) { for (int tileRow = 0, tileId = 0, xPos = 0; tileRow < 20; tileId++) { Draw.Text(tileId.ToString(), 8, xPos*32, tileRow*32); xPos++; if (xPos >= 58) { xPos = 0; tileRow++; } } } else { for (int tileRow = 0, tileId = 0, xPos = 0; tileRow < 20; tileId++) { xPos++; if (xPos >= 57) { xPos = 0; tileRow++; } } } tileCollider.Render(); } public void showTileMap(bool show) { if (show) { for (int tileRow = 0, tileId = 0, xPos = 0; tileRow < 20; tileId++) { TileMap.SetTile(xPos, tileRow, tileId); xPos++; if (xPos >= 58) { xPos = 0; tileRow++; } } } else { for (int tileRow = 0, tileId = 0, xPos = 0; tileRow < 20; tileId++) { TileMap.ClearTile(xPos, tileRow); xPos++; if (xPos >= 57) { xPos = 0; tileRow++; } } } } } }