using System; using System.Collections.Generic; using System.Text; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Content;
namespace Animated_Sprite_Test_1 { /// <summary> /// Represents the game's playing state /// </summary> public class MapGameState : GameState { SpriteBatch spriteBatch; SpriteFont spriteFont; Sprite trainer;
Dialog dialog1;
Map map1;
public class Map { public byte[] data; ContentManager content; Texture2D tiles; public Map(Game game1) { content = game1.Services.GetService(typeof(ContentManager)) as ContentManager; tiles = content.Load<Texture2D>("Tilesheet 1"); } public void Draw(SpriteBatch spritebatch) { int x = 0; int y = 0; foreach(byte bite in data) { spritebatch.Draw(tiles, new Vector2(x * 16, y * 16), new Rectangle(bite * 16, 0, 16, 16), Color.White); x++; if (x >= 10) { x = 0; y++; } } } } public MapGameState(Game game) : base(game) { //load the bullet and compute the center
dialog1 = new Dialog(@"This is a dialog test. Ya like it? Didn't think so. At least it works though, =P.", game); map1 = new Map(game); /*map1.data = new byte[]{08, 08, 06, 06, 08, 08, 08, 08, 08, 08 ,08, 08, 06, 06, 08, 08, 08, 08, 08, 08 ,08, 08, 06, 06, 06, 06, 06, 06, 06, 06 ,08, 08, 06, 06, 06, 06, 06, 06, 06, 06 ,08, 08, 08, 08, 08, 08, 08, 08, 08, 08 ,08, 08, 08, 08, 08, 08, 08, 08, 08, 08};*/ map1.data = new byte[]{ 03, 03, 03, 07, 00, 01, 07, 03, 03, 03, 03, 03, 03, 07, 02, 02, 07, 03, 03, 03, 07, 07, 07, 07, 02, 02, 07, 07, 07, 07, 03, 03, 03, 03, 02, 02, 03, 03, 03, 03, 03, 03, 03, 03, 02, 02, 03, 03, 03, 03, 03, 03, 03, 08, 02, 02, 02, 02, 02, 02, 09, 09, 10, 08, 11, 12, 11, 12, 02, 02, 04, 04, 03, 08, 06, 06, 06, 06, 06, 06, 05, 05, 03, 08, 06, 06, 06, 06, 06, 06, }; //dialog1 = new Dialog(@"", game);
//because we rotate the whole game on Zune, we need to swap the //screen's width and height values when creating the players
spriteBatch = new SpriteBatch(GraphicsDevice); spriteFont = Content.Load<SpriteFont>("Font1"); //trainer_walking_south.sprites.Add(Content.Load<Texture2D>("Trainer\\Standing")); //trainer_standing_south = Content.Load<Texture2D>("Trainer\\Standing"); trainer = new Sprite(); trainer.Position = new Vector2(15, 15); trainer.AddAnimation(Content, "Trainer_South_Walking", "Trainer\\South\\", new string[] { "Standing", "Walking_1", "Standing", "Walking_2" }); trainer.AddAnimation(Content, "Trainer_South_Standing", "Trainer\\South\\Standing"); trainer.AddAnimation(Content, "Trainer_North_Standing", "Trainer\\North\\Standing"); trainer.SetAnimation("Trainer_South_Standing", 5); //trainer.SetAnimation("Trainer_Walking_South", 5); //trainer.Scale = 3f;
int screenWidth = GraphicsDevice.Viewport.Height; int screenHeight = GraphicsDevice.Viewport.Width;
//dialog1.Show();
//DrawMode = "Landscape"; }
public override void Update(GameTime gameTime) { //allow the players to pause the game using either the game pads or the Enter key on the keyboard if (InputHelper.IsNewButtonPress(Buttons.Back)) //InputHelper.IsNewButtonPress(pause) || //InputHelper.IsNewKeyPress(Keys.Enter)) { Manager.CurrentState = AAGameState.Paused; return; }
if (dialog1.Showing) { if (InputHelper.IsNewTap(InputHelper.Dir.Center)) { if (!dialog1.NextLine()) dialog1.Hide(); } } else { if (InputHelper.IsNewTap(InputHelper.Dir.North)) { trainer.SetAnimation("Trainer_North_Standing", 0); }
if (InputHelper.IsNewTap(InputHelper.Dir.South)) { trainer.SetAnimation("Trainer_South_Standing", 0); }
if (InputHelper.IsNewButtonPress(Buttons.DPadDown)) { trainer.SetAnimation("Trainer_South_Walking", 5); }
if (InputHelper.IsNewTap(InputHelper.Dir.Center)) { dialog1.SetLine(0); dialog1.Show(); }
trainer.Update(gameTime, Vector2.Zero, Vector2.Zero); }
}
private void CheckPlayerLives() {
}
public override void Draw(GameTime gameTime) { spriteBatch.Begin(SpriteBlendMode.AlphaBlend); map1.Draw(spriteBatch); trainer.Draw(spriteBatch); if (dialog1.Showing) dialog1.Draw(spriteBatch, spriteFont); spriteBatch.End(); } } }
using System; using System.Collections.Generic; using System.Text; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Content; namespace Animated_Sprite_Test_1 { /// <summary> /// Represents the game's playing state /// </summary> public class MapGameState : GameState { SpriteBatch spriteBatch; SpriteFont spriteFont; Sprite trainer; Dialog dialog1; Map map1; public class Map { public byte[] data; ContentManager content; Texture2D tiles; public Map(Game game1) { content = game1.Services.GetService(typeof(ContentManager)) as ContentManager; tiles = content.Load<Texture2D>("Tilesheet 1"); } public void Draw(SpriteBatch spritebatch) { int x = 0; int y = 0; foreach(byte bite in data) { spritebatch.Draw(tiles, new Vector2(x * 16, y * 16), new Rectangle(bite * 16, 0, 16, 16), Color.White); x++; if (x >= 10) { x = 0; y++; } } } } public MapGameState(Game game) : base(game) { //load the bullet and compute the center dialog1 = new Dialog(@"This is a dialog test. Ya like it? Didn't think so. At least it works though, =P.", game); map1 = new Map(game); /*map1.data = new byte[]{08, 08, 06, 06, 08, 08, 08, 08, 08, 08 ,08, 08, 06, 06, 08, 08, 08, 08, 08, 08 ,08, 08, 06, 06, 06, 06, 06, 06, 06, 06 ,08, 08, 06, 06, 06, 06, 06, 06, 06, 06 ,08, 08, 08, 08, 08, 08, 08, 08, 08, 08 ,08, 08, 08, 08, 08, 08, 08, 08, 08, 08};*/ map1.data = new byte[]{ 03, 03, 03, 07, 00, 01, 07, 03, 03, 03, 03, 03, 03, 07, 02, 02, 07, 03, 03, 03, 07, 07, 07, 07, 02, 02, 07, 07, 07, 07, 03, 03, 03, 03, 02, 02, 03, 03, 03, 03, 03, 03, 03, 03, 02, 02, 03, 03, 03, 03, 03, 03, 03, 08, 02, 02, 02, 02, 02, 02, 09, 09, 10, 08, 11, 12, 11, 12, 02, 02, 04, 04, 03, 08, 06, 06, 06, 06, 06, 06, 05, 05, 03, 08, 06, 06, 06, 06, 06, 06, }; //dialog1 = new Dialog(@"", game); //because we rotate the whole game on Zune, we need to swap the //screen's width and height values when creating the players spriteBatch = new SpriteBatch(GraphicsDevice); spriteFont = Content.Load<SpriteFont>("Font1"); //trainer_walking_south.sprites.Add(Content.Load<Texture2D>("Trainer\\Standing")); //trainer_standing_south = Content.Load<Texture2D>("Trainer\\Standing"); trainer = new Sprite(); trainer.Position = new Vector2(15, 15); trainer.AddAnimation(Content, "Trainer_South_Walking", "Trainer\\South\\", new string[] { "Standing", "Walking_1", "Standing", "Walking_2" }); trainer.AddAnimation(Content, "Trainer_South_Standing", "Trainer\\South\\Standing"); trainer.AddAnimation(Content, "Trainer_North_Standing", "Trainer\\North\\Standing"); trainer.SetAnimation("Trainer_South_Standing", 5); //trainer.SetAnimation("Trainer_Walking_South", 5); //trainer.Scale = 3f; int screenWidth = GraphicsDevice.Viewport.Height; int screenHeight = GraphicsDevice.Viewport.Width; //dialog1.Show(); //DrawMode = "Landscape"; } public override void Update(GameTime gameTime) { //allow the players to pause the game using either the game pads or the Enter key on the keyboard if (InputHelper.IsNewButtonPress(Buttons.Back)) //InputHelper.IsNewButtonPress(pause) || //InputHelper.IsNewKeyPress(Keys.Enter)) { Manager.CurrentState = AAGameState.Paused; return; } if (dialog1.Showing) { if (InputHelper.IsNewTap(InputHelper.Dir.Center)) { if (!dialog1.NextLine()) dialog1.Hide(); } } else { if (InputHelper.IsNewTap(InputHelper.Dir.North)) { trainer.SetAnimation("Trainer_North_Standing", 0); } if (InputHelper.IsNewTap(InputHelper.Dir.South)) { trainer.SetAnimation("Trainer_South_Standing", 0); } if (InputHelper.IsNewButtonPress(Buttons.DPadDown)) { trainer.SetAnimation("Trainer_South_Walking", 5); } if (InputHelper.IsNewTap(InputHelper.Dir.Center)) { dialog1.SetLine(0); dialog1.Show(); } trainer.Update(gameTime, Vector2.Zero, Vector2.Zero); } } private void CheckPlayerLives() { } public override void Draw(GameTime gameTime) { spriteBatch.Begin(SpriteBlendMode.AlphaBlend); map1.Draw(spriteBatch); trainer.Draw(spriteBatch); if (dialog1.Showing) dialog1.Draw(spriteBatch, spriteFont); spriteBatch.End(); } } }
|