creation jeu avec affichage du quadrillage
This commit is contained in:
parent
2859664a32
commit
3264ccfe28
2
Makefile
2
Makefile
|
@ -37,7 +37,7 @@ exemple: exemple.c graphics.o
|
|||
|
||||
jeu: jeu.c jeu.o
|
||||
$(CC) $(CFLAGS) -c jeu.c
|
||||
$(CC) $(CFLAGS) graphics.o jeu.o main.c -o puissance4 $(LIBS)
|
||||
$(CC) $(CFLAGS) graphics.o jeu.o main.c -o morpion $(LIBS)
|
||||
|
||||
tar: clean
|
||||
rm -rf $(DIR)
|
||||
|
|
37
graphics.c
37
graphics.c
|
@ -91,8 +91,8 @@ void affiche_all() {
|
|||
|
||||
void synchro() { affiche_all(); }
|
||||
|
||||
COULEUR couleur_RGB(int r, int g, int b) {
|
||||
COULEUR C;
|
||||
couleur couleur_RGB(int r, int g, int b) {
|
||||
couleur C;
|
||||
return ((r%256)<<16) + ((g%256)<<8) + (b%256);
|
||||
return C;
|
||||
}
|
||||
|
@ -195,11 +195,11 @@ point wait_clic() {
|
|||
return P;
|
||||
}
|
||||
|
||||
void fill_screen(COULEUR color) {
|
||||
void fill_screen(couleur color) {
|
||||
int i,j;
|
||||
for (i=0;i<WIDTH;i++)
|
||||
for (j=0;j<HEIGHT;j++)
|
||||
*((COULEUR *)SDL_screen->pixels + (HEIGHT-j-1) * WIDTH + i) = color;
|
||||
*((couleur *)SDL_screen->pixels + (HEIGHT-j-1) * WIDTH + i) = color;
|
||||
if (SDL_AFFICHE_AUTO)
|
||||
affiche_all();
|
||||
}
|
||||
|
@ -212,14 +212,14 @@ int dans_ecran(int x, int y) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
#define add_pix(x,y,color) if (dans_ecran((x),(y))) *((COULEUR *)SDL_screen->pixels + (HEIGHT-(y)-1) * WIDTH + (x)) = (color)
|
||||
#define add_pix(x,y,color) if (dans_ecran((x),(y))) *((couleur *)SDL_screen->pixels + (HEIGHT-(y)-1) * WIDTH + (x)) = (color)
|
||||
|
||||
void draw_pixel(point p, COULEUR color) {
|
||||
void draw_pixel(point p, couleur color) {
|
||||
add_pix(p.x,p.y,color);
|
||||
if (SDL_AFFICHE_AUTO) affiche_all();
|
||||
}
|
||||
|
||||
void draw_line(point p1, point p2, COULEUR color) {
|
||||
void draw_line(point p1, point p2, couleur color) {
|
||||
int xmin, xmax;
|
||||
int ymin, ymax;
|
||||
int i,j;
|
||||
|
@ -258,7 +258,7 @@ void draw_line(point p1, point p2, COULEUR color) {
|
|||
if (SDL_AFFICHE_AUTO) affiche_all();
|
||||
}
|
||||
|
||||
void draw_rectangle(point p1, point p2, COULEUR color) {
|
||||
void draw_rectangle(point p1, point p2, couleur color) {
|
||||
int xmin, xmax;
|
||||
int ymin, ymax;
|
||||
int i,j;
|
||||
|
@ -274,7 +274,7 @@ void draw_rectangle(point p1, point p2, COULEUR color) {
|
|||
if (SDL_AFFICHE_AUTO) affiche_all();
|
||||
}
|
||||
|
||||
void draw_fill_rectangle(point p1, point p2, COULEUR color) {
|
||||
void draw_fill_rectangle(point p1, point p2, couleur color) {
|
||||
int xmin, xmax;
|
||||
int ymin, ymax;
|
||||
int i,j;
|
||||
|
@ -286,7 +286,7 @@ void draw_fill_rectangle(point p1, point p2, COULEUR color) {
|
|||
if (SDL_AFFICHE_AUTO) affiche_all();
|
||||
}
|
||||
|
||||
void draw_circle(point centre, int rayon, COULEUR color) {
|
||||
void draw_circle(point centre, int rayon, couleur color) {
|
||||
point min, max;
|
||||
int i,j;
|
||||
float dx, dy, rr;
|
||||
|
@ -314,7 +314,7 @@ void draw_circle(point centre, int rayon, COULEUR color) {
|
|||
if (SDL_AFFICHE_AUTO) affiche_all();
|
||||
}
|
||||
|
||||
void draw_fill_circle(point centre, int rayon, COULEUR color) {
|
||||
void draw_fill_circle(point centre, int rayon, couleur color) {
|
||||
point min, max;
|
||||
int i,j;
|
||||
float dx, dy, rr;
|
||||
|
@ -334,17 +334,24 @@ void draw_fill_circle(point centre, int rayon, COULEUR color) {
|
|||
if (SDL_AFFICHE_AUTO) affiche_all();
|
||||
}
|
||||
|
||||
void draw_square(point p, int taille, COULEUR color) {
|
||||
void draw_square(point p, int taille, couleur color) {
|
||||
point p1 = {p.x-taille/2, p.y-taille/2}, p2 = {p.x+taille/2, p.y+taille/2};
|
||||
draw_rectangle(p1, p2, color);
|
||||
}
|
||||
|
||||
void draw_fill_square(point p, int taille, COULEUR color) {
|
||||
void draw_fill_square(point p, int taille, couleur color) {
|
||||
point p1 = {p.x-taille/2, p.y-taille/2}, p2 = {p.x+taille/2, p.y+taille/2};
|
||||
draw_fill_rectangle(p1, p2, color);
|
||||
}
|
||||
|
||||
void aff_pol(char *a_ecrire, int taille, point p, COULEUR C) {
|
||||
void draw_cross(point p, int taille, couleur color) {
|
||||
point p1 = {p.x-taille/2, p.y-taille/2}, p2 = {p.x+taille/2, p.y+taille/2};
|
||||
point p3 = {p.x-taille/2, p.y+taille/2}, p4 = {p.x+taille/2, p.y-taille/2};
|
||||
draw_line(p1, p2, color);
|
||||
draw_line(p3, p4, color);
|
||||
}
|
||||
|
||||
void aff_pol(char *a_ecrire, int taille, point p, couleur C) {
|
||||
#ifdef SDL_TTF_OK
|
||||
int i;
|
||||
SDL_Color color;
|
||||
|
@ -388,7 +395,7 @@ void aff_pol(char *a_ecrire, int taille, point p, COULEUR C) {
|
|||
|
||||
|
||||
|
||||
void aff_int(int n, int taille, point p, COULEUR C) {
|
||||
void aff_int(int n, int taille, point p, couleur C) {
|
||||
char s[32];
|
||||
sprintf(s,"%d",n);
|
||||
aff_pol(s,taille,p,C);
|
||||
|
|
27
graphics.h
27
graphics.h
|
@ -14,7 +14,7 @@
|
|||
|
||||
typedef struct point {int x,y;} point;
|
||||
|
||||
typedef Uint32 COULEUR;
|
||||
typedef Uint32 couleur;
|
||||
|
||||
typedef int BOOL;
|
||||
|
||||
|
@ -34,24 +34,25 @@ void affiche_auto_off();
|
|||
void affiche_all();
|
||||
void synchro();
|
||||
|
||||
COULEUR couleur_RGB(int r, int g, int b);
|
||||
couleur couleur_RGB(int r, int g, int b);
|
||||
|
||||
point get_mouse();
|
||||
void wait_escape();
|
||||
point wait_clic();
|
||||
|
||||
void fill_screen(COULEUR color);
|
||||
void draw_pixel(point p, COULEUR color);
|
||||
void draw_line(point p1, point p2, COULEUR color);
|
||||
void draw_rectangle(point p1, point p2, COULEUR color);
|
||||
void draw_fill_rectangle(point p1, point p2, COULEUR color);
|
||||
void draw_circle(point centre, int rayon, COULEUR color);
|
||||
void draw_fill_circle(point centre, int rayon, COULEUR color);
|
||||
void draw_square(point p1, int taille, COULEUR color);
|
||||
void draw_fill_square(point p1, int taille, COULEUR color);
|
||||
void fill_screen(couleur color);
|
||||
void draw_pixel(point p, couleur color);
|
||||
void draw_line(point p1, point p2, couleur color);
|
||||
void draw_rectangle(point p1, point p2, couleur color);
|
||||
void draw_fill_rectangle(point p1, point p2, couleur color);
|
||||
void draw_circle(point centre, int rayon, couleur color);
|
||||
void draw_fill_circle(point centre, int rayon, couleur color);
|
||||
void draw_square(point p1, int taille, couleur color);
|
||||
void draw_fill_square(point p1, int taille, couleur color);
|
||||
void draw_cross(point p, int taille, couleur color);
|
||||
|
||||
void aff_pol(char *a_ecrire, int taille, point p, COULEUR C);
|
||||
void aff_int(int n, int taille, point p, COULEUR C);
|
||||
void aff_pol(char *a_ecrire, int taille, point p, couleur C);
|
||||
void aff_int(int n, int taille, point p, couleur C);
|
||||
|
||||
void attendre(int millisecondes);
|
||||
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
#include "jeu.h"
|
||||
|
||||
void init_board(int board[10][10]) {
|
||||
for(int i = 0; i < 10; i++) {
|
||||
for(int j = 0; j < 10; j++) {
|
||||
board[i][j] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void draw_board(int board[10][10]) {
|
||||
point p1, p2;
|
||||
for(int i = 0; i < 10; i++) {
|
||||
for(int j = 0; j < 10; j++) {
|
||||
p1.x = i*60+60; p1.y = 0;
|
||||
p2.x = i*60+60; p2.y = 600;
|
||||
draw_line(p1,p2,blanc);
|
||||
p1.y = i*60+60; p1.x = 0;
|
||||
p2.y = i*60+60; p2.x = 600;
|
||||
draw_line(p1,p2,blanc);
|
||||
draw_player(board, i, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void draw_player(int board[10][10] ,int i, int j) {
|
||||
point p = {i*60+30, j*60+30};
|
||||
if(board[i][j] == 1)
|
||||
draw_cross(p, 60, blue);
|
||||
if(board[i][j] == 2)
|
||||
draw_circle(p, 30, red);
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
#ifndef JEU_H
|
||||
#define JEU_H
|
||||
#include "graphics.h"
|
||||
|
||||
int board[10][10];
|
||||
|
||||
void init_board(int[10][10]);
|
||||
|
||||
void draw_board(int[10][10]);
|
||||
|
||||
void draw_player(int[10][10] ,int, int);
|
||||
|
||||
|
||||
|
||||
#endif
|
|
@ -0,0 +1,11 @@
|
|||
#include "jeu.h"
|
||||
|
||||
int main() {
|
||||
init_graphics(600,600);
|
||||
init_board(board);
|
||||
board[2][6] = 1;
|
||||
board[3][8] = 2;
|
||||
draw_board(board);
|
||||
wait_escape();
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue