/* * MatrixTextEffect.cs * Authors: * Copyright (c) 2007-2008 Cornell University This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System.Collections.Generic; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; using Random = Util.Random; namespace StarJack { /// /// This class wil create a matirx text effect! /// class MatrixTextEffect { private List> mLetters; private List mSpeedVariance; private float mSpeed; private int mHeight; private int mWidth; //private string mSpriteFont; private float mElapsed; private Viewport mView; private Color mTextColor = new Color(175, 255, 175, 255); public MatrixTextEffect(Viewport view, int height, int width, float speed, float minSpeed) { mView = view; mHeight = height; mWidth = width; mSpeed = speed; int row = view.Height / mHeight ; int col = view.Width / mWidth ; mLetters = new List>(); MatrixLetter tLetter; for (int a = 0; a < row; a++) { mLetters.Add( new List()); for (int b = 0; b < col; b++) { char c = (char)Random.Next(32, 103+1); tLetter = new MatrixLetter(c+""); tLetter.Color = mTextColor ; tLetter.ShadowColor = Color.Lime; tLetter.X = b*mWidth; tLetter.Y = a*mHeight; tLetter.Width = mWidth; tLetter.Height = mHeight; mLetters[a].Add(tLetter); } } mSpeedVariance = new List(); for (int a = 0; a < col; a++) { mSpeedVariance.Add(Random.NextFloat(minSpeed,speed)); } mElapsed = 0; } public void LoadCOntent(ContentManager content) { for (int a = 0; a < mLetters.Count; a++) { for (int b = 0; b < mLetters[a].Count; b++) { mLetters[a][b].LoadContent(content); } } } public void Update(GameTime time) { mElapsed = time.ElapsedGameTime.Milliseconds; for (int a = 0; a < mLetters.Count; a++) { for (int b = 0; b < mLetters[a].Count; b++) { mLetters[a][b].Y += (int)((mElapsed / 1000) * mSpeedVariance[b]); if (mLetters[a][b].Y >= mView.Y + mView.Height) { mLetters[a][b].Y = 0; mLetters[a][b].Text = "" + (char)Random.Next(32, 126+1); if (Random.Next(0, 3) == 0) { mLetters[a][b].ShadowColor = Color.Black; mLetters[a][b].Color = Color.Black; } else { if (Random.Next(0, 4) == 0) { mLetters[a][b].Color = Color.White; mLetters[a][b].ShadowColor = Color.Lime; } else { mLetters[a][b].Color = mTextColor; mLetters[a][b].ShadowColor = Color.Lime; } } } mLetters[a][b].Update(time); } } } public void Draw(SpriteBatch pSpritebatch) { for (int a = 0; a < mLetters.Count; a++) { for (int b = 0; b < mLetters[a].Count; b++) { mLetters[a][b].Draw(pSpritebatch); } } } } }