Guest User

Untitled

a guest
Jul 21st, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. #pragma once
  2. #include <windows.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <vector>
  6. #include <algorithm>
  7. #include <iostream>
  8. #include <GL/gl.h>
  9. #include <GL/glu.h>
  10. #include "GL/glut.h"
  11. #include "IL/il.h"
  12. #include "IL/ilu.h"
  13. #include "IL/ilut.h"
  14. #include "Vector.h"
  15. #include "Timer.h"
  16. #include "RigidBody.h"
  17.  
  18. #include <string>
  19.  
  20. class XY_Coordinate
  21. {
  22. public:
  23. XY_Coordinate(float _x, float _y, float _u, float _v){ x=_x; y=_y; u = _u; v=_v;}
  24. ~XY_Coordinate(){}
  25. float x,y;
  26. float u,v;
  27. };
  28.  
  29. class SpriteAnimation
  30. {
  31. public:
  32. SpriteAnimation(void)
  33. {
  34. currentFrame = 0;
  35. doesLoop = true;
  36. }
  37. ~SpriteAnimation(void){}
  38.  
  39. void nextFrame()
  40. {
  41. int numFrames = coords.size();
  42. currentFrame++;
  43. if(currentFrame >= numFrames)
  44. {
  45. if(doesLoop) currentFrame = 0;
  46. else currentFrame = numFrames - 1;
  47. }
  48. }
  49.  
  50. void setLooping(bool loop) {doesLoop = loop;}
  51.  
  52. /* each animation has a list of x,y coordinates
  53. that can be cycled through */
  54. std::vector<XY_Coordinate*> coords;
  55. bool doesLoop;
  56. int currentFrame;
  57. };
  58.  
  59. typedef struct _SpriteSheetInfo
  60. {
  61. unsigned int textureID;
  62. float width,height;
  63. }SpriteSheetInfo;
  64.  
  65. typedef struct _SpriteSize
  66. {
  67. float width, height;
  68. float normalizedWidth,normalizedHeight;
  69. }SpriteSize;
  70.  
  71. /* Sprite class
  72. * - this class takes care of everything
  73. related to sprites
  74. loading/drawing/setting states etc.
  75. */
  76. class Sprite
  77. {
  78. public:
  79. Sprite(std::string spriteSheetFilename);
  80. ~Sprite(void);
  81.  
  82. void loadSpriteSheet(const char *filename);
  83. void setSpriteFrameSize(int width, int height);
  84. void setNumberOfAnimations(int num);
  85. void addSpriteAnimFrame(int animationNumber, int x, int y);
  86. void addSpriteAnimRow(int animationNumber, float startX, float startY, float spacingX, float spacingY, int numFrames);
  87.  
  88. void setLayerID(float value) {
  89. layerID = value;
  90. }
  91.  
  92. void setCenter(float x, float y) {
  93. centerX = x; centerY = y;
  94. }
  95. void setPosition(float x, float y) {
  96. positionX = x; positionY = y;
  97. }
  98. void setOrientation(float _theta) {
  99. theta = _theta;
  100. }
  101. float getRadius(){
  102. return sqrt((centerX * centerX) + (centerY * centerY));
  103. }
  104. float getOrientation() {return theta;}
  105.  
  106. /* drawing */
  107. virtual void draw();
  108.  
  109. void setCurrentAnimation(int anim) {
  110. currentAnimation = anim;
  111. if(currentAnimation >= animations.size()) currentAnimation = 0;
  112. }
  113. /* update */
  114. virtual void update();
  115.  
  116. void nextFrame(){
  117. animations[currentAnimation]->nextFrame();
  118. }
  119.  
  120. /* sprite info */
  121. SpriteSize sz;
  122. SpriteSheetInfo sheet;
  123. int numberOfAnimations;
  124. int currentAnimation;
  125.  
  126. /* position/center/orientation */
  127. /* these should be VECTORS! */
  128. float positionX,positionY;
  129. float centerX,centerY;
  130. float theta;
  131.  
  132. Vector *velocityVector;
  133.  
  134. Timer *updateTimer;
  135.  
  136. // which layer this sprite is on, lower is further away,
  137. // background is 0, foreground > 0
  138. int layerID;
  139.  
  140. /* list of animations */
  141. std::vector<SpriteAnimation*> animations;
  142.  
  143.  
  144. };
Add Comment
Please, Sign In to add comment