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
test
player.cpp@0:3817adfaeb06, 2016-03-15 (annotated)
- Committer:
- michaeljson
- Date:
- Tue Mar 15 19:09:51 2016 +0000
- Revision:
- 0:3817adfaeb06
- Child:
- 20:ede4fa57d082
Upload Mbed Space Invader version 1.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
michaeljson | 0:3817adfaeb06 | 1 | #include "player.h" |
michaeljson | 0:3817adfaeb06 | 2 | #include "missile.h" |
michaeljson | 0:3817adfaeb06 | 3 | |
michaeljson | 0:3817adfaeb06 | 4 | void draw_player_object(int blk_x, int blk_y, int player_color, int p_width, int p_height) |
michaeljson | 0:3817adfaeb06 | 5 | { |
michaeljson | 0:3817adfaeb06 | 6 | uLCD.filled_rectangle(blk_x,blk_y,blk_x+p_width,blk_y+p_height,player_color); |
michaeljson | 0:3817adfaeb06 | 7 | } |
michaeljson | 0:3817adfaeb06 | 8 | |
michaeljson | 0:3817adfaeb06 | 9 | void erase_player(int blk_x, int blk_y, int p_width, int p_height) |
michaeljson | 0:3817adfaeb06 | 10 | { |
michaeljson | 0:3817adfaeb06 | 11 | uLCD.filled_rectangle(blk_x,blk_y,blk_x+p_width,blk_y+p_height,BACKGROUND_COLOR); |
michaeljson | 0:3817adfaeb06 | 12 | } |
michaeljson | 0:3817adfaeb06 | 13 | |
michaeljson | 0:3817adfaeb06 | 14 | void player_init(player_t * g, int blk_x, int blk_y, int color) |
michaeljson | 0:3817adfaeb06 | 15 | { |
michaeljson | 0:3817adfaeb06 | 16 | g->player_blk_x = blk_x; |
michaeljson | 0:3817adfaeb06 | 17 | g->player_blk_y = blk_y; |
michaeljson | 0:3817adfaeb06 | 18 | g->player_color = 0x00FF00; |
michaeljson | 0:3817adfaeb06 | 19 | g->player_height = 8; |
michaeljson | 0:3817adfaeb06 | 20 | g->player_width = 8; |
michaeljson | 0:3817adfaeb06 | 21 | g->status = PLAYER_ALIVE; |
michaeljson | 0:3817adfaeb06 | 22 | } |
michaeljson | 0:3817adfaeb06 | 23 | |
michaeljson | 0:3817adfaeb06 | 24 | void player_show(player_t * g) |
michaeljson | 0:3817adfaeb06 | 25 | { |
michaeljson | 0:3817adfaeb06 | 26 | draw_player_object(g->player_blk_x, g->player_blk_y, g->player_color, g->player_width, g->player_height); |
michaeljson | 0:3817adfaeb06 | 27 | } |
michaeljson | 0:3817adfaeb06 | 28 | |
michaeljson | 0:3817adfaeb06 | 29 | void player_erase(player_t *g) |
michaeljson | 0:3817adfaeb06 | 30 | { |
michaeljson | 0:3817adfaeb06 | 31 | erase_player(g->player_blk_x, g->player_blk_y, g->player_width, g->player_height); |
michaeljson | 0:3817adfaeb06 | 32 | } |
michaeljson | 0:3817adfaeb06 | 33 | |
michaeljson | 0:3817adfaeb06 | 34 | int check_player(player_t * g, missile_t * h) |
michaeljson | 0:3817adfaeb06 | 35 | { |
michaeljson | 0:3817adfaeb06 | 36 | int player_died = 0; |
michaeljson | 0:3817adfaeb06 | 37 | if (g->status == PLAYER_ALIVE |
michaeljson | 0:3817adfaeb06 | 38 | && ((h->missile_blk_x >= g->player_blk_x) && (h->missile_blk_x <= (g->player_blk_x + g->player_width)))) |
michaeljson | 0:3817adfaeb06 | 39 | { |
michaeljson | 0:3817adfaeb06 | 40 | player_erase(g); |
michaeljson | 0:3817adfaeb06 | 41 | g->status = PLAYER_DEAD; |
michaeljson | 0:3817adfaeb06 | 42 | player_died = 1; |
michaeljson | 0:3817adfaeb06 | 43 | h->status = ENEMY_MISSILE_EXPLODED; |
michaeljson | 0:3817adfaeb06 | 44 | } |
michaeljson | 0:3817adfaeb06 | 45 | |
michaeljson | 0:3817adfaeb06 | 46 | return player_died; |
michaeljson | 0:3817adfaeb06 | 47 | } |