/* * Wormhole.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 { /// /// Creates wormholes in the meteor madness game. /// The player can connect to a wormhole with their "wormhole connector beam." /// The wormhole disappears from memory after fading out several seconds after connection, leaving /// the meteor madness game to spawn a UFO in its location. /// class Wormhole : Entity { protected static Texture2D mSpriteSheet; // Wormhole sprites protected Animation mLayer2; // Additional textures are needed for a layered look protected float mAngle1 = 0; // Rotational position of the base layer protected float mAngle2 = 0; // Rotational position of the middle layer protected float mRotationSpeed = (float)Math.PI /2; // Angular velocity of all rotations protected float mSpawnedArcPosition; // Holds the original spawning position so UFOs can spawn where the wormhole initially appeared private Vector3 mSpace3DSize; // Size of this entity in space3D coordinates public float SpawnedArcPosition { get { return mSpawnedArcPosition; } } 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 coordinates /// In Space3D coordinates /// Initial position to spawn the wormhole /// If the wormhole is a player wormhole public Wormhole(float width, float height, float depth, float spawnedArcPosition, bool isPlayer) : base() { mSpace3DSize = new Vector3(width, height, depth); mSpawnedArcPosition = spawnedArcPosition; if (mSpriteSheet == null) { mSpriteSheet = TextureManager.Load(@"Content\MiniGames\Wormholes"); } mSprite = new Animation(mSpriteSheet.Width / 2, mSpriteSheet.Height / 2); mLayer2 = new Animation(mSpriteSheet.Width / 2, mSpriteSheet.Height / 2); mSprite.AddClip("Default", mSpriteSheet, 1, 0, 0f); mLayer2.AddClip("Red", mSpriteSheet, 1, 1, 0f); mLayer2.AddClip("Green", mSpriteSheet, 1, 2, 0f); mSprite.Play("Default"); if (isPlayer) mLayer2.Play("Green"); else mLayer2.Play("Red"); } /// /// Performs necessary logic, including position and rotation updates /// public override void Update() { base.Update(); float dt = AstroBaseApplication.GameManager.ElapsedSeconds; mAngle1 += mRotationSpeed * dt; mAngle2 += mRotationSpeed * 1.75F * dt; mAngle1 %= (float)(2.0F * Math.PI); mAngle2 %= (float)(2.0F * Math.PI); } /// /// Draws based on the Space3D cylinder X,Y,Z coordinates /// /// public void Draw(SpriteBatch spriteBatch, Space3D gameBoard) { // Project into screen coordinates Rectangle projected = Space3D.Project(mPos.X, mPos.Y, mPos.Z, mSpace3DSize.X, mSpace3DSize.Y, -1f); if (mVisible) { // Draw all 3 layers float depth = mPos.Z - gameBoard.MinZ + AstroBaseApplication.GameManager.MeteorCameraFocalLength; float depthRange = gameBoard.MaxZ - gameBoard.MinZ + AstroBaseApplication.GameManager.MeteorCameraFocalLength; mSprite.Draw( spriteBatch, new Rectangle((int)(projected.X), (int)(projected.Y), (int)projected.Width, (int)projected.Height), new Color(mTint.R, mTint.G, mTint.B, (byte)(Math.Max(Opacity - .25f, 0f) * 255)), (float)mRot + mAngle1, SpriteEffects.None, 1F * depth / depthRange); mLayer2.Draw( spriteBatch, new Rectangle((int)(projected.X), (int)(projected.Y), (int)(projected.Width * .80f), (int)(projected.Height * .80f)), new Color(mTint.R, mTint.G, mTint.B, (byte)(Math.Max(Opacity - .50f, 0f) * 255)), (float)mRot - mAngle2, SpriteEffects.None, .9999F * depth / depthRange); } } } }