Tir secondaire

This commit is contained in:
leo 2021-07-12 13:31:43 +02:00
parent 9b5fb92e86
commit c80d0c4817
3 changed files with 136 additions and 41 deletions

View file

@ -6,6 +6,8 @@ Queue "Queue_J\nchoc joueur" as Queue_J
Queue "Queue_E\nchoc ennemie" as Queue_E
Queue "Queue_F\nfin du jeu" as Queue_F
Queue "Queue_N\nnouveau projectile" as Queue_N
component "Table_ennemis" as table
component "joueur" as J
component t_gm[
Thread : game_master
===
@ -63,4 +65,8 @@ Queue_N --> [t_proj]
[t_gm]..>[t_ennemie] : suspend
[t_gm]..>[t_proj] : suspend
[t_j1] ..> J : ecris
[t_ennemie] ..> table : ecris
[t_proj] ..> J : lis
[t_proj] ..> table : lis
@enduml

View file

@ -77,6 +77,7 @@ osThreadId Joueur_1Handle;
osThreadId Block_EnemieHandle;
osThreadId ProjectileHandle;
osThreadId HUDHandle;
osThreadId chargeurHandle;
osMessageQId Queue_FHandle;
osMessageQId Queue_NHandle;
osMessageQId Queue_JHandle;
@ -107,6 +108,7 @@ void f_Joueur_1(void const *argument);
void f_block_enemie(void const * argument);
void f_projectile(void const * argument);
void f_HUD(void const * argument);
void f_chargeur(void const * argument);
/* USER CODE BEGIN PFP */
uint8_t proba_bernoulli(uint32_t numerateur, uint32_t denominateur);
@ -178,6 +180,22 @@ struct Collision
uint8_t damage;
};
struct Led
{
GPIO_TypeDef* port;
uint16_t pin;
};
struct Led Leds[] = {
{LED18_GPIO_Port, LED18_Pin},
{LED17_GPIO_Port, LED17_Pin},
{LED16_GPIO_Port, LED16_Pin},
{LED15_GPIO_Port, LED15_Pin},
{LED14_GPIO_Port, LED14_Pin},
{LED13_GPIO_Port, LED13_Pin},
{LED12_GPIO_Port, LED12_Pin},
{LED11_GPIO_Port, LED11_Pin}};
// Définition des paramètres du joueurs
struct Joueur joueur = {200, 200, 1, 1, 3, {0, 0, 0, -1, MISSILE_AMI, 1, 1}};
@ -188,6 +206,8 @@ uint32_t LCD_COLOR_BACKGROUND = LCD_COLOR_BLACK;
// Number of waves of enemies before the game is won.
uint8_t wave = 0;
uint8_t kill = 0;
uint8_t charge = 0;
// Tableau des monstres (8 par ligne, sur 3 ligne)
struct Monster Table_ennemis[8][3];
@ -314,6 +334,10 @@ int main(void)
osThreadDef(HUD, f_HUD, osPriorityBelowNormal, 0, 1024);
HUDHandle = osThreadCreate(osThread(HUD), NULL);
/* definition and creation of chargeur */
osThreadDef(chargeur, f_chargeur, osPriorityBelowNormal, 0, 128);
chargeurHandle = osThreadCreate(osThread(chargeur), NULL);
/* USER CODE BEGIN RTOS_THREADS */
vQueueAddToRegistry(Queue_NHandle, "Queue Missile");
vQueueAddToRegistry(Queue_JHandle, "Queue Missile");
@ -404,7 +428,8 @@ void SystemClock_Config(void)
}
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
@ -475,6 +500,7 @@ static void MX_ADC1_Init(void)
/* USER CODE BEGIN ADC1_Init 2 */
/* USER CODE END ADC1_Init 2 */
}
/**
@ -524,6 +550,7 @@ static void MX_ADC3_Init(void)
/* USER CODE BEGIN ADC3_Init 2 */
/* USER CODE END ADC3_Init 2 */
}
/**
@ -554,6 +581,7 @@ static void MX_CRC_Init(void)
/* USER CODE BEGIN CRC_Init 2 */
/* USER CODE END CRC_Init 2 */
}
/**
@ -591,6 +619,7 @@ static void MX_DAC_Init(void)
/* USER CODE BEGIN DAC_Init 2 */
/* USER CODE END DAC_Init 2 */
}
/**
@ -627,6 +656,7 @@ static void MX_DMA2D_Init(void)
/* USER CODE BEGIN DMA2D_Init 2 */
/* USER CODE END DMA2D_Init 2 */
}
/**
@ -688,6 +718,7 @@ static void MX_LTDC_Init(void)
/* USER CODE BEGIN LTDC_Init 2 */
/* USER CODE END LTDC_Init 2 */
}
/**
@ -713,6 +744,7 @@ static void MX_RNG_Init(void)
/* USER CODE BEGIN RNG_Init 2 */
/* USER CODE END RNG_Init 2 */
}
/**
@ -759,6 +791,7 @@ static void MX_TIM1_Init(void)
/* USER CODE BEGIN TIM1_Init 2 */
/* USER CODE END TIM1_Init 2 */
}
/**
@ -803,6 +836,7 @@ static void MX_TIM2_Init(void)
/* USER CODE BEGIN TIM2_Init 2 */
/* USER CODE END TIM2_Init 2 */
}
/**
@ -868,6 +902,7 @@ static void MX_TIM3_Init(void)
/* USER CODE END TIM3_Init 2 */
HAL_TIM_MspPostInit(&htim3);
}
/**
@ -912,6 +947,7 @@ static void MX_TIM5_Init(void)
/* USER CODE BEGIN TIM5_Init 2 */
/* USER CODE END TIM5_Init 2 */
}
/**
@ -990,6 +1026,7 @@ static void MX_TIM8_Init(void)
/* USER CODE END TIM8_Init 2 */
HAL_TIM_MspPostInit(&htim8);
}
/* FMC initialization function */
@ -1080,7 +1117,8 @@ static void MX_GPIO_Init(void)
HAL_GPIO_WritePin(LCD_DISP_GPIO_Port, LCD_DISP_Pin, GPIO_PIN_SET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOH, LED13_Pin | LED17_Pin | LED11_Pin | LED12_Pin | LED2_Pin | LED18_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOH, LED13_Pin|LED17_Pin|LED11_Pin|LED12_Pin
|LED2_Pin|LED18_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(EXT_RST_GPIO_Port, EXT_RST_Pin, GPIO_PIN_RESET);
@ -1101,7 +1139,8 @@ static void MX_GPIO_Init(void)
/*Configure GPIO pins : ULPI_D7_Pin ULPI_D6_Pin ULPI_D5_Pin ULPI_D2_Pin
ULPI_D1_Pin ULPI_D4_Pin */
GPIO_InitStruct.Pin = ULPI_D7_Pin | ULPI_D6_Pin | ULPI_D5_Pin | ULPI_D2_Pin | ULPI_D1_Pin | ULPI_D4_Pin;
GPIO_InitStruct.Pin = ULPI_D7_Pin|ULPI_D6_Pin|ULPI_D5_Pin|ULPI_D2_Pin
|ULPI_D1_Pin|ULPI_D4_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
@ -1190,7 +1229,8 @@ static void MX_GPIO_Init(void)
/*Configure GPIO pins : LED13_Pin LED17_Pin LED11_Pin LED12_Pin
LED2_Pin LED18_Pin */
GPIO_InitStruct.Pin = LED13_Pin | LED17_Pin | LED11_Pin | LED12_Pin | LED2_Pin | LED18_Pin;
GPIO_InitStruct.Pin = LED13_Pin|LED17_Pin|LED11_Pin|LED12_Pin
|LED2_Pin|LED18_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
@ -1286,6 +1326,7 @@ static void MX_GPIO_Init(void)
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
}
/* USER CODE BEGIN 4 */
@ -1455,7 +1496,8 @@ void f_Joueur_1(void const *argument)
struct Missile missile;
uint8_t bouton_relache = 1;
uint8_t bp_1_relache = 1;
uint8_t bp_2_relache = 1;
ADC_ChannelConfTypeDef sConfig3 = {0};
sConfig3.Rank = ADC_REGULAR_RANK_1;
@ -1516,18 +1558,35 @@ void f_Joueur_1(void const *argument)
if (joueur.health <= 0)
xQueueSend(Queue_FHandle, &end, 0);
if ((!HAL_GPIO_ReadPin(BP1_GPIO_Port, BP1_Pin)) && bouton_relache)
if ((!HAL_GPIO_ReadPin(BP1_GPIO_Port, BP1_Pin)) && bp_1_relache)
{
bouton_relache = 0;
bp_1_relache = 0;
missile = joueur.missile;
missile.x = joueur.x + joueur_width / 2;
missile.y = joueur.y;
xQueueSend(Queue_NHandle, &missile, 0);
HAL_GPIO_TogglePin(LED11_GPIO_Port, LED11_Pin);
}
if (HAL_GPIO_ReadPin(BP1_GPIO_Port, BP1_Pin))
bouton_relache = 1;
bp_1_relache = 1;
if ((!HAL_GPIO_ReadPin(BP2_GPIO_Port, BP2_Pin)) && bp_2_relache && (charge == 8))
{
bp_2_relache = 0;
missile = joueur.missile;
missile.x = joueur.x + joueur_width / 2;
missile.y = joueur.y;
for (int idx_tirs = -3; idx_tirs <= 3; idx_tirs++)
{
missile.dy = -3;
missile.dx = idx_tirs;
xQueueSend(Queue_NHandle, &missile, 0);
}
charge = 0;
}
if (HAL_GPIO_ReadPin(BP2_GPIO_Port, BP2_Pin))
bp_2_relache = 1;
vTaskDelayUntil(&xLastWakeTime, xPeriodeTache);
}
@ -1563,6 +1622,8 @@ void f_block_enemie(void const *argument)
while (xQueueReceive(Queue_EHandle, &collision, 0) == pdPASS)
{
Table_ennemis[collision.idx1][collision.idx2].health -= collision.damage;
if (Table_ennemis[collision.idx1][collision.idx2].health <= 0)
kill++;
}
for (int idx1 = 0; idx1 < 8; idx1++)
@ -1741,18 +1802,47 @@ void f_HUD(void const *argument)
TickType_t xLastWakeTime;
xLastWakeTime = xTaskGetTickCount();
const TickType_t xPeriodeTache = 100 / portTICK_PERIOD_MS; // Toutes les 200 ms
uint8_t line_hud[50] = "";
const uint8_t base[50] = "vie : %2u - vague : %2u";
uint8_t line_hud[100] = "";
const uint8_t base[100] = "vie : %2u - vague : %2u - kill : %2u";
/* Infinite loop */
for (;;)
{
sprintf(line_hud, base, (uint)joueur.health, (uint)wave);
sprintf(line_hud, base, (uint)joueur.health, (uint)wave, (uint)kill);
lcd_plot_text_line(0, line_hud, Couleur_missile);
vTaskDelayUntil(&xLastWakeTime, xPeriodeTache);
}
/* USER CODE END f_HUD */
}
/* USER CODE BEGIN Header_f_chargeur */
/**
* @brief Function implementing the chargeur thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_f_chargeur */
void f_chargeur(void const * argument)
{
/* USER CODE BEGIN f_chargeur */
TickType_t xLastWakeTime;
xLastWakeTime = xTaskGetTickCount();
const TickType_t xPeriodeTache = 5000/ 8 / portTICK_PERIOD_MS; // Toutes les 200 ms
/* Infinite loop */
for(;;)
{
if (charge < 8)
{
charge++;
for (int idx = 0; idx<=8; idx++){
HAL_GPIO_WritePin(Leds[idx].port, Leds[idx].pin, !(charge<idx));
}
}
vTaskDelayUntil(&xLastWakeTime, xPeriodeTache);
}
/* USER CODE END f_chargeur */
}
/**
* @brief Period elapsed callback in non blocking mode
* @note This function is called when TIM6 interrupt took place, inside
@ -1766,8 +1856,7 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
/* USER CODE BEGIN Callback 0 */
/* USER CODE END Callback 0 */
if (htim->Instance == TIM6)
{
if (htim->Instance == TIM6) {
HAL_IncTick();
}
/* USER CODE BEGIN Callback 1 */

View file

@ -17,7 +17,7 @@ FREERTOS.INCLUDE_vTaskDelayUntil=1
FREERTOS.IPParameters=Tasks01,configUSE_APPLICATION_TASK_TAG,configUSE_RECURSIVE_MUTEXES,configUSE_COUNTING_SEMAPHORES,configUSE_IDLE_HOOK,configUSE_MALLOC_FAILED_HOOK,configCHECK_FOR_STACK_OVERFLOW,configTOTAL_HEAP_SIZE,FootprintOK,Mutexes01,INCLUDE_vTaskDelayUntil,configENABLE_FPU,Queues01,configRECORD_STACK_HIGH_ADDRESS,configGENERATE_RUN_TIME_STATS
FREERTOS.Mutexes01=MutexLCD,Dynamic,NULL
FREERTOS.Queues01=Queue_F,8,enum End_type,0,Dynamic,NULL,NULL;Queue_N,8,struct Missile,0,Dynamic,NULL,NULL;Queue_J,8,uint8_t,0,Dynamic,NULL,NULL;Queue_E,8,struct Collision,0,Dynamic,NULL,NULL
FREERTOS.Tasks01=GameMaster,2,1024,f_GameMaster,Default,NULL,Dynamic,NULL,NULL;Joueur_1,1,1024,f_Joueur_1,Default,NULL,Dynamic,NULL,NULL;Block_Enemie,-2,1024,f_block_enemie,Default,NULL,Dynamic,NULL,NULL;Projectile,0,1024,f_projectile,Default,NULL,Dynamic,Dynamic,NULL;HUD,-1,1024,f_HUD,Default,NULL,Dynamic,NULL,NULL
FREERTOS.Tasks01=GameMaster,2,1024,f_GameMaster,Default,NULL,Dynamic,NULL,NULL;Joueur_1,1,1024,f_Joueur_1,Default,NULL,Dynamic,NULL,NULL;Block_Enemie,-2,1024,f_block_enemie,Default,NULL,Dynamic,NULL,NULL;Projectile,0,1024,f_projectile,Default,NULL,Dynamic,Dynamic,NULL;HUD,-1,1024,f_HUD,Default,NULL,Dynamic,NULL,NULL;chargeur,-1,128,f_chargeur,Default,NULL,Dynamic,NULL,NULL
FREERTOS.configCHECK_FOR_STACK_OVERFLOW=2
FREERTOS.configENABLE_FPU=1
FREERTOS.configGENERATE_RUN_TIME_STATS=0