Skip to content

Conversation

@davepagurek
Copy link
Member

This reverts commit 56191fe.

This reverts commit 56191fe.

To be able to save and share your code, go to https://codepen.io/signup, scroll down to **Free Plan**, and sign up.

Then, come back to this page, and go to http://codepen.io/pen?template=ONJQya&editors=0010 to set up a new project with p5.js and p5.play.js added already. Additionally, there is a small amount of CSS included for you to change the page background colour.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need to mention the CSS


If you remember from physics class, on the earth, gravity accelerates all objects towards the center of the planet at the same rate (approximately 9.81 meters per second squared, depending on your altitude and location.) If you look at the units, this means that every second, the velocity of an object under Earth's gravity will increase by 9.81 meters per second.

In general, `velocity := acceleration * time` (where `:=` means "is defined as"; this is not valid Javascript.) To simulate this, in our game, we're going to define a gravity vector, and every frame, we are going to add this vector to the player's velocity vector. Our gravity vector shouldn't affect the horizontal movement of the character, so its x component should be 0, and its y component should be positive to cause the player to move downwards. Start with a small y value such as 1 and play around until it feels right.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just say the velocity is the acceleration times time.


### Refactoring our game to use classes

When programming, a restructuring of code to make it easier to add new features (or cleaner, easier to use, or different in general) is called a **refactor.** We're going to do one of those now by making classes for our game objects instead of treating each one as its own unique case. All of our game objects were originally made with `createSprite`, which returns an instance of the p5.js `Sprite` class, so it makes sense to use that as our base class. Because `Sprite` is from p5.js, we can only access it with in `setup` or `draw`, so like other game elements, we have to declare it outside both, but define it in `setup`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"we have to declare it outside both, but define it in setup" is confusing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants