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
Fork of el17dg by
Diff: game/game.cpp
- Revision:
- 6:100b46be4bea
- Parent:
- 5:2b9181bc5c89
- Child:
- 7:42376925945c
--- a/game/game.cpp Mon Mar 04 20:15:55 2019 +0000
+++ b/game/game.cpp Tue Mar 05 15:01:53 2019 +0000
@@ -13,14 +13,27 @@
int x_ship_pos = 0;
int y_ship_pos = 24;
+int fire_shot_time_counter = 0;
+int shot_step_counter = 0;
+int fire_shot_traveled = 0;
+
const int ship_step_incremetion = 2;
+bool is_fire_shot = false;
+
bool Game::updateAndDraw() {
+
+ shipMovment();
+ if (gamepad.check_event(gamepad.B_PRESSED)){
+ is_fire_shot = true;
+ }
+ if (is_fire_shot){
+ shipFire();
+ }
- shipMovment();
lcd.drawSprite(x_ship_pos, y_ship_pos, spaceship1_width, spaceship1_height, spaceShip1);
-
+ printf("%i\n", fire_shot_traveled);
/*char buffer[4];
sprintf(buffer,"%i\n",(int)(x_dir.read()*84));
printf(buffer);*/
@@ -62,12 +75,29 @@
}
-void Game::shipFire(){
- //if (gamepad.check_event(gamepad.B_PRESSED){
+void Game::shipFire(){ //IMPROVE OR SIMPLIFY
+ if (fire_shot_time_counter == 0){
+ lcd.drawSprite((x_ship_pos + spaceship1_width), (y_ship_pos + spaceship1_height/2), 1, 6, simpleLaserShot);
+
+ }
+ else if (fire_shot_time_counter == 2){
+ shot_step_counter += 3;
+ fire_shot_traveled = (x_ship_pos + spaceship1_width) + shot_step_counter;
- //}
+ lcd.drawSprite((x_ship_pos + spaceship1_width), (y_ship_pos + spaceship1_height/2), 1, 3, simpleLaserShotDissapear);
+ lcd.drawSprite(fire_shot_traveled, (y_ship_pos + spaceship1_height/2), 1, 3, simpleLaserShot);
+ fire_shot_time_counter = 0;
+ }
+ fire_shot_time_counter += 1;
-
+ if ( fire_shot_traveled > 84){
+ fire_shot_time_counter = 0;
+ shot_step_counter = 0;
+ fire_shot_traveled = 0;
+ is_fire_shot = !is_fire_shot;
+ return;
+ }
+
}
