-
Notifications
You must be signed in to change notification settings - Fork 0
/
image.h
190 lines (141 loc) · 6.57 KB
/
image.h
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/*
Group #: 3
Members: Chris Prosser, Jacob Gearhart, Kory Kappel, Andrew Miller
Course: COMP 322, Advanced Programming
Date: 28 October 2013
Description: This file is inherited from the skeleton
provided by Charles Kelly.
*/
// Programming 2D Games
// Copyright (c) 2011 by:
// Charles Kelly
// image.h v1.2
#ifndef _IMAGE_H // Prevent multiple definitions if this
#define _IMAGE_H // file is included in more than one place
#define WIN32_LEAN_AND_MEAN
#include "textureManager.h"
#include "constants.h"
class Image
{
// Image properties
protected:
Graphics *graphics; // pointer to graphics
TextureManager *textureManager; // pointer to texture manager
// spriteData contains the data required to draw the image by Graphics::drawSprite()
SpriteData spriteData; // SpriteData is defined in "graphics.h"
COLOR_ARGB colorFilter; // applied as a color filter (use WHITE for no change)
int cols; // number of cols (1 to n) in multi-frame sprite
int startFrame; // first frame of current animation
int endFrame; // end frame of current animation
int currentFrame; // current frame of animation
float frameDelay; // how long between frames of animation
float animTimer; // animation timer
HRESULT hr; // standard return type
bool loop; // true to loop frames
bool visible; // true when visible
bool initialized; // true when successfully initialized
bool animComplete; // true when loop is false and endFrame has finished displaying
public:
// Constructor
Image();
// Destructor
virtual ~Image();
////////////////////////////////////////
// Get functions //
////////////////////////////////////////
// Return reference to SpriteData structure.
const virtual SpriteData& getSpriteInfo() {return spriteData;}
// Return visible parameter.
virtual bool getVisible() {return visible;}
// Return X position.
virtual float getX() {return spriteData.x;}
// Return Y position.
virtual float getY() {return spriteData.y;}
// Return scale factor.
virtual float getScale() {return spriteData.scale;}
// Return width.
virtual int getWidth() {return spriteData.width;}
// Return height.
virtual int getHeight() {return spriteData.height;}
// Return center X.
virtual float getCenterX() {return spriteData.x + spriteData.width/2*getScale();}
// Return center Y.
virtual float getCenterY() {return spriteData.y + spriteData.height/2*getScale();}
// Return rotation angle in degrees.
virtual float getDegrees() {return spriteData.angle*(180.0f/(float)PI);}
// Return rotation angle in radians.
virtual float getRadians() {return spriteData.angle;}
// Return delay between frames of animation.
virtual float getFrameDelay() {return frameDelay;}
// Return number of starting frame.
virtual int getStartFrame() {return startFrame;}
// Return number of ending frame.
virtual int getEndFrame() {return endFrame;}
// Return number of current frame.
virtual int getCurrentFrame() {return currentFrame;}
// Return RECT structure of Image.
virtual RECT getSpriteDataRect() {return spriteData.rect;}
// Return state of animation complete.
virtual bool getAnimationComplete() {return animComplete;}
// Return colorFilter.
virtual COLOR_ARGB getColorFilter() {return colorFilter;}
////////////////////////////////////////
// Set functions //
////////////////////////////////////////
// Set X location.
virtual void setX(float newX) {spriteData.x = newX;}
// Set Y location.
virtual void setY(float newY) {spriteData.y = newY;}
// Set scale.
virtual void setScale(float s) {spriteData.scale = s;}
// Set rotation angle in degrees.
// 0 degrees is up. Angles progress clockwise.
virtual void setDegrees(float deg) {spriteData.angle = deg*((float)PI/180.0f);}
// Set rotation angle in radians.
// 0 radians is up. Angles progress clockwise.
virtual void setRadians(float rad) {spriteData.angle = rad;}
// Set visible.
virtual void setVisible(bool v) {visible = v;}
// Set delay between frames of animation.
virtual void setFrameDelay(float d) {frameDelay = d;}
// Set starting and ending frames of animation.
virtual void setFrames(int s, int e){startFrame = s; endFrame = e;}
// Set current frame of animation.
virtual void setCurrentFrame(int c);
// Set spriteData.rect to draw currentFrame
virtual void setRect();
// Set spriteData.rect to r.
virtual void setSpriteDataRect(RECT r) {spriteData.rect = r;}
// Set animation loop. lp = true to loop.
virtual void setLoop(bool lp) {loop = lp;}
// Set animation complete Boolean.
virtual void setAnimationComplete(bool a) {animComplete = a;};
// Set color filter. (use WHITE for no change)
virtual void setColorFilter(COLOR_ARGB color) {colorFilter = color;}
// Set TextureManager
virtual void setTextureManager(TextureManager *textureM)
{ textureManager = textureM; }
////////////////////////////////////////
// Other functions //
////////////////////////////////////////
// Initialize Image
// Pre: *g = pointer to Graphics object
// width = width of Image in pixels (0 = use full texture width)
// height = height of Image in pixels (0 = use full texture height)
// ncols = number of columns in texture (1 to n) (0 same as 1)
// *textureM = pointer to TextureManager object
virtual bool Image::initialize(Graphics *g, int width, int height,
int ncols, TextureManager *textureM);
// Flip image horizontally (mirror)
virtual void flipHorizontal(bool flip) {spriteData.flipHorizontal = flip;}
// Flip image vertically
virtual void flipVertical(bool flip) {spriteData.flipVertical = flip;}
// Draw Image using color as filter. Default color is WHITE.
virtual void draw(COLOR_ARGB color = graphicsNS::WHITE);
// Draw this image using the specified SpriteData.
// The current SpriteData.rect is used to select the texture.
virtual void draw(SpriteData sd, COLOR_ARGB color = graphicsNS::WHITE); // draw with SpriteData using color as filter
// Update the animation. frameTime is used to regulate the speed.
virtual void update(float frameTime);
};
#endif