Advertisement
apexsquirt

[C++ / GrAPic] birb

Jan 31st, 2020
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.82 KB | None | 0 0
  1. #include <Grapic.h>
  2. #include <math.h>
  3. #include <iostream>
  4. #include <windows.h>
  5.  
  6. // si vous vous demandez pourquoi y a tout ça là :
  7. const float pi = 3.141592653;
  8. struct complex { float x, y; };
  9. complex C (float x, float y) { struct complex ret; ret.x = x; ret.y = y; return ret; }
  10. complex C_exp (float rho, float theta) { complex ret; ret.x = rho*cos(theta); ret.y = rho*sin(theta); return ret; }
  11. complex operator+ (complex a, complex b) { complex ret; ret.x = a.x + b.x; ret.y = a.y + b.y; return ret; }
  12. complex operator- (complex a, complex b) { complex ret; ret.x = a.x - b.x; ret.y = a.y - b.y; return ret; }
  13. complex operator* (float a, complex b) { complex ret; ret.x = a * b.x; ret.y = a * b.y; return ret; }
  14. complex operator* (complex a, complex b) { complex ret; ret.x = a.x * b.x - a.y * b.y; ret.y = a.x * b.y + a.y * b.x; return ret; }
  15. complex scale (complex p, float x, float y, float lambda) { return lambda*(p-C(x,y)); }
  16. complex translate (complex P, float dx, float dy) { complex ret; ret = P+C(dx,dy); return ret; }
  17. complex rotate (complex p, float x, float y, float theta) { return (p-C(x,y))*C_exp(1,theta)+C(x,y); }
  18. void show (complex z) { std::cout << z.x << " + " << z.y << " i"; }
  19. float abs (complex z) { return sqrt(z.x*z.x + z.y*z.y); }
  20. float arg (complex z) { if (z.x > 0 or z.y != 0) return 2*atan(z.y/(z.x+abs(z))); else -pi; }
  21. // c'est du bout d'code que j'ai mis dans un .h et qu'j'ai include après, du coup j'ai juste copié-collé l'contenu du header ^^'
  22.  
  23. using namespace grapic;
  24. const int DIMW = 500;
  25. const int MAX = 500;
  26.  
  27. struct birb {
  28.     complex pos = C(DIMW/2,DIMW/2);
  29.     complex lwing = C(DIMW/2-40,DIMW/2);
  30.     complex rwing = C(DIMW/2+40,DIMW/2);
  31. };
  32.  
  33. void draw (birb uwu) {
  34.     color(255,255,0);
  35.     triangleFill(uwu.pos.x,uwu.pos.y-5,uwu.pos.x,uwu.pos.y+5,uwu.lwing.x,uwu.lwing.y);
  36.     triangleFill(uwu.pos.x,uwu.pos.y-5,uwu.pos.x,uwu.pos.y+5,uwu.rwing.x,uwu.rwing.y);
  37.     circleFill(uwu.pos.x,uwu.pos.y,10);
  38. }
  39.  
  40. void update (birb& uwu) {
  41.     if (uwu.pos.y > 10) uwu.pos.y -= 0.02;
  42.     uwu.lwing.y = uwu.pos.y;
  43.     uwu.rwing.y = uwu.pos.y;
  44. }
  45.  
  46. int main (int, char**) {
  47.     bool stop = false;
  48.     winInit("birb",DIMW,DIMW);
  49.     backgroundColor(100,50,200);
  50.     birb uwu;
  51.     float keyPressTime = elapsedTime();
  52.     while (!stop) {
  53.         winClear();
  54.         draw(uwu);
  55.         update(uwu);
  56.         if (isKeyPressed(SDLK_UP) or elapsedTime() < keyPressTime) {
  57.             uwu.lwing = rotate(C(DIMW/2-40,uwu.pos.y),uwu.pos.x,uwu.pos.y,(20*cos(5*elapsedTime()+pi))*pi/180);
  58.             uwu.rwing = rotate(C(DIMW/2+40,uwu.pos.y),uwu.pos.x,uwu.pos.y,(20*cos(5*elapsedTime()))*pi/180);
  59.             keyPressTime = elapsedTime()+0.002;
  60.             if (uwu.pos.y < DIMW-10)   uwu.pos.y += 0.1;
  61.         }
  62.         stop = winDisplay();
  63.     }
  64.     pressSpace();
  65.     winQuit();
  66.     return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement