Advertisement
much101141

collision

Apr 26th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.72 KB | None | 0 0
  1. #ifndef OBJECT_H
  2. #define OBJECT_H
  3. #include "Player.h"
  4. #include "collider.h"
  5. #include<SFML/Graphics.hpp>
  6. #include <iostream>
  7. #include "select.h"
  8. class object
  9. {
  10. public:
  11. object(sf::Texture* textarrayin,sf::Vector2f sizee,sf::Vector2f position,int fullnumber,int first,float timef,int priceplant,int pricesell);
  12. object(sf::Texture* texture1,sf::Vector2f sizee,int money);
  13. void plantorbuild(Player player,sf::Texture *textarrayin,sf::Time timep,sf::Clock clockp,int &money);
  14. virtual ~object();
  15. void Draw(sf::RenderWindow &window);
  16. void Draw(sf::RenderWindow &window,int money);
  17. collider getcollider(){return collider(body);}
  18. void plantorbuild(Player player,sf::Texture* texture1,sf::Texture* texture2,sf::Texture* texture3,sf::Time timep,sf::Clock clockp,int &money);
  19. void checkplant(tex texx,Player player,sf::Texture* texture1);
  20.  
  21. protected:
  22.  
  23. private:
  24. sf::RectangleShape body;
  25. float timeforplant;
  26. int full;
  27. int type;
  28. //char nameobject[20];
  29. int priceobjecttoplant;
  30. int priceobjecttosell;
  31. int firsttime;
  32. float timedoing;
  33. sf::Text text1;
  34. sf::Font font;
  35. bool ismoney;
  36.  
  37.  
  38. };
  39. /*void plant(sf::RenderWindow window,int mapcheck[][],object seed)
  40. {
  41. if(mapcheck[body.getPosition().x/50][body.getPosition().y/50]==0)
  42. {
  43. window.draw(body);
  44. mapcheck[body.getPosition().x/50][body.getPosition().y/50]==1;
  45.  
  46. }
  47. }*/
  48. object:: object(sf::Texture *textarrayin,sf::Vector2f sizee,sf::Vector2f position,int fullnumber,int first,float timef,int priceplant,int pricesell){
  49. ismoney=0;
  50. body.setSize(sizee);
  51. body.setOrigin(sizee/2.0f);
  52. body.setTexture(&textarrayin[0]);
  53. body.setPosition(position);
  54. full=fullnumber;
  55. timeforplant=timef;
  56. firsttime=first;
  57. priceobjecttoplant=priceplant;
  58. priceobjecttosell=pricesell;
  59. }
  60. object:: object(sf::Texture* texture1,sf::Vector2f sizee,int money)
  61. {
  62. ismoney=1;
  63. char moneyy[20];
  64. sprintf(moneyy,"%s%d","Money $ ",money);
  65. if(!font.loadFromFile("arial.ttf"))
  66. {
  67. }
  68. text1.setFont(font);
  69. text1.setCharacterSize(30);
  70. text1.setString(moneyy);
  71. text1.setColor(sf::Color::Black);
  72. text1.setPosition(sf::Vector2f(40.0f,45.0f));
  73.  
  74. body.setSize(sizee);
  75. body.setPosition(sf::Vector2f(200.0f,50.0f));
  76. body.setOrigin(sizee/2.0f);
  77. body.setTexture(texture1);
  78.  
  79. }
  80. void object::Draw(sf::RenderWindow &window,int money){
  81. char moneyy[20];
  82. sprintf(moneyy,"%s%d","Money $ ",money);
  83. text1.setString(moneyy);
  84. window.draw(body);
  85. window.draw(text1);
  86. }
  87. void object::Draw(sf::RenderWindow &window)
  88. {
  89. window.draw(body);
  90. }
  91. object::~object()
  92. {
  93. //dtor
  94. }
  95.  
  96. void object::plantorbuild(Player player,sf::Texture *textarrayin,sf::Time timep,sf::Clock clockp,int &money)
  97. {
  98. float timecheck;
  99. int ped=0;
  100. if(sf::Keyboard::isKeyPressed(sf::Keyboard::Num1)&&full==0)
  101. {
  102. type=0;
  103. type*=2;
  104. ped++;
  105. }
  106. if(sf::Keyboard::isKeyPressed(sf::Keyboard::Num2)&&full==0)
  107. {
  108. type=1;
  109. type*=2;
  110. ped++;
  111. }
  112. if(sf::Keyboard::isKeyPressed(sf::Keyboard::Num3)&&full==0)
  113. {
  114. type=2;
  115. type*=2;
  116. ped++;
  117. }
  118. if(sf::Keyboard::isKeyPressed(sf::Keyboard::Num4)&&full==0)
  119. {
  120. type=3;
  121. type*=2;
  122. ped++;
  123. }
  124.  
  125. timep=clockp.getElapsedTime();
  126. timecheck=timep.asSeconds();
  127. if(timeforplant<=(timecheck-timedoing)&&full==1)
  128. {
  129. //cout<<"YOUR FUCKING PLANT READY TO COLLECT "<<endl;
  130. body.setTexture(&textarrayin[2+type]);
  131. }
  132. if(getcollider().checkcolliderforplant(player.getcollider()))
  133. {
  134.  
  135. if(ped!=0&&full==0)
  136. {
  137. //cout<<"EIEI"<<endl;
  138. if(firsttime==0&&((money-priceobjecttoplant)>=0))
  139. {
  140. timep=clockp.getElapsedTime();
  141. body.setTexture(&textarrayin[1+type]);
  142. full=1;
  143. // cout<<"FULL = "<<full<<endl;
  144. timedoing=timep.asSeconds();
  145. // cout<<"Time = "<<timep.asSeconds()<<endl;
  146. // cout<<"YOU HAVE PLANT YOUR FUCKING SEED "<<endl;
  147. firsttime=1;
  148. money-=priceobjecttoplant;
  149. }
  150.  
  151. }
  152. if(sf::Keyboard::isKeyPressed(sf::Keyboard::P)&&full==1)
  153. {
  154. timep=clockp.getElapsedTime();
  155. timecheck=timep.asSeconds();
  156. // cout<<timecheck<<endl;
  157. if(timeforplant<=(timecheck-timedoing))
  158. {
  159. body.setTexture(&textarrayin[0]);
  160. full=0;
  161. //cout<<"FULL = "<<full<<endl;
  162. firsttime=0;
  163. // cout<<"Time = "<<timep.asSeconds()<<endl;
  164. // cout<<"CONGRATULATION YOU GOT FUCKING PLANT FOR YOU "<<endl;
  165. money+=priceobjecttosell;
  166. // cout<<"YOUR FUCKING MONEY = "<<money<<endl;
  167. }
  168.  
  169. }
  170. }
  171. }
  172.  
  173. void object::checkplant(tex texx,Player player,sf::Texture* texture1)
  174. {
  175. if(getcollider().checkcolliderforplant(player.getcollider()))
  176. {
  177. if(sf::Keyboard::isKeyPressed(sf::Keyboard::Num1)&&full==0)
  178. {
  179.  
  180.  
  181. /*body.setTexture(texture1);
  182. full=1;*/
  183.  
  184. }
  185. if(sf::Keyboard::isKeyPressed(sf::Keyboard::Num2))
  186. {
  187. //body.setTexture(texx.gettexture(1));
  188. }
  189. if(sf::Keyboard::isKeyPressed(sf::Keyboard::Num3))
  190. {
  191. // body.setTexture(texx.gettexture(1));
  192. }
  193. }
  194. }
  195.  
  196.  
  197. #endif // OBJECT_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement