-
Notifications
You must be signed in to change notification settings - Fork 1
Revert "remove gamedev" #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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`. |
There was a problem hiding this comment.
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
This reverts commit 56191fe.