desculpa luciano ve se agpora ficou bom !
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using LoaderMapFromMappy;
namespace arkanoidxna
{
/// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
clsSprite myBase; // sprite para a basse
clsSprite myBall; // sprite para a bolinha
clsSprite[] myBackground = new clsSprite[10]; //sprite para a imagem de fundo ou telas
private MappyLoader mappyLoader;
private MapLayer mapLayer;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
/// <summary>
/// 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.
/// </summary>
protected override void Initialize()
{
// TODO: Add your initialization logic here
this.mappyLoader = new MappyLoader();
this.mapLayer = new MapLayer(this);
base.Initialize();
}
/// <summary>
/// LoadContent will be called once per game and is the place to load
/// all of your content.
/// </summary>
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
this.spriteBatch = new SpriteBatch(GraphicsDevice);
this.Services.AddService(typeof(SpriteBatch), this.spriteBatch);
this.mapLayer.LoadContent("mapa1.FMP", this.mappyLoader);
this.mapLayer.TileStripTexture = this.Content.Load<Texture2D>("tilebloco");
this.mapLayer.BuildSourceRectanglesTileStrip(3, 2, 5);
myBase = new clsSprite(Content.Load<Texture2D>("base-arkanoide"),
new Vector2(280f, 570f), new Vector2(64f, 64f),
graphics.PreferredBackBufferWidth,
graphics.PreferredBackBufferHeight);
myBall = new clsSprite(Content.Load<Texture2D>("bolinha"),
new Vector2(365f, 540f), new Vector2(64f, 64f),
graphics.PreferredBackBufferWidth,
graphics.PreferredBackBufferHeight);
graphics.PreferredBackBufferWidth = 800;
graphics.PreferredBackBufferHeight = 600;
graphics.ApplyChanges();
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
}
/// <summary>
/// UnloadContent will be called once per game and is the place to unload
/// all content.
/// </summary>
protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}
/// <summary>
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
// TODO: Add your update logic here
base.Update(gameTime);
}
/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
// TODO: Add your drawing code here
this.graphics.GraphicsDevice.Clear(Color.Black);
this.spriteBatch.Begin();
this.mapLayer.Draw(gameTime);
this.spriteBatch.End();
spriteBatch.Draw(myBall.texture, myBall.position, Color.White);
spriteBatch.Draw(myBase.texture, myBase.position, Color.White);
base.Draw(gameTime);
}
}
class clsSprite
{
public Texture2D texture; // plano de fundo
public Vector2 position; // posição do desenho
public Vector2 size; // tamanho do desenho em pixels
public Vector2 screenSize; // tamanho da tela
public Vector2 velocity; // velocidade do movimento
// controle de velocidade do objeto
public void Move()
{
// if we'll move out of the screen, invert velocity
// checking right boundary
if (position.X + size.X + velocity.X > screenSize.X)
velocity.X = -velocity.X;
// checking bottom boundary
if (position.Y + size.Y + velocity.Y > screenSize.Y)
velocity.Y = -velocity.Y;
// checking left boundary
if (position.X + velocity.X < 0)
velocity.X = -velocity.X;
// checking bottom boundary
if (position.Y + velocity.Y < 0)
velocity.Y = -velocity.Y;
// since we adjusted the velocity, just add it to the current position
position += velocity;
}
public clsSprite(Texture2D newTexture, Vector2 newPosition, Vector2 newSize, int ScreenWidth, int ScreenHeight)
{
texture = newTexture;
position = newPosition;
size = newSize;
screenSize = new Vector2(ScreenWidth, ScreenHeight);
}
}
}