101Fermer103
PolluxLe 25/05/2004 à 21:08
hop j'ai rajouté deux lignes pour gérer ça :

sans table :
int x=123,y=32;
int yd=0;

while (!exit_game) {
  if (key.jump && can_jump()) yd=8;
  y+=yd--;
  while (under_ground(y))
    y++,yd=0;

  ... afficher, modifier la position en x ...
 }


avec table :
int jump_table[8]={1,3,4,3,1,-4,-10,-20};

int x=123,y0=32;
int jump_idx=-1;

while (!exit_game) {
  if (key.jump && can_jump()) jump_idx=0;
  if (jump_idx<0 && !under_ground(y0-1))
    jump_idx=2, y0-=jump_table[jump_idx];
  int y=jump_idx<0 ? y0 : y0+jump_table[jump_idx];
  while (under_ground(y))
    y++,jump_idx=-1;
  if (jump_idx<0)
    y0=y;
  else if (++jump_idx>=8)
    jump_idx--;

  ... afficher, modifier la position en x ...
 }


10 lignes au lieu de 4, sans commentaire...