public TileList(Gmap gamemap, Unit ghost) { EntityList = new List<DepthSortedEntity>(); DepthSortedEntity tmp = null; /* Get the tiles (DIAMOND SHAPE !): */ for (int i = 0; i < gamemap.height; i++) { for (int j = 0; j < i+1; j++) { tmp = new DepthSortedEntity( j, i-j, gamemap.getHeight(j, i-j), gamemap.tileType(j, i-j), 0F ); EntityList.Add(tmp); } } for (int i = 1; i < gamemap.height+1; i++) { for (int j = 0; j < gamemap.width-i; j++) { tmp = new DepthSortedEntity(i + j, gamemap.width - j - 1, gamemap.getHeight(i + j, gamemap.width - j - 1), gamemap.tileType(i + j, gamemap.width - j - 1), 0F); EntityList.Add(tmp); } } /* Add the ghost (HIS INDEX IS 7 FROM NOW ON !!!!): */ tmp = new DepthSortedEntity(ghost.pos.PosXMatrix, ghost.pos.PosYMatrix, gamemap.getHeight(ghost.pos.PosXMatrix, ghost.pos.PosYMatrix), 7, 0F); EntityList.Add(tmp); this.SortList(); }
/* ===================================== * THIS UPDATES THE INPUT IN EACH FRAME: * ===================================== */ private void UpdateInput() { KeyboardState KBstate_new = Keyboard.GetState(); MouseState MSstate_new = Mouse.GetState(); /* If curNewCng == 1 -> the cursor has changed tiles. */ int curNewCng = _cursor.calc_pos_matrix(MSstate_new.X + _cam.x * TILE_WIDTH / 2, MSstate_new.Y + _cam.y * TILE_HEIGHT / 2, TILE_WIDTH, TILE_HEIGHT); DepthSortedEntity tmp; /* KEYBOARD - MAP SCROLLING: */ if (KBstate_new.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.A)) { _cam.dx = -1; } else if (KBstate_new.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D)) { _cam.dx = 1; } else { _cam.dx = 0; } if (KBstate_new.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.W)) { _cam.dy = -1; } else if (KBstate_new.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.S)) { _cam.dy = 1; } else { _cam.dy = 0; } /* KEYBOARD - ESC PRESSED: */ if (KBstate_new.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Escape) && !(KBstate_old.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Escape))) { Exit(); } /* MOUSE: */ /* LMB PRESSED ONCE: */ if ((MSstate_new.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed && MSstate_old.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Released)) { /* Find the according Entity in TheList: */ tmp = _theList.EntityList.Find((a => (a.y == _cursor.PosXMatrix) && (a.x == _cursor.PosYMatrix))); /* If there is nothing: */ if (_gamemap.tileType(_cursor.PosYMatrix, _cursor.PosXMatrix) == 0) { _gamemap.setTileType(_cursor.PosYMatrix, _cursor.PosXMatrix, 2); tmp.tileType = 2; _sfxBuildObstacle.Play(); _lastBuildOrder = 1; } /* If there already is a blueprint: */ else if (_gamemap.tileType(_cursor.PosYMatrix, _cursor.PosXMatrix) == 2) { _gamemap.setTileType(_cursor.PosYMatrix, _cursor.PosXMatrix, 0); tmp.tileType = 0; _lastBuildOrder = 0; } } /* LMB PRESSED CONTINOUSLY: */ else if (((MSstate_new.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed && MSstate_old.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed) && curNewCng == 1)) { /* Find the according Entity in TheList: */ tmp = _theList.EntityList.Find((a => (a.y == _cursor.PosXMatrix) && (a.x == _cursor.PosYMatrix))); /* If there is nothing AND last time we've build a blueprint: */ if (_gamemap.tileType(_cursor.PosYMatrix, _cursor.PosXMatrix) == 0 && _lastBuildOrder == 1) { _gamemap.setTileType(_cursor.PosYMatrix, _cursor.PosXMatrix, 2); tmp.tileType = 2; _sfxBuildObstacle.Play(); _lastBuildOrder = 1; } /* If there already is a blueprint AND last time a blueprint was deleted: */ else if (_gamemap.tileType(_cursor.PosYMatrix, _cursor.PosXMatrix) == 2 && _lastBuildOrder == 0) { _gamemap.setTileType(_cursor.PosYMatrix, _cursor.PosXMatrix, 0); tmp.tileType = 0; _lastBuildOrder = 0; } } /* RMB PRESSED ONCE: */ if (MSstate_new.RightButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed) { /* Find the according Entity in TheList: */ //tmp = TheList.EntityList.Find((a => (a.y == cursor_new.pos_x_matrix) && (a.x == cursor_new.pos_y_matrix))); tmp = _theList.EntityList.Find(a => (a.tileType == 7)); _someString = tmp.depthValue.ToString(); } KBstate_old = KBstate_new; MSstate_old = MSstate_new; }
public TileList(Gmap gamemap, Unit ghost) { EntityList = new List <DepthSortedEntity>(); DepthSortedEntity tmp = null; /* Get the tiles (DIAMOND SHAPE !): */ for (int i = 0; i < gamemap.height; i++) { for (int j = 0; j < i + 1; j++) { tmp = new DepthSortedEntity(j, i - j, gamemap.getHeight(j, i - j), gamemap.tileType(j, i - j), 0F); EntityList.Add(tmp); } } for (int i = 1; i < gamemap.height + 1; i++) { for (int j = 0; j < gamemap.width - i; j++) { tmp = new DepthSortedEntity(i + j, gamemap.width - j - 1, gamemap.getHeight(i + j, gamemap.width - j - 1), gamemap.tileType(i + j, gamemap.width - j - 1), 0F); EntityList.Add(tmp); } } /* Add the ghost (HIS INDEX IS 7 FROM NOW ON !!!!): */ tmp = new DepthSortedEntity(ghost.pos.PosXMatrix, ghost.pos.PosYMatrix, gamemap.getHeight(ghost.pos.PosXMatrix, ghost.pos.PosYMatrix), 7, 0F); EntityList.Add(tmp); this.SortList(); }