Ajout paramètre dans le fichier game.c
This commit is contained in:
@@ -5,39 +5,24 @@
|
||||
#include "../fichier.h/terrain.h"
|
||||
#include "../fichier.h/pastille.h"
|
||||
|
||||
void Update_Serpent(int segment, int direction, int pos_x[60], int pos_y[60]){
|
||||
int old_x[60];
|
||||
int old_y[60];
|
||||
int x = 600;
|
||||
int y = 400;
|
||||
int t, fond, i = 0, serpent;
|
||||
fond = ChargerSprite("../img/fond.png");
|
||||
AfficherSprite(fond, pos_x[segment-1], pos_y[segment-1]);
|
||||
AfficherSprite(serpent, pos_x[0], pos_y[0]);
|
||||
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;
|
||||
}
|
||||
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++){
|
||||
old_x[i]=pos_x[i];
|
||||
old_y[i]=pos_y[i];
|
||||
}
|
||||
void InitialiserSerpent(Serpent *serpent, int x, int y) {
|
||||
serpent->longueur = 10;
|
||||
serpent->directionX = 1;
|
||||
serpent->directionY = 0;
|
||||
serpent->corps[0].x = x;
|
||||
serpent->corps[0].y = y;
|
||||
}
|
||||
void DeplacerSerpent(Serpent *serpent) {
|
||||
int i;
|
||||
|
||||
for ( i = serpent->longueur - 1; i > 0; i--) {
|
||||
serpent->corps[i] = serpent->corps[i - 1];
|
||||
}
|
||||
|
||||
serpent->corps[0].x += serpent->directionX * 20;
|
||||
serpent->corps[0].y += serpent->directionY * 20;
|
||||
}
|
||||
|
||||
void Controle(int* direction , int* go_on) {
|
||||
int t;
|
||||
int last_direction = 0;
|
||||
@@ -74,41 +59,22 @@ void Controle(int* direction , int* go_on) {
|
||||
}
|
||||
}
|
||||
}
|
||||
int Collision_Serpent(int* go_on){
|
||||
int pos_x[60];
|
||||
int pos_y[60];
|
||||
int murx[50];
|
||||
int mury[50];
|
||||
int segment = 10;
|
||||
int VerifierCollision(const Serpent *serpent) {
|
||||
int teteX = serpent->corps[0].x;
|
||||
int teteY = serpent->corps[0].y;
|
||||
int i;
|
||||
/*Serpent contre coté*/
|
||||
if (pos_x[0] >1160 || pos_x[0]<=20){
|
||||
return *go_on= 0;
|
||||
} else{
|
||||
|
||||
if (teteX < 0 || teteX >= 1200 || teteY < 0 || teteY >= 900-80) {
|
||||
return 1;
|
||||
}
|
||||
/*Serpent contre coté*/
|
||||
if (pos_y[0]<40 || pos_y[0] >=700){
|
||||
return *go_on= 0;
|
||||
} else{
|
||||
return 1;
|
||||
|
||||
for (i = 1; i < serpent->longueur; i++) {
|
||||
if (teteX == serpent->corps[i].x && teteY == serpent->corps[i].y) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
/*Serpent contre Serpent*/
|
||||
for (i = 1; i < segment; i++) {
|
||||
if (pos_x[0] == pos_x[i] && pos_y[0] == pos_y[i]){
|
||||
return *go_on = 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
/*Serpent contre mur*/
|
||||
for(i=0; i<30;i++){
|
||||
if(pos_x[0] == murx[i] && pos_y[0] == mury[i]){
|
||||
return *go_on= 0;
|
||||
}else{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
void Score(int segment){
|
||||
int nombre;
|
||||
@@ -121,15 +87,25 @@ void Score(int segment){
|
||||
EcrireTexte(1000,760,"Score: ",2);
|
||||
EcrireTexte(1100,760,score,2);
|
||||
}
|
||||
void Serpent(int* go_on) {
|
||||
int direction=0;
|
||||
int pos_x[60];
|
||||
int pos_y[60];
|
||||
int* pointeur_pos_x= pos_x;
|
||||
int* pointeur_pos_y= pos_y;
|
||||
int* pointeur_direction=&direction;
|
||||
void DessinerSerpent(const Serpent *serpent) {
|
||||
int i;
|
||||
couleur couleurSerpent = CouleurParComposante(34, 139, 34);
|
||||
|
||||
Controle(pointeur_direction, go_on);
|
||||
Update_Serpent(segment, direction, pointeur_pos_x, pointeur_pos_y );
|
||||
Collision_Serpent(go_on);
|
||||
ChoisirEcran(1);
|
||||
|
||||
EffacerEcran(CouleurParNom("grey"));
|
||||
|
||||
|
||||
ChoisirCouleurDessin(couleurSerpent);
|
||||
/* Afficher la tête du serpent */
|
||||
RemplirRectangle(serpent->corps[0].x, serpent->corps[0].y, 20, 20);
|
||||
|
||||
|
||||
for (i = 0; i < serpent->longueur; i++) {
|
||||
RemplirRectangle(serpent->corps[i].x, serpent->corps[i].y, 20, 20);
|
||||
}
|
||||
ChoisirEcran(0);
|
||||
AfficherFenetre();
|
||||
CopierZone(1, 0, 0, 0, LARGEUR_FENETRE, HAUTEUR_FENETRE, 0, 0);
|
||||
|
||||
}
|
Reference in New Issue
Block a user