Coding game: catching coins and avoiding bombs

image(image, width, height);

this won’t work. background(image); is better.

  • wrong: image(image, width, height);
  • it would be image(image, 0, 0); OR
  • image(image, 0,0, width, height); // which is not good style (img, pos and size as parameters)

Your question

Look here:

I don’t have your images and can’t run your code but I see here that you have coins and bombs in the same class Ball. That’s the problem!

  • The image for the bomb is called bombe (good name here) the image for the coin is named image (bad name, doesn’t tell its purpose).

Remark

In the function display() in the class Ball you display both images!!!

    image(image, x, y);
    image(bombe, x, y);

That won’t work.

It’s okay that you handle both types in ONE class but you need to distinguish between them!!!

For example make a variable boolean isCoin=false; in the Ball class.

In the constr say if (random(1) < 0.5) isCoin = true; else isCoin = false;

then use isCoin :

    if(isCoin)
          image(image, x, y);
    else 
        image(bombe, x, y);

and use if(isCoin) also when you register a HIT to either decrease health or increase score.

OK?

Warm regards,

Chrisir

1 Like