1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
| #include <SDL.h>
#include <SDL_image.h>
#include <assert.h>
int main() {
int boucle = 1;
SDL_Surface* ecran;
SDL_Point mouse_position;
if(SDL_Init(SDL_INIT_VIDEO) != 0) {
printf("SDL_Init error: %s\n", SDL_GetError());
exit(1);
}
class ligne ()
SDL_Window* win = SDL_CreateWindow("Bonjour", 0, 0, 1280, 720,
SDL_WINDOW_SHOWN);
if(win == 0) {
printf("SDL_CreateWindow: %s\n", SDL_GetError());
SDL_Quit();
exit(1);
}
SDL_Renderer* ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
if (ren == NULL) {
SDL_DestroyWindow(win);
printf("SDL_CreateRenderer Error: %s\n", SDL_GetError());
SDL_Quit();
exit(1);
}
SDL_SetRenderDrawColor(ren, 255, 255, 255, 2);
SDL_Surface* monimage;
monimage = IMG_Load("Points.bmp");
assert(monimage);
SDL_Surface* fond;
fond = IMG_Load("blanc.jpg");
assert(fond);
SDL_Texture* tfond;
tfond = SDL_CreateTextureFromSurface(ren, fond);
assert(tfond);
SDL_Texture* matexture;
matexture = SDL_CreateTextureFromSurface(ren, monimage);
assert(matexture);
SDL_FreeSurface(monimage);
SDL_Surface* J1;
J1 = IMG_Load("Joueur1h.bmp");
assert(J1);
SDL_Texture* tJ1;
tJ1 = SDL_CreateTextureFromSurface(ren, J1);
assert(tJ1);
SDL_GetMouseState(
&mouse_position.x,
&mouse_position.y
);
//Rectangles
SDL_Rect fene = {.x = 0, .y = 0, .w = 1280, .h = 720 };
SDL_Rect coord = {.x = 315, .y = 35, .w = 650, .h = 650};
int x = 436 || 518 || 600 || 682 || 764;
int y = 151 || 233 || 315 || 397 || 479;
//Coordonnées lignes
SDL_Rect l1 = {.x = 436, .y = 151, .w = 86, .h = 12};
SDL_Rect l2 = {.x = 518, .y = 151, .w = 86, .h = 12};
SDL_Rect l3 = {.x = 600, .y = 151, .w = 86, .h = 12};
SDL_Rect l4 = {.x = 682, .y = 151, .w = 86, .h = 12};
SDL_Rect l5 = {.x = 764, .y = 151, .w = 86, .h = 12};
//Image de fond
SDL_RenderCopy(ren, tfond,0,&fene);
SDL_RenderPresent(ren);
SDL_RenderClear(ren);
int ligne (int x, int y) {
for(x=436;x<840;x+82);
}
int colonne (int x, int y) {
for(y=151;y<558;y+82);
}
//Boucle de jeu
while(boucle) {
SDL_Event event;
SDL_PollEvent(&event);
switch (event.type)
{
case SDL_QUIT:
boucle = 0;
break;
case SDL_KEYUP:
switch(event.key.keysym.sym) {
}
case SDL_MOUSEBUTTONUP:
if(event.button.button == SDL_BUTTON_LEFT) {
int mouseX = event.motion.x;
int mouseY = event.motion.y;
if(mouseX> l1.x && mouseX< (l1.x + l1.w) && mouseY> l1.y && mouseY< (l1.y + l1.h)){
SDL_RenderCopy(ren,tJ1,0,&l1);
break;
}
}
break;
}
SDL_RenderCopy(ren, matexture,0,&coord);
SDL_RenderPresent(ren);
}
return 0;
} |
Partager