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: Gold/Gold.cpp
- Revision:
- 10:51870f8e2e1a
- Parent:
- 8:c5969685cf02
- Child:
- 12:07a9f2140d9b
--- a/Gold/Gold.cpp Sun Apr 26 14:00:59 2020 +0000
+++ b/Gold/Gold.cpp Sun Apr 26 16:46:14 2020 +0000
@@ -38,14 +38,16 @@
void Gold::update()
{
- for (int i=0;i<_gold_num;i++){
- while(_gold_caught[i]==1){
+ for (int i=0;i<_gold_num;i++) {
+
+ if (_gold_caught[i]==1&&_gold_reached[i]==0) {
_y[i]-=1;
- if (_y[i]<=14) {
- gold_reached(i);
- }
- }
+ if (_y[i]<=14) {
+ _gold_reached[i]=1;
+ _gold_left--;
+ }
}
+ }
}
void Gold::gold_caught(int caught_i)
@@ -53,14 +55,6 @@
_gold_caught[caught_i]=1;
}
-void Gold::gold_reached(int reached_i)
-{
- _gold_reached[reached_i]=1;
- _gold_left--;
-}
-
-
-
int Gold::get_reached_num()
{
int n=0;
@@ -86,7 +80,7 @@
void Gold::set_pos(Vector2D p) {
for (int i=0;i<_gold_num;i++){
- while(_gold_reached[i]==0){
+ if(_gold_reached[i]==0){
_x[i] = p.x;
_y[i] = p.y;
}