This code contains the game Starship designed for the STM32F429i-DISC1 board. It requires a keyboard to play.

Dependencies:   Starship LCD_DISCO_F429ZI USBHost mbed

Dependents:   Starship

Committer:
Oshyrath
Date:
Fri Nov 17 02:23:33 2017 +0000
Revision:
1:527a11035e0b
First Publish of the code.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Oshyrath 1:527a11035e0b 1 #include "PowerUp.h"
Oshyrath 1:527a11035e0b 2
Oshyrath 1:527a11035e0b 3 struct PowerUp * powerUpPTR;
Oshyrath 1:527a11035e0b 4 int16_t powerUpCount;
Oshyrath 1:527a11035e0b 5
Oshyrath 1:527a11035e0b 6 enum PowerUpType getRandomType()//fix!!!
Oshyrath 1:527a11035e0b 7 {
Oshyrath 1:527a11035e0b 8 int randVal = randomInt(0,NUMBER_OF_POWER_UPS_TYPES-1);
Oshyrath 1:527a11035e0b 9 switch(randVal)
Oshyrath 1:527a11035e0b 10 {
Oshyrath 1:527a11035e0b 11 case 0: return PU_RapidFire;
Oshyrath 1:527a11035e0b 12 case 1: return PU_PowerShot;
Oshyrath 1:527a11035e0b 13 case 2: return PU_FreezeEnemies;
Oshyrath 1:527a11035e0b 14 case 3: return PU_WideShot;
Oshyrath 1:527a11035e0b 15 case 4: return PU_Explosion;
Oshyrath 1:527a11035e0b 16 case 5: return PU_BonusHealth;
Oshyrath 1:527a11035e0b 17 case 6: return PU_Shield;
Oshyrath 1:527a11035e0b 18 }
Oshyrath 1:527a11035e0b 19 return PU_BonusHealth;
Oshyrath 1:527a11035e0b 20 }
Oshyrath 1:527a11035e0b 21 void addPowerUp(int16_t x_pos, int16_t y_pos)
Oshyrath 1:527a11035e0b 22 {
Oshyrath 1:527a11035e0b 23 struct PowerUp * newPowerUp = (struct PowerUp *) malloc(sizeof(struct PowerUp));
Oshyrath 1:527a11035e0b 24 newPowerUp->x_pos = x_pos;
Oshyrath 1:527a11035e0b 25 newPowerUp->y_pos = y_pos;
Oshyrath 1:527a11035e0b 26 newPowerUp->type = getRandomType();
Oshyrath 1:527a11035e0b 27 newPowerUp->expirationTimer = POWER_UP_EXPERATION_TIME;
Oshyrath 1:527a11035e0b 28 powerUpCount++;
Oshyrath 1:527a11035e0b 29 if(powerUpCount==1)
Oshyrath 1:527a11035e0b 30 {
Oshyrath 1:527a11035e0b 31 newPowerUp->prev = newPowerUp;
Oshyrath 1:527a11035e0b 32 newPowerUp->next = newPowerUp;
Oshyrath 1:527a11035e0b 33 powerUpPTR = newPowerUp;
Oshyrath 1:527a11035e0b 34 return;
Oshyrath 1:527a11035e0b 35 }
Oshyrath 1:527a11035e0b 36 struct PowerUp * tempNext = powerUpPTR->next;
Oshyrath 1:527a11035e0b 37 powerUpPTR->next = newPowerUp;
Oshyrath 1:527a11035e0b 38 newPowerUp->prev = powerUpPTR;
Oshyrath 1:527a11035e0b 39 tempNext->prev = newPowerUp;
Oshyrath 1:527a11035e0b 40 newPowerUp->next = tempNext;
Oshyrath 1:527a11035e0b 41 }
Oshyrath 1:527a11035e0b 42
Oshyrath 1:527a11035e0b 43 void removePowerUp(struct PowerUp * removePTR)
Oshyrath 1:527a11035e0b 44 {
Oshyrath 1:527a11035e0b 45 if(powerUpCount<=0)
Oshyrath 1:527a11035e0b 46 return;
Oshyrath 1:527a11035e0b 47 powerUpCount--;
Oshyrath 1:527a11035e0b 48 if(powerUpCount == 0)
Oshyrath 1:527a11035e0b 49 powerUpPTR = (struct PowerUp *) 0;
Oshyrath 1:527a11035e0b 50 else
Oshyrath 1:527a11035e0b 51 {
Oshyrath 1:527a11035e0b 52 powerUpPTR = removePTR->prev;
Oshyrath 1:527a11035e0b 53 struct PowerUp * tempNext = removePTR->next;
Oshyrath 1:527a11035e0b 54 powerUpPTR->next = tempNext;
Oshyrath 1:527a11035e0b 55 tempNext->prev = powerUpPTR;
Oshyrath 1:527a11035e0b 56 }
Oshyrath 1:527a11035e0b 57 free(removePTR);
Oshyrath 1:527a11035e0b 58 }
Oshyrath 1:527a11035e0b 59 void clearPowerUps()
Oshyrath 1:527a11035e0b 60 {
Oshyrath 1:527a11035e0b 61 while(powerUpCount)
Oshyrath 1:527a11035e0b 62 removePowerUp(powerUpPTR);
Oshyrath 1:527a11035e0b 63 }
Oshyrath 1:527a11035e0b 64 void updatePowerUpTimer(struct PowerUp * powerUp)
Oshyrath 1:527a11035e0b 65 {
Oshyrath 1:527a11035e0b 66 powerUp->expirationTimer = powerUp->expirationTimer ? (powerUp->expirationTimer - 1) : 0;
Oshyrath 1:527a11035e0b 67 }
Oshyrath 1:527a11035e0b 68 void updatePowerUpTimer_All()
Oshyrath 1:527a11035e0b 69 {
Oshyrath 1:527a11035e0b 70 int i;
Oshyrath 1:527a11035e0b 71 for(i = powerUpCount; i; i--)
Oshyrath 1:527a11035e0b 72 {
Oshyrath 1:527a11035e0b 73 updatePowerUpTimer(powerUpPTR);
Oshyrath 1:527a11035e0b 74 powerUpPTR = powerUpPTR->next;
Oshyrath 1:527a11035e0b 75 }
Oshyrath 1:527a11035e0b 76 }
Oshyrath 1:527a11035e0b 77 void removePowerUpIfExpired(struct PowerUp * powerUp)
Oshyrath 1:527a11035e0b 78 {
Oshyrath 1:527a11035e0b 79 if(!(powerUp->expirationTimer))
Oshyrath 1:527a11035e0b 80 removePowerUp(powerUp);
Oshyrath 1:527a11035e0b 81 }
Oshyrath 1:527a11035e0b 82 void removePowerUpIfExpired_All()
Oshyrath 1:527a11035e0b 83 {
Oshyrath 1:527a11035e0b 84 int i;
Oshyrath 1:527a11035e0b 85 for(i = powerUpCount; i; i--)
Oshyrath 1:527a11035e0b 86 {
Oshyrath 1:527a11035e0b 87 powerUpPTR = powerUpPTR->next;
Oshyrath 1:527a11035e0b 88 removePowerUpIfExpired(powerUpPTR);
Oshyrath 1:527a11035e0b 89 }
Oshyrath 1:527a11035e0b 90 }
Oshyrath 1:527a11035e0b 91 void callMultiFuncPowerUp()
Oshyrath 1:527a11035e0b 92 {
Oshyrath 1:527a11035e0b 93 removePowerUpIfExpired_All();
Oshyrath 1:527a11035e0b 94 updatePowerUpTimer_All();
Oshyrath 1:527a11035e0b 95 }