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
|
#include <graphics.h>
#include <conio.h>
#include <stdlib.h>
#include <stdio.h>
void Initialisation(int *aDriver, int *aMode)
{
aDriver = DETECT; //Detection auto
initgraph(aDriver, aMode, "c:\\tc\\bgi");
setfillstyle(1,RED); //motif de remplissage
}
int main(void)
{
int x = 0, y = 0; //Coordonées
int dx = 1, dy = 1; //Direction
int vitesse = 4;
int Driver,Mode;
Initialisation(&Driver,&Mode);
//Dessin du cercle
circle(50,50,50);
floodfill(50,50,WHITE); //Coloriage du rond
//Allocation dynamique
unsigned Taille;
void *Image;
Taille = imagesize(0,0,100,100);
Image = malloc(Taille);
//Récupération de l'image;
getimage(0,0,100,100,image);
//On efface tout
cleardevice();
//boucle principale
char touche;
while (touche != 27) //Tant que !esc
{
putimage(x,y,image, XOR_PUT); //Affichage
delay(50);
putimage(x,y,image, XOR_PUT); //Erase l'image
x += dx * vitesse; //Déplacement des coordonnée
y += dy * vitesse;
//Gestion des collisions
if ((x < 1) || ((x+100) > getmaxx()))
{
dx = -dx;
}
if ((y < 1) || ((y+100) > getmaxy()))
{
dy = -dy;
}
//Lecture Buffer
while (kbhit())
{
touche = getch();
}
}
closegraph();
return 0;
} |
Partager