- Un poc de neteja del codi que controla el moviment de Sam.
This commit is contained in:
46
prota.cpp
46
prota.cpp
@@ -93,54 +93,40 @@ Uint8 Prota::update() {
|
|||||||
Uint8 eixir = 0;
|
Uint8 eixir = 0;
|
||||||
|
|
||||||
if( this->o < 4 ) {
|
if( this->o < 4 ) {
|
||||||
Uint8 dir = 0;
|
Uint8 dir = 4;
|
||||||
if ( JI_KeyPressed(SDL_SCANCODE_DOWN) ) {
|
if ( JI_KeyPressed(SDL_SCANCODE_DOWN) ) {
|
||||||
if( (this->x-20)%65 == 0 ) {
|
if( (this->x-20)%65 == 0 ) this->o = 0;
|
||||||
this->o = 0;
|
dir = this->o;
|
||||||
dir = 1;
|
|
||||||
} else {
|
|
||||||
dir = this->o + 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if ( JI_KeyPressed(SDL_SCANCODE_UP) ) {
|
if ( JI_KeyPressed(SDL_SCANCODE_UP) ) {
|
||||||
if( (this->x-20)%65 == 0 ) {
|
if( (this->x-20)%65 == 0 ) this->o = 1;
|
||||||
this->o = 1;
|
dir = this->o;
|
||||||
dir = 2;
|
|
||||||
} else {
|
|
||||||
dir = this->o + 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if( JI_KeyPressed( SDL_SCANCODE_RIGHT ) ) {
|
if( JI_KeyPressed( SDL_SCANCODE_RIGHT ) ) {
|
||||||
if( (this->y-30)%35 == 0 ) {
|
if( (this->y-30)%35 == 0 ) this->o = 2;
|
||||||
this->o = 2;
|
dir = this->o;
|
||||||
dir = 3;
|
|
||||||
} else {
|
|
||||||
dir = this->o + 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if( JI_KeyPressed( SDL_SCANCODE_LEFT ) ) {
|
if( JI_KeyPressed( SDL_SCANCODE_LEFT ) ) {
|
||||||
if( (this->y-30)%35 == 0 ) {
|
if( (this->y-30)%35 == 0 ) this->o = 3;
|
||||||
this->o = 3;
|
dir = this->o;
|
||||||
dir = 4;
|
|
||||||
} else {
|
|
||||||
dir = this->o + 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch( dir ) {
|
switch( dir ) {
|
||||||
case 1:
|
case 0:
|
||||||
if( this->y < 170 ) this->y++;
|
if( this->y < 170 ) this->y++;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 1:
|
||||||
if( this->y > 30 ) this->y--;
|
if( this->y > 30 ) this->y--;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 2:
|
||||||
if( this->x < 280 ) this->x++;
|
if( this->x < 280 ) this->x++;
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 3:
|
||||||
if( this->x > 20 ) this->x--;
|
if( this->x > 20 ) this->x--;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if( dir == 0 ) {
|
|
||||||
|
if( dir == 4 ) {
|
||||||
this->cur_frame = 0;
|
this->cur_frame = 0;
|
||||||
} else {
|
} else {
|
||||||
this->frame_pejades++;
|
this->frame_pejades++;
|
||||||
|
|||||||
Reference in New Issue
Block a user