   [C++]Key press
  So I'm trying to figure out how to make the computer only detect a key being pressed, but not held down. You see, in the script I'm working on, the character(more like the box) jumps and lands on platforms correctly, but jumping around while holding the UP key presents some problems...Here is the code(Yes, it's long for a forum.):----------------------------------------------------------------------#include <allegro.h>#include <cstdlib>int x = 64;//xint y = 472;//yint life = 1;//Currently not usedint jumping = 0;//Used to check whether the character is jumping or notint falling = 0;//Used to check whether the character is falling or notbool fBool = 0;//Used to make the character start fallingint gy = 480;int blockLeft1 = 300;//Left of block 1; xint blockRight1 = 400;//Right of block 1; xint blockTop1 = 440;//Top of block 1; yint blockBottom1 = 480;//Bottom of block 1; ybool xlc=0;//Determines if a left collision is truebool xrc=0;//Determines if a right collision is truebool yuc=0;//Determines if an upper collision is truebool ylc=0;//Determines if a lower collison is trueBITMAP* buffer;void collisionCheck(){if(x==blockLeft1&&x<blockRight1&&y>blockTop1){xrc=1;}else{  xrc=0;  }if(x>blockLeft1&&x==blockRight1+32&&y>blockTop1){ xlc=1; }else{xlc=0;}if(x>blockLeft1&&x<blockRight1+32&&y>blockTop1-3){ ylc=1; gy=blockTop1; }else{ylc=0;gy=480;}  }void moveCharacter(){rectfill(buffer,x,y,x-32,y-32,makecol(255,255,255));   collisionCheck();   if(yuc==1){jumping=40;}if(falling>=0&&y<gy&&ylc==0){  y+=3; }  if(jumping>0&&jumping<41&&falling==0&&yuc==0){   jumping+=1;   y-=6;   }    if(jumping==40){fBool=1;jumping=0;}    if(fBool==1){  falling+=1;  }    if(falling==40){jumping=0;falling=0;fBool=0;}   if(jumping==0&&falling==0&&key[KEY_UP])    {    jumping+=1;    }    if(key[KEY_LEFT]&&x>32&&xlc==0)    {    --x;    }    if(key[KEY_RIGHT]&&x<640&&xrc==0)    {    ++x;    } acquire_screen();    rectfill(buffer,x,y,x-32,y-32,makecol(0,255,0));    draw_sprite(screen,buffer,0,0);   release_screen();   rest(10);    }int main(){    allegro_init();    install_keyboard();    set_color_depth(16);    set_gfx_mode( GFX_AUTODETECT, 640, 480, 0, 0);    buffer = create_bitmap(640,480);    acquire_screen();    clear_to_color(buffer,makecol(255,255,255));    while( !key[KEY_ESC]){  moveCharacter(); rectfill(buffer,blockLeft1,blockBottom1,blockRight1,blockTop1,makecol(0,0,0));    }   return(0);    }END_OF_MAIN();   
Quote:Original post by X19OV1Here is the code(Yes, it's long for a forum.If you use [source][/source] tags, it'll be a lot better! [smile]  And can you tell us specifically what those jumping around problems are?  It's a lot easier to debug code if we can 1) read it (meaning source tags are your friend), and 2) if we know what's wrong (i.e. what you're expecting and what you're getting).   ;  Thanks, I'll try those tags.^^ The main problem I'm concerned about is, while holding the Up arrow key when you jump off the platform I made, the box will appear as if it was bouncing on air. I know it's hard to understand, but it's the best way I could say it.   