In this assignment you will demonstrate low-level technical knowledge of programming components such as values and expressions, craft expressions to carry out a desired computation, and craft objects to represent real-world data. You will continue your development of programming skills by building a game incorporating gravity and collision detection with third-party library.
Do the readings, watch the videos, write the essays, and program the applications below.
Submit, via Brightspace, the following:
Just read and/or watch the following. You do not have to take notes or write reports on them; however, don’t cheat yourself by skipping them. These independent learning units must be done individually, but please feel free to discuss these items with your friends and classmates. You are encouraged to share your thoughts on these materials on course community channels (Brightspace Forums, Slack, Discord), and to post related items your classmates might be interested in. We learn together. Some of these resources have links to other resources, which you may wish to follow as time allows.
Many of these questions refer to the readings, videos, and activities above. Some questions may require additional research to answer well enough for full credit.
const info = { dog: 'cat', rat: 'dog', rex: 10 }; const response = { count: 2, locations: [ 'home', {lat: 33, lon: -112} ] }; const dog = 'rex'; const colors = ['Cyan', 'Magenta', 'Yellow'];What do each of the following JavaScript expressions evaluate to? Use a REPL to find out. (Note: make sure to write out the complete result of the evaluations. Some REPLs will not write out complete values.) Make sure you understand each of the results. Ask for help if there is anything you do not understand.
-10 < -5 < -1
colors[2][3]
info["dog"]
info[dog]
response.locations[1]
0.1 + 0.2
Number.isSafeInteger(Math.pow(2, 55))
57093424755811 * 1946127975092301
57093424755811n * 1946127975092301n
'I do not think it will be a good pudding'.split(' ', 4)
{ dog, c: ['Black', 'Purple', ...colors, 'Cyan'] }
JSON.stringify(response.locations)
colors.includes(dog) ? 'Hai' : 'Not today'
info.bat ?? 100
(x => -x)(response.count)
2 * 5 - 7 / - 6 + 4
2 > 4 || true && false
1 <= 2 <= 3
! x || ! y && z || 6 / 5 & 1
- - 9 - --x
m
miles,” you would answer m * 1.609344
.
s
.
x
.
a
.
a
.
sick
, weekend
, or holiday
is true.
a
(expressed using the spread operator).
x
dollars.
.repeat
s
contains a poop emoji or a winking face emoji.
x
property of the 3rd element of the 5th element t
, where t
is an array of 10 arrays of 10 objects.
x
is a positive integer less than one million times π.
present
that they wanted to turn into an English sentence. But instead of writing:
const notice = "She is" + (present ? "" : "n't") + " here."they wrote:
const notice = "She is" + present ? "" : "n't" + " here."What is the effect of this (incorrect) code? That is, what does it do, at a high level? And why, exactly, does that behavior occur? Next, rewrite this declaration using string interpolation instead of concatenation. Does doing so make the bug impossible to occur? Why or why not?
const WIDTH_IN_LIGHT_YEARS = 93e9; const SPEED_OF_LIGHT = 299792458; const DAYS_PER_YEAR = 365.2422; const SECONDS_PER_DAY = /* Fill this in */; const METERS_PER_YOTTAMETER = /* Fill this in */; const WIDTH_IN_YOTTAMETERS = /* Fill this in */; console.log(`The universe is ${WIDTH_IN_YOTTAMETERS} Ym wide.`);
{ call: 'mark', next: { call: 'ready', next: { call: 'set', next: { call: 'go', next: null } } } }
const
and use very well-chosen, descriptive, names.
Make a Flappy Bird game in p5.js. It does not have to be fancy. Your bird can be a simple circle. You are required to implement gravity, raise the bird on a space bar, and detect collisions with the pipes. Implement the bird and the pipes as instances of classes (called Bird
and Pipe
). Indicate a collision by coloring the collided-with pipe red. After three collisions, announce “GAME OVER” in big letters centered on the canvas, and call noLoop
. To discover when the bird collides with a pipe, use the p5collide2d library, which you can find on the p5.js Libraries page.
Here’s the rubric I’ll use to score your submission.
Requirement | Out Of | You got |
---|---|---|
Problem 1 | 15 | |
Problem 2 | 5 | |
Problem 3 | 15 | |
Problem 4 | 5 | |
Problem 5 | 5 | |
Problem 6 | 5 | |
Problem 7 | 5 | |
Problem 8 | 10 | |
Flappy Bird code style (use a formatter!) | 5 | |
Flappy Bird naming, code structure, DRYness, separation of concerns | 10 | |
Flappy Bird Gravity | 5 | |
Flappy Bird Keyboard Interaction | 3 | |
Flappy Bird Animation | 3 | |
Flappy Bird Collision Detection | 3 | |
Flappy Bird Collision Scoring | 3 | |
Flappy Bird Game Over state | 3 | |
Misc. Bonus points or penalties at discretion of Prof. | 0 | |
Total | 100 |