//James Doyle project 6 //creature bounces off wall and collision int size; float border; //setting the perimeter for constraining float oneX,oneY,oneDX, oneDY; ///creature number one float twoX,twoY, twoDX, twoDY; ///creature number two float treX,treY,treDX,treDY; ///creature number three boolean hit; //for collision void setup() { size(600,400); border=height; begin(); smooth(); frameRate(30); noStroke(); } void scene() { background(255,0,0); fill(0); text("James Doyle project 6",10,20); } void begin() { oneX=random(600); oneY=random(400); oneDX=random(5); oneDY=random(5); twoX=random(600); twoY=random(400); twoDX=random(5); twoDY=random(5); treX=random(600); treY=random(400); treDX=random(5); treDY=random(5); } void draw() { scene(); guy(); def(); tre(); } void guy() { ///creature one movement oneX=oneX+oneDX; oneY=oneY+oneDY; if(oneX>width||oneX<0) { oneDX=-oneDX; } if(oneY>height||oneY<0) { oneDY=-oneDY; } ///draw creature one fill(255); rect(oneX,oneY,40,60); ellipseMode(CENTER); fill(0,201,87); ellipse(oneX+20,oneY-5,25,25); } void def() { twoX=twoX+twoDX; twoY=twoY+twoDY; if(twoX>width||twoX<0) { twoDX=-twoDX; } if(twoY>height||twoY<0) { twoDY=-twoDY; } //draw creature two fill(0); rect(twoX,twoY,40,60); fill(0,201,87); ellipse(twoX+20,twoY-5,25,25); } void tre() { treX=treX+treDX; treY=treY+treDY; if(treX>width||treX<0) { treDX=-treDX; } if(treY>height||treY<0) { treDY=-treDY; } //draw creature three fill(0,0,255); rect(treX,treY,40,60); fill(0,201,87); ellipse(treX+20,treY-5,25,25); } void collision() { if(oneX=twoX||oneX=treX) { oneDX=-oneDX; } if(oneY=twoY||oneY=treY) { oneDY=-oneDY; } if(twoX=oneX||twoX=treX) { twoDX=-twoDX; }