} //isDocked public void onTarget(float deltaY, ArcheryTarget target, ContentManager content) { isOnTarget = true; archerytarget = new ArcheryTarget(content); archerytarget.changePosY(target.getPosition().Y); changeY = deltaY; } //onTarget
public void update(float angle, GameTime gametime) { if (!inAir && isOnTarget) { archerytarget.update(); this.Position.Y = archerytarget.getPosition().Y + changeY; } if (inAir) { if (docked & !beenshot) { rotation = angle; Position.Y = 768 - 45 + (float)Math.Sin(angle) * 18; Position.X = 20 + (float)Math.Cos(angle) * 16; } else if (!docked && !beenshot) { elapsed += (float)gametime.ElapsedGameTime.TotalSeconds; if (stopxveloc) { Velocity.X = 0; Velocity.Y = 10f; } else if (!isOnTarget) { Velocity.X = initVeloc.X; Velocity.Y = (float)(initVeloc.Y + (9.8 * 2) * elapsed); } Position.X += Velocity.X; Position.Y += Velocity.Y; rotation = (float)Math.Atan(Velocity.Y / Velocity.X); Collidable.Rotation = this.rotation; Collidable.Position = this.Position; if (Position.Y > SCREEN_HEIGHT - texture.Height * 3) { Position.Y = SCREEN_HEIGHT - texture.Height * 3.5f; docked = true; beenshot = true; inAir = false; } } } //ifinAir } // update
} // Draw public void HandleCollisions() { nyanCollide = nyancat.getCollidableObject(); bool resetarrows = false; foreach (Arrow arrow in bow.getArrows()) { if (!arrow.isinAir && arrow.isonTarget()) { arrow.changeArcheryTargetPosY(archeryTarget.getPosition().Y); } if (arrow.isinAir == true) { if (arrow.getCollidableObject().IsColliding(nyanCollide)) { nyancat.isdead(); } switch (gameState) { case GameState.Target: if (arrow.getCollidableObject().IsColliding(archeryTarget.getCollidable())) { arrow.isinAir = false; arrow.velocity = new Vector2(0, 0); arrow.onTarget(Math.Abs(arrow.position.Y - archeryTarget.getPosition().Y), archeryTarget, Content); targetModeScore += 50; } if (arrow.position.Y < 10 && arrow.position.X < 100) { resetarrows = true; gameState = GameState.Menu; } break; case GameState.Bear: foreach (Bear bear in bearMode.getBears()) { if (!bear.isDead) { if (!arrow.isDocked() && arrow.getCollidableObject().IsColliding(bear.getCollidable())) { bear.isDead = true; bearMode.bearsKilled += 1; arrow.stopXVeloc(); } if (player.getCollidable().IsColliding(bear.getCollidable())) { resetarrows = true; gameState = GameState.GameOver; } } } break; case GameState.Menu: if (arrow.getCollidableObject().IsColliding(menuObjects[0])) // "Archer" logo { arrow.isinAir = false; } if (arrow.getCollidableObject().IsColliding(menuObjects[1])) // "Target" logo { arrow.isinAir = false; resetarrows = true; gameState = GameState.Target; break; } if (arrow.getCollidableObject().IsColliding(menuObjects[2])) // "Bear" logo { arrow.isinAir = false; resetarrows = true; gameState = GameState.Bear; bearMode.reset(); break; } if (arrow.getCollidableObject().IsColliding(menuObjects[3])) // "Exit" logo { this.Exit(); } if (arrow.position.Y < 10 && arrow.position.X < 100 && !LoggedIn) // "Login" logo { resetarrows = true; gameState = GameState.Login; } break; } // switch statement } // if isInAir } // foreach arrow if (resetarrows) { bow.resetArrows(Content); } } // HandleCollisions
public void onTarget(float deltaY, ArcheryTarget target, ContentManager content) { isOnTarget = true; archerytarget = new ArcheryTarget(content); archerytarget.changePosY(target.getPosition().Y); changeY = deltaY; }