Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed wave_player mbed-rtos 4DGL-uLCD-SE SDFileSystem
enemy.cpp
00001 #include "enemy.h" 00002 #include "missile.h" 00003 00004 void draw_enemy(int blk_x, int blk_y, int enemy_color, int e_width, int e_height) 00005 { 00006 uLCD.filled_rectangle(blk_x,blk_y,blk_x+e_width,blk_y-e_height,enemy_color); 00007 } 00008 00009 void erase_enemy(int blk_x, int blk_y, int enemy_color, int e_width, int e_height) 00010 { 00011 uLCD.filled_rectangle(blk_x,blk_y,blk_x+e_width,blk_y-e_height,BACKGROUND_COLOR); 00012 } 00013 00014 int move_enemy(enemy_t * g, int MOVE_DOWN, int DIRECTION) 00015 { 00016 if (g->status == ENEMY_ALIVE) 00017 { 00018 if (DIRECTION == 1) 00019 { 00020 enemy_erase(g); 00021 g->enemy_blk_x += 1; 00022 enemy_show(g); 00023 00024 if (g->enemy_blk_y >= 110) 00025 { 00026 MOVE_DOWN = 2; 00027 } 00028 } 00029 else if (DIRECTION == 2) 00030 { 00031 enemy_erase(g); 00032 g->enemy_blk_x -= 1; 00033 enemy_show(g); 00034 00035 if (g->enemy_blk_y >= 110) 00036 { 00037 MOVE_DOWN = 2; 00038 } 00039 } 00040 00041 if ((g->enemy_blk_x+g->enemy_width) > (128-g->enemy_width) 00042 || (g->enemy_blk_x < (0+g->enemy_width))) 00043 { 00044 MOVE_DOWN = 1; 00045 } 00046 } 00047 return MOVE_DOWN; 00048 } 00049 00050 void enemy_init(enemy_t * g, unsigned int blk_x, unsigned int blk_y, unsigned int color) 00051 { 00052 g->enemy_blk_x = blk_x; 00053 g->enemy_blk_y = blk_y; 00054 g->enemy_color = color; 00055 g->enemy_width = 8; 00056 g->enemy_height = 8; 00057 g->status = ENEMY_ALIVE; 00058 } 00059 00060 void enemy_show(enemy_t * g) 00061 { 00062 draw_enemy(g->enemy_blk_x, g->enemy_blk_y, g->enemy_color, g->enemy_width, g->enemy_height); 00063 } 00064 00065 void enemy_erase(enemy_t * g) 00066 { 00067 erase_enemy(g->enemy_blk_x, g->enemy_blk_y, g->enemy_color, g->enemy_width, g->enemy_height); 00068 } 00069 00070 int check_enemy(enemy_t * g, missile_t * h) 00071 { 00072 int enemy_died = 0; 00073 if (g->status == ENEMY_ALIVE 00074 && ((h->missile_blk_x >= g->enemy_blk_x) && (h->missile_blk_x <= (g->enemy_blk_x + g->enemy_width)))) 00075 { 00076 enemy_erase(g); 00077 g->status = ENEMY_DEAD; 00078 enemy_died = 1; 00079 h->status = PLAYER_MISSILE_EXPLODED; 00080 } 00081 00082 return enemy_died; 00083 }
Generated on Fri Jul 15 2022 11:23:44 by
1.7.2