/* * Flotsam.cs * Authors: August Zinsser * * Copyright Matthew Belmonte 2007 */ using System; using System.Collections.Generic; using System.Text; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using tAC_Engine; namespace Astropolis { /// /// The items that the friendly ships in Meteor Madness throw to the player /// They upgrade the player's weapon and grant him/her a resource when the player's ship collides with this /// class Flotsam : UFO { private string mResource; private int mValue; /// /// Constructor /// /// Type of resource to award the player for collecting this powerup /// Amount of that resource to award /// Image of the powerup /// In Space3D units /// In Space3D units /// In Space3D units public Flotsam(string resourceType, int value, Texture2D texture, float width, float height, float depth) : base(texture, width, height, depth, 10) { mResource = resourceType; mValue = value; // Add a bit of rotation for aesthetics mAngVel = GenericBaseApplication.GameManager.RandomNumber(-5f, 5f); mRot = GenericBaseApplication.GameManager.RandomNumber(0f, (float)Math.PI * 2f); } /// /// Deals the specified amount of damage to this flotsam, potentially destroying it /// /// public override void GetHit(int damage) { mHitPoints -= damage; if (mHitPoints < 0) Destroy(); } /// /// Flotsam does not react, so this method does nothing /// /// public override bool React(CheetahFighter playerShip) { return false; } /// /// Spawns the appropriate particle effects and/or entities /// public override void Destroy() { mAlive = false; } /// /// Some flotsam moves based on the player's location /// /// public void Update(Entity playerShip) { base.Update(); if (mResource == AstroResources.Credits) { // Home in on the player Vector3 oldTraj = mVel; float speed = Math.Max(mVel.Length(), ((MeteorMadness)AstroBaseApplication.MiniGame).ShooterSpeed * 10f); float correctionFactor = 1 - Math.Min(.925f, mPos.Z); Vector3 correctiveTraj; if (playerShip != null) correctiveTraj = playerShip.Position - mPos; else correctiveTraj = mPos; correctiveTraj.Normalize(); correctiveTraj = Vector3.Multiply(correctiveTraj, correctionFactor); oldTraj.Normalize(); oldTraj = Vector3.Multiply(oldTraj, 1 - correctionFactor); mVel = correctiveTraj + oldTraj; mVel = Vector3.Multiply(mVel, speed); } } /// /// Awards the appropriate resources and upgrades the players' weapons /// public override void CollideWithPlayer(Entity player) { int screenCenterX = GenericBaseApplication.GameManager.ScreenWidth / 2; int screenCenterY = GenericBaseApplication.GameManager.ScreenHeight / 2; Rectangle proj = Space3D.Project(player.X, player.Y, player.Z, this.Width, this.Height, -1f); if (mResource != "") { // Gather the resource AstroBaseApplication.MiniGame.Score.Gather(mResource, mValue); if (((MeteorMadness)AstroBaseApplication.MiniGame).DisplayWaitTimer < 0) { // Display a ticker string text = "+"; if (mResource == "Money") text += "$" + mValue; else text += mResource; Ticker.Display( text, null, Vector2.Zero, new Vector2(proj.X - screenCenterX, proj.Y - screenCenterY), new Vector2(0, -50f), Ticker.Font.InGame_Tiny, Color.LimeGreen, 1f, 1f, true); ((MeteorMadness)AstroBaseApplication.MiniGame).ResetDisplayWaitTimer(); } Logger.LogCode(Logger.ExperimentalCode.MM_ShooterPlayerCollectibleCollision, mResource); } else { // Upgrade weapons ((MeteorMadness)AstroBaseApplication.MiniGame).CollectedUpgrades = ((MeteorMadness)AstroBaseApplication.MiniGame).CollectedUpgrades + 1; AstroBaseApplication.GameManager.DotWeaponCooldown *= .90f; Ticker.Display( "+Weapon", null, Vector2.Zero, new Vector2(proj.X - screenCenterX, proj.Y - screenCenterY), new Vector2(0, -50f), Ticker.Font.InGame_Tiny, Color.Aqua, 1f, 1f, true); Logger.LogCode(Logger.ExperimentalCode.MM_ShooterPlayerCollectibleCollision, "Weapon Upgrade"); } mAlive = false; } } }