Skip to content
Snippets Groups Projects
Commit 0bd89e8e authored by remi.greub's avatar remi.greub
Browse files

mode avec le moins de pixels mangés git add G3_TP1_labyrinth_etu/

parent e5e6ae6a
No related branches found
No related tags found
No related merge requests found
...@@ -123,7 +123,7 @@ int main(void) ...@@ -123,7 +123,7 @@ int main(void)
xTaskCreate(Algo_main_ball, (signed portCHAR *)"Masterball", xTaskCreate(Algo_main_ball, (signed portCHAR *)"Masterball",
configMINIMAL_STACK_SIZE, &ball_param_th[0], tskIDLE_PRIORITY+1, configMINIMAL_STACK_SIZE, &ball_param_th[0], tskIDLE_PRIORITY+1,
NULL); NULL);
xTaskCreate(Algo_bots, (signed portCHAR *)"libreball1", /*xTaskCreate(Algo_bots, (signed portCHAR *)"libreball1",
configMINIMAL_STACK_SIZE, &ball_param_th[2], tskIDLE_PRIORITY+1, configMINIMAL_STACK_SIZE, &ball_param_th[2], tskIDLE_PRIORITY+1,
NULL); NULL);
xTaskCreate(Algo_bots, (signed portCHAR *)"libreball2", xTaskCreate(Algo_bots, (signed portCHAR *)"libreball2",
...@@ -131,7 +131,7 @@ int main(void) ...@@ -131,7 +131,7 @@ int main(void)
NULL); NULL);
xTaskCreate(Algo_bots, (signed portCHAR *)"libreball3", xTaskCreate(Algo_bots, (signed portCHAR *)"libreball3",
configMINIMAL_STACK_SIZE, &ball_param_th[4], tskIDLE_PRIORITY+1, configMINIMAL_STACK_SIZE, &ball_param_th[4], tskIDLE_PRIORITY+1,
NULL); NULL);*/
vTaskStartScheduler(); // launch scheduler vTaskStartScheduler(); // launch scheduler
LPC_TIM0->TCR = 1; LPC_TIM0->TCR = 1;
...@@ -144,39 +144,65 @@ void Algo_main_ball(void *params){ ...@@ -144,39 +144,65 @@ void Algo_main_ball(void *params){
ball_param_th_t *ball = (ball_param_th_t *)params; ball_param_th_t *ball = (ball_param_th_t *)params;
accel_t ball_acc; accel_t ball_acc;
int un_ou_moins_un_x = 1, un_ou_moins_un_y = 1; int un_ou_moins_un_x = 1, un_ou_moins_un_y = 1;
//bool collision_prev=false;
while(1){ while(1){
lcd_filled_circle(ball->ball.pos.x, ball->ball.pos.y, ball->ball.radius, LCD_BLACK); lcd_filled_circle(ball->ball.pos.x, ball->ball.pos.y, ball->ball.radius, LCD_BLACK);
int CollisionState = test_collision(&ball->ball); int CollisionState = test_collision(&ball->ball);
if(CollisionState != NO_COLLISION){ if(CollisionState != NO_COLLISION){
//ralentissement de 10% de la vitesse de la balle //ralentissement de 10% de la vitesse de la balle
ball->ball.speed.x = ball->ball.speed.x - (ball->ball.speed.x/10); //ball->ball.speed.x = ball->ball.speed.x - (ball->ball.speed.x/10);
ball->ball.speed.y = ball->ball.speed.y - (ball->ball.speed.y/10); //ball->ball.speed.y = ball->ball.speed.y - (ball->ball.speed.y/10);
if(CollisionState & TOUCH_LEFT){ if(CollisionState & TOUCH_LEFT){
un_ou_moins_un_x = -1; un_ou_moins_un_x = -1;
ball->ball.pos.x += ball->ball.radius/3; ball->ball.speed.x = ball->ball.speed.x - (ball->ball.speed.x/10);
} //ball->ball.speed.x *= -REBOUND_FACTOR;
if(CollisionState & TOUCH_RIGHT){ //ball->ball.pos.x += ball->ball.radius*0.4; //round
un_ou_moins_un_x = -1; ball->ball.pos.x += 2;
ball->ball.pos.x -= ball->ball.radius/3;
} }
if(CollisionState & TOUCH_UP){ if(CollisionState & TOUCH_UP){
un_ou_moins_un_y = -1; un_ou_moins_un_y = -1;
ball->ball.pos.y += ball->ball.radius/3; ball->ball.speed.y = ball->ball.speed.y - (ball->ball.speed.y/10);
//ball->ball.speed.y *= -REBOUND_FACTOR;
//ball->ball.pos.y += ball->ball.radius*0.4; //round()
ball->ball.pos.y += 2;
}
if(CollisionState & TOUCH_RIGHT){
un_ou_moins_un_x = -1;
ball->ball.speed.x = ball->ball.speed.x - (ball->ball.speed.x/10);
//ball->ball.speed.x *= -REBOUND_FACTOR;
//ball->ball.pos.x -= ball->ball.radius*0.4; //round()
ball->ball.pos.x -= 2;
} }
if(CollisionState & TOUCH_DOWN){ if(CollisionState & TOUCH_DOWN){
un_ou_moins_un_y = -1; un_ou_moins_un_y = -1;
ball->ball.pos.y -= ball->ball.radius/3; ball->ball.speed.y = ball->ball.speed.y - (ball->ball.speed.y/10);
//ball->ball.speed.y *= -REBOUND_FACTOR;
//ball->ball.pos.y -= ball->ball.radius*0.4; //round()
ball->ball.pos.y -= 2;
} }
ball->ball.pos.x = round(ball->ball.pos.x);
ball->ball.pos.y = round(ball->ball.pos.y);
//collision_prev = true;
}else{ }else{
accel_read(&ball_acc); 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.x =((ball_acc.accel_x*0.4)+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.speed.y = ((ball_acc.accel_y*0.4)+ball->ball.speed.y)*(un_ou_moins_un_y);
ball->ball.speed.x = (ball->ball.speed.x >= SPEED_MAX) ? SPEED_MAX: ball->ball.speed.x;
ball->ball.speed.y = (ball->ball.speed.y >= SPEED_MAX) ? SPEED_MAX: ball->ball.speed.y;
ball->ball.speed.x = (ball->ball.speed.x <= -SPEED_MAX) ? -SPEED_MAX: ball->ball.speed.x;
ball->ball.speed.y = (ball->ball.speed.y <= -SPEED_MAX) ? -SPEED_MAX: ball->ball.speed.y;
ball->ball.pos.x = ball->ball.pos.x + ball->ball.speed.x*(un_ou_moins_un_x); 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); ball->ball.pos.y = ball->ball.pos.y + ball->ball.speed.y*(un_ou_moins_un_y);
un_ou_moins_un_y = 1; un_ou_moins_un_y = 1;
un_ou_moins_un_x = 1; un_ou_moins_un_x = 1;
//if(collision_prev){
ball->ball.pos.x = round(ball->ball.pos.x);
ball->ball.pos.y = round(ball->ball.pos.y);
//collision_prev = false;
//}
} }
//détection des collisions sur les bords de l'ecran LCD //détection des collisions sur les bords de l'ecran LCD
...@@ -186,15 +212,14 @@ void Algo_main_ball(void *params){ ...@@ -186,15 +212,14 @@ void Algo_main_ball(void *params){
if(ball->ball.pos.y <= ball->ball.radius){ if(ball->ball.pos.y <= ball->ball.radius){
ball->ball.pos.y = ball->ball.radius+1; ball->ball.pos.y = ball->ball.radius+1;
} }
if(ball->ball.pos.x >= LCD_MAX_WIDTH-ball->ball.radius){ if(ball->ball.pos.x >= (LCD_MAX_WIDTH - (ball->ball.radius))){
ball->ball.pos.x = LCD_MAX_WIDTH-ball->ball.radius; ball->ball.pos.x = (LCD_MAX_WIDTH - (ball->ball.radius+1));
} }
if(ball->ball.pos.y >= LCD_MAX_HEIGHT-ball->ball.radius){ if(ball->ball.pos.y >= (LCD_MAX_HEIGHT - (ball->ball.radius))){
ball->ball.pos.y = LCD_MAX_HEIGHT-ball->ball.radius; ball->ball.pos.y = (LCD_MAX_HEIGHT - (ball->ball.radius+1));
} }
lcd_filled_circle(ball->ball.pos.x, ball->ball.pos.y, ball->ball.radius, ball->ball.color); lcd_filled_circle(ball->ball.pos.x, ball->ball.pos.y, ball->ball.radius, ball->ball.color);
vTaskDelay((portTickType)20/portTICK_RATE_MS); vTaskDelay((portTickType)20/portTICK_RATE_MS);
} }
} }
...@@ -235,23 +260,22 @@ void Algo_bots(void *params){ ...@@ -235,23 +260,22 @@ void Algo_bots(void *params){
ball->ball.pos.y = ball->ball.pos.y + ball->ball.speed.y*(un_ou_moins_un_y); ball->ball.pos.y = ball->ball.pos.y + ball->ball.speed.y*(un_ou_moins_un_y);
un_ou_moins_un_y = 1; un_ou_moins_un_y = 1;
un_ou_moins_un_x = 1; un_ou_moins_un_x = 1;
}
//} if(ball->ball.pos.x <= ball->ball.radius){
if(ball->ball.pos.x <= ball->ball.radius){ ball->ball.pos.x = ball->ball.radius+1;
ball->ball.pos.x = ball->ball.radius+1; }
} if(ball->ball.pos.y <= ball->ball.radius){
if(ball->ball.pos.y <= ball->ball.radius){ ball->ball.pos.y = ball->ball.radius+1;
ball->ball.pos.y = ball->ball.radius+1; }
} if(ball->ball.pos.x >= LCD_MAX_WIDTH-ball->ball.radius){
if(ball->ball.pos.x >= LCD_MAX_WIDTH-ball->ball.radius){ 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){
if(ball->ball.pos.y >= LCD_MAX_HEIGHT-ball->ball.radius){ 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); lcd_filled_circle(ball->ball.pos.x, ball->ball.pos.y, ball->ball.radius, ball->ball.color);
vTaskDelay((portTickType)20/portTICK_RATE_MS); vTaskDelay((portTickType)20/portTICK_RATE_MS);
} }
} }
...@@ -262,10 +286,4 @@ void RandAccel(accel_t *accel){ ...@@ -262,10 +286,4 @@ void RandAccel(accel_t *accel){
float y = (float)(rnd32()%100)-50; float y = (float)(rnd32()%100)-50;
accel->accel_x = x/100; accel->accel_x = x/100;
accel->accel_y = y/100; accel->accel_y = y/100;
//accel->accel_z = (float)(rnd32()%500)/100;
accel->magneto_x = 0;
accel->magneto_y = 0;
accel->magneto_z = 0;
accel->temperature = 0;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment