Last active
October 14, 2015 05:14
-
-
Save bmoren/1c78979ddeb6d4a5eaa8 to your computer and use it in GitHub Desktop.
Rectangle Rectangle Collision p5js
This file contains hidden or 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
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