Created
December 11, 2018 21:51
-
-
Save mrzachxu/106ebb9332bed07709a3be3c9825e026 to your computer and use it in GitHub Desktop.
This file contains 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
let me; | |
let you; | |
let gravity; | |
let rectarray = []; | |
let caught = false; | |
function setup() { | |
frameRate(50); | |
createCanvas(1500,800) | |
rectMode(CENTER) | |
me = new Rectangles | |
you = new Ball(height/2,20,3) | |
} | |
function draw() { | |
background(0,0,0) | |
border() | |
you.moveBall(); | |
you.getCaught(); | |
you.drawBall(); | |
//print(caught); | |
if (frameCount % 30 == 0) { | |
let r = new Rectangles(random(0,width), height-30, 500, -4); | |
rectarray.push(r); | |
//print(rectarray); | |
} | |
for (let i = 0; i < rectarray.length; i++) { | |
rectarray[i].drawRect(); | |
rectarray[i].moveRect(); | |
} | |
} | |
class Rectangles{ | |
constructor(x,y, width, speed){ | |
this.x = x; | |
this.y = y; | |
this.speed = speed; | |
this.width = width; | |
} | |
drawRect(){ | |
stroke(0); | |
fill("white"); | |
rect(this.x,this.y,500,10); | |
rect(this.x+600, this.y, 500,10) | |
rect(this.x-600, this.y, 500,10) | |
rect(this.x-1200, this.y, 500,10) | |
} | |
moveRect(){ | |
this.x; | |
this.y = this.y-4; | |
} | |
} | |
class Ball{ | |
constructor(x,y, speed){ | |
this.x = x; | |
this.y = y; | |
this.speed = speed; | |
} | |
drawBall(){ | |
stroke(0); | |
fill("yellow"); | |
ellipse(this.x,this.y,30,30); | |
} | |
moveBall(){ | |
for (let i = 0; i < rectarray.length; i++) { | |
if (keyIsDown(65)){ | |
this.x -= 3; | |
} | |
if (keyIsDown(68)){ | |
this.x += 3; | |
} | |
if (this.x>0 && caught == false){ | |
this.y= this.y+.5; | |
} | |
} | |
} | |
getCaught(){ | |
for (let i = 0; i < rectarray.length; i++) { | |
if (this.x >= rectarray[i].x-250 && this.x <= rectarray[i].x+ 250 && this.y >= rectarray[i].y-10 && this.y <=rectarray[i].y){ | |
caught = true; | |
this.y = rectarray[i].y-10; | |
print("hit rectangle "+[i]+" at y value "+rectarray[i].y); | |
} | |
else { | |
caught = false; | |
} | |
} | |
} | |
} | |
function border(){ | |
fill(255,255,255) | |
rect(0,0,3000,10) | |
rect(0,800,3000,10) | |
rect(0,0,10,3000) | |
rect(1500,0,10,2000) | |
} |
lizzybrooks
commented
Dec 12, 2018
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment