0% found this document useful (0 votes)
26 views3 pages

Girls Who Code at Home Meteor Catcher Part 3 - Reference Guide

Uploaded by

ifunanyaijah2005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views3 pages

Girls Who Code at Home Meteor Catcher Part 3 - Reference Guide

Uploaded by

ifunanyaijah2005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Girls Who Code At Home

Meteor Catcher Game: Part 3


Reference Guide
Meteor Catcher Game: Part 3 - Reference Guide
In this document you will find all of the answers to some of the questions in the activity.
Follow along with the activity and when you see this icon, stop and check your ideas
here.

Step 1: Using variables in p5.js


JAVASCRIPT

let meteorX = 200; //store the X position of the meteor


let meteorY = 0; //store the Y position of the meteor
let meteorDiameter = 20; //store diameter of the meteor

function setup() {
createCanvas(400, 400);
}

function draw() {
background(0, 0, 0);
noStroke();

//Draw the meteor


fill(0, 254, 202);
ellipse(meteorX, meteorY, meteorDiameter, meteorDiameter);
}

Step 2: Make observations about motion


Examine this sketch and use your observations to write a line of pseudocode to tell the program how to
move the ball.

There are many different ways you could write this. Here are a couple:
➔ Increase the value of x by a certain amount each time the program loops through.
➔ Add a small value to the xPosition variable in draw().
2
Step 3: Add motion to your meteor

JAVASCRIPT RESULT

let meteorX = 200;


let meteorY = 0;
let meteorDiameter = 20;
let speed = 0.5; //store speed of the meteor

function setup() {
createCanvas(400, 400);
}

function draw() {
background(0, 0, 0);
noStroke();

//Draw the meteor


fill(0, 254, 202);
ellipse(meteorX, meteorY, meteorDiameter,
meteorDiameter); Note: In this example sketch the meteor is
programmed to reset. Your sketch will not do
// Make the meteor fall this until Part 5.
meteorY = meteorY + speed;
}

Step 5: Check for Understanding


How would you change the speed equation to make the meteor move from the bottom of the screen to
the top?

Use the subtraction arithmetic operator - instead of the addition arithmetic operator +. This would cause
the y value to decrease after each loop and change the vertical position of the meteor:

meteorY = meteorY - speed

You might also like