Loading...
Logo
Processing Forum
Hello , i'm close to complete a first version of a game i have to make for Java class.
My code is verry basic and almoste every thing works.
the explanaitions are in french but i think most of you won't need it anyways.
you moove wht ther zqsd keys caus of the french key board.
the problem is that as soon as the character you moove touches the upper side of the canvas i made he freezes...
i have no idea why, i would be so verry gratefull whit a bit ouf your help. I'll attatch a zip file whit the code and image files you need.

Replies(3)

Hello, I had a look at your code and have re-ordered the if statements, it was also getting caught if you went to the far left of the screen too.  I also made the hero a bit faster so I could win. ;)

//_____________________________Ce void gère l'affichage et le mouvement du héros _______________________________________________________________________________
void Heros() {
 
  image (BH, x, y);// fait appel à l'image du héros et l'affiche aux coordonnées x et y prédéfinies
  if (p==0) {//ici la condition p=0 indique que le jeu est en marche (voir void pause)
    if (keyPressed) {
      if (key== 's'||key== 'S') {
         if (y<425) {
              y=y+10;
          }
      } else if (key== 'z'||key== 'Z') {
         if (y>75) {
           y=y-10;
         }
      } else if (key == 'd'|| key == 'D') { //mouvement horizontal vers la droite
          if (x<950) {
            x=x+10;
          }
      } else if (key== 'Q' || key == 'q') { //mouvement horizontal vers la gauchedddd          
          if (x>50) {
            x=x-10;
          }
        }
      }
  }
  else {//cette condition est le retour de la condition de mise en marche du jeu. Si le jeu a été mis en pause, les variables x et y restent fixes (voir void pause)
    x=x;
    y=y;
  }
}
Thank you verry much this helped me out a lot, could you try to explain me why my code didn't work, i do understand the changes you made but still don't get what was so wrong about my code...
It was because you were checking to see if x>75 everytime the key was pressed so when it hit the top it would never be true.