Open
Conversation
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. |
Member
Author
There was a problem hiding this comment.
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. |
Member
There was a problem hiding this comment.
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`. |
Contributor
There was a problem hiding this comment.
"we have to declare it outside both, but define it in setup" is confusing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This reverts commit 56191fe.