Updated Space Invaders on the mbed. Improved upon Michael Son's "Mbed Space Invaders" at https://os.mbed.com/users/michaeljson/notebook/mbed-space-invaders/.

Dependencies:   mbed wave_player mbed-rtos 4DGL-uLCD-SE SparkfunAnalogJoystick SDFileSystem LSM9DS1_Library_cal_updated

Fork of Two-PlayerSpaceInvaders by William Minix

test

Committer:
wminix3
Date:
Sun Apr 25 03:13:50 2021 +0000
Revision:
20:ede4fa57d082
Parent:
0:3817adfaeb06
Child:
21:a6b4c5598083
Improved analog click skin changes, add victory music, added victory LED lighting effect;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
michaeljson 0:3817adfaeb06 1 #include "player.h"
michaeljson 0:3817adfaeb06 2 #include "missile.h"
michaeljson 0:3817adfaeb06 3
wminix3 20:ede4fa57d082 4 #define GREEN 0x00FF00
wminix3 20:ede4fa57d082 5 #define BLUE 0x0000FF
wminix3 20:ede4fa57d082 6 #define PINK 0xFFC0CB
wminix3 20:ede4fa57d082 7 #define YELLOW 0xFFFF00
wminix3 20:ede4fa57d082 8 #define BROWN 0xD2691E
wminix3 20:ede4fa57d082 9 #define DIRT BROWN
wminix3 20:ede4fa57d082 10 void draw_img(int u, int v, const char* img)
wminix3 20:ede4fa57d082 11 {
wminix3 20:ede4fa57d082 12 int colors[11*11];
wminix3 20:ede4fa57d082 13 for (int i = 0; i < 11*11; i++)
wminix3 20:ede4fa57d082 14 {
wminix3 20:ede4fa57d082 15 if (img[i] == 'R') colors[i] = RED;
wminix3 20:ede4fa57d082 16 else if (img[i] == 'Y') colors[i] = YELLOW;
wminix3 20:ede4fa57d082 17 else if (img[i] == 'G') colors[i] = GREEN;
wminix3 20:ede4fa57d082 18 else if (img[i] == 'D') colors[i] = DIRT;
wminix3 20:ede4fa57d082 19 else if (img[i] == '5') colors[i] = LGREY;
wminix3 20:ede4fa57d082 20 else if (img[i] == '3') colors[i] = DGREY;
wminix3 20:ede4fa57d082 21 else if (img[i] == 'W') colors[i] = WHITE;
wminix3 20:ede4fa57d082 22 else if (img[i] == 'U') colors[i] = BLUE;
wminix3 20:ede4fa57d082 23 else colors[i] = BLACK;
wminix3 20:ede4fa57d082 24 }
wminix3 20:ede4fa57d082 25 uLCD.BLIT(u, v, 11, 11, colors);
wminix3 20:ede4fa57d082 26 wait_us(250); // Recovery time!
wminix3 20:ede4fa57d082 27 }
wminix3 20:ede4fa57d082 28
michaeljson 0:3817adfaeb06 29 void draw_player_object(int blk_x, int blk_y, int player_color, int p_width, int p_height)
michaeljson 0:3817adfaeb06 30 {
wminix3 20:ede4fa57d082 31 //uLCD.filled_rectangle(blk_x,blk_y,blk_x+p_width,blk_y+p_height,player_color);
wminix3 20:ede4fa57d082 32 const int* colors = [
wminix3 20:ede4fa57d082 33 uLCD.BLIT(blk_x, blk_y, e_width, e_height,
michaeljson 0:3817adfaeb06 34 }
michaeljson 0:3817adfaeb06 35
michaeljson 0:3817adfaeb06 36 void erase_player(int blk_x, int blk_y, int p_width, int p_height)
michaeljson 0:3817adfaeb06 37 {
michaeljson 0:3817adfaeb06 38 uLCD.filled_rectangle(blk_x,blk_y,blk_x+p_width,blk_y+p_height,BACKGROUND_COLOR);
michaeljson 0:3817adfaeb06 39 }
michaeljson 0:3817adfaeb06 40
michaeljson 0:3817adfaeb06 41 void player_init(player_t * g, int blk_x, int blk_y, int color)
michaeljson 0:3817adfaeb06 42 {
michaeljson 0:3817adfaeb06 43 g->player_blk_x = blk_x;
michaeljson 0:3817adfaeb06 44 g->player_blk_y = blk_y;
michaeljson 0:3817adfaeb06 45 g->player_color = 0x00FF00;
michaeljson 0:3817adfaeb06 46 g->player_height = 8;
michaeljson 0:3817adfaeb06 47 g->player_width = 8;
michaeljson 0:3817adfaeb06 48 g->status = PLAYER_ALIVE;
michaeljson 0:3817adfaeb06 49 }
michaeljson 0:3817adfaeb06 50
michaeljson 0:3817adfaeb06 51 void player_show(player_t * g)
michaeljson 0:3817adfaeb06 52 {
michaeljson 0:3817adfaeb06 53 draw_player_object(g->player_blk_x, g->player_blk_y, g->player_color, g->player_width, g->player_height);
michaeljson 0:3817adfaeb06 54 }
michaeljson 0:3817adfaeb06 55
michaeljson 0:3817adfaeb06 56 void player_erase(player_t *g)
michaeljson 0:3817adfaeb06 57 {
michaeljson 0:3817adfaeb06 58 erase_player(g->player_blk_x, g->player_blk_y, g->player_width, g->player_height);
michaeljson 0:3817adfaeb06 59 }
michaeljson 0:3817adfaeb06 60
michaeljson 0:3817adfaeb06 61 int check_player(player_t * g, missile_t * h)
michaeljson 0:3817adfaeb06 62 {
michaeljson 0:3817adfaeb06 63 int player_died = 0;
michaeljson 0:3817adfaeb06 64 if (g->status == PLAYER_ALIVE
michaeljson 0:3817adfaeb06 65 && ((h->missile_blk_x >= g->player_blk_x) && (h->missile_blk_x <= (g->player_blk_x + g->player_width))))
michaeljson 0:3817adfaeb06 66 {
michaeljson 0:3817adfaeb06 67 player_erase(g);
michaeljson 0:3817adfaeb06 68 g->status = PLAYER_DEAD;
michaeljson 0:3817adfaeb06 69 player_died = 1;
michaeljson 0:3817adfaeb06 70 h->status = ENEMY_MISSILE_EXPLODED;
michaeljson 0:3817adfaeb06 71 }
michaeljson 0:3817adfaeb06 72
michaeljson 0:3817adfaeb06 73 return player_died;
michaeljson 0:3817adfaeb06 74 }