/*
* Meteor.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.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
using tAC_Engine;
namespace Astropolis
{
///
/// Represents the flying meteors in Meteor Madness.
/// The player can shoot them, and they explode.
/// Meteors can also crash into the player, causing it damage
///
class Meteor : Entity
{
private static Animation[] mMeteorSprites;
private float mSpawnDepth; // How far away (along the z-axis) from the player that the meteors spawn at
private float mKillDepth; // The z-depth where the meteors should kill themselves (which should be behind the player and off camera)
private bool mAlive = true; // If the meteor is alive or not
private Vector3 mSpace3DSize; // Size of this entity in space3D coordinates
public float SpawnDepth { get { return mSpawnDepth; } }
public float KillDepth { set { mKillDepth = value; } get { return mKillDepth; } }
public bool Alive { set { mAlive = value; } get { return mAlive; } }
public override float Width { set { mSpace3DSize.X = value; } get { return mSpace3DSize.X; } }
public override float Height { set { mSpace3DSize.Y = value; } get { return mSpace3DSize.Y; } }
public override Vector3 Size { get { return mSpace3DSize; } }
///
/// Constructor
///
/// In Space3D units
/// In Spacce3D units
/// In Spacce3D units
/// Space3D units/second
/// Space3D depth to spawn meteors
/// Space3D depth to kill meteors
public Meteor(float width, float height, float depth, float speed, float spawnDepth, float killDepth)
: base()
{
// Load the meteor sprite sheet
if (mMeteorSprites == null)
{
mMeteorSprites = new Animation[4];
Texture2D spriteSheet = TextureManager.Load(@"content\MiniGames\Meteors");
for (int i = 0; i < mMeteorSprites.Length; i++)
{
mMeteorSprites[i] = new Animation(new Vector2(spriteSheet.Width / 2, spriteSheet.Height / 2));
mMeteorSprites[i].AddClip("Default", spriteSheet, 1, i, 1f);
mMeteorSprites[i].Play("Default");
}
}
double p = GenericBaseApplication.GameManager.RandomNumber();
if (p < .3333)
mSprite = mMeteorSprites[0];
else if (p < .6667)
mSprite = mMeteorSprites[1];
else
mSprite = mMeteorSprites[2];
mSpace3DSize = new Vector3(width, height, depth);
mVel.Z = -1 * speed;
mSpawnDepth = spawnDepth;
mKillDepth = killDepth;
mAngVel = (spawnDepth + 3) * (2 * GenericBaseApplication.GameManager.RandomNumber() - 1);
double ArcPosition = Math.PI * 2 * GenericBaseApplication.GameManager.RandomNumber();
Vector2 PositionFromOrigin = new Vector2((float)Math.Cos(ArcPosition), (float)Math.Sin(ArcPosition));
mPos.X = .8F * PositionFromOrigin.X;
mPos.Y = .8F * PositionFromOrigin.Y;
mPos.Z = spawnDepth;
mSize.Z = width;
}
///
/// Scrolls the meteor towards the player
///
public override void Update()
{
base.Update();
// Kill the meteor if it has scrolled past the player
if (mPos.Z < mKillDepth)
{
mAlive = false;
}
}
}
}