SHOW:
|
|
- or go back to the newest paste.
| 1 | using System; | |
| 2 | using System.Collections.Generic; | |
| 3 | using System.Linq; | |
| 4 | using System.Text; | |
| 5 | ||
| 6 | namespace CatTetris | |
| 7 | {
| |
| 8 | using System; | |
| 9 | using System.Collections.Generic; | |
| 10 | using System.Linq; | |
| 11 | using System.Text; | |
| 12 | using Microsoft.Xna.Framework; | |
| 13 | using Microsoft.Xna.Framework.Content; | |
| 14 | using Microsoft.Xna.Framework.Graphics; | |
| 15 | ||
| 16 | ||
| 17 | public class Sprite | |
| 18 | {
| |
| 19 | public Vector2 Position = new Vector2(0, 0); | |
| 20 | public Vector2 offset = new Vector2(0, 0); | |
| 21 | public Texture2D mSpriteTexture; | |
| 22 | public string AssetName; | |
| 23 | public Rectangle Size; | |
| 24 | private float mScale = 1.0f; | |
| 25 | ||
| 26 | private Texture2D pixel; | |
| 27 | ||
| 28 | public Vector2 origin; | |
| 29 | ||
| 30 | public Sprite() | |
| 31 | {
| |
| 32 | ||
| 33 | } | |
| 34 | ||
| 35 | //Load content | |
| 36 | public void LoadContent(ContentManager theContentManager, String theAssetName) | |
| 37 | {
| |
| 38 | mSpriteTexture = theContentManager.Load<Texture2D>(theAssetName); | |
| 39 | AssetName = theAssetName; | |
| 40 | ||
| 41 | pixel = theContentManager.Load<Texture2D>("pixel");
| |
| 42 | ||
| 43 | Size = new Rectangle((int)Position.X, (int)Position.Y, (int)(mSpriteTexture.Width * Scale), (int)(mSpriteTexture.Height * Scale)); | |
| 44 | } | |
| 45 | ||
| 46 | public void Update(Vector2 position, Vector2 offset) | |
| 47 | {
| |
| 48 | Position = (position + offset); | |
| 49 | } | |
| 50 | ||
| 51 | - | //theSpriteBatch.Draw(pixel, origin, new Rectangle(0,0,10,10), Color.White, 0.0f, Vector2.Zero, Scale, SpriteEffects.None, 0); |
| 51 | + | |
| 52 | {
| |
| 53 | theSpriteBatch.Draw(mSpriteTexture, Position, | |
| 54 | - | public void Update(GameTime theGameTime, Vector2 theSpeed, Vector2 theDirection) |
| 54 | + | |
| 55 | ||
| 56 | - | Position += theDirection * theSpeed * (float)theGameTime.ElapsedGameTime.TotalSeconds; |
| 56 | + | |
| 57 | //theSpriteBatch.Draw(pixel, Position, new Rectangle(0,0,10,10), Color.White, 0.0f, Vector2.Zero, Scale, SpriteEffects.None, 0); | |
| 58 | - | //Update the origin of the sprite |
| 58 | + | |
| 59 | - | origin = new Vector2((int)(Position.X + mSpriteTexture.Width/2), (int)(Position.Y + mSpriteTexture.Height/2)); |
| 59 | + | |
| 60 | public float Scale | |
| 61 | {
| |
| 62 | get { return mScale; }
| |
| 63 | set | |
| 64 | {
| |
| 65 | mScale = value; | |
| 66 | Size = new Rectangle(0, 0, (int)(mSpriteTexture.Width * Scale), (int)(mSpriteTexture.Height * Scale)); | |
| 67 | } | |
| 68 | } | |
| 69 | public Rectangle BoundingBox() | |
| 70 | {
| |
| 71 | return new Rectangle( | |
| 72 | (int)Position.X + 1, | |
| 73 | (int)Position.Y + 1, | |
| 74 | mSpriteTexture.Width + 1, | |
| 75 | mSpriteTexture.Height + 1); | |
| 76 | } | |
| 77 | ||
| 78 | ||
| 79 | } | |
| 80 | } |