-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sprite.cs
129 lines (102 loc) · 1.92 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
namespace Badass_Teroids
{
abstract class Sprite
{
Texture2D texture;
Vector2 position;
Vector2 center;
Vector2 velocity;
float rotation;
float scale;
bool alive;
int index;
Color color = Color.White;
public Sprite(Texture2D texture)
{
this.texture = texture;
position = Vector2.Zero;
center = new Vector2(texture.Width / 2, texture.Height / 2);
velocity = Vector2.Zero;
Rotation = 0.0f;
Scale = 1.0f;
alive = false;
index = 0;
}
public Sprite()
{
}
public Texture2D Texture
{
get { return texture; }
set { texture = value; }
}
public Vector2 Position
{
get { return position; }
set { position = value; }
}
public Vector2 Center
{
get { return center; }
}
public Vector2 Velocity
{
get { return velocity; }
set { velocity = value; }
}
public float Rotation
{
get { return rotation; }
set
{
rotation = value;
if (rotation < -MathHelper.TwoPi)
rotation = MathHelper.TwoPi;
if (rotation > MathHelper.TwoPi)
rotation = -MathHelper.TwoPi;
}
}
public float Scale
{
get { return scale; }
set { scale = value; }
}
public bool Alive
{
get { return alive; }
}
public int Index
{
get { return index; }
set { index = value; }
}
public int Width
{
get { return texture.Width; }
}
public int Height
{
get { return texture.Height; }
}
public void Create()
{
alive = true;
}
public void Kill()
{
alive = false;
}
public abstract void Update();
public virtual void Draw(SpriteBatch spriteBatch)
{
spriteBatch.Draw(this.Texture, this.Position, null, Color.White, this.Rotation, this.Center, this.Scale, SpriteEffects.None, 1.0f);
}
}
}