Skip to content

Instantly share code, notes, and snippets.

@bmoren
Last active October 14, 2015 05:14
Show Gist options
  • Save bmoren/1c78979ddeb6d4a5eaa8 to your computer and use it in GitHub Desktop.
Save bmoren/1c78979ddeb6d4a5eaa8 to your computer and use it in GitHub Desktop.
Rectangle Rectangle Collision p5js
var posx,posy, size
var times = 0
function setup() {
createCanvas(windowWidth,windowHeight);
posx = width/2
posy = height/2
size = 100;
meSize = 100;
}
function draw() {
background(255);
rectMode(CENTER);
rect(posx,posy,size,size)
rect(mouseX,mouseY,meSize,meSize);
if (
mouseX - meSize/2 < posx + size/2 &&
mouseX + meSize/2 > posx - size/2 &&
mouseY - meSize/2 < posy + size/2 &&
mouseY + meSize/2 > posy - size/2
){
times++
print("hit "+ times);
print("----------")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment