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
Parent:
0:c9afe145b57b
First Publish of the code.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Oshyrath 0:c9afe145b57b 1 #include "Player.h"
Oshyrath 1:527a11035e0b 2
Oshyrath 1:527a11035e0b 3 struct Player player;
Oshyrath 1:527a11035e0b 4
Oshyrath 1:527a11035e0b 5 void resetPlayer()
Oshyrath 0:c9afe145b57b 6 {
Oshyrath 1:527a11035e0b 7 player.x_pos = LCD_WIDTH/2-PLAYER_WIDTH/2;
Oshyrath 1:527a11035e0b 8 player.y_pos = LCD_HEIGHT-PLAYER_HEIGHT-HEALTH_BAR_SIZE;
Oshyrath 1:527a11035e0b 9 player.health = PLAYER_STARTING_HEALTH;
Oshyrath 1:527a11035e0b 10 player.rapidFireTimer = 0;
Oshyrath 1:527a11035e0b 11 player.powerShotTimer = 0;
Oshyrath 1:527a11035e0b 12 player.wideShotTimer = 0;
Oshyrath 1:527a11035e0b 13 player.shieldTimer = 0;
Oshyrath 1:527a11035e0b 14 player.gunTimer = 0;
Oshyrath 1:527a11035e0b 15 //player.fastMovementTimer = 0;
Oshyrath 1:527a11035e0b 16 player.RFT_Timer = 0;
Oshyrath 1:527a11035e0b 17 //player.speedFireTimer = 0;
Oshyrath 1:527a11035e0b 18 }
Oshyrath 1:527a11035e0b 19 void movePlayer(int8_t x_dir, int8_t y_dir)
Oshyrath 1:527a11035e0b 20 {
Oshyrath 1:527a11035e0b 21 player.x_pos += PLAYER_VELOCITY * x_dir;
Oshyrath 1:527a11035e0b 22 player.y_pos += PLAYER_VELOCITY * y_dir;
Oshyrath 1:527a11035e0b 23 //}
Oshyrath 0:c9afe145b57b 24 if(player.x_pos<=0)
Oshyrath 0:c9afe145b57b 25 player.x_pos=0;
Oshyrath 0:c9afe145b57b 26 else if(player.x_pos>=LCD_WIDTH-PLAYER_WIDTH)
Oshyrath 0:c9afe145b57b 27 player.x_pos = LCD_WIDTH-PLAYER_WIDTH;
Oshyrath 0:c9afe145b57b 28 if(player.y_pos<=0)
Oshyrath 0:c9afe145b57b 29 player.y_pos = 0;
Oshyrath 1:527a11035e0b 30 else if(player.y_pos>=LCD_HEIGHT-PLAYER_HEIGHT-HEALTH_BAR_SIZE)
Oshyrath 1:527a11035e0b 31 player.y_pos = LCD_HEIGHT-PLAYER_HEIGHT-HEALTH_BAR_SIZE;
Oshyrath 0:c9afe145b57b 32 }
Oshyrath 0:c9afe145b57b 33 void updatePlayerTimers()
Oshyrath 0:c9afe145b57b 34 {
Oshyrath 0:c9afe145b57b 35 player.rapidFireTimer = player.rapidFireTimer ? player.rapidFireTimer-1 : 0;
Oshyrath 0:c9afe145b57b 36 player.powerShotTimer = player.powerShotTimer ? player.powerShotTimer-1 : 0;
Oshyrath 0:c9afe145b57b 37 player.wideShotTimer = player.wideShotTimer ? player.wideShotTimer-1 : 0;
Oshyrath 0:c9afe145b57b 38 player.shieldTimer = player.shieldTimer ? player.shieldTimer-1 : 0;
Oshyrath 0:c9afe145b57b 39 player.gunTimer = player.gunTimer ? player.gunTimer-1 : 0;
Oshyrath 1:527a11035e0b 40 //player.fastMovementTimer = player.fastMovementTimer ? player.fastMovementTimer-1 : 0;
Oshyrath 1:527a11035e0b 41 //player.speedFireTimer = player.speedFireTimer ? player.speedFireTimer-1 : 0;
Oshyrath 1:527a11035e0b 42 player.RFT_Timer = player.RFT_Timer ? player.RFT_Timer-1 : RFT_PERIOD;
Oshyrath 1:527a11035e0b 43 }
Oshyrath 1:527a11035e0b 44 int16_t getPlayerBulletPos(int8_t XorY)
Oshyrath 1:527a11035e0b 45 {
Oshyrath 1:527a11035e0b 46 if(XorY)
Oshyrath 1:527a11035e0b 47 return player.x_pos+PLAYER_WIDTH/2-BULLET_SIZE/2;
Oshyrath 1:527a11035e0b 48 return player.y_pos-BULLET_SIZE/2;
Oshyrath 1:527a11035e0b 49 }
Oshyrath 1:527a11035e0b 50 int8_t dealDamageToPlayer()
Oshyrath 1:527a11035e0b 51 {
Oshyrath 1:527a11035e0b 52 if(player.shieldTimer)
Oshyrath 1:527a11035e0b 53 return 0;
Oshyrath 1:527a11035e0b 54 player.health--;
Oshyrath 1:527a11035e0b 55 return !(player.health) ? 1 : 0;
Oshyrath 1:527a11035e0b 56 }
Oshyrath 1:527a11035e0b 57 int8_t shouldFire(int8_t didUserRequestFire)
Oshyrath 1:527a11035e0b 58 {
Oshyrath 1:527a11035e0b 59 if(player.rapidFireTimer)
Oshyrath 1:527a11035e0b 60 {
Oshyrath 1:527a11035e0b 61 return !player.RFT_Timer ? 1 : 0;
Oshyrath 1:527a11035e0b 62 }
Oshyrath 1:527a11035e0b 63 return !player.gunTimer && didUserRequestFire ? 1 : 0;
Oshyrath 1:527a11035e0b 64 }
Oshyrath 1:527a11035e0b 65 void callMultiFuncPlayer()
Oshyrath 1:527a11035e0b 66 {
Oshyrath 1:527a11035e0b 67 updatePlayerTimers();
Oshyrath 1:527a11035e0b 68 }
Oshyrath 1:527a11035e0b 69 /*
Oshyrath 1:527a11035e0b 70 int8_t callMultiFuncPlayer(int8_t x_dir, int8_t y_dir, int8_t didUserRequestFire)
Oshyrath 1:527a11035e0b 71 {
Oshyrath 1:527a11035e0b 72 movePlayer(x_dir,y_dir);
Oshyrath 1:527a11035e0b 73 updatePlayerTimers();
Oshyrath 1:527a11035e0b 74 return shouldFire(didUserRequestFire);
Oshyrath 1:527a11035e0b 75 }*/