diff --git a/G3_TP1_labyrinth_etu/src/labyrinth.c b/G3_TP1_labyrinth_etu/src/labyrinth.c index 1d811b7d8060eef488ae477c99667b8decf89d8e..3c614c73a402fe23e4cc1d3e31ca2f5049991e1e 100644 --- a/G3_TP1_labyrinth_etu/src/labyrinth.c +++ b/G3_TP1_labyrinth_etu/src/labyrinth.c @@ -150,20 +150,19 @@ void Algo_main_ball(void *params){ un_ou_moins_un_x = -1; ball->ball.pos.x += ball->ball.radius/2; } - if(CollisionState & TOUCH_UP){ - un_ou_moins_un_y = -1; - ball->ball.pos.y += ball->ball.radius/2; - } if(CollisionState & TOUCH_RIGHT){ un_ou_moins_un_x = -1; ball->ball.pos.x -= ball->ball.radius/2; } + if(CollisionState & TOUCH_UP){ + un_ou_moins_un_y = -1; + ball->ball.pos.y += ball->ball.radius/2; + } if(CollisionState & TOUCH_DOWN){ un_ou_moins_un_y = -1; ball->ball.pos.y -= ball->ball.radius/2; } }else{ - //lcd_filled_circle(ball->ball.pos.x, ball->ball.pos.y, ball->ball.radius, LCD_BLACK); accel_read(&ball_acc); ball->ball.speed.x = ((ball_acc.accel_x*0.1)+ball->ball.speed.x)*(un_ou_moins_un_x); ball->ball.speed.y = ((ball_acc.accel_y*0.1)+ball->ball.speed.y)*(un_ou_moins_un_y); @@ -173,18 +172,19 @@ void Algo_main_ball(void *params){ un_ou_moins_un_y = 1; un_ou_moins_un_x = 1; } - //} + + //détection des collisions sur les bords de l'ecran LCD if(ball->ball.pos.x <= ball->ball.radius){ ball->ball.pos.x = ball->ball.radius+1; } if(ball->ball.pos.y <= ball->ball.radius){ ball->ball.pos.y = ball->ball.radius+1; } - if(ball->ball.pos.x == LCD_MAX_WIDTH-ball->ball.radius){ - ball->ball.pos.x -= ball->ball.radius; + if(ball->ball.pos.x >= LCD_MAX_WIDTH-ball->ball.radius){ + ball->ball.pos.x = LCD_MAX_WIDTH-ball->ball.radius; } - if(ball->ball.pos.y == LCD_MAX_HEIGHT-ball->ball.radius){ - ball->ball.pos.y -= ball->ball.radius; + if(ball->ball.pos.y >= LCD_MAX_HEIGHT-ball->ball.radius){ + ball->ball.pos.y = LCD_MAX_HEIGHT-ball->ball.radius; } lcd_filled_circle(ball->ball.pos.x, ball->ball.pos.y, ball->ball.radius, ball->ball.color); vTaskDelay((portTickType)20/portTICK_RATE_MS); @@ -221,10 +221,9 @@ void Algo_bots(void *params){ ball->ball.pos.y -= ball->ball.radius/2; } }else{ - //lcd_filled_circle(ball->ball.pos.x, ball->ball.pos.y, ball->ball.radius, LCD_BLACK); RandAccel(&ball_acc); - ball->ball.speed.x = ((ball_acc.accel_x*0.08)+ball->ball.speed.x)*(un_ou_moins_un_x); - ball->ball.speed.y = ((ball_acc.accel_y*0.08)+ball->ball.speed.y)*(un_ou_moins_un_y); + ball->ball.speed.x = ((ball_acc.accel_x*0.1)+ball->ball.speed.x)*(un_ou_moins_un_x); + ball->ball.speed.y = ((ball_acc.accel_y*0.1)+ball->ball.speed.y)*(un_ou_moins_un_y); ball->ball.pos.x = ball->ball.pos.x + ball->ball.speed.x*(un_ou_moins_un_x); ball->ball.pos.y = ball->ball.pos.y + ball->ball.speed.y*(un_ou_moins_un_y); @@ -238,11 +237,11 @@ void Algo_bots(void *params){ if(ball->ball.pos.y <= ball->ball.radius){ ball->ball.pos.y = ball->ball.radius+1; } - if(ball->ball.pos.x == LCD_MAX_WIDTH-ball->ball.radius){ - ball->ball.pos.x -= ball->ball.radius; + if(ball->ball.pos.x >= LCD_MAX_WIDTH-ball->ball.radius){ + ball->ball.pos.x = LCD_MAX_WIDTH-ball->ball.radius; } - if(ball->ball.pos.y == LCD_MAX_HEIGHT-ball->ball.radius){ - ball->ball.pos.y -= ball->ball.radius; + if(ball->ball.pos.y >= LCD_MAX_HEIGHT-ball->ball.radius){ + ball->ball.pos.y = LCD_MAX_HEIGHT-ball->ball.radius; } lcd_filled_circle(ball->ball.pos.x, ball->ball.pos.y, ball->ball.radius, ball->ball.color); vTaskDelay((portTickType)20/portTICK_RATE_MS); @@ -250,12 +249,14 @@ void Algo_bots(void *params){ } } + +//random d'accélérations void RandAccel(accel_t *accel){ - float x = rnd32()%500; - float y = rnd32()%500; + float x = (float)(rnd32()%100)-50; + float y = (float)(rnd32()%100)-50; accel->accel_x = x/100; accel->accel_y = y/100; - accel->accel_z = (float)(rnd32()%500)/100; + //accel->accel_z = (float)(rnd32()%500)/100; accel->magneto_x = 0; accel->magneto_y = 0;