private Invader RetrieveCurrentSelectedInvader(UpdateParams uparams) { Invader retval = mSelectedInvader; if (retval != null && retval.State != InvaderState.Alive) { retval = null; } if (uparams.Input.SelectObject) { // if they click, then reset the selection retval = null; for (int i = mInvaders.Count - 1; i > -1; --i) { Invader invader = mInvaders[i]; if (invader.State == InvaderState.Alive) { GsRectangle box = invader.GetBoundingBox(uparams.Offset); if (box.Contains(uparams.Input.CursorPosition)) { retval = invader; i = -1; } } } } mSelectedInvader = retval; return(retval); }
private static GridCell[] GetCellsWithCenterContainedIn(GridCell[,] grid, GsRectangle box, GsVector cellOffset) { int ColCount = grid.GetLength(0); int RowCount = grid.GetLength(1); List <GridCell> cells = new List <GridCell>(100); for (int c = 0; c < ColCount; ++c) { for (int r = 0; r < RowCount; ++r) { GridCell cell = grid[c, r]; GsVector center = cell.Bounds.Location + cellOffset; center.X += (cell.Width / 2f); center.Y += (cell.Height / 2f); if (box.Contains(center)) { cells.Add(cell); } } } return(cells.ToArray()); }
private void OnSelectClick(UpdateParams uparams) { // ignore this function if the buttons have the mouse if (btnSell.MouseCaptured || btnUpgrade.MouseCaptured) { return; } // always clear the current selection ClearSelection(); // if the user has no selection, then select the piece if (lstPieces.SelectedIndex == -1) { // the piece is invalid. Find the piece that they clicked on. bool found = false; for (int i = 0; !found && i < mPieces.Count; ++i) { Piece piece = mPieces[i]; GsRectangle box = new GsRectangle(piece.Position + uparams.Offset, piece.Size); if (box.Contains(uparams.Input.CursorPosition)) { // set selection found = true; SetSelection(piece); } } } }
private void UpdateProjectiles(UpdateParams uparams) { float dx = CellWidth * 2f; float dy = CellHeight * 2f; GsRectangle viewport = new GsRectangle(X - dx, Y - dy, Width + dx, Height + dy); for (int i = mProjectiles.Count - 1; i > -1; --i) { // get the projectile Projectile projectile = mProjectiles[i]; // update the projectile data projectile.Update(uparams.Elapsed); // get the polygon data GsPolygon polygon = projectile.GetHull(uparams.Offset); // if the projectile is still alive, check to see if it went out of bounds if (projectile.IsAlive) { bool projectileIntersectsWithBounds = viewport.IntersectsWith(projectile.Bounds); bool projectileInsideBounds = viewport.Contains(projectile.Bounds); projectile.IsAlive = projectile.StayAlive || (projectileInsideBounds || projectileIntersectsWithBounds); } // if the projectile is still alive, check to see if it hit anything if (projectile.IsAlive) { CheckCollisions(projectile, polygon, uparams); } // if the projectile is dead, then remove it from the list if (!projectile.IsAlive) { mProjectiles.RemoveAt(i); OnProjectileRemoved(projectile); } } }