- Un poc de neteja del codi que controla el moviment de Sam.

This commit is contained in:
2025-07-04 13:54:09 +02:00
parent 83cf446c37
commit 6474d731d0

View File

@@ -93,54 +93,40 @@ Uint8 Prota::update() {
Uint8 eixir = 0;
if( this->o < 4 ) {
Uint8 dir = 0;
Uint8 dir = 4;
if ( JI_KeyPressed(SDL_SCANCODE_DOWN) ) {
if( (this->x-20)%65 == 0 ) {
this->o = 0;
dir = 1;
} else {
dir = this->o + 1;
}
if( (this->x-20)%65 == 0 ) this->o = 0;
dir = this->o;
}
if ( JI_KeyPressed(SDL_SCANCODE_UP) ) {
if( (this->x-20)%65 == 0 ) {
this->o = 1;
dir = 2;
} else {
dir = this->o + 1;
}
if( (this->x-20)%65 == 0 ) this->o = 1;
dir = this->o;
}
if( JI_KeyPressed( SDL_SCANCODE_RIGHT ) ) {
if( (this->y-30)%35 == 0 ) {
this->o = 2;
dir = 3;
} else {
dir = this->o + 1;
}
if( (this->y-30)%35 == 0 ) this->o = 2;
dir = this->o;
}
if( JI_KeyPressed( SDL_SCANCODE_LEFT ) ) {
if( (this->y-30)%35 == 0 ) {
this->o = 3;
dir = 4;
} else {
dir = this->o + 1;
}
if( (this->y-30)%35 == 0 ) this->o = 3;
dir = this->o;
}
switch( dir ) {
case 1:
case 0:
if( this->y < 170 ) this->y++;
break;
case 2:
case 1:
if( this->y > 30 ) this->y--;
break;
case 3:
case 2:
if( this->x < 280 ) this->x++;
break;
case 4:
case 3:
if( this->x > 20 ) this->x--;
break;
}
if( dir == 0 ) {
if( dir == 4 ) {
this->cur_frame = 0;
} else {
this->frame_pejades++;