Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Sprite.h v2.0
- #ifndef SPRITE_H
- #define SPRITE_H
- #include <allegro5\allegro.h>
- #include <allegro5\allegro_image.h>
- #include <stdio.h>
- #include "Common.h"
- #define PIXPERMTR 30
- #define RADPERDEG 0.0174532925f
- #define DEFAULT "Default"
- class CSprite
- {
- protected:
- //enum {PIXPERMTR = 30}; // How many pixels in a meter?
- ALLEGRO_BITMAP* m_pSprite;
- char* m_name;
- float m_x; // X coordinate in pixels of m_pSprite
- float m_y; // Y coordinate in pixels of m_pSprite
- float m_width; // Width of m_pSprite in pixels
- float m_height; // Height of m_pSprite in pxels // Height of pSprite before scaling in pixels
- float m_scale; // Scale of the bitmap
- float m_degrees; //
- bool m_is_visible; // Draw the sprite?
- bool m_is_broken; // Is the class broken?
- ALLEGRO_COLOR m_alpha; // Background color that should not be drawn
- //////////////////////
- // Private Methods //
- //////////////////////
- private:
- void reset (void);
- //////////////////////////
- // Protected Methods //
- //////////////////////////
- protected:
- void calculate (ALLEGRO_BITMAP* bitmap = NULL);
- //////////////////////
- // Public Methods //
- //////////////////////
- public:
- explicit CSprite (void); // Default Constructor
- CSprite (const char* file_name, ALLEGRO_COLOR alpha = al_map_rgb(0,0,0));
- CSprite (ALLEGRO_BITMAP* temp, ALLEGRO_COLOR alpha = al_map_rgb(0,0,0));
- CSprite (CSprite & item); // Copy Constructor
- ~CSprite (void); // Destructor
- bool load (const char* file_name); // Assigns a bitmap to this sprite class
- bool draw (int dx, int dy, int flags = 0); // Attempts to draw the sprite to the screen
- bool draw (int flags = 0); // Attempts to draw the sprite to the screen. (Uses current member x and y values)
- bool draw_rotated (float dX, float dY, float angle, int flags = 0); // Attempts to draw the sprite rotated onto the screen
- bool draw_rotated (float cX, float cY, float dX, float dY, float angle, int flags = 0);
- bool draw_scaled (float dX, float dY, float dW = 0, float dH = 0, int flags = 0); // Attempts to draw the sprite scaled to the screen. dW and dH are set to what the m_W and m_H are and scaled by the percentage of m_scale if their argument is omitted.
- bool draw_scaled_rotated (void); // Attempts to draw the sprite scaled and rotated to the screen
- // Sets
- void set_name (const char* name);
- //////////////////////
- // Inline Methods //
- //////////////////////
- // Is'
- bool is_broken (void) { return m_is_broken; } const // Is the class broken?
- bool is_visible (void) { return m_is_visible; } const // Draw the sprite?
- float get_x (void) { return m_x; } const // X in pixels
- float get_x_mtrs (void) { return m_x / PIXPERMTR; } const // X in pixels converted to meters
- float get_y (void) { return m_y; } // Y in pixels
- float get_y_mtrs (void) { return m_y / PIXPERMTR; } const // Y in pixels converted to meters
- float get_width (void) { return m_width; } const // Width of m_pSprite in pixels
- float get_width_mtrs (void) { return m_width / PIXPERMTR; } const // Width of m_pSprite in meters
- float get_height (void) { return m_height; } const // Height of m_pSprite in pixels
- float get_height_mtrs (void) { return m_height / PIXPERMTR;} const // Height of m_pSprite in meters
- const char* get_name (void) { return m_name;} const
- // Sets
- void set_alpha (ALLEGRO_COLOR alpha) { m_alpha = alpha; } // Background color that should not be drawn
- void set_x (float tX) { m_x = tX; } // (pixels to pixels)
- void set_x_mtrs (float tX) { m_x = tX * PIXPERMTR; } // (meters converted to pixels)
- void set_y (float tY) { m_y = tY; } // (pixels to pixels)
- void set_y_mtrs (float tY) { m_y = tY * PIXPERMTR; }
- void set_scale (float scale) { if (scale > 0.0f) { m_scale = scale; } else m_scale = 1.0f; }
- void set_rotation (float degrees) { if (degrees >= 0.0f && degrees < 360.0f) m_degrees = degrees; else degrees = 0.0f; }
- void set_rotation_mtrs (float radians) { if (radians >= 0.0f && radians < 6.28318531f) m_degrees = radians * RADPERDEG; else m_degrees = 0.0f; }
- // Disables
- // Overloaded Operators
- CSprite& operator=(const CSprite & item); // Overloaded Assignment operator
- };
- #endif // End SPRITE_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement