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:
- 4:71d01af424c1
- Parent:
- 3:f894534ca2d1
- Child:
- 5:58932f73fc35
diff -r f894534ca2d1 -r 71d01af424c1 MinerEngine/MinerEngine.cpp --- a/MinerEngine/MinerEngine.cpp Sat Apr 25 07:57:55 2020 +0000 +++ b/MinerEngine/MinerEngine.cpp Sat Apr 25 08:55:23 2020 +0000 @@ -307,30 +307,25 @@ { // read current claw attributes Vector2D claw_pos = _claw.get_pos(); - Vector2D claw_velocity = _claw.get_velocity(); - - // check winch first - Vector2D winch_pos = _winch.get_pos(); + - // see if claw has hit the winch by checking for overlaps - if ( - (claw_pos.y >= winch_pos.y) && //top - (claw_pos.y <= winch_pos.y + _winch_height) && //bottom - (claw_pos.x >= _winch_x) && //left - (claw_pos.x <= _winch_x + _winch_width) //right - ) { - // if it has, fix position and reflect x velocity - claw_pos.x = _winch_x + _winch_width; - claw_velocity.x = -claw_velocity.x; - // audio feedback - pad.tone(1000.0,0.1); + 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 } + } } void MinerEngine::claw_down(){ _catching = 1; - claw.set_velocity(1); - Vector2D claw_pos = claw.get_pos(); + _claw.set_velocity(1); + Vector2D claw_pos = _claw.get_pos(); if (claw_pos.y>HEIGHT-4||_claw_get==1) { _claw_get==0; @@ -338,7 +333,7 @@ } if (claw_pos.y<=14) { - claw.set_velocity(0); + _claw.set_velocity(0); _catching = 0; } } @@ -452,6 +447,12 @@ wait(0.8); lcd.clear(); } +void MinerEngine::gold_reload_check() { + int gold_num = _gold.get_reached_num(); + if (gold_num<1) { + _gold.init(9); + } +} // check claw next /* Vector2D claw_pos = _claw.get_pos();