Quelcode des Partikelsystems Boden
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

checkedInVisitor.cpp 8.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. //
  2. // checkedInVisitor.cpp
  3. // Projekt_FORUM
  4. //
  5. // Created by Sebastian Holzki on 19.06.19.
  6. //
  7. #include "checkedInVisitor.hpp"
  8. CheckedInVisitor::CheckedInVisitor(){
  9. started = false;
  10. xVelocityMax = 1.5000;
  11. age = 0;
  12. setupInOfAppIsFinished = false;
  13. startingAnimationIsFinished = false;
  14. }
  15. // -----------------------------------------
  16. CheckedInVisitor::~CheckedInVisitor(){
  17. }
  18. // -----------------------------------------
  19. void CheckedInVisitor::setup(int _playerType, int _checkedInStele, float sceneWidth, float sceneHeight){
  20. //Everytime a visitor checks in, we will generate a "CheckedInVisitor".
  21. //Depending, what playerType checked in, a different image will be loaded into ofImage imageOfType, representing the playerType.
  22. //We also scale and set the default color here. Later we might be able to also pass the "greatWhole" information about the currentMode of the system,
  23. //so we can play around with the CheckedInVisitors as well.
  24. k1 = ofRandom(0.3,0.5); // random value for k1*sin(...)+...
  25. k2 = ofRandom(0.3,1.2); // random value for ...*sin(k2*age)+....
  26. k3 = ofRandom(0.8, 1.2);
  27. checkedInStele = _checkedInStele;
  28. playerType = _playerType;
  29. switch ( playerType ){
  30. case 1: {
  31. imageOfType.load("images/image1_color.png");
  32. hexagon.load("images/hexagon_1.png");
  33. break;
  34. }
  35. case 2: {
  36. imageOfType.load("images/image2_color.png");
  37. hexagon.load("images/hexagon_2.png");
  38. break;
  39. }
  40. case 3: {
  41. imageOfType.load("images/image3_color.png");
  42. hexagon.load("images/hexagon_3.png");
  43. break;
  44. }
  45. case 4: {
  46. imageOfType.load("images/image4_color.png");
  47. hexagon.load("images/hexagon_4.png");
  48. break;
  49. }
  50. default:
  51. imageOfType.load("images/noplayertype.png");
  52. } //end of switch
  53. setupPosition(sceneWidth, sceneHeight, checkedInStele);
  54. imageOfType.resize(imageOfType.getWidth()*0.5, imageOfType.getHeight()*0.5);
  55. hexagon.resize(hexagon.getWidth()*0.5, hexagon.getHeight()*0.5);
  56. // pixelsWithValues(sceneWidth, sceneHeight, hexagon);
  57. }
  58. // -----------------------------------------
  59. void CheckedInVisitor::update(float deltaT, float sceneWidth, float sceneHeight){
  60. aging(deltaT);
  61. move(deltaT, sceneWidth, sceneHeight);
  62. if(age > 3 && started == false){
  63. setupVelocity();
  64. started = true;
  65. }
  66. // updateAttractingPixels();
  67. positionLastFrame = position;
  68. }
  69. // -----------------------------------------
  70. void CheckedInVisitor::draw(){
  71. ofSetColor(255,255,255);
  72. imageOfType.draw(position);
  73. hexagon.draw(position);
  74. if(attractingPixelsOfHexagon.size()){
  75. ofDrawBitmapString(ofToString(attractingPixelsOfHexagon.at(0).x), position.x, position.y - 20);
  76. ofDrawBitmapString(ofToString(position.x), position.x, position.y - 40);
  77. }
  78. }
  79. // -----------------------------------------
  80. ofVec2f CheckedInVisitor::getPosition(){
  81. return position;
  82. }
  83. // -----------------------------------------
  84. ofVec2f CheckedInVisitor::getBottom(){
  85. ofVec2f bottom = this->position;
  86. bottom.x += hexagon.getWidth()/2;
  87. bottom.y += hexagon.getHeight()*0.99;
  88. return bottom;
  89. }
  90. // -----------------------------------------
  91. void CheckedInVisitor::aging(float deltaT){
  92. age += deltaT;
  93. }
  94. // -----------------------------------------
  95. vector<ofVec2f> CheckedInVisitor::getPositionsOfAttractingPixels(){
  96. return attractingPixelsOfHexagon;
  97. }
  98. // -----------------------------------------
  99. bool CheckedInVisitor::getIfEmitterIsDeleted(){
  100. return emitterHasBeenDeleted;
  101. }
  102. // -----------------------------------------
  103. void CheckedInVisitor::updateAttractingPixels(){
  104. float differenceX = positionLastFrame.x - position.x;
  105. float differenceY = positionLastFrame.y - position.y;
  106. for(int i = 0; i < attractingPixelsOfHexagon.size(); i++){
  107. attractingPixelsOfHexagon.at(i).x -= differenceX;
  108. attractingPixelsOfHexagon.at(i).y -= differenceY;
  109. }
  110. }
  111. // -----------------------------------------
  112. void CheckedInVisitor::pixelsWithValues(float sceneWidth, float sceneHeight, ofImage _hexagon){
  113. int hexagonWidth = _hexagon.getWidth();
  114. int hexagonHeight = _hexagon.getHeight();
  115. ofPixels pixels;
  116. pixels = hexagon.getPixels();
  117. int counter = 11;
  118. // Iterate trough the pixels, skip 3 do 1 because only 1 channel is needed
  119. for(int i = 3; i <= pixels.size(); i+=4){
  120. if(pixels[i] > 0){ //if the pixel has a value jump into saving it
  121. int width = pixels.getWidth();
  122. int y = i / 4 / width ;
  123. int x = i / 4 % width ;
  124. ofVec2f pixelPosition;
  125. pixelPosition.set(position.x + x, position.y + y);
  126. if(counter > 10){
  127. attractingPixelsOfHexagon.push_back(pixelPosition);
  128. counter = 0;
  129. }
  130. counter++;
  131. }
  132. }
  133. }
  134. // -----------------------------------------
  135. void CheckedInVisitor::setupPosition(int sceneWidth, int sceneHeight, int checkedInStele){
  136. position.y = sceneHeight - imageOfType.getHeight()/2;
  137. position.x = sceneHeight + ((sceneWidth - sceneHeight)/6)*(checkedInStele - 1); //Hinter Kreis + 1/2 Stele
  138. position.x += (sceneWidth - sceneHeight)/12 - imageOfType.getWidth()/4;
  139. positionLastFrame = position;
  140. }
  141. // -----------------------------------------
  142. void CheckedInVisitor::setupCornerPositions(float sceneWidth, float sceneHeight){
  143. //save the corners of the generated hexagon as positions into an array
  144. //try with ofCircles
  145. ofSetColor(255,0,0);
  146. ofDrawCircle(position.x + hexagon.getWidth()/4, position.y, 10);
  147. // attractingPixelsOfHexagon.push_back(
  148. }
  149. // -----------------------------------------
  150. void CheckedInVisitor::setPosition(ofVec2f _position){
  151. position = _position;
  152. }
  153. // -----------------------------------------
  154. void CheckedInVisitor::setStateOfSetup(bool stateToSet){
  155. setupInOfAppIsFinished = stateToSet;
  156. }
  157. // -----------------------------------------
  158. bool CheckedInVisitor::getStateOfSetup(){
  159. return setupInOfAppIsFinished;
  160. }
  161. // -----------------------------------------
  162. void CheckedInVisitor::move(float deltaT, float sceneWidth, float sceneHeight){
  163. int startingSpeed = 65;
  164. if(startingAnimationIsFinished != true){
  165. startingAnimation(startingSpeed, sceneWidth, sceneHeight);
  166. position += velocity * startingSpeed * deltaT;
  167. }
  168. if(startingAnimationIsFinished == true){
  169. position.y += k1*sin(age*k2);
  170. position += velocity * startingSpeed * deltaT * k3;
  171. }
  172. //jump from right to left
  173. if(position.x > (sceneWidth - (sceneWidth - 0.5*sceneHeight)/36 )){
  174. position.x = sceneHeight;
  175. }
  176. }
  177. // -----------------------------------------
  178. void CheckedInVisitor::startingAnimation(float startingSpeed, float sceneWidth, float sceneHeight){
  179. if(position.y < sceneHeight*0.4){
  180. velocity.y *= 0.99 ;
  181. }
  182. if(position.y < sceneHeight*0.4 && startedMovingToTheRight == false){
  183. velocity.x = 0.1;
  184. startedMovingToTheRight = true;
  185. }
  186. if(velocity.x < xVelocityMax){
  187. velocity.x *= 1.02;
  188. }
  189. if( (((xVelocityMax - velocity.x) < 0.0001)) && ((velocity.y < 0.0001)) ){
  190. velocity.x = xVelocityMax;
  191. velocity.y = 0;
  192. startingAnimationIsFinished = true;
  193. }
  194. }
  195. // -----------------------------------------
  196. void CheckedInVisitor::setupVelocity(){
  197. velocity.set(0.0, -2.0);
  198. }
  199. // -----------------------------------------
  200. float CheckedInVisitor::getAge(){
  201. return age;
  202. }
  203. // -----------------------------------------
  204. void CheckedInVisitor::clipToLastCheckedInVisitor(CheckedInVisitor _avatar){
  205. //Read coordinates to clip to:
  206. ofVec2f tempCoords = _avatar.getPosition();
  207. if( tempCoords.y == 0 ){
  208. position.x = tempCoords.x + 20 ;
  209. position.y = tempCoords.y + 20 ;
  210. }else{
  211. position.x = tempCoords.x + 20 ;
  212. position.y = tempCoords.y - 20 ;
  213. }
  214. }