CONNEXION
  • RetourJeux
    • Sorties
    • Hit Parade
    • Les + populaires
    • Les + attendus
    • Soluces
    • Tous les Jeux
    • Gaming
  • RetourActu Gaming
    • News
    • Astuces
    • Tests
    • Previews
    • Toute l'actu gaming
  • RetourBons plans
    • Bons plans
    • Bons plans Smartphone
    • Bons plans Hardware
    • Bons plans Image et Son
    • Bons plans Amazon
    • Bons plans Cdiscount
    • Bons plans Decathlon
    • Bons plans Fnac
    • Tous les Bons plans
  • RetourJVTech
    • Actus High-Tech
    • Intelligence Artificielle
    • Smartphones
    • Mobilité urbaine
    • Hardware
    • Image et son
    • Tutoriels
    • Tests produits High-Tech
    • Guides d'achat High-Tech
    • JVTech
  • RetourCulture
    • Actus Culture
    • Culture
  • RetourVidéos
    • A la une
    • Gaming Live
    • Vidéos Tests
    • Vidéos Previews
    • Gameplay
    • Trailers
    • Chroniques
    • Replay Web TV
    • Toutes les vidéos
  • RetourForums
    • Hardware PC
    • PS5
    • Switch 2
    • Xbox Series
    • Switch
    • Pokemon pocket
    • FC 25 Ultimate Team
    • League of Legends
    • Tous les Forums
  • PC
  • PS5
  • Xbox Series
  • Switch 2
  • PS4
  • One
  • Switch
  • iOS
  • Android
  • MMO
  • RPG
  • FPS
En ce moment Genshin Impact Valhalla Breath of the wild Animal Crossing GTA 5 Red dead 2
Liste des sujets

Besoin d'aide sur les colisions

dromar34
dromar34
Niveau 9
17 août 2005 à 18:21:39

bonsoir a tous je suis en train de crée un :pacg: pacman mais j´ai des problemes pour les colision si une ame charitable pouvai m´aider ce serais cool
PS:je crée mon jeux grace au NGCK de lapintade je met le code sources si ca interrese kelkun
/ /
--------------------------------------------------
---------

  1. include " ../Ngck_moteur/Ngck.h"

/ /
--------------------------------------------------
---------
int x;
int y;
int xg1;
int yg1;
int xg2;
int yg2;
int DirectionPac;
int blockx, blocky;

void Position(void){

/*////////////////////////////////////////////////
//*/
/ *//AFFICHE L´IMAGE PAR RAPPORT A LA DIRECTION//*/

/*////////////////////////////////////////////////
//*/
KSetDisplayColor(YELLOW);
if(DirectionPac==1)
KPrintPac(x,y);
if(DirectionPac==2)
KPrintPacG(x,y);
if(DirectionPac==3)
KPrintPacH(x,y);
if(DirectionPac==4)
KPrintPacB(x,y);
}
void map(){
for(blockx=0;blockx<6;blockx++)
KPrintSquare(blockx,16);
for(blockx=3;blockx<6;blockx++)
KPrintSquare(blockx,4);
for(blockx=18;blockx<16;blockx++)
KPrintSquare(blockx,17);
for(blockx=8;blockx<15;blockx++)
KPrintSquare(blockx,13);
for(blockx=9;blockx<15;blockx++)
KPrintSquare(blockx,10);
for(blockx=17;blockx<21;blockx++)
KPrintSquare(blockx,11);
for(blockx=15;blockx<23;blockx++)
KPrintSquare(blockx,15);
for(blockx=12;blockx<15;blockx++)
KPrintSquare(blockx,2);
for(blockx=15;blockx<22;blockx++)
KPrintSquare(blockx,3);
for(blocky=2;blocky<13;blocky++)
KPrintSquare(3,blocky);
for(blocky=4;blocky<16;blocky++);
KPrintSquare(6,blocky);
for(blocky=0;blocky<10;blocky++)
KPrintSquare(9,blocky);
for(blocky=12;blocky<17;blocky++)
KPrintSquare(8,blocky);
for(blocky=15;blocky<17;blocky++);
KPrintSquare(11,blocky);
for(blocky=13;blocky<15;blocky++)
KPrintSquare(15,blocky);
for(blocky=15;blocky<19;blocky++)
KPrintSquare(23,blocky);
for(blocky=4;blocky<7;blocky++)
KPrintSquare(12,blocky);
for(blocky=2;blocky<10;blocky++)
KPrintSquare(15,blocky);
for(blocky=6;blocky<11;blocky++)
KPrintSquare(17,blocky);
for(blocky=2;blocky<11;blocky++)
KPrintSquare(21,blocky);
}

/ //
--------------------------------- ----------------
--------------------------------------------------
-----------------------------
void InitialiseGame()
{
int DirectionPac=0;
xg1=3;
yg1=3;
xg2=5;
yg2=5;
x=14;
y=9;
}
/ /
--------------------------------------------------
--------------------------------------------------
-------------------------------
void GameLoop()
{
int h;
int h2;

/ ///////////////////////////////////////////////
/ //////////////////////////////////////////////
int DirOK;
int i;

KSetDisplayColor(WHITE);
map();
/ / Dessine la barre du haut et la barre du bas
for ( i=0; i<30; i++) {
KPrintSquare(i, 0);
KPrintSquare(i, 19);
}
/ / Dessine la barre de droite et la barre de gauche
for ( i=0; i<20; i++) {
KPrintSquare(0, i);
KPrintSquare(29, i);
}
/ / Dessine la barre de separation
for(i=0; i<20; i++) {
KPrintSquare(24,i);
}
KSetDisplayColor(YELLOW);
/ ////////////GESTION DES TOUCHES////////////
if(DirOK!=1){
if ( KGetRight()){

DirectionPac=1;
x = x + 1;
KPrintPac(x,y);
}
}
if(DirOK!=2){
if ( KGetLeft() ) {
DirectionPac=2;
x = x - 1;
KPrintPacG(x,y);
}
}
if(DirOK!=3){
if ( KGetUp() ) {
DirectionPac=3;
y = y - 1;
KPrintPacH(x, y);
}
}
if(DirOK!=4){
if ( KGetDown() ) {
DirectionPac=4;
y = y + 1;
KPrintPacB(x, y);
}
}
KPrintGhost(3,3);

Position();
/ ///////COLISION//////////

/ /////////////ENNEMIE N°1////////////
h=rand()%4;
if(h==1)
xg1++;
if(h==2)
xg1--;
if(h==3)
yg1++;
if(h==4)
yg1--;
KSetDisplayColor(RED);
KPrintGhost(xg1,yg1);
/ ////////////////ENNEMIE N°2//////////
KSetDisplayColor(BLUE);
h2=rand()%4;
if(h2==1)
xg2++;
if(h2==2)
xg2--;
if(h2==3)
yg2++;
if(h2==4)
yg2--;
/ //////////////////PERLES///////////////////
KSetDisplayColor(GREEN);
KPrintBille(13,8);
}
/ /
--------------------------------------------------
---------
/ *KPrintGhost(3,3);
KPrintPac(15,15);
KPrintBille(13,8);*/

Re-PS: je suis un " debutan confirmé" :-) donc mon code n´est pas parfait.Toutes les remarque serons les bien venu :merci:

Lapintade
Lapintade
Niveau 30
17 août 2005 à 20:00:33

Il faut stocker les murs dans un tableau a deux dimensions, comme ca les collisions seront trés simples ( ce meme tableau peut etre utiliser pour l´affichage aussi). Tu peux aussi mettre les pastille dans ce tableau.

int monecran[30][20];

dedans tu mets :

0 = rien
1 = mur
2 = pastille

Lapintade
Lapintade
Niveau 30
17 août 2005 à 20:01:17

Si tu veux faire plus propre dans ton code, tu devrais faire d´abord tout la gestion, et ensuite tout l´affichage ( et non pas melanger les deux).

Sous forums
  • Aide à l'achat Mac
  • Internet
  • Macintosh
  • Création de sites web
  • Création de Jeux
  • Linux
  • Programmation
  • Steam Deck
  • Hardware