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.
Diff: main.cpp
- Revision:
- 9:e6832bf222b7
- Parent:
- 8:421f94b816c4
- Child:
- 10:28575a6eaa13
--- a/main.cpp Tue May 07 16:02:12 2019 +0000
+++ b/main.cpp Tue May 07 17:40:29 2019 +0000
@@ -17,43 +17,17 @@
Options opt;
Donkey dky;
GameEngine eng;
-Barrel barrel;
int fps = 24;
int direction;
int menu_option_pos = 0;
int arrow_pos = 0;
-// Game State--------------------------------------------------------------
-
-GameEngine::GameEngine()
-{
-
-}
-
-GameEngine::~GameEngine()
-{
-
-}
-
-void GameEngine::gameengine_run(Gamepad &pad, N5110 &lcd) {
- wait_ms(250);
-
- while (pad.check_event(Gamepad::BACK_PRESSED) == false) {
- //printf("Game State");
- lcd.clear();
- lcd.printString("Game",0,0);
- dky.donkeykong_movement(pad, lcd);
- barrel.barrel_drop(pad, lcd);
- wait_ms(1.0f/fps);
- }
-}
-
// Donkey -----------
int donkeykong_x = 0;
int donkeykong_y = 32;
-int donkey_kong_speed = 25;
+int donkey_kong_speed = 10;
Donkey::Donkey()
{
@@ -69,16 +43,15 @@
if (direction == NE || direction == E || direction == SE) {
donkeykong_x = donkeykong_x + 1;
lcd.drawSprite(donkeykong_x,donkeykong_y,16,16,(int *)game_dk_walking_right_1);
- wait_ms(donkey_kong_speed);
}
else if (direction == NW || direction == W || direction == SW) {
donkeykong_x = donkeykong_x - 1;
lcd.drawSprite(donkeykong_x,donkeykong_y,16,16,(int *)game_dk_walking_left_1);
- wait_ms(donkey_kong_speed);
}
else {
lcd.drawSprite(donkeykong_x,donkeykong_y,16,16,(int *)game_dk_stationary);
}
+ wait_ms(donkey_kong_speed);
lcd.refresh();
if (donkeykong_x > 68) {
donkeykong_x = 68;
@@ -88,11 +61,12 @@
}
}
// Barrel -----------
-int barrel_x = 0;
+int barrel_x = 30;
int barrel_y = 0;
int barrel_speed = 0;
int barrel_min = 0;
int barrel_max = 76;
+float barrel_time = 0;
Barrel::Barrel()
{
@@ -105,12 +79,50 @@
}
void Barrel::barrel_drop(Gamepad &pad, N5110 &lcd) {
- barrel_x = rand() % (barrel_max + 1 - barrel_min) + barrel_min;
lcd.drawSprite(barrel_x,barrel_y,4,8,(int *)game_barrel);
lcd.refresh();
+ wait_ms(50);
+ barrel_y = barrel_y + 1 + barrel_time;
+ if (barrel_y > 44) {
+ barrel_y = 0;
+ barrel_x = rand() % (barrel_max + 1 - barrel_min) + barrel_min;
+ barrel_time = barrel_time + 0.1;
+ }
+}
+
+
+// Banana -----------
+
+
+// Game State--------------------------------------------------------------
+
+GameEngine::GameEngine()
+{
+
}
-// Banana -----------
+GameEngine::~GameEngine()
+{
+
+}
+
+void GameEngine::gameengine_run(Gamepad &pad, N5110 &lcd, Barrel &barrel) {
+ wait_ms(250);
+
+ while (pad.check_event(Gamepad::BACK_PRESSED) == false) {
+ //printf("Game State");
+ lcd.clear();
+ lcd.printString("Game",0,0);
+ dky.donkeykong_movement(pad, lcd);
+ barrel.barrel_drop(pad, lcd);
+ if ((barrel_y >= 34) & ((barrel_x + 7) >= donkeykong_x) & (barrel_x <= (donkeykong_x + 15))) {
+ lcd.clear();
+ lcd.printString("OVER",0,0);
+ wait_ms(1000);
+ }
+ wait_ms(1.0f/fps);
+ }
+}
// Controls State----------------------------------------------------------
void controls_run() {
@@ -264,7 +276,7 @@
if (pad.check_event(Gamepad::A_PRESSED) == true) {
if (menu_option_pos == 0) {
// printf("GameEngine");
- eng.gameengine_run(pad, lcd);
+ eng.gameengine_run(pad, lcd, barrel);
}
if (menu_option_pos == 1) {
// printf("Controls");