Only the last class variable counted?
in
Programming Questions
•
1 years ago
Hey everyone, I'm was going through my sketch, a run and jump game. I was going through the jumps, trying to see if the jumps worked if there was more than one....Needless to say, it didn't. I put the person on the jump as a boolean, and if it was there, the endingy would be of the jump. The jump part of the code is this:
- class jump{
- float jx;
- boolean above=false;
- nicolai nn;
- jump(int ix, nicolai inn){
- jx=ix;
- nn=inn;
- }
- void display(){
- imageMode(CORNER);
- image(a,jx,jumpy);
- }
- void update(){
- if(jx<nn.nx+25 && jx>nn.nx-193){
- if(!above && keys[2]){
- xvel=0;
- xacc=0;
- }
- }
- if(jx>nn.nx-218 && jx<nn.nx-60){
- if(!above && keys[1]){
- xvel=0;
- xacc=0;
- }
- }
- jx = jx + ((keys[1]&&x<=0&&nn.nx<=200)?xvel:0) -
- ((keys[2]&&x>=-10000&&nn.nx>=400)?xvel:0);
- if(nn.nx>=jx && nn.nx<=jx+193){
- onjump=true;
- }else{onjump=false;}
- if(nn.y<=jumpy-25){
- above=true;
- }else{above=false;}
- }
- }
- void jump(){
- if(!jumping && keys[0]){
- jumping=true;
- yvel=-20;
- if(onjump){
- endingy=jumpy-25;
- }else{endingy=ground-25;}
- }
- if(jumping && can){
- fall=false;
- if(y+yvel<endingy){
- if(keys[0]){
- if(grav>.6){
- grav=grav-.175*grav;
- }
- }
- if(onjump){
- endingy=jumpy-25;
- }else{endingy=ground-25;}
- y=y+yvel;
- yvel=yvel+grav;
- }else{jumping=false; off=false; y=endingy; fall=true;
- if(keys[0]){can=false;}grav=3;
- }
- }
- }
1