From 6474d731d011c46b08e60a6efb314791dc5b3a31 Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Fri, 4 Jul 2025 13:54:09 +0200 Subject: [PATCH] - Un poc de neteja del codi que controla el moviment de Sam. --- prota.cpp | 46 ++++++++++++++++------------------------------ 1 file changed, 16 insertions(+), 30 deletions(-) diff --git a/prota.cpp b/prota.cpp index 9550b4d..75d34cd 100644 --- a/prota.cpp +++ b/prota.cpp @@ -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++;