Interactive Animations Game

Student want’s chip bag and banana peel sprites to respawn at the top of the screen when they touch “Critter”. He also wants to use a score variable and have score go up by one each time critter touces one of the objects. Any advice?

don’t use sprite

  • you don’t have it declared
  • it won’t change the property you want
  • it will error out since it doesn’t exist
  • be explicit in what you wish to change in the sprite object variable it is assigned to
if (critter.isTouching(chipBag)) {
  score = score + 10;
  chipBag.x = randomNumber(1, 390);
  chipBag.y = 0;
}
if (critter.isTouching(ChipBag2)) {
  score = score + 10;
  ChipBag2.x = randomNumber(1, 390);
  ChipBag2.y = 0;
}
if (critter.isTouching(BananaPeel2)) {
  score = score + 10;
  BananaPeel2.x = randomNumber(1, 390);
  BananaPeel2.y = 0;
}
if (critter.isTouching(BananaPeel)) {
  score = score + 10;
  BananaPeel.x = randomNumber(1, 390);
  BananaPeel.y = 0;
}

Varrience