/*
* EscapeScreen.cs
* Authors: Karl Orosz, Brian Chesborough
* 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;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using tAC_Engine.Graphics.Entities;
using Util;
namespace StarJack
{
///
/// This is the main type for your game
///
public class EscapeScreen : GameScreen
{
public const String TextureDirectory = @"Texture\";
private readonly List mMenuItems = new List();
private int mItemSelected;
private SpriteBatch mSpriteBatch;
private SpriteFont mSpriteFont;
public int curWorld;
public int curLevel;
public int curRoom;
private Entity mBackground;
private Entity mMenuBackground;
private InputHandler inputHandler;
//The list of the components that this screen will own
private List mComponents = new List();
///
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
///
public override void Initialize()
{
Entity.RootDirectory = RootDirectory;
inputHandler = GetInputHandler();
mMenuItems.Add("Continue");
mMenuItems.Add("Mini Game Selection");
mMenuItems.Add("Exit");
inputHandler.Initialize();
inputHandler.BindButton(Keys.Down, Trigger.Activated, (int)EventCode.MenuDown);
inputHandler.BindButton(Keys.Up, Trigger.Activated, (int)EventCode.MenuUp);
inputHandler.BindButton(Keys.Enter, Trigger.Activated, (int)EventCode.MenuSelect);
inputHandler.BindButton(Keys.Escape, Trigger.Activated, (int)EventCode.MenuCancel);
mBackground = new Entity("Back");
mBackground.TextureName = "Square";
mBackground.Width = 800;
mBackground.Height = 600;
mBackground.Color = new Color(0, 0, 0, 155);
mBackground.X = 0;
mBackground.Y = 0;
mMenuBackground = new Entity("MenuBack");
mMenuBackground.TextureName = "Wires";
mMenuBackground.X = 200;
mMenuBackground.Y = 200;
mMenuBackground.Width = 200;
mMenuBackground.Height = 200;
base.Initialize();
#if DEBUG
ShowFPS();
#endif
}
///
/// LoadContent will be called once per game and is the place to load
/// all of your content.
///
protected override void LoadContent()
{
mSpriteBatch = new SpriteBatch(GraphicsDevice);
foreach (GameComponent gc in mComponents)
{
EntitySprite s = gc as EntitySprite;
if (s != null)
{
s.SpriteBatch = mSpriteBatch;
}
}
mSpriteFont = Content.Load(@"Fonts\menufont");
mMenuBackground.LoadContent(Content);
mBackground.LoadContent(Content);
base.LoadContent();
}
///
/// UnloadContent will be called once per game and is the place to unload
/// all content.
///
protected override void UnloadContent()
{
base.UnloadContent();
}
public override void Reinitialize()
{
inputHandler.Enable();
Enabled = true;
Visible = true;
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
mSpriteBatch.Dispose();
}
base.Dispose(disposing);
}
///
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
///
/// Provides a snapshot of timing values.
public override void Update(GameTime gameTime)
{
base.Update(gameTime);
while (inputHandler.HasEvent())
{
InputEvent e = inputHandler.GetNextEvent();
switch ((EventCode)e.EventCode)
{
case EventCode.MenuDown:
mItemSelected = (mItemSelected + 1) % mMenuItems.Count;
//SoundManager.SoundManager.PlayEffect("Menu_Move");
break;
case EventCode.MenuUp:
mItemSelected = (mItemSelected - 1 + mMenuItems.Count) % mMenuItems.Count;
//SoundManager.SoundManager.PlayEffect("Menu_Move");
break;
case EventCode.MenuSelect:
//SoundManager.SoundManager.PlayEffect("Menu_Select");
if (mMenuItems[mItemSelected] == "Continue")
{
Done();
}
else if (mMenuItems[mItemSelected] == "Mini Game Selection")
{
Done();
}
else if (mMenuItems[mItemSelected] == "Exit")
{
Exit();
}
break;
case EventCode.MenuCancel:
Done();
break;
}
}
}
///
/// This is called when the game should draw itself.
///
/// Provides a snapshot of timing values.
public override void Draw(GameTime gameTime)
{
base.Draw(gameTime);
Vector2 location = new Vector2(200, 200);
Vector2 shadow = new Vector2(202, 202);
mBackground.Draw(mSpriteBatch);
mMenuBackground.Draw(mSpriteBatch);
mSpriteBatch.Begin();
mSpriteBatch.DrawString(mSpriteFont, StarJackInfo.Name, shadow, Color.Black);
mSpriteBatch.DrawString(mSpriteFont, StarJackInfo.Name, location, Color.BurlyWood);
for (int i = 0; i < mMenuItems.Count; ++i)
{
location.Y += 75;
shadow.Y += 75;
mSpriteBatch.DrawString(mSpriteFont, mMenuItems[i], shadow, Color.Black);
if (i == mItemSelected)
{
mSpriteBatch.DrawString(mSpriteFont, mMenuItems[i], location, Color.Yellow);
}
else
{
mSpriteBatch.DrawString(mSpriteFont, mMenuItems[i], location, Color.White);
}
}
mSpriteBatch.End();
}
}
}