Week 10: Falling apples

Concept:

For this week’s assignment, I made mini game using matter.js. The user is required to move the basket (boundary) with the right arrow or left arrow key and catch as many apples as possible. Once three apples have fallen, the game restarts on its own.

Sketch:

Code and challenges:

let moveAmount = 6; 

if (keyIsDown(LEFT_ARROW)) {
  let pos = movableBoundary.body.position;
  Body.setPosition(movableBoundary.body, { x: pos.x - moveAmount, y: pos.y });
} else if (keyIsDown(RIGHT_ARROW)) {
  let pos = movableBoundary.body.position;
  Body.setPosition(movableBoundary.body, { x: pos.x + moveAmount, y: pos.y });
}

In this code snippet, I made the boundary move according to the user’s key press.

Future Improvements:

I would want to make it look more visually appealing as well as make the apples move to wherever the basket is moving.

Reference:

  • https://nature-of-code-2nd-edition.netlify.app/physics-libraries/#static-matterjs-bodies (Example 6.5)

Leave a Reply

Your email address will not be published. Required fields are marked *