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:
- 10:51870f8e2e1a
- Parent:
- 9:9a30f26fed81
- Child:
- 11:9da147cd7c18
diff -r 9a30f26fed81 -r 51870f8e2e1a MinerEngine/MinerEngine.cpp
--- a/MinerEngine/MinerEngine.cpp Sun Apr 26 14:00:59 2020 +0000
+++ b/MinerEngine/MinerEngine.cpp Sun Apr 26 16:46:14 2020 +0000
@@ -94,6 +94,9 @@
_monster_collision=0;//是否撞到怪物
_now_score = 0;
_highest_score = 0;
+ for (int i=0;i<9;i++) {
+ _gold_reached_num[i] = 0;
+ }
}
@@ -132,7 +135,9 @@
}
void MinerEngine::instruction(Gamepad &pad, N5110 &lcd) {
+ lcd.clear();
lcd.printString(" Instructions",4,2);//testing
+ lcd.refresh();
}
void MinerEngine::menu(Gamepad &pad, N5110 &lcd) {
@@ -211,18 +216,22 @@
void MinerEngine::check_gold_collision(Gamepad &pad)//只检查金子Y<=13
{
for (int i=0;i<9;i++) {
-
- Vector2D gold_pos = _gold.get_pos(i);
+
+ if (_gold_reached_num[i]==0) {
+ Vector2D gold_pos = _gold.get_pos(i);
- if (gold_pos.y < 14) {
- _now_score++;
- _claw.add_now_score();
- pad.tone(1500.0,0.5);
- pad.leds_on();
- wait(0.5);
- pad.leds_off();
+ if (gold_pos.y <= 14) {
+ _claw_get=0;
+ _now_score++;
+ _claw.add_now_score();
+ _gold_reached_num[i] = 1;
+ //pad.tone(1500.0,0.5);
+ pad.leds_on();
+ wait(0.5);
+ pad.leds_off();
+ }
+ }
}
- }
}
void MinerEngine::print_scores(N5110 &lcd) {
@@ -306,17 +315,23 @@
Vector2D claw_pos = _claw.get_pos();// read current claw attributes
for (int i=0;i<9;i++) {
+ if (_gold_reached_num[i]==0) {
Vector2D gold_pos = _gold.get_pos(i);
- if ((claw_pos.x+3)-gold_pos.x<5&&
- (claw_pos.x+3)-gold_pos.x>-5&&
+ if (claw_pos.x-gold_pos.x<5&&
+ claw_pos.x-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
+ }
}
if (claw_pos.y>HEIGHT-4||_claw_get==1) {
- _claw_get=0;
+ //_claw_get=0;
_claw.set_velocity(-1.0);
+ pad.tone(1500.0,0.1);
+ pad.leds_on();
+ wait(0.2);
+ pad.leds_off();
}
if (claw_pos.y<=14) {
@@ -465,11 +480,9 @@
int gold_left = _gold.get_left_num();
if (gold_left<1) {
_gold.init(9);
+ for (int i=0;i<9;i++) {
+ _gold_reached_num[i] = 0;
}
+ }
}
-void MinerEngine::fix_x() {
- while(_catching==1) {
- Vector2D claw_pos=_claw.get_pos();
- }
-}