Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Grapic.h>
- #include <math.h>
- #include <iostream>
- #include <windows.h>
- // si vous vous demandez pourquoi y a tout ça là :
- const float pi = 3.141592653;
- struct complex { float x, y; };
- complex C (float x, float y) { struct complex ret; ret.x = x; ret.y = y; return ret; }
- complex C_exp (float rho, float theta) { complex ret; ret.x = rho*cos(theta); ret.y = rho*sin(theta); return ret; }
- complex operator+ (complex a, complex b) { complex ret; ret.x = a.x + b.x; ret.y = a.y + b.y; return ret; }
- complex operator- (complex a, complex b) { complex ret; ret.x = a.x - b.x; ret.y = a.y - b.y; return ret; }
- complex operator* (float a, complex b) { complex ret; ret.x = a * b.x; ret.y = a * b.y; return ret; }
- 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; }
- complex scale (complex p, float x, float y, float lambda) { return lambda*(p-C(x,y)); }
- complex translate (complex P, float dx, float dy) { complex ret; ret = P+C(dx,dy); return ret; }
- complex rotate (complex p, float x, float y, float theta) { return (p-C(x,y))*C_exp(1,theta)+C(x,y); }
- void show (complex z) { std::cout << z.x << " + " << z.y << " i"; }
- float abs (complex z) { return sqrt(z.x*z.x + z.y*z.y); }
- float arg (complex z) { if (z.x > 0 or z.y != 0) return 2*atan(z.y/(z.x+abs(z))); else -pi; }
- // 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 ^^'
- using namespace grapic;
- const int DIMW = 500;
- const int MAX = 500;
- struct birb {
- complex pos = C(DIMW/2,DIMW/2);
- complex lwing = C(DIMW/2-40,DIMW/2);
- complex rwing = C(DIMW/2+40,DIMW/2);
- };
- void draw (birb uwu) {
- color(255,255,0);
- triangleFill(uwu.pos.x,uwu.pos.y-5,uwu.pos.x,uwu.pos.y+5,uwu.lwing.x,uwu.lwing.y);
- triangleFill(uwu.pos.x,uwu.pos.y-5,uwu.pos.x,uwu.pos.y+5,uwu.rwing.x,uwu.rwing.y);
- circleFill(uwu.pos.x,uwu.pos.y,10);
- }
- void update (birb& uwu) {
- if (uwu.pos.y > 10) uwu.pos.y -= 0.02;
- uwu.lwing.y = uwu.pos.y;
- uwu.rwing.y = uwu.pos.y;
- }
- int main (int, char**) {
- bool stop = false;
- winInit("birb",DIMW,DIMW);
- backgroundColor(100,50,200);
- birb uwu;
- float keyPressTime = elapsedTime();
- while (!stop) {
- winClear();
- draw(uwu);
- update(uwu);
- if (isKeyPressed(SDLK_UP) or elapsedTime() < keyPressTime) {
- uwu.lwing = rotate(C(DIMW/2-40,uwu.pos.y),uwu.pos.x,uwu.pos.y,(20*cos(5*elapsedTime()+pi))*pi/180);
- uwu.rwing = rotate(C(DIMW/2+40,uwu.pos.y),uwu.pos.x,uwu.pos.y,(20*cos(5*elapsedTime()))*pi/180);
- keyPressTime = elapsedTime()+0.002;
- if (uwu.pos.y < DIMW-10) uwu.pos.y += 0.1;
- }
- stop = winDisplay();
- }
- pressSpace();
- winQuit();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement