Arcade Shooter
SpriteBatch.h
1 
2 /* ██╗ ██╗ █████╗ ████████╗ █████╗ ███╗ ██╗ █████╗
3  ██║ ██╔╝ ██╔══██╗ ╚══██╔══╝ ██╔══██╗ ████╗ ██║ ██╔══██╗
4  █████╔╝ ███████║ ██║ ███████║ ██╔██╗ ██║ ███████║
5  ██╔═██╗ ██╔══██║ ██║ ██╔══██║ ██║╚██╗██║ ██╔══██║
6  ██║ ██╗ ██║ ██║ ██║ ██║ ██║ ██║ ╚████║ ██║ ██║
7  ╚═╝ ╚═╝ ╚═╝ ╚═╝/\ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝
8  /vvvvvvvvvvvvvvvvvvv \=========================================,
9  `^^^^^^^^^^^^^^^^^^^ /---------------------------------------"
10  Katana Engine \/ © 2012 - Shuriken Studios LLC */
11 
12 #pragma once
13 
14 namespace KatanaEngine
15 {
17  enum class TextAlign
18  {
19  LEFT,
20  CENTER,
21  RIGHT
22  };
23 
27  enum class SpriteSortMode
28  {
30  DEFERRED,
32  IMMEDIATE,
33  TEXTURE
34  };
35 
37  enum class BlendState
38  {
39  ALPHA,
40  ADDITIVE
41  };
42 
45  {
46 
47  public:
48 
49  SpriteBatch() { m_isStarted = false; }
50  ~SpriteBatch() { }
51 
56  void Begin(const SpriteSortMode sortMode = SpriteSortMode::DEFERRED,
57  const BlendState blendState = BlendState::ALPHA,
58  ALLEGRO_TRANSFORM *pTransformation = NULL);
59 
62  void End(/*bool test = false*/);
63 
74  void DrawString(const Font *pFont, std::string *text, const Vector2 position,
75  const Color color = Color::White, const TextAlign alignment = TextAlign::LEFT,
76  const float drawDepth = 0);
77 
90  void Draw(const Texture *pTexture, const Vector2 position, const Region region,
91  const Color color = Color::White, const Vector2 origin = Vector2::Zero,
92  const Vector2 scale = Vector2::One, const float rotation = 0,
93  const float drawDepth = 0);
94 
108  void Draw(const Texture *pTexture, const Vector2 position,
109  const Color color = Color::White, const Vector2 origin = Vector2::Zero,
110  const Vector2 scale = Vector2::One, const float rotation = 0,
111  const float drawDepth = 0);
112 
126  void Draw(Animation *pAnimation, const Vector2 position,
127  const Color color = Color::White, const Vector2 origin = Vector2::Zero,
128  const Vector2 scale = Vector2::One, const float rotation = 0,
129  float drawDepth = 0);
130 
135  void GetBatchSettings(SpriteSortMode &sortMode, BlendState &blendState, ALLEGRO_TRANSFORM *pTransformation);
136 
137 
138  private:
139 
140  struct Drawable
141  {
142  bool isBitmap;
143  ALLEGRO_COLOR color;
144  int x, y;
145  float depth;
146 
147  union
148  {
149  struct
150  {
151  ALLEGRO_FONT *pFont;
152  std::string *text;
153  TextAlign align;
154  };
155 
156  struct
157  {
158  ALLEGRO_BITMAP *pBitmap;
159  float rotation;
160  int cx, cy;
161  int sx, sy, sw, sh;
162  float scx, scy;
163  unsigned short id;
164  };
165 
166  } Union;
167 
168  bool operator<(const Drawable& other) const
169  {
170  return (depth < other.depth);
171  }
172  };
173 
174  struct CompareBackToFront
175  {
176  bool operator()(const Drawable* l, const Drawable* r) { return (*l < *r); }
177  };
178 
179  struct CompareFrontToBack
180  {
181  bool operator()(const Drawable* l, const Drawable* r) { return (*r < *l); }
182  };
183 
184  std::vector<Drawable *> m_drawables;
185  std::vector<Drawable *> m_inactiveDrawables;
186  std::vector<Drawable *>::iterator m_it;
187 
188  unsigned short m_lastID;
189 
190  SpriteSortMode m_sortMode;
191 
192  BlendState m_blendState;
193 
194  ALLEGRO_TRANSFORM *m_pTransformation;
195 
196  bool m_isStarted;
197 
198  void DrawBitmap(Drawable *drawable);
199  void DrawFont(Drawable *drawable);
200 
201  };
202 }
BlendState
Defines the way in which textures blending will be calculated.
Definition: SpriteBatch.h:37
Represents a 2D grid of texels.
Definition: Texture.h:17
static const Color White
White.
Definition: Color.h:198
Represents a font or true-type font.
Definition: Font.h:17
Represents a four-component color using red, green, blue, and alpha data.
Definition: Color.h:17
static const Vector2 Zero
A vector with both of its components set to zero.
Definition: Vector2.h:29
TextAlign
Defines the states for text alignment.
Definition: SpriteBatch.h:17
Defines a vector with 2 components (x and y). This is additional information...
Definition: Vector2.h:18
Represents timing and framing values for texture animations.
Definition: Animation.h:17
Defines a rectangular region defined by a point, height, width.
Definition: Region.h:17
Enables a group of sprites to be drawn using the same settings.
Definition: SpriteBatch.h:44
SpriteSortMode
Defines the methods for sorting sprites before rendering.
Definition: SpriteBatch.h:27
static const Vector2 One
A vector with both of its components set to one.
Definition: Vector2.h:30
Katana Engine is a library of classes, interfaces, and value types that provides a foundation for dev...
Definition: Animation.cpp:14