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
Diff: Gameengine/Gameengine.cpp
- Revision:
- 21:7a7a115d910d
- Parent:
- 20:78bd235f8caa
- Child:
- 23:1ee8686af747
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Gameengine/Gameengine.cpp Wed Apr 03 01:17:38 2019 +0000
@@ -0,0 +1,84 @@
+#include "Gameengine.h"
+
+Gameengine::Gameengine()
+{
+}
+
+Gameengine::~Gameengine()
+{
+}
+
+void Gameengine::game_init()
+{
+ _level_select = 1;
+ _miner.miner_init(3, 33);
+ _lives = 3;
+}
+
+void Gameengine::read_direction(Gamepad &pad)
+{
+ _d = pad.get_direction();
+}
+
+void Gameengine::update(N5110 &lcd, Gamepad &pad)
+{
+ t.start();
+ read_direction(pad);
+ _miner.miner_move(_d, lcd);
+ _miner.miner_gravity(lcd);
+ _miner.miner_jump(lcd, pad);
+ _miner.miner_land(lcd);
+ lose_life(lcd);
+ game_over();
+ next_level(lcd);
+}
+
+void Gameengine::draw(N5110 &lcd, Gamepad &pad)
+{
+ if (_level_select == 1) {
+
+ _miner.miner_draw(lcd);
+ _l1.level_platforms(lcd);
+ _l1.soft_blocks(lcd);
+ _l1.solid_blocks(lcd);
+ _l1.keys(lcd, pad);
+ _l1.keys_collected();
+ _l1.spikes(lcd);
+ }
+ if(_level_select == 2) {
+
+ _miner.miner_draw(lcd);
+ lcd.drawLine(0,47,83,47,1);
+ //printf("level 2 time = %f \n", t.read());
+ }
+}
+
+void Gameengine::lose_life(N5110 &lcd)
+{
+
+ if (_l1.spikes(lcd) == 1) {
+ _lives--;
+ _miner.miner_init(3, 33);
+ wait(0.5);
+ }
+}
+
+bool Gameengine::game_over()
+{
+ if(_lives == 0 || t.read() > 60){
+ t.stop();
+ return true;
+ } else {
+ return false;
+ }
+}
+
+void Gameengine::next_level(N5110 &lcd)
+{
+ if(_l1.level1_exit(lcd) == true){
+ t.stop();
+ _level_select = 2;
+ _miner.miner_init(3,0);
+ printf("Final score is %f \n ",_lives * (60 - t.read())+ (10 * _l1.keys_collected()));
+ }
+}
\ No newline at end of file