Space Invaders - Embedded Systems Project 15/16 - Avinash Patel 200860407
Dependencies: Joystick N5110 SDFileSystem mbed
Diff: main.cpp
- Revision:
- 3:544b59d60ab8
- Parent:
- 2:d34c95990605
- Child:
- 4:a99953ef9e42
--- a/main.cpp Sun Mar 27 17:30:13 2016 +0000 +++ b/main.cpp Sun Mar 27 18:47:07 2016 +0000 @@ -377,13 +377,16 @@ if (g_shoot_pressed_flag) { g_shoot_pressed_flag = false; - pc.printf("Shot Fired\n"); + if (!cannon_shot_on_screen) { + cannon_shot_on_screen = true; + + pc.printf("Shot Fired\n"); - //Add 4 to cannon x_pos to get shot x_pos - cannon_shot_x_pos = cannon_xpos + 4; - cannon_shot_y_pos = 40; - cannon_shot_on_screen = true; - move_cannon_shot.attach(&move_cannon_shot_isr, 0.1); + //Add 4 to cannon x_pos to get shot x_pos + cannon_shot_x_pos = cannon_xpos + 4; + cannon_shot_y_pos = 40; + move_cannon_shot.attach(&move_cannon_shot_isr, 0.1); + } } //Move the cannon's shot if (g_move_cannon_shot_flag) { @@ -391,7 +394,7 @@ //Checks bullet will not go beyond the bounds of the screen map if (cannon_shot_y_pos > -1) { - //Loops throught the shot bitmap and sets the pixels in the screen map + //Loops throught the shot bitmap and clears the pixels in the screen map for (int row = 0; row < 3; row++) { //Clears the position where the bullet was screen_map[cannon_shot_x_pos][cannon_shot_y_pos + row] = EMPTY; @@ -400,37 +403,45 @@ //Increments the shot going up the screen cannon_shot_y_pos--; + //Checks to see what the shot hits. If it hits nothing the shot gets pushed to the screen map for (int row = 0; row < 3; row++) { - switch (screen_map[cannon_shot_x_pos][cannon_shot_y_pos + row]) { - case SMALL: - pc.printf("Small Hit\n"); - cannon_shot_on_screen = false; - move_cannon_shot.detach(); - break; - case MEDIUM: - pc.printf("Medium Hit\n"); - cannon_shot_on_screen = false; - move_cannon_shot.detach(); - break; - case LARGE: - pc.printf("Large Hit\n"); - cannon_shot_on_screen = false; - move_cannon_shot.detach(); - break; - case BARRIER: - pc.printf("Barrier Hit\n"); - cannon_shot_on_screen = false; - move_cannon_shot.detach(); - break; - case UFO: - pc.printf("UFO Hit\n"); - cannon_shot_on_screen = false; - move_cannon_shot.detach(); - break; - default: - screen_map[cannon_shot_x_pos][cannon_shot_y_pos + row] = CANNON_SHOT; + if (screen_map[cannon_shot_x_pos][cannon_shot_y_pos + row] == SMALL) + { + pc.printf("Small Hit\n"); + cannon_shot_on_screen = false; + move_cannon_shot.detach(); + break; + } else if (screen_map[cannon_shot_x_pos][cannon_shot_y_pos + row] == MEDIUM) { + pc.printf("Medium Hit\n"); + cannon_shot_on_screen = false; + move_cannon_shot.detach(); + break; + } else if (screen_map[cannon_shot_x_pos][cannon_shot_y_pos + row] == LARGE) { + pc.printf("Large Hit\n"); + cannon_shot_on_screen = false; + move_cannon_shot.detach(); + break; + } else if (screen_map[cannon_shot_x_pos][cannon_shot_y_pos + row] == BARRIER) { + pc.printf("Barrier Hit\n"); + cannon_shot_on_screen = false; + move_cannon_shot.detach(); + break; + } else if (screen_map[cannon_shot_x_pos][cannon_shot_y_pos + row] == UFO) { + pc.printf("UFO Hit\n"); + cannon_shot_on_screen = false; + move_cannon_shot.detach(); + break; + } else { + screen_map[cannon_shot_x_pos][cannon_shot_y_pos + row] = CANNON_SHOT; } + } + } else { + //Loops throught the shot bitmap and clears the pixels in the screen map + for (int row = 1; row < 3; row++) { + //Clears the position where the bullet was + screen_map[cannon_shot_x_pos][cannon_shot_y_pos + row] = EMPTY; } + cannon_shot_on_screen = false; } } }