//method to keep objects within screen /// <summary> /// Ensures that object is within top and bottom bounds of the screen, targeted to be used with player object but can take any GameEntity object /// </summary> /// <param name="obj">Any GameEntity object to be checked and kept within top and bottom of screen</param> public void screenLimit(GameEntity obj) { if (obj.pos.Y <= 0 ) //at top wall obj.pos.Y = 0; //if closer than the 0 that means Sprite would go outside, so reset if (obj.pos.Y >= (Game1.Instance.Window.ClientBounds.Height )) //at bottom wall obj.pos.Y = (Game1.Instance.Window.ClientBounds.Height ); //reset if too close to bottom wall, same as other }
//if enenmy hit by player Check /// <summary> /// Checks if the enemy was hit by player bullet, removes the enemy and bullet if so /// </summary> /// <param name="obj">Any GameEntity (enemy,comet,etc.) object to be checked</param> void enemyHit(GameEntity obj) { for (int i = 0; i < playerBullet.Count; ++i) //for all player bullets { if (playerBullet[i].me.Intersects(obj.me)) //if player bullet intersects object currently checked { score += obj.scoreGain; //increase score enemyList.Remove(obj); //remove object(enemy only takes one shot playerBullet.Remove(playerBullet[i]); //remove bullet --i; //fix index } } }
//checks if obj has passed by the left wall /// <summary> /// Checks if an enemy has passed by the player to the left and returns a boolean /// </summary> /// <param name="obj">Object that will be checked if it has passed by the player to the left</param> /// <returns></returns> public bool enemyPassed(GameEntity obj) { if (obj.pos.X <= -obj.Sprite.Width / 2) return true; return false; }