public override void update(Player human, EnemyShot[] shotList) { bool complete = false; base.update(human, shotList); if (action == 0) { base.moveTo(300, 300); } else if (action == 1) { //Do other stuff } else if (action == 2) { //Do differant stuff } Console.WriteLine("Boss Health: " + Convert.ToString(health)); if (complete) { action++; } }
/// <summary> /// Checks to see if there is a collision between the bullet and the player /// </summary> /// <param name="player">the player to check the collision against</param> /// <returns>True if there is a collision, otherwise false</returns> public bool collidsWith(Player player) { //get the distance to the sides of the player's hitbox int xDif1 = player.hitBox.X - (xPos + (int)origin.X); int xDif2 = (player.hitBox.X + player.hitBox.Width) - (xPos + (int)origin.X); int yDif1 = player.hitBox.Y - (yPos + (int)origin.Y); int yDif2 = (player.hitBox.Y + player.hitBox.Width) - (yPos + (int)origin.Y); // choose the smallest distance for x and y int xDif; int yDif; if (Math.Abs(xDif1) > Math.Abs(xDif2)) { xDif = xDif2; }else { xDif = xDif1; } if (Math.Abs(yDif1) > Math.Abs(yDif2)) { yDif = yDif2; } else { yDif = yDif1; } //int xDif = player.xPos - (xPos + (int)origin.X); //int yDif = player.yPos - (yPos + (int)origin.Y); if (-20 < xDif && xDif < 20 && -5 < yDif && yDif < 5) { int i = 0; } double line = Math.Pow(xDif, 2) + Math.Pow(yDif, 2); if (line < radius * radius * radius) { return true; } else { return false; } }
public new bool aim(Player human) { float humanAngle = getAngleToHuman(human); //if not aimed at human if (!isAimedAt(human, humanAngle)) { if (rotAngle <= humanAngle) { rotSpeed = maxRotSpeed; return false; } else { rotSpeed = -1 * maxRotSpeed; return false; } } else { rotSpeed = 0; return true; } }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { LoadContent(); Constants constants = new Constants(); activeList = new Enemy[20]; shotList = new EnemyShot[100000]; // Create Level Reader LevelReader reader = new LevelReader(); // Load Background ArrayList tmpRemoveLst = new ArrayList(); foreach (Enemy enemy in reader.enemyList) { if (enemy is Grunt) { enemy.init(enemyText, enemyShot, constants); enemyList.Add(enemy); } else if (enemy is Boss) { boss = (Boss)enemy; boss.init(enemyText, enemyShot, constants); } } foreach (Boss boss in tmpRemoveLst) { enemyList.Remove(boss); } // load background song if (reader.levelSong != "none") { Uri uri = new Uri(reader.levelSong,UriKind.Relative); try { bsong = Song.FromUri(reader.levelSong, uri); //MediaPlayer.Play(bsong); } catch (System.ArgumentException) { Console.Error.WriteLine("Error loading file: " + (string)reader.levelSong + " ... Ignoring"); } } // Load background if (reader.background != "none") { try { Stream str = File.OpenRead(reader.background); backgroundTexture = Texture2D.FromStream(GraphicsDevice, str); } catch (System.IO.DirectoryNotFoundException) { Console.Error.WriteLine("Could not locate file: " + (string)reader.background + " Using default."); backgroundTexture = singlePix; } } else { backgroundTexture = singlePix; } //create player humanAnimatedTexture = new AnimatedSprite(humanTexture, constants.HUMAN_NEUTRAL_FRAME, constants.HUMAN_NEUTRAL_FRAME, constants.MAX_HUMAN_FRAMES, constants.HUMAN_SPRITE_WIDTH, constants.HUMAN_SPRITE_HEIGHT); human = new Player(humanAnimatedTexture, shotTexture, constants.HUMAN_START_X, constants.HUMAN_START_Y, constants.MAX_HUMAN_SPEED); base.Initialize(); }
public override void update(Player human, EnemyShot[] shotList) { foreach (Shot shot in human.shotList) { if (hitBox.Intersects(shot.hitBox)) { // subtract health from hit health = health - shot.damage; // if no health, set to dead if (health <= 0) { alive = false; } // regester that the shot has connected shot.hit = true; } } // Aiming Code //moveID = 1; //if (rotAngle >= 360 || rotAngle < 0) //{ // rotAngle = 0; //} if (moveID == 0) { if(moveTo(tarx, tary)) { //moveID++; shoot(ref shotList); } }else if(moveID == 1) { if (aim(human)) { //moveID++; } moveID++; } else if (moveID == 2) { if (moveTo(tarx, -110)) { moveID++; } } else { alive = false; } //handle rotation this.rotAngle = rotAngle + (float)rotSpeed; //update shots }
public override bool isAimedAt(Player human, float humanAngle) { //if (rotAngle <= humanAngle + aimTolerance || rotAngle >= humanAngle - aimTolerance) if (rotAngle == humanAngle) { return true; } else { return false; } }
/// <summary> /// Updates the enemy's position, damage, and alive statues /// </summary> /// <param name="human"></param> public virtual void update(Player human, EnemyShot[] shotList) { foreach (Shot shot in human.shotList) { if (hitBox.Intersects(shot.hitBox)) { // subtract health from hit health = health - shot.damage; // if no health, set to dead if (health <= 0) { alive = false; } // regester that the shot has connected shot.hit = true; } } }
/// <summary> /// Gets the angle to the player /// </summary> /// <param name="human">player to get angle to</param> /// <returns>the angle to the human</returns> public virtual float getAngleToHuman(Player human) { // TOTO: fix this up, it's still derpy float angle = 0; //get angle to human need to fix int a = Math.Abs(xPos + (spriteWidth / 2) - (human.xPos + human.sprite.spriteWidth / 2)); int b = Math.Abs(yPos + (spriteHeight / 2) - (human.yPos + human.sprite.spriteHeight / 2)); double c = Math.Sqrt(Math.Pow(a, 2) + Math.Pow(b, 2)); angle = (float)Math.Sin(a / c); //TODO find way to make angle transitions more smooth //if human is up and left of enemy if (human.xPos < xPos && human.yPos < yPos) { angle = angle + 90; } //if human is down and left of enemy else if (human.xPos > xPos && human.yPos < yPos) { angle = angle + 180; } else if (human.xPos > xPos && human.yPos > yPos) { angle = angle + 270; } return angle; }