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: MinerEngine/MinerEngine.cpp
- Revision:
- 8:c5969685cf02
- Parent:
- 7:5bb5cde8951a
- Child:
- 9:9a30f26fed81
diff -r 5bb5cde8951a -r c5969685cf02 MinerEngine/MinerEngine.cpp
--- a/MinerEngine/MinerEngine.cpp Sun Apr 26 07:30:22 2020 +0000
+++ b/MinerEngine/MinerEngine.cpp Sun Apr 26 13:17:27 2020 +0000
@@ -195,12 +195,14 @@
}
void MinerEngine::game_run(Gamepad &pad, N5110 &lcd) {
- while(1) {
+ _monster_collision=0;
+ while(_monster_collision==0) {
+ lcd.clear();
read_input(pad);
- claw_down(pad);//get _d &_mag
update(pad);
draw(lcd);
lcd.refresh();
+
}
}
/////////////
@@ -231,41 +233,53 @@
// print to LCD
char buffer1[14];
sprintf(buffer1,"%2d",_now_score);
- lcd.printString(buffer1,WIDTH/2 - 20,1); // font is 8 wide, so leave 4 pixel gape from middle assuming two digits
+ lcd.printString(buffer1,1,0); // font is 8 wide, so leave 4 pixel gape from middle assuming two digits
char buffer2[14];
sprintf(buffer2,"%2d",_highest_score);
- lcd.printString(buffer2,WIDTH/2 + 4,1);
+ lcd.printString(buffer2,WIDTH-13,0);
}
void MinerEngine::read_input(Gamepad &pad)
{
_d = pad.get_direction();
_mag = pad.get_mag();
+ if (pad.check_event(Gamepad::A_PRESSED) == true){
+ _catching=1;
+ _claw.set_velocity(1.0);
+ }
}
void MinerEngine::draw(N5110 &lcd)
{
// draw the elements in the LCD buffer
// pitch
+
lcd.drawRect(0,0,WIDTH,HEIGHT,FILL_TRANSPARENT);
//horizontal line
lcd.drawLine(0,13,WIDTH,13,1);
-
+ lcd.drawLine(0,0,WIDTH,0,0);
print_scores(lcd);
-
+
_winch.draw(lcd);
_claw.draw(lcd);
_gold.draw(lcd);
_monster.draw(lcd);
+
+
}
void MinerEngine::update(Gamepad &pad)
{
- _winch.update(_d,_mag);
- _claw.update(_d,_mag);
+ //if (_catching==0) {
+ _winch.update(_d,_mag);
+ // }
+ Vector2D winch_pos = _winch.get_pos();
+ _claw.update(_d,_mag,winch_pos);
+ wait(0.05);
+
_monster.update();
_gold.update();
-
+
check_monster_collision(pad);
check_claw_collision(pad);
check_gold_collision(pad);
@@ -289,41 +303,34 @@
void MinerEngine::check_claw_collision(Gamepad &pad)
{
- // read current claw attributes
- Vector2D claw_pos = _claw.get_pos();
+ Vector2D claw_pos = _claw.get_pos();// read current claw attributes
-
for (int i=0;i<9;i++) {
Vector2D gold_pos = _gold.get_pos(i);
if ((claw_pos.x+3)-gold_pos.x<5&&
(claw_pos.x+3)-gold_pos.x>-5&&
(claw_pos.y+3)-gold_pos.y>-2) {
-
_claw_get=1;
_gold.gold_caught(i);
- pad.tone(1000.0,0.1); // audio feedback
- }
+ pad.tone(1000.0,0.1); }// audio feedback
}
-}
-
-void MinerEngine::claw_down(Gamepad &pad){
- while( pad.check_event(Gamepad::A_PRESSED) == true) {
- _catching = 1;
- _claw.set_velocity(1);
- Vector2D claw_pos = _claw.get_pos();
-
- if (claw_pos.y>HEIGHT-4||_claw_get==1) {
+ if (claw_pos.y>HEIGHT-4||_claw_get==1) {
_claw_get=0;
- _claw.set_velocity(-1);
+ _claw.set_velocity(-1.0);
}
if (claw_pos.y<=14) {
- _claw.set_velocity(0);
+ _claw.set_velocity(0.0);
_catching = 0;
}
- }
}
+//void MinerEngine::claw_down(Gamepad &pad){
+
+
+
+//}
+
/////////////////////////////////////////////////////
void MinerEngine::welcome(Gamepad &pad, N5110 &lcd) {
@@ -336,11 +343,11 @@
lcd.drawLine(0,47,84,47,1);
lcd.refresh();
- while ( pad.check_event(Gamepad::START_PRESSED) == false) {
- play_music(pad);
- }
- screen_rollup(pad,lcd);
- loading(pad,lcd);
+ // while ( pad.check_event(Gamepad::START_PRESSED) == false) {
+ // play_music(pad);
+ //}
+ // screen_rollup(pad,lcd);
+ // loading(pad,lcd);
}
void MinerEngine::game_over(Gamepad &pad, N5110 &lcd) {
@@ -455,8 +462,8 @@
lcd.clear();
}
void MinerEngine::check_gold_reload() {
- int gold_num = _gold.get_reached_num();
- if (gold_num<1) {
+ int gold_left = _gold.get_left_num();
+ if (gold_left<1) {
_gold.init(9);
}
}