![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
IMU is outputting garbage value to the terminal
Dependencies: mbed wave_player mbed-rtos 4DGL-uLCD-SE SDFileSystem
missile.cpp@0:3817adfaeb06, 2016-03-15 (annotated)
- Committer:
- michaeljson
- Date:
- Tue Mar 15 19:09:51 2016 +0000
- Revision:
- 0:3817adfaeb06
- Child:
- 1:618aa2c4ca6a
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 "missile.h" |
michaeljson | 0:3817adfaeb06 | 2 | |
michaeljson | 0:3817adfaeb06 | 3 | void draw_missile_object(int blk_x, int blk_y, int missile_color, int m_width, int m_height) |
michaeljson | 0:3817adfaeb06 | 4 | { |
michaeljson | 0:3817adfaeb06 | 5 | uLCD.filled_rectangle(blk_x,blk_y-1,blk_x+m_width,blk_y-m_height,missile_color); |
michaeljson | 0:3817adfaeb06 | 6 | } |
michaeljson | 0:3817adfaeb06 | 7 | |
michaeljson | 0:3817adfaeb06 | 8 | void erase_missile(int blk_x, int blk_y, int m_width, int m_height) |
michaeljson | 0:3817adfaeb06 | 9 | { |
michaeljson | 0:3817adfaeb06 | 10 | uLCD.filled_rectangle(blk_x,blk_y-1,blk_x+m_width,blk_y-m_height,BACKGROUND_COLOR); |
michaeljson | 0:3817adfaeb06 | 11 | } |
michaeljson | 0:3817adfaeb06 | 12 | |
michaeljson | 0:3817adfaeb06 | 13 | void update_missile_pos(missile_t *g) |
michaeljson | 0:3817adfaeb06 | 14 | { |
michaeljson | 0:3817adfaeb06 | 15 | if (g->missile_blk_y < 18) |
michaeljson | 0:3817adfaeb06 | 16 | { |
michaeljson | 0:3817adfaeb06 | 17 | g->status = PLAYER_MISSILE_EXPLODED; |
michaeljson | 0:3817adfaeb06 | 18 | } |
michaeljson | 0:3817adfaeb06 | 19 | |
michaeljson | 0:3817adfaeb06 | 20 | if (g->status == PLAYER_MISSILE_ACTIVE) |
michaeljson | 0:3817adfaeb06 | 21 | { |
michaeljson | 0:3817adfaeb06 | 22 | missile_erase(g); |
michaeljson | 0:3817adfaeb06 | 23 | g->missile_blk_y = g->missile_blk_y-3; |
michaeljson | 0:3817adfaeb06 | 24 | missile_show(g); |
michaeljson | 0:3817adfaeb06 | 25 | } |
michaeljson | 0:3817adfaeb06 | 26 | else if (g->status == PLAYER_MISSILE_EXPLODED) |
michaeljson | 0:3817adfaeb06 | 27 | { |
michaeljson | 0:3817adfaeb06 | 28 | missile_erase(g); |
michaeljson | 0:3817adfaeb06 | 29 | g->status = PLAYER_MISSILE_INACTIVE; |
michaeljson | 0:3817adfaeb06 | 30 | g->missile_blk_y = 109; |
michaeljson | 0:3817adfaeb06 | 31 | } |
michaeljson | 0:3817adfaeb06 | 32 | } |
michaeljson | 0:3817adfaeb06 | 33 | |
michaeljson | 0:3817adfaeb06 | 34 | void update_enemy_missile_pos(missile_t *g) |
michaeljson | 0:3817adfaeb06 | 35 | { |
michaeljson | 0:3817adfaeb06 | 36 | if (g->missile_blk_y > 128) |
michaeljson | 0:3817adfaeb06 | 37 | { |
michaeljson | 0:3817adfaeb06 | 38 | g->status = ENEMY_MISSILE_EXPLODED; |
michaeljson | 0:3817adfaeb06 | 39 | } |
michaeljson | 0:3817adfaeb06 | 40 | |
michaeljson | 0:3817adfaeb06 | 41 | if (g->status == ENEMY_MISSILE_ACTIVE) |
michaeljson | 0:3817adfaeb06 | 42 | { |
michaeljson | 0:3817adfaeb06 | 43 | missile_erase(g); |
michaeljson | 0:3817adfaeb06 | 44 | g->missile_blk_y = g->missile_blk_y+1; |
michaeljson | 0:3817adfaeb06 | 45 | missile_show(g); |
michaeljson | 0:3817adfaeb06 | 46 | } |
michaeljson | 0:3817adfaeb06 | 47 | else if (g->status == ENEMY_MISSILE_EXPLODED) |
michaeljson | 0:3817adfaeb06 | 48 | { |
michaeljson | 0:3817adfaeb06 | 49 | missile_erase(g); |
michaeljson | 0:3817adfaeb06 | 50 | g->status = ENEMY_MISSILE_INACTIVE; |
michaeljson | 0:3817adfaeb06 | 51 | } |
michaeljson | 0:3817adfaeb06 | 52 | } |
michaeljson | 0:3817adfaeb06 | 53 | |
michaeljson | 0:3817adfaeb06 | 54 | void missile_init(missile_t * g, int blk_x, int blk_y, int color) |
michaeljson | 0:3817adfaeb06 | 55 | { |
michaeljson | 0:3817adfaeb06 | 56 | g->missile_blk_x = blk_x; |
michaeljson | 0:3817adfaeb06 | 57 | g->missile_blk_y = blk_y; |
michaeljson | 0:3817adfaeb06 | 58 | g->missile_color = color; |
michaeljson | 0:3817adfaeb06 | 59 | g->missile_width = 1; |
michaeljson | 0:3817adfaeb06 | 60 | g->missile_height = 8; |
michaeljson | 0:3817adfaeb06 | 61 | g->status = PLAYER_MISSILE_INACTIVE; |
michaeljson | 0:3817adfaeb06 | 62 | } |
michaeljson | 0:3817adfaeb06 | 63 | |
michaeljson | 0:3817adfaeb06 | 64 | void enemy_missile_init(missile_t * g, int blk_x, int blk_y, int color) |
michaeljson | 0:3817adfaeb06 | 65 | { |
michaeljson | 0:3817adfaeb06 | 66 | g->missile_blk_x = blk_x; |
michaeljson | 0:3817adfaeb06 | 67 | g->missile_blk_y = blk_y; |
michaeljson | 0:3817adfaeb06 | 68 | g->missile_color = color; |
michaeljson | 0:3817adfaeb06 | 69 | g->missile_width = 1; |
michaeljson | 0:3817adfaeb06 | 70 | g->missile_height = 8; |
michaeljson | 0:3817adfaeb06 | 71 | g->status = ENEMY_MISSILE_INACTIVE; |
michaeljson | 0:3817adfaeb06 | 72 | } |
michaeljson | 0:3817adfaeb06 | 73 | |
michaeljson | 0:3817adfaeb06 | 74 | void missile_show(missile_t * g) |
michaeljson | 0:3817adfaeb06 | 75 | { |
michaeljson | 0:3817adfaeb06 | 76 | draw_missile_object(g->missile_blk_x, g->missile_blk_y, g->missile_color, g->missile_width, g->missile_height); |
michaeljson | 0:3817adfaeb06 | 77 | } |
michaeljson | 0:3817adfaeb06 | 78 | |
michaeljson | 0:3817adfaeb06 | 79 | void missile_erase(missile_t *g) |
michaeljson | 0:3817adfaeb06 | 80 | { |
michaeljson | 0:3817adfaeb06 | 81 | erase_missile(g->missile_blk_x, g->missile_blk_y, g->missile_width, g->missile_height); |
michaeljson | 0:3817adfaeb06 | 82 | } |