-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sprite.cs
59 lines (47 loc) · 1.38 KB
/
Sprite.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace ReduceReuseRecycle
{
public abstract class Sprite
{
protected /*readonly*/ Texture2D _texture;
public Vector2 Location;
protected Rectangle gameBoundaries;
protected Vector2 Size;
public Rectangle boundingBox
{
get { return new Rectangle((int)Location.X, (int)Location.Y, Width, Height); }
}
public Vector2 Velocity
{
get;
protected set;
}
public int Width
{
get { return _texture.Width; }
}
public int Height
{
get { return _texture.Height; }
}
public Sprite(Texture2D texture, Vector2 location, Rectangle gameBoundaries)
{
this._texture = texture;
this.Location = location;
this.Velocity = Vector2.Zero;
this.gameBoundaries = gameBoundaries;
}
public void Draw(SpriteBatch spritebatch)
{
spritebatch.Draw(_texture, Location, Color.White);
}
public virtual void Update(GameTime gameTime, gameObjects gameObjects)
{
Location += Velocity;
CheckBounds();
}
protected abstract void CheckBounds();
}
}