réglage beug serpent
This commit is contained in:
parent
3e87799671
commit
9450a335f5
@ -4,13 +4,8 @@
|
||||
#include <graph.h>
|
||||
#include <time.h>
|
||||
#define CYCLE 10000L
|
||||
int seconde=0;
|
||||
int minute=0;
|
||||
int seconde_actuel=0;
|
||||
int old_seconde=0;
|
||||
unsigned long int suivant;
|
||||
char timer[6];
|
||||
void DessinerScene(int murx[30], int mury[30]){
|
||||
|
||||
void DessinerScene(int murx[], int mury[], int minute, int seconde, char timer []){
|
||||
int mur;
|
||||
int i;
|
||||
int fond;
|
||||
@ -30,7 +25,7 @@ void DessinerScene(int murx[30], int mury[30]){
|
||||
void Score(int segment){
|
||||
int nombre;
|
||||
char score[4];
|
||||
nombre= (segment-10)*10;
|
||||
nombre= (segment-10)*25;
|
||||
snprintf(score,4,"%04d0", nombre);
|
||||
ChoisirCouleurDessin(CouleurParNom("black"));
|
||||
RemplirRectangle(1100,700,1200,800);
|
||||
@ -38,7 +33,7 @@ void Score(int segment){
|
||||
EcrireTexte(1000,760,"Score: ",2);
|
||||
EcrireTexte(1100,760,score,2);
|
||||
}
|
||||
void Update_Timer(){
|
||||
void Update_Timer(int minute, int seconde, char timer[]){
|
||||
snprintf(timer,6,"%02d:%02d", minute, seconde);
|
||||
ChoisirCouleurDessin(CouleurParComposante(0,0,0));
|
||||
RemplirRectangle(10,700,12000,800);
|
||||
@ -46,21 +41,40 @@ void Update_Timer(){
|
||||
EcrireTexte(50,760,"time: ",2);
|
||||
EcrireTexte(120,760,timer,2);
|
||||
}
|
||||
void Update_Serpent(int pos_x[], int pos_y[], int segment, int old_x[], int old_y[]){
|
||||
void Update_Serpent(int pos_x[], int pos_y[], int segment, int old_x[], int old_y[], int* direction){
|
||||
int i = 0;
|
||||
int serpent;
|
||||
AfficherSprite(serpent, pos_x[0], pos_y[0]);
|
||||
int serpent=ChargerSprite("../img/serpent.png");
|
||||
int fond = ChargerSprite("../img/fond.png");
|
||||
for (i=1 ; i<segment ; i++){
|
||||
pos_x[i]=old_x[i-1];
|
||||
pos_y[i]=old_y[i-1];
|
||||
AfficherSprite(serpent, pos_x[i], pos_y[i]);
|
||||
}
|
||||
old_x[0]=pos_x[0];
|
||||
old_y[0]=pos_y[0];
|
||||
for (i=1 ; i<segment ; i++){
|
||||
|
||||
if (*direction == 1){
|
||||
pos_y[0]=old_y[0]-20;
|
||||
}
|
||||
if (*direction == 2) {
|
||||
pos_y[0]=old_y[0]+20;
|
||||
}
|
||||
if (*direction == 3) {
|
||||
pos_x[0]=old_x[0]-20;
|
||||
}
|
||||
if (*direction == 4) {
|
||||
pos_x[0]=old_x[0]+20;
|
||||
}
|
||||
|
||||
for (i=0 ; i<segment ; i++){
|
||||
printf("fond : %d %d\n",old_x[i],old_y[i]);
|
||||
AfficherSprite(fond, old_x[i], old_y[i]);
|
||||
old_x[i]=pos_x[i];
|
||||
old_y[i]=pos_y[i];
|
||||
}
|
||||
|
||||
for (i=0 ; i<segment ; i++){
|
||||
printf("serpent : %d %d\n",pos_x[i],pos_y[i]);
|
||||
AfficherSprite(serpent, pos_x[i], pos_y[i]);
|
||||
}
|
||||
|
||||
}
|
||||
void Collision_Serpent(int pos_x[], int pos_y[], int segment, int murx[], int mury[], int *go_on){
|
||||
int mur;
|
||||
@ -76,8 +90,9 @@ void Collision_Serpent(int pos_x[], int pos_y[], int segment, int murx[], int mu
|
||||
}
|
||||
/*Serpent contre Serpent*/
|
||||
for (i = 1; i < segment; i++) {
|
||||
if (pos_x[0] == pos_x[i] && pos_y[0] == pos_y[i])
|
||||
if (pos_x[0] == pos_x[i] && pos_y[0] == pos_y[i]){
|
||||
*go_on = 0;
|
||||
}
|
||||
}
|
||||
/*Serpent contre mur*/
|
||||
for(i=0; i<30;i++){
|
||||
@ -86,19 +101,19 @@ void Collision_Serpent(int pos_x[], int pos_y[], int segment, int murx[], int mu
|
||||
}
|
||||
}
|
||||
}
|
||||
void Timer(){
|
||||
if(Microsecondes()> suivant){
|
||||
suivant = Microsecondes()+CYCLE;
|
||||
seconde_actuel = (suivant/1000000)%10;
|
||||
void Timer(int *minute, int *seconde, unsigned long int *suivant, int *seconde_actuel, int *old_seconde, char timer[]){
|
||||
if(Microsecondes()> *suivant){
|
||||
*suivant = Microsecondes()+CYCLE;
|
||||
*seconde_actuel = (*suivant/1000000)%10;
|
||||
if(seconde_actuel !=old_seconde){
|
||||
old_seconde = seconde_actuel;
|
||||
if(seconde == 59){
|
||||
minute=minute+1;
|
||||
seconde=0;
|
||||
Update_Timer();
|
||||
}else;{
|
||||
seconde = seconde+1;
|
||||
Update_Timer();
|
||||
*old_seconde = *seconde_actuel;
|
||||
if(*seconde == 59){
|
||||
*minute=*minute+1;
|
||||
*seconde=0;
|
||||
Update_Timer(*minute, *seconde, timer);
|
||||
}else{
|
||||
*seconde = *seconde+1;
|
||||
Update_Timer(*minute, *seconde, timer);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -139,32 +154,15 @@ void Controle(int *direction, int last_direction, int *go_on) {
|
||||
}
|
||||
void Serpent(int pos_x[], int pos_y[], int old_x[], int old_y[], int *segment, int murx[], int mury[], int *go_on, int *direction) {
|
||||
int serpent;
|
||||
int x = 600;
|
||||
int y = 400;
|
||||
pos_x[0] = 600;
|
||||
pos_y[0] = 400;
|
||||
int i = 0;
|
||||
serpent=ChargerSprite("../img/serpent.png");
|
||||
for (i = 0; i < *segment; i++){
|
||||
AfficherSprite(serpent, x-(i*20), y);
|
||||
pos_x[i]=x-(i*20);
|
||||
pos_y[i]=y;
|
||||
pos_x[i]= pos_x[0];
|
||||
pos_y[i]= pos_y[0];
|
||||
old_x[i]=pos_x[i];
|
||||
old_y[i]=pos_y[i];
|
||||
}
|
||||
if (*direction == 1 && *direction != 2 ){
|
||||
pos_y[0]=old_y[0]-20;
|
||||
}
|
||||
if (*direction == 2 && *direction != 1) {
|
||||
pos_y[0]=old_y[0]+20;
|
||||
}
|
||||
if (*direction == 3 & *direction != 4) {
|
||||
pos_x[0]=old_x[0]-20;
|
||||
}
|
||||
if (*direction == 4 && *direction != 3) {
|
||||
pos_x[0]=old_x[0]+20;
|
||||
}
|
||||
Update_Serpent(pos_x, pos_y, *segment, old_x, old_y);
|
||||
Collision_Serpent(pos_x, pos_y, *segment, murx, mury, go_on);
|
||||
usleep(100000);
|
||||
}
|
||||
void InitialiserPommes(int pommex[], int pommey[], int segment) {
|
||||
int p;
|
||||
@ -195,6 +193,11 @@ int main(void){
|
||||
int segment = 10;
|
||||
int go_on = 1;
|
||||
int direction = 4;
|
||||
int minute = 0;
|
||||
int seconde = 0;
|
||||
int seconde_actuel = 0;
|
||||
int old_seconde = 0;
|
||||
unsigned long int suivant;
|
||||
int pos_x[60];
|
||||
int pos_y[60];
|
||||
int old_x[60];
|
||||
@ -203,21 +206,30 @@ int main(void){
|
||||
int pommey[5];
|
||||
int murx[30];
|
||||
int mury[30];
|
||||
char timer[6];
|
||||
int *pointeur_segment = &segment;
|
||||
int *pointeur_go_on = &go_on;
|
||||
int *pointeur_direction = &direction;
|
||||
int *pointeur_minute = &minute;
|
||||
int *pointeur_seconde = &seconde;
|
||||
unsigned long int *pointeur_suivant = &suivant;
|
||||
int *pointeur_seconde_actuel = &seconde_actuel;
|
||||
int *pointeur_old_seconde = &old_seconde;
|
||||
InitialiserGraphique();
|
||||
CreerFenetre(350,100,1200,900);
|
||||
EffacerEcran(CouleurParComposante(0,0,0));
|
||||
suivant = Microsecondes()+CYCLE;
|
||||
old_seconde=(suivant/1000000)%10;
|
||||
DessinerScene(murx, mury);
|
||||
DessinerScene(murx, mury, minute, seconde ,timer);
|
||||
InitialiserPommes(pommex, pommey, segment);
|
||||
Serpent(pos_x, pos_y, old_x, old_y, pointeur_segment, murx, mury, pointeur_go_on, pointeur_direction);
|
||||
while(go_on){
|
||||
Timer();
|
||||
Score(*pointeur_segment);
|
||||
Timer( pointeur_minute, pointeur_seconde, pointeur_suivant, pointeur_seconde_actuel, pointeur_old_seconde, timer);
|
||||
Score(segment);
|
||||
Controle(pointeur_direction, 0, pointeur_go_on);
|
||||
Serpent(pos_x, pos_y, old_x, old_y, pointeur_segment, murx, mury, pointeur_go_on, pointeur_direction);
|
||||
Update_Serpent(pos_x, pos_y, segment, old_x, old_y, pointeur_direction);
|
||||
Collision_Serpent(pos_x, pos_y, segment, murx, mury, pointeur_go_on);
|
||||
usleep(1000000);
|
||||
Pomme(pos_x, pos_y, pommex, pommey, pointeur_segment);
|
||||
}
|
||||
FermerGraphique();
|
||||
|
Loading…
Reference in New Issue
Block a user