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:
- 6:3381131afe50
- Parent:
- 5:58932f73fc35
- Child:
- 7:5bb5cde8951a
--- a/MinerEngine/MinerEngine.cpp Sat Apr 25 10:29:42 2020 +0000 +++ b/MinerEngine/MinerEngine.cpp Sat Apr 25 10:41:47 2020 +0000 @@ -91,6 +91,7 @@ _state = 0; _catching = 0;//是否正在抓取,x轴锁定 _claw_get = 0;//是否已经碰到金子 + _monster_collision=0;是否撞到怪物 _now_score = 0; _highest_score = 0; } @@ -274,33 +275,15 @@ { // read current claw attributes Vector2D claw_pos = _claw.get_pos(); - ///检查怪物和爪子X是否一样 - - - - - Vector2D claw_velocity = _claw.get_velocity();////////////// + int monster_x = _monster.get_pos(); - // check if hit top wall - if (claw_pos.y <= 1) { // 1 due to 1 pixel boundary/////改/检查怪物和爪子X是否一样 - claw_pos.y = 1; // bounce off ceiling without going off screen - claw_velocity.y = -claw_velocity.y; - // audio feedback - pad.tone(750.0,0.1); + while(_catching==1){ + if (monster_x==claw_pos.x && claw_pos.y>=22) { + _monster_collision=1; + state=4; + pad.tone(750.0,0.1);// audio feedback + } } - // check if hit bottom wall - else if (claw_pos.y + _claw_size >= (HEIGHT-1) ) { // bottom pixel is 47 - // hit bottom - claw_pos.y = (HEIGHT-1) - _claw_size; // stops claw going off screen - claw_velocity.y = -claw_velocity.y; - // audio feedback - pad.tone(750.0,0.1); - } - - // update claw parameters - _claw.set_velocity(claw_velocity); - _claw.set_pos(claw_pos); - } void MinerEngine::check_claw_collision(Gamepad &pad)