Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.70 KB | None | 0 0
  1. // Sprite.h v2.0
  2. #ifndef SPRITE_H
  3. #define SPRITE_H
  4.  
  5. #include <allegro5\allegro.h>
  6. #include <allegro5\allegro_image.h>
  7. #include <stdio.h>
  8. #include "Common.h"
  9.  
  10. #define PIXPERMTR 30
  11. #define RADPERDEG 0.0174532925f
  12. #define DEFAULT "Default"
  13. class CSprite
  14. {
  15. protected:
  16. //enum {PIXPERMTR = 30}; // How many pixels in a meter?
  17. ALLEGRO_BITMAP* m_pSprite;
  18. char* m_name;
  19. float m_x; // X coordinate in pixels of m_pSprite
  20. float m_y; // Y coordinate in pixels of m_pSprite
  21. float m_width; // Width of m_pSprite in pixels
  22. float m_height; // Height of m_pSprite in pxels // Height of pSprite before scaling in pixels
  23. float m_scale; // Scale of the bitmap
  24. float m_degrees; //
  25. bool m_is_visible; // Draw the sprite?
  26. bool m_is_broken; // Is the class broken?
  27. ALLEGRO_COLOR m_alpha; // Background color that should not be drawn
  28. //////////////////////
  29. // Private Methods //
  30. //////////////////////
  31. private:
  32. void reset (void);
  33.  
  34. //////////////////////////
  35. // Protected Methods //
  36. //////////////////////////
  37. protected:
  38. void calculate (ALLEGRO_BITMAP* bitmap = NULL);
  39.  
  40. //////////////////////
  41. // Public Methods //
  42. //////////////////////
  43.  
  44. public:
  45. explicit CSprite (void); // Default Constructor
  46. CSprite (const char* file_name, ALLEGRO_COLOR alpha = al_map_rgb(0,0,0));
  47. CSprite (ALLEGRO_BITMAP* temp, ALLEGRO_COLOR alpha = al_map_rgb(0,0,0));
  48. CSprite (CSprite & item); // Copy Constructor
  49. ~CSprite (void); // Destructor
  50.  
  51. bool load (const char* file_name); // Assigns a bitmap to this sprite class
  52.  
  53.  
  54. bool draw (int dx, int dy, int flags = 0); // Attempts to draw the sprite to the screen
  55. bool draw (int flags = 0); // Attempts to draw the sprite to the screen. (Uses current member x and y values)
  56. bool draw_rotated (float dX, float dY, float angle, int flags = 0); // Attempts to draw the sprite rotated onto the screen
  57. bool draw_rotated (float cX, float cY, float dX, float dY, float angle, int flags = 0);
  58. 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.
  59. bool draw_scaled_rotated (void); // Attempts to draw the sprite scaled and rotated to the screen
  60.  
  61. // Sets
  62. void set_name (const char* name);
  63. //////////////////////
  64. // Inline Methods //
  65. //////////////////////
  66.  
  67. // Is'
  68. bool is_broken (void) { return m_is_broken; } const // Is the class broken?
  69. bool is_visible (void) { return m_is_visible; } const // Draw the sprite?
  70. float get_x (void) { return m_x; } const // X in pixels
  71. float get_x_mtrs (void) { return m_x / PIXPERMTR; } const // X in pixels converted to meters
  72. float get_y (void) { return m_y; } // Y in pixels
  73. float get_y_mtrs (void) { return m_y / PIXPERMTR; } const // Y in pixels converted to meters
  74. float get_width (void) { return m_width; } const // Width of m_pSprite in pixels
  75. float get_width_mtrs (void) { return m_width / PIXPERMTR; } const // Width of m_pSprite in meters
  76. float get_height (void) { return m_height; } const // Height of m_pSprite in pixels
  77. float get_height_mtrs (void) { return m_height / PIXPERMTR;} const // Height of m_pSprite in meters
  78. const char* get_name (void) { return m_name;} const
  79. // Sets
  80. void set_alpha (ALLEGRO_COLOR alpha) { m_alpha = alpha; } // Background color that should not be drawn
  81. void set_x (float tX) { m_x = tX; } // (pixels to pixels)
  82. void set_x_mtrs (float tX) { m_x = tX * PIXPERMTR; } // (meters converted to pixels)
  83. void set_y (float tY) { m_y = tY; } // (pixels to pixels)
  84. void set_y_mtrs (float tY) { m_y = tY * PIXPERMTR; }
  85. void set_scale (float scale) { if (scale > 0.0f) { m_scale = scale; } else m_scale = 1.0f; }
  86. void set_rotation (float degrees) { if (degrees >= 0.0f && degrees < 360.0f) m_degrees = degrees; else degrees = 0.0f; }
  87. void set_rotation_mtrs (float radians) { if (radians >= 0.0f && radians < 6.28318531f) m_degrees = radians * RADPERDEG; else m_degrees = 0.0f; }
  88.  
  89. // Disables
  90.  
  91.  
  92. // Overloaded Operators
  93. CSprite& operator=(const CSprite & item); // Overloaded Assignment operator
  94. };
  95. #endif // End SPRITE_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement