debeug serpent + pomme
This commit is contained in:
parent
12062a0d0d
commit
574061ee02
@ -9,19 +9,8 @@ int seconde=0;
|
|||||||
int minute=0;
|
int minute=0;
|
||||||
int seconde_actuel=0;
|
int seconde_actuel=0;
|
||||||
int old_seconde=0;
|
int old_seconde=0;
|
||||||
char timer[6];
|
|
||||||
unsigned long int suivant;
|
unsigned long int suivant;
|
||||||
|
char timer[6];
|
||||||
/*fin de jeu*/
|
|
||||||
int go_on=1;
|
|
||||||
|
|
||||||
/*serpent*/
|
|
||||||
int segment=10;
|
|
||||||
|
|
||||||
int nombre;
|
|
||||||
char score[4];
|
|
||||||
|
|
||||||
|
|
||||||
void DessinerScene(int murx[30], int mury[30]){
|
void DessinerScene(int murx[30], int mury[30]){
|
||||||
int mur;
|
int mur;
|
||||||
int i;
|
int i;
|
||||||
@ -39,7 +28,9 @@ void DessinerScene(int murx[30], int mury[30]){
|
|||||||
AfficherSprite(mur, murx[i], mury[i]);
|
AfficherSprite(mur, murx[i], mury[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void Score(){
|
void Score(int segment){
|
||||||
|
int nombre;
|
||||||
|
char score[4];
|
||||||
nombre= (segment-10)*10;
|
nombre= (segment-10)*10;
|
||||||
snprintf(score,4,"%04d0", nombre);
|
snprintf(score,4,"%04d0", nombre);
|
||||||
ChoisirCouleurDessin(CouleurParNom("black"));
|
ChoisirCouleurDessin(CouleurParNom("black"));
|
||||||
@ -56,19 +47,9 @@ void Update_Timer(){
|
|||||||
EcrireTexte(50,760,"time: ",2);
|
EcrireTexte(50,760,"time: ",2);
|
||||||
EcrireTexte(120,760,timer,2);
|
EcrireTexte(120,760,timer,2);
|
||||||
}
|
}
|
||||||
/*serpent*/
|
void Update_Serpent(int pos_x[], int pos_y[], int segment, int old_x[], int old_y[]){
|
||||||
int serpent;
|
|
||||||
int x = 600;
|
|
||||||
int y = 400;
|
|
||||||
int direction = 4;
|
|
||||||
int t;
|
|
||||||
|
|
||||||
int segment=10;
|
|
||||||
int old_x[60];
|
|
||||||
int old_y[60];
|
|
||||||
|
|
||||||
void Update_Serpent(int *pos_x[60], int *pos_y[60], int* segment, int *old_x[60], int *old_y[60]){
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
int serpent;
|
int serpent;
|
||||||
AfficherSprite(serpent, pos_x[0], pos_y[0]);
|
AfficherSprite(serpent, pos_x[0], pos_y[0]);
|
||||||
for (i=1 ; i<segment ; i++){
|
for (i=1 ; i<segment ; i++){
|
||||||
@ -84,31 +65,27 @@ void Update_Serpent(int *pos_x[60], int *pos_y[60], int* segment, int *old_x[60]
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Collision_Serpent(int pos_x[60], int pos_y[60], int* segment, int murx[30], int mury[30]){
|
void Collision_Serpent(int pos_x[], int pos_y[], int segment, int murx[], int mury[], int *go_on){
|
||||||
int mur;
|
int mur;
|
||||||
int i;
|
int i;
|
||||||
int *pointeur_murx;
|
|
||||||
pointeur_murx = murx;
|
|
||||||
int *pointeur_mury;
|
|
||||||
pointeur_mury = mury;
|
|
||||||
mur = ChargerSprite("../img/mur.png");
|
mur = ChargerSprite("../img/mur.png");
|
||||||
/*Serpent contre coté*/
|
/*Serpent contre coté*/
|
||||||
if (pos_x[0] >1160 || pos_x[0]<=20){
|
if (pos_x[0] >1160 || pos_x[0]<=20){
|
||||||
go_on=0;
|
*go_on=0;
|
||||||
}
|
}
|
||||||
/*Serpent contre coté*/
|
/*Serpent contre coté*/
|
||||||
if (pos_y[0]<40 || pos_y[0] >=700){
|
if (pos_y[0]<40 || pos_y[0] >=700){
|
||||||
go_on=0;
|
*go_on=0;
|
||||||
}
|
}
|
||||||
/*Serpent contre Serpent*/
|
/*Serpent contre Serpent*/
|
||||||
for (i = 1; i < segment; i++) {
|
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;
|
*go_on = 0;
|
||||||
}
|
}
|
||||||
/*Serpent contre mur*/
|
/*Serpent contre mur*/
|
||||||
for(i=0; i<30;i++){
|
for(i=0; i<30;i++){
|
||||||
if(pos_x[0] == murx[i] && pos_y[0] == mury[i]){
|
if(pos_x[0] == murx[i] && pos_y[0] == mury[i]){
|
||||||
go_on=0;
|
*go_on=0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -132,64 +109,49 @@ void Timer(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Controle(int direction, int last_direction) {
|
void Controle(int *direction, int last_direction, int *go_on) {
|
||||||
int t;
|
int t;
|
||||||
while(ToucheEnAttente()) {
|
while(ToucheEnAttente()) {
|
||||||
t = Touche();
|
t = Touche();
|
||||||
switch(t) {
|
switch(t) {
|
||||||
case XK_Left:
|
case XK_Left:
|
||||||
if (last_direction != 4) {
|
if (last_direction != 4) {
|
||||||
direction = 3;
|
*direction = 3;
|
||||||
}
|
}
|
||||||
break;
|
return;
|
||||||
case XK_Right:
|
case XK_Right:
|
||||||
if (last_direction != 3) {
|
if (last_direction != 3) {
|
||||||
direction = 4;
|
*direction = 4;
|
||||||
}
|
}
|
||||||
break;
|
return;
|
||||||
case XK_Up:
|
case XK_Up:
|
||||||
if (last_direction != 2) {
|
if (last_direction != 2) {
|
||||||
direction = 1;
|
*direction = 1;
|
||||||
}
|
}
|
||||||
break;
|
return;
|
||||||
case XK_Down:
|
case XK_Down:
|
||||||
if (last_direction != 1) {
|
if (last_direction != 1) {
|
||||||
direction = 2;
|
*direction = 2;
|
||||||
}
|
}
|
||||||
break;
|
return;
|
||||||
case XK_Escape:
|
case XK_Escape:
|
||||||
direction = 0;
|
*direction = 0;
|
||||||
go_on = 0;
|
*go_on = 0;
|
||||||
break;
|
return;
|
||||||
case XK_p:
|
case XK_p:
|
||||||
direction = 0;
|
*direction = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Serpent(int pos_x[60], int pos_y[60], int old_x[60], int old_y[60], int* segment, int murx[30], int mury[30]) {
|
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 x = 600;
|
||||||
int y = 400;
|
int y = 400;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
/*Pointeur Position serpent*/
|
|
||||||
int *pointeur_pos_x;
|
|
||||||
pointeur_pos_x = pos_x;
|
|
||||||
int *pointeur_pos_y ;
|
|
||||||
pointeur_pos_y = pos_y;
|
|
||||||
int *pointeur_segment = &segment;
|
|
||||||
/*Pointeur ancienne position*/
|
|
||||||
int *pointeur_old_x;
|
|
||||||
pointeur_old_x = old_x;
|
|
||||||
int *pointeur_old_y;
|
|
||||||
pointeur_old_y = old_y;
|
|
||||||
/*Pointeur mur*/
|
|
||||||
int *pointeur_murx;
|
|
||||||
pointeur_murx = murx;
|
|
||||||
int *pointeur_mury;
|
|
||||||
pointeur_mury = mury;
|
|
||||||
|
|
||||||
serpent=ChargerSprite("../img/serpent.png");
|
serpent=ChargerSprite("../img/serpent.png");
|
||||||
for (i = 0; i < segment; i++){
|
for (i = 0; i < *segment; i++){
|
||||||
AfficherSprite(serpent, x-(i*20), y);
|
AfficherSprite(serpent, x-(i*20), y);
|
||||||
pos_x[i]=x-(i*20);
|
pos_x[i]=x-(i*20);
|
||||||
pos_y[i]=y;
|
pos_y[i]=y;
|
||||||
@ -197,42 +159,47 @@ void Serpent(int pos_x[60], int pos_y[60], int old_x[60], int old_y[60], int* se
|
|||||||
old_y[i]=pos_y[i];
|
old_y[i]=pos_y[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (direction == 1 && direction != 2 ){
|
if (*direction == 1 && *direction != 2 ){
|
||||||
pos_y[0]=old_y[0]-20;
|
pos_y[0]=old_y[0]-20;
|
||||||
}
|
}
|
||||||
if (direction == 2 && direction != 1) {
|
if (*direction == 2 && *direction != 1) {
|
||||||
pos_y[0]=old_y[0]+20;
|
pos_y[0]=old_y[0]+20;
|
||||||
}
|
}
|
||||||
if (direction == 3 & direction != 4) {
|
if (*direction == 3 & *direction != 4) {
|
||||||
pos_x[0]=old_x[0]-20;
|
pos_x[0]=old_x[0]-20;
|
||||||
}
|
}
|
||||||
if (direction == 4 && direction != 3) {
|
if (*direction == 4 && *direction != 3) {
|
||||||
pos_x[0]=old_x[0]+20;
|
pos_x[0]=old_x[0]+20;
|
||||||
}
|
}
|
||||||
|
|
||||||
Update_Serpent(*pointeur_pos_x, *pointeur_pos_y, *pointeur_segment, *pointeur_old_x, *pointeur_old_y);
|
Update_Serpent(pos_x, pos_y, *segment, old_x, old_y);
|
||||||
Collision_Serpent(*pointeur_pos_x, *pointeur_pos_y, *pointeur_segment, *pointeur_murx, *pointeur_mury);
|
Collision_Serpent(pos_x, pos_y, *segment, murx, mury, go_on);
|
||||||
usleep(100000);
|
usleep(100000);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
void InitialiserPommes(int pommex[], int pommey[], int segment) {
|
||||||
void Pomme(int pos_x[60], int pos_y[60], int *pommex[5], int *pommey[5]){
|
int p;
|
||||||
int p = 0;
|
|
||||||
int pp = 0;
|
|
||||||
int pomme;
|
int pomme;
|
||||||
|
|
||||||
pomme = ChargerSprite("../img/pomme.png");
|
pomme = ChargerSprite("../img/pomme.png");
|
||||||
|
|
||||||
for (p = 0; p < 5; p++) {
|
for (p = 0; p < 5; p++) {
|
||||||
pommex[p] = ((rand() % (55) + 1) * 20);
|
pommex[p] = ((rand() % (55) + 1) * 20);
|
||||||
pommey[p] = ((rand() % (35) + 1) * 20);
|
pommey[p] = ((rand() % (35) + 1) * 20);
|
||||||
AfficherSprite(pomme, pommex[p], pommey[p]);
|
AfficherSprite(pomme, pommex[p], pommey[p]);
|
||||||
}
|
}
|
||||||
for(pp = 0; pp < 5; ++pp){
|
|
||||||
AfficherSprite(pomme, pommex[pp], pommey[pp]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for(p=0; p<6; p++){
|
void Pomme(int pos_x[], int pos_y[], int pommex[], int pommey[], int *segment){
|
||||||
|
int p;
|
||||||
|
int pomme;
|
||||||
|
pomme=ChargerSprite("../img/pomme.png");
|
||||||
|
for (p = 0; p < 5; p++) {
|
||||||
|
AfficherSprite(pomme, pommex[p],pommey[p]);
|
||||||
|
}
|
||||||
|
for(p=0; p<5; p++){
|
||||||
if(pommex[p]==pos_x[0] && pommey[p]==pos_y[0]){
|
if(pommex[p]==pos_x[0] && pommey[p]==pos_y[0]){
|
||||||
segment+=2;
|
(*segment) +=2;
|
||||||
pommex[p] = ((rand() % (60)+1)*20);
|
pommex[p] = ((rand() % (60)+1)*20);
|
||||||
pommey[p] = ((rand() % (27)+1)*20);
|
pommey[p] = ((rand() % (27)+1)*20);
|
||||||
}
|
}
|
||||||
@ -240,37 +207,34 @@ void Pomme(int pos_x[60], int pos_y[60], int *pommex[5], int *pommey[5]){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(void){
|
||||||
int main(){
|
int segment = 10;
|
||||||
/*Pointeur Position serpent*/
|
int go_on = 1;
|
||||||
int *pointeur_pos_x;
|
int direction = 4;
|
||||||
pointeur_pos_x = pos_x;
|
int pos_x[60];
|
||||||
int *pointeur_pos_y ;
|
int pos_y[60];
|
||||||
pointeur_pos_y = pos_y;
|
int old_x[60];
|
||||||
|
int old_y[60];
|
||||||
|
int pommex[5];
|
||||||
|
int pommey[5];
|
||||||
|
int murx[30];
|
||||||
|
int mury[30];
|
||||||
int *pointeur_segment = &segment;
|
int *pointeur_segment = &segment;
|
||||||
/*Pointeur ancienne position*/
|
int *pointeur_go_on = &go_on;
|
||||||
int *pointeur_old_x;
|
int *pointeur_direction = &direction;
|
||||||
pointeur_old_x = old_x;
|
|
||||||
int *pointeur_old_y;
|
|
||||||
pointeur_old_y = old_y;
|
|
||||||
/*Pointeur pomme*/
|
|
||||||
int *pointeur_pommex;
|
|
||||||
pointeur_pommex = pommex;
|
|
||||||
int *pointeur_pommey;
|
|
||||||
pointeur_pommey = pommey;
|
|
||||||
InitialiserGraphique();
|
InitialiserGraphique();
|
||||||
CreerFenetre(350,100,1200,900);
|
CreerFenetre(350,100,1200,900);
|
||||||
EffacerEcran(CouleurParComposante(0,0,0));
|
EffacerEcran(CouleurParComposante(0,0,0));
|
||||||
suivant = Microsecondes()+CYCLE;
|
suivant = Microsecondes()+CYCLE;
|
||||||
old_seconde=(suivant/1000000)%10;
|
old_seconde=(suivant/1000000)%10;
|
||||||
DessinerScene(30,30);
|
DessinerScene(murx, mury);
|
||||||
|
InitialiserPommes(pommex, pommey, segment);
|
||||||
while(go_on){
|
while(go_on){
|
||||||
Timer();
|
Timer();
|
||||||
Score();
|
Score(*pointeur_segment);
|
||||||
Controle(4, 0);
|
Controle(pointeur_direction, 0, pointeur_go_on);
|
||||||
Serpent(10);
|
Serpent(pos_x, pos_y, old_x, old_y, pointeur_segment, murx, mury, pointeur_go_on, pointeur_direction);
|
||||||
Pomme(*pointeur_pos_x, *pointeur_pos_y, *pointeur_pommex, *pointeur_pommey);
|
Pomme(pos_x, pos_y, pommex, pommey, pointeur_segment);
|
||||||
}
|
}
|
||||||
FermerGraphique();
|
FermerGraphique();
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
Loading…
Reference in New Issue
Block a user