PasteAll.org
http://pasteall.org/1148/csharp 16 Jun 2008 11:49
Loading
		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();
}
}
}
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using Microsoft.Xna.Framework;
  5. using Microsoft.Xna.Framework.Graphics;
  6. using Microsoft.Xna.Framework.Input;
  7. using Microsoft.Xna.Framework.Content;
  8.  
  9. namespace Animated_Sprite_Test_1
  10. {
  11.         /// <summary>
  12.         /// Represents the game's playing state
  13.         /// </summary>
  14.         public class MapGameState : GameState
  15.         {
  16.                 SpriteBatch spriteBatch;
  17.                 SpriteFont spriteFont;
  18.         Sprite trainer;
  19.  
  20.         Dialog dialog1;
  21.  
  22.         Map map1;
  23.  
  24.         public class Map
  25.         {
  26.             public byte[] data;
  27.             ContentManager content;
  28.             Texture2D tiles;
  29.             public Map(Game game1)
  30.             {
  31.                 content =  game1.Services.GetService(typeof(ContentManager)) as ContentManager;
  32.                 tiles = content.Load<Texture2D>("Tilesheet 1");
  33.             }
  34.             public void Draw(SpriteBatch spritebatch)
  35.             {
  36.                 int x = 0;
  37.                 int y = 0;
  38.                 foreach(byte bite in data)
  39.                 {
  40.                     spritebatch.Draw(tiles, new Vector2(x * 16, y * 16), new Rectangle(bite * 16, 0, 16, 16), Color.White);
  41.                     x++;
  42.                     if (x >= 10)
  43.                     {
  44.                         x = 0;
  45.                         y++;
  46.                     }
  47.                 }
  48.             }
  49.         }
  50.        
  51.         public MapGameState(Game game)
  52.                         : base(game)
  53.                 {
  54.                         //load the bullet and compute the center
  55.  
  56.             dialog1 = new Dialog(@"This is a dialog test. Ya like it? Didn't think so. At least it works though, =P.", game);
  57.             map1 = new Map(game);
  58.             /*map1.data = new byte[]{08, 08, 06, 06, 08, 08, 08, 08, 08, 08
  59.                                                ,08, 08, 06, 06, 08, 08, 08, 08, 08, 08
  60.                                                ,08, 08, 06, 06, 06, 06, 06, 06, 06, 06
  61.                                                ,08, 08, 06, 06, 06, 06, 06, 06, 06, 06
  62.                                                ,08, 08, 08, 08, 08, 08, 08, 08, 08, 08
  63.                                                ,08, 08, 08, 08, 08, 08, 08, 08, 08, 08};*/
  64.             map1.data = new byte[]{
  65.                               03, 03, 03, 07, 00, 01, 07, 03, 03, 03,
  66.                               03, 03, 03, 07, 02, 02, 07, 03, 03, 03,
  67.                               07, 07, 07, 07, 02, 02, 07, 07, 07, 07,
  68.                               03, 03, 03, 03, 02, 02, 03, 03, 03, 03,
  69.                               03, 03, 03, 03, 02, 02, 03, 03, 03, 03,
  70.                               03, 03, 03, 08, 02, 02, 02, 02, 02, 02,
  71.                               09, 09, 10, 08, 11, 12, 11, 12, 02, 02,
  72.                               04, 04, 03, 08, 06, 06, 06, 06, 06, 06,
  73.                               05, 05, 03, 08, 06, 06, 06, 06, 06, 06,
  74.                               };
  75.             //dialog1 = new Dialog(@"", game);
  76.  
  77.                         //because we rotate the whole game on Zune, we need to swap the
  78.                         //screen's width and height values when creating the players
  79.  
  80.             spriteBatch = new SpriteBatch(GraphicsDevice);
  81.             spriteFont = Content.Load<SpriteFont>("Font1");
  82.            
  83.             //trainer_walking_south.sprites.Add(Content.Load<Texture2D>("Trainer\\Standing"));
  84.             //trainer_standing_south = Content.Load<Texture2D>("Trainer\\Standing");
  85.             trainer = new Sprite();
  86.             trainer.Position = new Vector2(15, 15);
  87.             trainer.AddAnimation(Content, "Trainer_South_Walking", "Trainer\\South\\", new string[] { "Standing", "Walking_1", "Standing", "Walking_2" });
  88.             trainer.AddAnimation(Content, "Trainer_South_Standing", "Trainer\\South\\Standing");
  89.             trainer.AddAnimation(Content, "Trainer_North_Standing", "Trainer\\North\\Standing");
  90.             trainer.SetAnimation("Trainer_South_Standing", 5);
  91.             //trainer.SetAnimation("Trainer_Walking_South", 5);
  92.             //trainer.Scale = 3f;
  93.  
  94.             int screenWidth = GraphicsDevice.Viewport.Height;
  95.                         int screenHeight = GraphicsDevice.Viewport.Width;
  96.  
  97.             //dialog1.Show();
  98.  
  99.             //DrawMode = "Landscape";
  100.                 }
  101.  
  102.                 public override void Update(GameTime gameTime)
  103.                 {
  104.                         //allow the players to pause the game using either the game pads or the Enter key on the keyboard
  105.                         if (InputHelper.IsNewButtonPress(Buttons.Back))
  106.                                 //InputHelper.IsNewButtonPress(pause) ||
  107.                                 //InputHelper.IsNewKeyPress(Keys.Enter))
  108.                         {
  109.                                 Manager.CurrentState = AAGameState.Paused;
  110.                                 return;
  111.                         }
  112.  
  113.             if (dialog1.Showing)
  114.             {
  115.                 if (InputHelper.IsNewTap(InputHelper.Dir.Center))
  116.                 {
  117.                     if (!dialog1.NextLine())
  118.                         dialog1.Hide();
  119.                 }
  120.             }
  121.             else
  122.             {
  123.                 if (InputHelper.IsNewTap(InputHelper.Dir.North))
  124.                 {
  125.                     trainer.SetAnimation("Trainer_North_Standing", 0);
  126.                 }
  127.  
  128.                 if (InputHelper.IsNewTap(InputHelper.Dir.South))
  129.                 {
  130.                     trainer.SetAnimation("Trainer_South_Standing", 0);
  131.                 }
  132.  
  133.                 if (InputHelper.IsNewButtonPress(Buttons.DPadDown))
  134.                 {
  135.                     trainer.SetAnimation("Trainer_South_Walking", 5);
  136.                 }
  137.  
  138.                 if (InputHelper.IsNewTap(InputHelper.Dir.Center))
  139.                 {
  140.                     dialog1.SetLine(0);
  141.                     dialog1.Show();
  142.                 }
  143.  
  144.                 trainer.Update(gameTime, Vector2.Zero, Vector2.Zero);
  145.             }
  146.  
  147.                 }
  148.  
  149.                 private void CheckPlayerLives()
  150.                 {
  151.  
  152.                 }
  153.  
  154.                 public override void Draw(GameTime gameTime)
  155.                 {
  156.                         spriteBatch.Begin(SpriteBlendMode.AlphaBlend);
  157.             map1.Draw(spriteBatch);
  158.             trainer.Draw(spriteBatch);
  159.             if (dialog1.Showing)
  160.                 dialog1.Draw(spriteBatch, spriteFont);
  161.                         spriteBatch.End();
  162.                 }
  163.         }
  164. }
  165.  
go to heaven
PasteAll.org is brought to you by the monkeys of GraphicAll.org - About