Préparations Initialisation Serpent + Améliorations gen_pastille()
This commit is contained in:
parent
4851a7a4d9
commit
321e7af676
50
Test_Touches.c
Normal file
50
Test_Touches.c
Normal file
@ -0,0 +1,50 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <graph.h>
|
||||
|
||||
#define delta 1000000L
|
||||
|
||||
int main(void)
|
||||
{
|
||||
unsigned long suivant;
|
||||
int go_on=1;
|
||||
int n;
|
||||
|
||||
InitialiserGraphique();
|
||||
CreerFenetre(0,0,800,500);
|
||||
|
||||
while(go_on)
|
||||
{
|
||||
if (ToucheEnAttente() == 1)
|
||||
{
|
||||
switch (Touche())
|
||||
{
|
||||
case XK_Up:
|
||||
printf("Touche haut\n");
|
||||
break;
|
||||
case XK_Down:
|
||||
printf("Touche bas\n");
|
||||
break;
|
||||
case XK_Left:
|
||||
printf("Touche gauche\n");
|
||||
break;
|
||||
case XK_Right:
|
||||
printf("Touche droite\n");
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("Autre touche\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Microsecondes()>suivant)
|
||||
{
|
||||
n++;
|
||||
suivant=Microsecondes()+delta;
|
||||
}
|
||||
}
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
59
Test_pinguin.c
Normal file
59
Test_pinguin.c
Normal file
@ -0,0 +1,59 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
#include<graph.h>
|
||||
#define delta 1000000L
|
||||
|
||||
void DessinerScene(int sprite,int x,int y,int n)
|
||||
{
|
||||
char buf[100];
|
||||
ChoisirEcran(1);
|
||||
CopierZone(2,1,0,0,800,500,0,0);
|
||||
snprintf(buf,100,"temps : %05d",n);
|
||||
EcrireTexte(10,20,buf,0);
|
||||
AfficherSprite(sprite,x,y);
|
||||
CopierZone(1,0,0,0,800,500,0,0);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int pingouin;
|
||||
int x,y,old_x,old_y;
|
||||
int n;
|
||||
unsigned long suivant;
|
||||
int go_on=1;
|
||||
|
||||
InitialiserGraphique();
|
||||
CreerFenetre(0,0,800,500);
|
||||
ChoisirEcran(2);
|
||||
ChargerImageFond("/images/arctis2.jpg");
|
||||
pingouin=ChargerSprite("./images/walk-0.png");
|
||||
x=y=old_x=old_y=10;
|
||||
n=0;
|
||||
DessinerScene(pingouin,x,y,0);
|
||||
suivant=Microsecondes()+delta;
|
||||
|
||||
while(go_on)
|
||||
{
|
||||
if (SourisCliquee()) go_on=0;
|
||||
else
|
||||
{
|
||||
if (Microsecondes()>suivant)
|
||||
{
|
||||
n++;
|
||||
DessinerScene(pingouin,x,y,n);
|
||||
suivant=Microsecondes()+delta;
|
||||
}
|
||||
SourisPosition();
|
||||
x=_X;
|
||||
y=_Y;
|
||||
if (x!=old_x || y!=old_y)
|
||||
{
|
||||
DessinerScene(pingouin,x,y,n);
|
||||
old_x=x;
|
||||
old_y=y;
|
||||
}
|
||||
}
|
||||
}
|
||||
FermerGraphique();
|
||||
}
|
||||
|
BIN
images/arctis2.jpg
Normal file
BIN
images/arctis2.jpg
Normal file
Binary file not shown.
After ![]() (image error) Size: 18 KiB |
BIN
images/walk-0.png
Normal file
BIN
images/walk-0.png
Normal file
Binary file not shown.
After ![]() (image error) Size: 4.9 KiB |
21
main.c
21
main.c
@ -27,10 +27,13 @@ int ArrondirPixel(int nombre) /* Calcule un arrondi du pixel pour pouvoir respec
|
||||
return arrondi;
|
||||
}
|
||||
|
||||
void gen_pastille(int nb_pastille) /*Générer une pastille dans la grid*/
|
||||
void gen_pastille(int nb_pastille, int *p_pastilles) /* Ajout des pointeurs pour le futur tableau de pastilles */
|
||||
|
||||
/* nb_pastille = int nombre de pastille voulue , p_pastilles est un pointeur d'un tableau de pixels qui sont des pastilles*/
|
||||
/*Générer une pastille dans la grid*/
|
||||
/*Seulement le code n'est pas complet*/
|
||||
/*-Elles se génèrent à des endroits qui peuvent être les mêmes ou gêner le snake*/
|
||||
/*-Faire en sorte qu'elles se genèrent uniquement dans un x ou y multiple de T_PIXEL*/
|
||||
|
||||
{
|
||||
couleur r;
|
||||
int x_pastille,y_pastille,i;
|
||||
@ -40,6 +43,7 @@ void gen_pastille(int nb_pastille) /*Générer une pastille dans la grid*/
|
||||
|
||||
for(i=0;i<nb_pastille;i++)
|
||||
{
|
||||
|
||||
x_pastille= ArrondirPixel(rand()%W_GAME);
|
||||
y_pastille = ArrondirPixel(rand()%H_GAME);
|
||||
|
||||
@ -59,6 +63,7 @@ void gen_pastille(int nb_pastille) /*Générer une pastille dans la grid*/
|
||||
{
|
||||
y_pastille - DECALEMENT;
|
||||
}
|
||||
|
||||
printf("x : %d ; y : %d\n",x_pastille,y_pastille);
|
||||
|
||||
ChoisirCouleurDessin(r);
|
||||
@ -67,19 +72,19 @@ void gen_pastille(int nb_pastille) /*Générer une pastille dans la grid*/
|
||||
|
||||
}
|
||||
|
||||
void DessinerScene() /* Dessine la scène */
|
||||
void DessinerScene(int* pastilles) /* Dessine la scène */
|
||||
{
|
||||
couleur c;
|
||||
|
||||
c=CouleurParNom("lightgreen");
|
||||
ChoisirCouleurDessin(c);
|
||||
RemplirRectangle(T_PIXEL,T_PIXEL,W_GAME,H_GAME);
|
||||
gen_pastille(5);
|
||||
gen_pastille(5,pastilles);
|
||||
}
|
||||
|
||||
void InitialisationDuSerpent()
|
||||
void InitialisationDuSerpent() /* L'initialisation du serpent */
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
int main()
|
||||
@ -89,10 +94,12 @@ int main()
|
||||
int n;
|
||||
int x_pastille,y_pastille;
|
||||
int p_serpent[100];
|
||||
int pastilles[5];
|
||||
|
||||
InitialiserGraphique();
|
||||
CreerFenetre(10,10,W_WINDOW,H_WINDOW); /* Peut être changer cette ligne avec la fonction Maxx et Maxy fournie dans graph.h ??*/
|
||||
ChoisirTitreFenetre("SNAKE SAE11 IN C");
|
||||
DessinerScene();
|
||||
DessinerScene(pastilles);
|
||||
|
||||
while(go_on) /* Lancement du cycle pour les Inputs et le Jeu*/
|
||||
{
|
||||
|
BIN
prog
BIN
prog
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user