diff --git a/Examples/shooter2023/shooter2023.pde b/Examples/shooter2023/shooter2023.pde new file mode 100644 index 0000000..b901f37 --- /dev/null +++ b/Examples/shooter2023/shooter2023.pde @@ -0,0 +1,65 @@ +ArrayList bullets = new ArrayList(); +ArrayList enemies = new ArrayList(); +boolean wonthegame = false; +void setup() { + //fullScreen(); + size(800, 800); + for (int i = 50; i < 800; i += 100) { + enemies.add(new Target(50, i)); + } +} + +void draw() { + if (!wonthegame) { + background(50); + circle(400, 400, 10); + println(bullets.size()); + for (Projectile p : bullets) { + p.uad(); + } + for (Target t : enemies) { + t.display(); + } + + for (Projectile p : bullets) { + for (Target t : enemies) { + if (circleCircle(p.pos.x, p.pos.y, 5, t.pos.x, t.pos.y, t.d/2) == true) { + t.health -= 10; + p.removeme = true; + if (t.health <= 0) { + t.removeme = true; + } + } + } + } + + + + if (mousePressed && frameCount % 5 == 0) { + bullets.add(new Projectile(400, 400, mouseX, mouseY)); + } + + for (int i = bullets.size() - 1; i >= 0; i--) { + Projectile p = bullets.get(i); + if (p.removeme == true) { + bullets.remove(p); + } + } + + for (int i = enemies.size() - 1; i >= 0; i--) { + Target t = enemies.get(i); + if (t.removeme == true) { + enemies.remove(t); + } + } + if(enemies.size() == 0){ + wonthegame = true; + } + } else { + background(0, 255, 0); + text("you win", 400, 400); + } +} + +void mousePressed() { +} diff --git a/StudentFolders/A1/Reilly W/Array_list_class/Array_list_class.pde b/StudentFolders/A1/Reilly W/Array_list_class/Array_list_class.pde new file mode 100644 index 0000000..004d295 --- /dev/null +++ b/StudentFolders/A1/Reilly W/Array_list_class/Array_list_class.pde @@ -0,0 +1,25 @@ +ArrayList bounceyballs = new ArrayList(); +int numBalls = 15; +void setup() { + size (800, 600); + for (int i = 0; i < numBalls; i++) { + bounceyballs.add(new Bouncer()); + } + background(50); +} + + +void draw(){ + for( int i = 0; i < numBalls; i++){ + bounceyballs.get(i).display(); + bounceyballs.get(i).move(); + + } +} + + +void keyPressed(){ + for(int i = 0; iwidth-size/2 || pos.xheight-size/2 || pos.ymaxSize || size < minSize) { + change *= -1; + } + } + + void partyTime() { + c = color(random(0, 255), random(0, 255), random(0, 255)); + line(400, 0, 400, 100); + fill(c); + circle(400, 100, 50); + } + void toggleParty() { + flash = !flash; + } + void togglePulse() { + pulse =!pulse; + } +} diff --git a/StudentFolders/A1/Reilly W/Shooting_thing/Shooting_thing.pde b/StudentFolders/A1/Reilly W/Shooting_thing/Shooting_thing.pde new file mode 100644 index 0000000..e5f530c --- /dev/null +++ b/StudentFolders/A1/Reilly W/Shooting_thing/Shooting_thing.pde @@ -0,0 +1,58 @@ +/* + +Class ENEMY, + red + can move(.move) + can shoot(.shoot) +OBJECT + hp(int, not set) + shooting cooldown(int, not set) + strength(int, set) +*/ + +ArrayList bpos = new ArrayList(); +PVector shippos = new PVector (400, 550); +PVector enemypos = new PVector (400, 75); +int score = 0; + + + +void setup() { + size(800, 600); + + + println(bpos.size()); +} + + +void draw() { + background(50); + textSize(40); + text(score, 30, 30); + println(bpos.size()); + circle(shippos.x, shippos.y, 40); + circle(enemypos.x, enemypos.y, 50); + shippos.x = mouseX; + shippos.y = mouseY; + + for (int i =0; i < bpos.size(); i++) { + circle(bpos.get(i).x, bpos.get(i).y, 10); + //bpos.get(i).y -= 5; + PVector temp = bpos.get(i); + circle(temp.x, temp.y, 10); + temp.y -= 5; + if(circleCircle(temp.x, temp.y, 5, enemypos.x, enemypos.y, 25)){ + bpos.get(i).x = -100; + score ++; + enemypos.x = random(50, 750); + } + } + + +} + +void keyPressed() { + if (key == ' ') { + bpos.add(new PVector(shippos.x, shippos.y)); + } +} diff --git a/StudentFolders/A1/Reilly W/Shooting_thing/collisions.pde b/StudentFolders/A1/Reilly W/Shooting_thing/collisions.pde new file mode 100644 index 0000000..15878d9 --- /dev/null +++ b/StudentFolders/A1/Reilly W/Shooting_thing/collisions.pde @@ -0,0 +1,170 @@ +boolean pointCircle(float px, float py, float cx, float cy, float cr){ + if(dist(px, py, cx, cy) < cr){ + return true; + } else { + return false; + } +} + +boolean circleCircle(float cx1, float cy1, float cr1, float cx2, float cy2, float cr2){ + if(dist(cx1, cy1, cx2, cy2) < cr1 + cr2){ + return true; + } else { + return false; + } +} + +boolean pointRect(float px, float py, float rx, float ry, float rw, float rh) { + + // is the point inside the rectangle's bounds? + if (px >= rx && // right of the left edge AND + px <= rx + rw && // left of the right edge AND + py >= ry && // below the top AND + py <= ry + rh) { // above the bottom + return true; + } + return false; +} + +boolean rectRect(float r1x, float r1y, float r1w, float r1h, float r2x, float r2y, float r2w, float r2h) { + + // are the sides of one rectangle touching the other? + + if (r1x + r1w >= r2x && // r1 right edge past r2 left + r1x <= r2x + r2w && // r1 left edge past r2 right + r1y + r1h >= r2y && // r1 top edge past r2 bottom + r1y <= r2y + r2h) { // r1 bottom edge past r2 top + return true; + } + return false; +} + +// CIRCLE/RECTANGLE +boolean circleRect(float cx, float cy, float radius, float rx, float ry, float rw, float rh) { + + // temporary variables to set edges for testing + float testX = cx; + float testY = cy; + + // which edge is closest? + if (cx < rx) testX = rx; // test left edge + else if (cx > rx+rw) testX = rx+rw; // right edge + if (cy < ry) testY = ry; // top edge + else if (cy > ry+rh) testY = ry+rh; // bottom edge + + // get distance from closest edges + float distX = cx-testX; + float distY = cy-testY; + float distance = sqrt( (distX*distX) + (distY*distY) ); + + // if the distance is less than the radius, collision! + if (distance <= radius) { + return true; + } + return false; +} + +// LINE/POINT +boolean linePoint(float x1, float y1, float x2, float y2, float px, float py) { + + // get distance from the point to the two ends of the line + float d1 = dist(px,py, x1,y1); + float d2 = dist(px,py, x2,y2); + + // get the length of the line + float lineLen = dist(x1,y1, x2,y2); + + // since floats are so minutely accurate, add + // a little buffer zone that will give collision + float buffer = 0.1; // higher # = less accurate + + // if the two distances are equal to the line's + // length, the point is on the line! + // note we use the buffer here to give a range, + // rather than one # + if (d1+d2 >= lineLen-buffer && d1+d2 <= lineLen+buffer) { + return true; + } + return false; +} + +boolean lineCircle(float x1, float y1, float x2, float y2, float cx, float cy, float r) { + + // is either end INSIDE the circle? + // if so, return true immediately + boolean inside1 = pointCircle(x1,y1, cx,cy,r); + boolean inside2 = pointCircle(x2,y2, cx,cy,r); + if (inside1 || inside2) return true; + + // get length of the line + float distX = x1 - x2; + float distY = y1 - y2; + float len = sqrt( (distX*distX) + (distY*distY) ); + + // get dot product of the line and circle + float dot = ( ((cx-x1)*(x2-x1)) + ((cy-y1)*(y2-y1)) ) / pow(len,2); + + // find the closest point on the line + float closestX = x1 + (dot * (x2-x1)); + float closestY = y1 + (dot * (y2-y1)); + + // is this point actually on the line segment? + // if so keep going, but if not, return false + boolean onSegment = linePoint(x1,y1,x2,y2, closestX,closestY); + if (!onSegment) return false; + + // optionally, draw a circle at the closest + // point on the line + //fill(255,0,0); + //noStroke(); + //ellipse(closestX, closestY, 20, 20); + + // get distance to closest point + distX = closestX - cx; + distY = closestY - cy; + float distance = sqrt( (distX*distX) + (distY*distY) ); + + if (distance <= r) { + return true; + } + return false; +} + +// LINE/LINE +boolean lineLine(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) { + + // calculate the distance to intersection point + float uA = ((x4-x3)*(y1-y3) - (y4-y3)*(x1-x3)) / ((y4-y3)*(x2-x1) - (x4-x3)*(y2-y1)); + float uB = ((x2-x1)*(y1-y3) - (y2-y1)*(x1-x3)) / ((y4-y3)*(x2-x1) - (x4-x3)*(y2-y1)); + + // if uA and uB are between 0-1, lines are colliding + if (uA >= 0 && uA <= 1 && uB >= 0 && uB <= 1) { + + // optionally, draw a circle where the lines meet + float intersectionX = x1 + (uA * (x2-x1)); + float intersectionY = y1 + (uA * (y2-y1)); + //fill(255,0,0); + //noStroke(); + //ellipse(intersectionX,intersectionY, 20,20); + + return true; + } + return false; +} + +boolean lineRect(float x1, float y1, float x2, float y2, float rx, float ry, float rw, float rh) { + + // check if the line has hit any of the rectangle's sides + // uses the Line/Line function below + boolean left = lineLine(x1,y1,x2,y2, rx,ry,rx, ry+rh); + boolean right = lineLine(x1,y1,x2,y2, rx+rw,ry, rx+rw,ry+rh); + boolean top = lineLine(x1,y1,x2,y2, rx,ry, rx+rw,ry); + boolean bottom = lineLine(x1,y1,x2,y2, rx,ry+rh, rx+rw,ry+rh); + + // if ANY of the above are true, the line + // has hit the rectangle + if (left || right || top || bottom) { + return true; + } + return false; +} diff --git a/StudentFolders/A1/Reilly W/Shooting_thing/player.pde b/StudentFolders/A1/Reilly W/Shooting_thing/player.pde new file mode 100644 index 0000000..ee5a303 --- /dev/null +++ b/StudentFolders/A1/Reilly W/Shooting_thing/player.pde @@ -0,0 +1,7 @@ +class Player { + void display() { + fill(255); + circle(mouseX, height - 100, 50); + } + +} diff --git a/StudentFolders/A1/Reilly W/apple_game/Apple_and_Box_class.pde b/StudentFolders/A1/Reilly W/apple_game/Apple_and_Box_class.pde new file mode 100644 index 0000000..8db1f86 --- /dev/null +++ b/StudentFolders/A1/Reilly W/apple_game/Apple_and_Box_class.pde @@ -0,0 +1,81 @@ +PVector bullet; +class Bullet { + ArrayList pewpew = new ArrayList(); + color c; + float bVel = -8; + + Bullet() { + c = color(255, 0, 0); + bullet = new PVector(mouseX, height-100); + } + + void shoot() { + if (mousePressed && (mouseButton == LEFT)) { + c = color(255, 0, 0); + pewpew.add(new Bullet()); + + bullet.y += bVel; + } else if (mousePressed && (mouseButton == RIGHT)) { + c = color(0, 255, 0); + pewpew.add(new Bullet()); + bullet.y += bVel; + } + } + + void update() { + bullet.x = mouseX; + } + void display() { + fill(c); + circle(bullet.x, bullet.y, 10); + } +} + +class Apple { + int c; + PVector pos; + int score; + + float yVel = 2.5; + Apple(int col, float x, float y) { + c = col; + pos = new PVector(x, y); + //yVel = 2.5; + //if(c == 0) + } + + + void display() { + if (c == 0) { + fill(255, 0, 0); + } else { + fill(0, 255, 0); + } + circle(pos.x, pos.y, 50); + + + pos.y += yVel; + if (pos.y > width - 25) { + //i++; + pos.y = -50; + pos.x = random(50, width-50); + bullet.y = height-100; + yVel -= 0.5; + //pos.y += (2.5 + 0.5*i); + } else if (dist(bullet.x, bullet.y, pos.x, pos.y) < 35) { + //i ++; + //pos.y = -50; + //pos.x = random(50, width-50); + //pos.y += (2.5 + 0.5* i); + a.reset(); + b.reset(); + bullet.y = height-100; + yVel += 0.5; + } + } + + void reset() { + pos.y = -50; + pos.x = random(50, width-50); + } +} diff --git a/StudentFolders/A1/Reilly W/apple_game/apple_game.pde b/StudentFolders/A1/Reilly W/apple_game/apple_game.pde new file mode 100644 index 0000000..4ff656a --- /dev/null +++ b/StudentFolders/A1/Reilly W/apple_game/apple_game.pde @@ -0,0 +1,33 @@ +Apple a; +Apple b; +Bullet s; +Player x; + +void setup(){ + size(800, 600); + a = new Apple(1, random(50, width - 50), -50); + b = new Apple(0, random(50, width - 50), -50); + s = new Bullet(); + x = new Player(); +} + +void draw(){ + + background(255); + + s.update(); + s.shoot(); + + + a.display(); + b.display(); + s.display(); + //x.display(); + + //if c is touching a + //add 1 + + //if c is touching b + //subtract 1 + //println(yVel); +} diff --git a/StudentFolders/A1/Reilly W/apple_game_2/apple.pde b/StudentFolders/A1/Reilly W/apple_game_2/apple.pde new file mode 100644 index 0000000..420f8bc --- /dev/null +++ b/StudentFolders/A1/Reilly W/apple_game_2/apple.pde @@ -0,0 +1,92 @@ +//class Apples { +// float x; +// float y; +// float d; +// color r; +// color g; + +// Apples(){ +// } + +// void greenApple() { +// y=0; +// d=50; +// g=255; +// r=0; +// x=random((0+(d/2)), (width-(d/2))); +// } +// void redApple() { +// x=random((0+(d/2)), (width-(d/2))); +// y=0; +// d=50; +// g=0; +// r=255; +// } +// boolean offScreen() { +// if (y>(height+(d/2))) { +// return true; +// } else { +// return false; +// } +// } +// void movement() { +// y+=7.5; +// if (offScreen()==true) { +// y=0; +// x=random((0+(d/2)), (width-(d/2))); +// } +// } +// void display() { +// fill(r, g, 0); +// circle(x, y, d); +// } +//} + +float yVel = 2.5; + +class Apple { + int c; + PVector pos; + int score; + + + Apple(int col, float x, float y) { + c = col; + pos = new PVector(x, y); + //yVel = 2.5; + //if(c == 0) + } + + + void display() { + if (c == 0) { + fill(255, 0, 0); + } else { + fill(0, 255, 0); + } + circle(pos.x, pos.y, 50); + + + pos.y += yVel; + if (pos.y > width - 25) { + //i++; + pos.y = -50; + pos.x = random(50, width-50); + yVel -= 0.5; + //pos.y += (2.5 + 0.5*i); + //} else if (dist(bullet.x, bullet.y, pos.x, pos.y) < 50) { + //i ++; + //pos.y = -50; + //pos.x = random(50, width-50); + //pos.y += (2.5 + 0.5* i); + a.reset(); + b.reset(); + yVel += 0.5; + } + } + + void reset() { + pos.y = -50; + pos.x = random(50, width-50); + } +} diff --git a/StudentFolders/A1/Reilly W/apple_game_2/apple_game_2.pde b/StudentFolders/A1/Reilly W/apple_game_2/apple_game_2.pde new file mode 100644 index 0000000..6922786 --- /dev/null +++ b/StudentFolders/A1/Reilly W/apple_game_2/apple_game_2.pde @@ -0,0 +1,17 @@ +Apple a; +Apple b; +Bullet g; +Bullet r; +Player x; + +void setup() { + size(800, 600); + a = new Apple(1, random(50, width - 50), -50); + b = new Apple(0, random(50, width - 50), -50); +} + +void draw() { + background(200); + a.display(); + b.display(); +} diff --git a/StudentFolders/A1/Reilly W/apple_game_2/bullet.pde b/StudentFolders/A1/Reilly W/apple_game_2/bullet.pde new file mode 100644 index 0000000..134ee35 --- /dev/null +++ b/StudentFolders/A1/Reilly W/apple_game_2/bullet.pde @@ -0,0 +1,14 @@ +class Bullet{ + color c; + boolean isRed = true; + + Bullet(){ + + + } + + void display(){ + fill(c); + circle(mouseX, height - 150, 50); + } +} diff --git a/StudentFolders/A1/Reilly W/apple_game_2/collisions.pde b/StudentFolders/A1/Reilly W/apple_game_2/collisions.pde new file mode 100644 index 0000000..15878d9 --- /dev/null +++ b/StudentFolders/A1/Reilly W/apple_game_2/collisions.pde @@ -0,0 +1,170 @@ +boolean pointCircle(float px, float py, float cx, float cy, float cr){ + if(dist(px, py, cx, cy) < cr){ + return true; + } else { + return false; + } +} + +boolean circleCircle(float cx1, float cy1, float cr1, float cx2, float cy2, float cr2){ + if(dist(cx1, cy1, cx2, cy2) < cr1 + cr2){ + return true; + } else { + return false; + } +} + +boolean pointRect(float px, float py, float rx, float ry, float rw, float rh) { + + // is the point inside the rectangle's bounds? + if (px >= rx && // right of the left edge AND + px <= rx + rw && // left of the right edge AND + py >= ry && // below the top AND + py <= ry + rh) { // above the bottom + return true; + } + return false; +} + +boolean rectRect(float r1x, float r1y, float r1w, float r1h, float r2x, float r2y, float r2w, float r2h) { + + // are the sides of one rectangle touching the other? + + if (r1x + r1w >= r2x && // r1 right edge past r2 left + r1x <= r2x + r2w && // r1 left edge past r2 right + r1y + r1h >= r2y && // r1 top edge past r2 bottom + r1y <= r2y + r2h) { // r1 bottom edge past r2 top + return true; + } + return false; +} + +// CIRCLE/RECTANGLE +boolean circleRect(float cx, float cy, float radius, float rx, float ry, float rw, float rh) { + + // temporary variables to set edges for testing + float testX = cx; + float testY = cy; + + // which edge is closest? + if (cx < rx) testX = rx; // test left edge + else if (cx > rx+rw) testX = rx+rw; // right edge + if (cy < ry) testY = ry; // top edge + else if (cy > ry+rh) testY = ry+rh; // bottom edge + + // get distance from closest edges + float distX = cx-testX; + float distY = cy-testY; + float distance = sqrt( (distX*distX) + (distY*distY) ); + + // if the distance is less than the radius, collision! + if (distance <= radius) { + return true; + } + return false; +} + +// LINE/POINT +boolean linePoint(float x1, float y1, float x2, float y2, float px, float py) { + + // get distance from the point to the two ends of the line + float d1 = dist(px,py, x1,y1); + float d2 = dist(px,py, x2,y2); + + // get the length of the line + float lineLen = dist(x1,y1, x2,y2); + + // since floats are so minutely accurate, add + // a little buffer zone that will give collision + float buffer = 0.1; // higher # = less accurate + + // if the two distances are equal to the line's + // length, the point is on the line! + // note we use the buffer here to give a range, + // rather than one # + if (d1+d2 >= lineLen-buffer && d1+d2 <= lineLen+buffer) { + return true; + } + return false; +} + +boolean lineCircle(float x1, float y1, float x2, float y2, float cx, float cy, float r) { + + // is either end INSIDE the circle? + // if so, return true immediately + boolean inside1 = pointCircle(x1,y1, cx,cy,r); + boolean inside2 = pointCircle(x2,y2, cx,cy,r); + if (inside1 || inside2) return true; + + // get length of the line + float distX = x1 - x2; + float distY = y1 - y2; + float len = sqrt( (distX*distX) + (distY*distY) ); + + // get dot product of the line and circle + float dot = ( ((cx-x1)*(x2-x1)) + ((cy-y1)*(y2-y1)) ) / pow(len,2); + + // find the closest point on the line + float closestX = x1 + (dot * (x2-x1)); + float closestY = y1 + (dot * (y2-y1)); + + // is this point actually on the line segment? + // if so keep going, but if not, return false + boolean onSegment = linePoint(x1,y1,x2,y2, closestX,closestY); + if (!onSegment) return false; + + // optionally, draw a circle at the closest + // point on the line + //fill(255,0,0); + //noStroke(); + //ellipse(closestX, closestY, 20, 20); + + // get distance to closest point + distX = closestX - cx; + distY = closestY - cy; + float distance = sqrt( (distX*distX) + (distY*distY) ); + + if (distance <= r) { + return true; + } + return false; +} + +// LINE/LINE +boolean lineLine(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) { + + // calculate the distance to intersection point + float uA = ((x4-x3)*(y1-y3) - (y4-y3)*(x1-x3)) / ((y4-y3)*(x2-x1) - (x4-x3)*(y2-y1)); + float uB = ((x2-x1)*(y1-y3) - (y2-y1)*(x1-x3)) / ((y4-y3)*(x2-x1) - (x4-x3)*(y2-y1)); + + // if uA and uB are between 0-1, lines are colliding + if (uA >= 0 && uA <= 1 && uB >= 0 && uB <= 1) { + + // optionally, draw a circle where the lines meet + float intersectionX = x1 + (uA * (x2-x1)); + float intersectionY = y1 + (uA * (y2-y1)); + //fill(255,0,0); + //noStroke(); + //ellipse(intersectionX,intersectionY, 20,20); + + return true; + } + return false; +} + +boolean lineRect(float x1, float y1, float x2, float y2, float rx, float ry, float rw, float rh) { + + // check if the line has hit any of the rectangle's sides + // uses the Line/Line function below + boolean left = lineLine(x1,y1,x2,y2, rx,ry,rx, ry+rh); + boolean right = lineLine(x1,y1,x2,y2, rx+rw,ry, rx+rw,ry+rh); + boolean top = lineLine(x1,y1,x2,y2, rx,ry, rx+rw,ry); + boolean bottom = lineLine(x1,y1,x2,y2, rx,ry+rh, rx+rw,ry+rh); + + // if ANY of the above are true, the line + // has hit the rectangle + if (left || right || top || bottom) { + return true; + } + return false; +} diff --git a/StudentFolders/A1/Reilly W/apple_game_2/player.pde b/StudentFolders/A1/Reilly W/apple_game_2/player.pde new file mode 100644 index 0000000..e6f1b4f --- /dev/null +++ b/StudentFolders/A1/Reilly W/apple_game_2/player.pde @@ -0,0 +1,14 @@ +class Player { + void display() { + fill(255); + circle(mouseX, height - 150, 50); + } + void shoot(){ + if(mousePressed && (mouseButton == LEFT)){ + + }else if(mousePressed && (mouseButton == RIGHT)){ + + + } + } +} diff --git a/StudentFolders/A1/Reilly W/applegameee/apple.pde b/StudentFolders/A1/Reilly W/applegameee/apple.pde new file mode 100644 index 0000000..7260035 --- /dev/null +++ b/StudentFolders/A1/Reilly W/applegameee/apple.pde @@ -0,0 +1,41 @@ +class Apple { + color c; + ArrayList newton = new ArrayList(); + PVector apple; + int s = 0; + Apple(int col){ + c = col; + apple = new PVector(random(50, width-50),-50); + } + + void display(){ + if(c == 0){ + fill(255, 0, 0); + + }else{ + fill(0, 255, 0); + + } + circle(apple.x, apple.y, 50); + textAlign(RIGHT); + text("score:" + s, 25, 50); + + } + + void update(){ + apple.y += 7.5; + } + + void reset(){ + if(apple.y > width - 25){ + apple.y = -50; + apple.x = random(50, width-50); + s -= 10; + }else if(circleCircle(apple.x, apple.y, 25, bullet.x, bullet.y, 25)){ + + + + } + + } +} diff --git a/StudentFolders/A1/Reilly W/applegameee/applegameee.pde b/StudentFolders/A1/Reilly W/applegameee/applegameee.pde new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/StudentFolders/A1/Reilly W/applegameee/applegameee.pde @@ -0,0 +1 @@ + diff --git a/StudentFolders/A1/Reilly W/applegameee/bullet.pde b/StudentFolders/A1/Reilly W/applegameee/bullet.pde new file mode 100644 index 0000000..e0dada1 --- /dev/null +++ b/StudentFolders/A1/Reilly W/applegameee/bullet.pde @@ -0,0 +1,31 @@ +class Bullet{ + color c; + ArrayList pewpew = new ArrayList(); + PVector bullet; + float bVel = 8; + Bullet(float x, float y){ + c = color(255); + bullet = new PVector(x, y); + } + + void display(){ + fill(c); + circle(bullet.x, bullet.y, 10); + } + void update(){ + bullet.x = mouseX; +} + void shoot(){ + if(mousePressed && mouseButton == LEFT){ + c = color (255, 0, 0); + pewpew.add(new Bullet(mouseX, height- 100)); + bullet.y -= bVel; + }else if (mousePressed && mouseButton == RIGHT){ + c = color(0, 255, 0); + pewpew.add(new Bullet(mouseX, height - 100)); + bullet.y -= bVel; + } + + } + +} diff --git a/StudentFolders/A1/Reilly W/applegameee/collisions.pde b/StudentFolders/A1/Reilly W/applegameee/collisions.pde new file mode 100644 index 0000000..15878d9 --- /dev/null +++ b/StudentFolders/A1/Reilly W/applegameee/collisions.pde @@ -0,0 +1,170 @@ +boolean pointCircle(float px, float py, float cx, float cy, float cr){ + if(dist(px, py, cx, cy) < cr){ + return true; + } else { + return false; + } +} + +boolean circleCircle(float cx1, float cy1, float cr1, float cx2, float cy2, float cr2){ + if(dist(cx1, cy1, cx2, cy2) < cr1 + cr2){ + return true; + } else { + return false; + } +} + +boolean pointRect(float px, float py, float rx, float ry, float rw, float rh) { + + // is the point inside the rectangle's bounds? + if (px >= rx && // right of the left edge AND + px <= rx + rw && // left of the right edge AND + py >= ry && // below the top AND + py <= ry + rh) { // above the bottom + return true; + } + return false; +} + +boolean rectRect(float r1x, float r1y, float r1w, float r1h, float r2x, float r2y, float r2w, float r2h) { + + // are the sides of one rectangle touching the other? + + if (r1x + r1w >= r2x && // r1 right edge past r2 left + r1x <= r2x + r2w && // r1 left edge past r2 right + r1y + r1h >= r2y && // r1 top edge past r2 bottom + r1y <= r2y + r2h) { // r1 bottom edge past r2 top + return true; + } + return false; +} + +// CIRCLE/RECTANGLE +boolean circleRect(float cx, float cy, float radius, float rx, float ry, float rw, float rh) { + + // temporary variables to set edges for testing + float testX = cx; + float testY = cy; + + // which edge is closest? + if (cx < rx) testX = rx; // test left edge + else if (cx > rx+rw) testX = rx+rw; // right edge + if (cy < ry) testY = ry; // top edge + else if (cy > ry+rh) testY = ry+rh; // bottom edge + + // get distance from closest edges + float distX = cx-testX; + float distY = cy-testY; + float distance = sqrt( (distX*distX) + (distY*distY) ); + + // if the distance is less than the radius, collision! + if (distance <= radius) { + return true; + } + return false; +} + +// LINE/POINT +boolean linePoint(float x1, float y1, float x2, float y2, float px, float py) { + + // get distance from the point to the two ends of the line + float d1 = dist(px,py, x1,y1); + float d2 = dist(px,py, x2,y2); + + // get the length of the line + float lineLen = dist(x1,y1, x2,y2); + + // since floats are so minutely accurate, add + // a little buffer zone that will give collision + float buffer = 0.1; // higher # = less accurate + + // if the two distances are equal to the line's + // length, the point is on the line! + // note we use the buffer here to give a range, + // rather than one # + if (d1+d2 >= lineLen-buffer && d1+d2 <= lineLen+buffer) { + return true; + } + return false; +} + +boolean lineCircle(float x1, float y1, float x2, float y2, float cx, float cy, float r) { + + // is either end INSIDE the circle? + // if so, return true immediately + boolean inside1 = pointCircle(x1,y1, cx,cy,r); + boolean inside2 = pointCircle(x2,y2, cx,cy,r); + if (inside1 || inside2) return true; + + // get length of the line + float distX = x1 - x2; + float distY = y1 - y2; + float len = sqrt( (distX*distX) + (distY*distY) ); + + // get dot product of the line and circle + float dot = ( ((cx-x1)*(x2-x1)) + ((cy-y1)*(y2-y1)) ) / pow(len,2); + + // find the closest point on the line + float closestX = x1 + (dot * (x2-x1)); + float closestY = y1 + (dot * (y2-y1)); + + // is this point actually on the line segment? + // if so keep going, but if not, return false + boolean onSegment = linePoint(x1,y1,x2,y2, closestX,closestY); + if (!onSegment) return false; + + // optionally, draw a circle at the closest + // point on the line + //fill(255,0,0); + //noStroke(); + //ellipse(closestX, closestY, 20, 20); + + // get distance to closest point + distX = closestX - cx; + distY = closestY - cy; + float distance = sqrt( (distX*distX) + (distY*distY) ); + + if (distance <= r) { + return true; + } + return false; +} + +// LINE/LINE +boolean lineLine(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) { + + // calculate the distance to intersection point + float uA = ((x4-x3)*(y1-y3) - (y4-y3)*(x1-x3)) / ((y4-y3)*(x2-x1) - (x4-x3)*(y2-y1)); + float uB = ((x2-x1)*(y1-y3) - (y2-y1)*(x1-x3)) / ((y4-y3)*(x2-x1) - (x4-x3)*(y2-y1)); + + // if uA and uB are between 0-1, lines are colliding + if (uA >= 0 && uA <= 1 && uB >= 0 && uB <= 1) { + + // optionally, draw a circle where the lines meet + float intersectionX = x1 + (uA * (x2-x1)); + float intersectionY = y1 + (uA * (y2-y1)); + //fill(255,0,0); + //noStroke(); + //ellipse(intersectionX,intersectionY, 20,20); + + return true; + } + return false; +} + +boolean lineRect(float x1, float y1, float x2, float y2, float rx, float ry, float rw, float rh) { + + // check if the line has hit any of the rectangle's sides + // uses the Line/Line function below + boolean left = lineLine(x1,y1,x2,y2, rx,ry,rx, ry+rh); + boolean right = lineLine(x1,y1,x2,y2, rx+rw,ry, rx+rw,ry+rh); + boolean top = lineLine(x1,y1,x2,y2, rx,ry, rx+rw,ry); + boolean bottom = lineLine(x1,y1,x2,y2, rx,ry+rh, rx+rw,ry+rh); + + // if ANY of the above are true, the line + // has hit the rectangle + if (left || right || top || bottom) { + return true; + } + return false; +} diff --git a/StudentFolders/A1/Reilly W/applegameee/player.pde b/StudentFolders/A1/Reilly W/applegameee/player.pde new file mode 100644 index 0000000..1f66838 --- /dev/null +++ b/StudentFolders/A1/Reilly W/applegameee/player.pde @@ -0,0 +1,15 @@ +class Player{ + PVector player; + Player(){ + player = new PVector (mouseX, height -100); + } + + void display(){ + fill(255); + circle(player.x, player.y, 50); + } + + void update(){ + player.x = mouseX; + } +} diff --git a/StudentFolders/A1/Reilly W/blackBox/blackBox.pde b/StudentFolders/A1/Reilly W/blackBox/blackBox.pde new file mode 100644 index 0000000..10855fa --- /dev/null +++ b/StudentFolders/A1/Reilly W/blackBox/blackBox.pde @@ -0,0 +1,22 @@ +void setup() { + size (800, 600); +} + + +void draw() { + /*if ((mouseX) < (width/2) && (mouseY < height/2)){ + background(255, 0, 0); + }else if (mouseX < (width/2) && mouseY > height/2 ){ + background (0, 0 , 255); + }else if (mouseX> width/2&& mouseY< height /2){ + background (0, 255, 0); + }else { + background (0); + }*/ + + if (mouseX < (width/3)*2 && (mouseX > (width/3)) && (mouseY < (height/3*2)) && (mouseY> height/3)){ + background (0); + }else{ + background (255); + } +} diff --git a/StudentFolders/A1/Reilly W/bulletCode/bulletCode.pde b/StudentFolders/A1/Reilly W/bulletCode/bulletCode.pde new file mode 100644 index 0000000..0086fdc --- /dev/null +++ b/StudentFolders/A1/Reilly W/bulletCode/bulletCode.pde @@ -0,0 +1,29 @@ +float x = 400; +float y = 575; +float cy = 0; + + + +void setup() { + size(800, 600); +} + +void draw() { + background(255); + circle(x, y, 25); + y -= cy; + if (y<-25) { + cy = 0; + y = 575; + x = random(25, 775); + } +} + +void keyPressed() { + if (key ==' ') { + if (cy == 0) { + cy = 7 ; + + } + } +} diff --git a/StudentFolders/A1/Reilly W/dino_game/collisions.pde b/StudentFolders/A1/Reilly W/dino_game/collisions.pde new file mode 100644 index 0000000..15878d9 --- /dev/null +++ b/StudentFolders/A1/Reilly W/dino_game/collisions.pde @@ -0,0 +1,170 @@ +boolean pointCircle(float px, float py, float cx, float cy, float cr){ + if(dist(px, py, cx, cy) < cr){ + return true; + } else { + return false; + } +} + +boolean circleCircle(float cx1, float cy1, float cr1, float cx2, float cy2, float cr2){ + if(dist(cx1, cy1, cx2, cy2) < cr1 + cr2){ + return true; + } else { + return false; + } +} + +boolean pointRect(float px, float py, float rx, float ry, float rw, float rh) { + + // is the point inside the rectangle's bounds? + if (px >= rx && // right of the left edge AND + px <= rx + rw && // left of the right edge AND + py >= ry && // below the top AND + py <= ry + rh) { // above the bottom + return true; + } + return false; +} + +boolean rectRect(float r1x, float r1y, float r1w, float r1h, float r2x, float r2y, float r2w, float r2h) { + + // are the sides of one rectangle touching the other? + + if (r1x + r1w >= r2x && // r1 right edge past r2 left + r1x <= r2x + r2w && // r1 left edge past r2 right + r1y + r1h >= r2y && // r1 top edge past r2 bottom + r1y <= r2y + r2h) { // r1 bottom edge past r2 top + return true; + } + return false; +} + +// CIRCLE/RECTANGLE +boolean circleRect(float cx, float cy, float radius, float rx, float ry, float rw, float rh) { + + // temporary variables to set edges for testing + float testX = cx; + float testY = cy; + + // which edge is closest? + if (cx < rx) testX = rx; // test left edge + else if (cx > rx+rw) testX = rx+rw; // right edge + if (cy < ry) testY = ry; // top edge + else if (cy > ry+rh) testY = ry+rh; // bottom edge + + // get distance from closest edges + float distX = cx-testX; + float distY = cy-testY; + float distance = sqrt( (distX*distX) + (distY*distY) ); + + // if the distance is less than the radius, collision! + if (distance <= radius) { + return true; + } + return false; +} + +// LINE/POINT +boolean linePoint(float x1, float y1, float x2, float y2, float px, float py) { + + // get distance from the point to the two ends of the line + float d1 = dist(px,py, x1,y1); + float d2 = dist(px,py, x2,y2); + + // get the length of the line + float lineLen = dist(x1,y1, x2,y2); + + // since floats are so minutely accurate, add + // a little buffer zone that will give collision + float buffer = 0.1; // higher # = less accurate + + // if the two distances are equal to the line's + // length, the point is on the line! + // note we use the buffer here to give a range, + // rather than one # + if (d1+d2 >= lineLen-buffer && d1+d2 <= lineLen+buffer) { + return true; + } + return false; +} + +boolean lineCircle(float x1, float y1, float x2, float y2, float cx, float cy, float r) { + + // is either end INSIDE the circle? + // if so, return true immediately + boolean inside1 = pointCircle(x1,y1, cx,cy,r); + boolean inside2 = pointCircle(x2,y2, cx,cy,r); + if (inside1 || inside2) return true; + + // get length of the line + float distX = x1 - x2; + float distY = y1 - y2; + float len = sqrt( (distX*distX) + (distY*distY) ); + + // get dot product of the line and circle + float dot = ( ((cx-x1)*(x2-x1)) + ((cy-y1)*(y2-y1)) ) / pow(len,2); + + // find the closest point on the line + float closestX = x1 + (dot * (x2-x1)); + float closestY = y1 + (dot * (y2-y1)); + + // is this point actually on the line segment? + // if so keep going, but if not, return false + boolean onSegment = linePoint(x1,y1,x2,y2, closestX,closestY); + if (!onSegment) return false; + + // optionally, draw a circle at the closest + // point on the line + //fill(255,0,0); + //noStroke(); + //ellipse(closestX, closestY, 20, 20); + + // get distance to closest point + distX = closestX - cx; + distY = closestY - cy; + float distance = sqrt( (distX*distX) + (distY*distY) ); + + if (distance <= r) { + return true; + } + return false; +} + +// LINE/LINE +boolean lineLine(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) { + + // calculate the distance to intersection point + float uA = ((x4-x3)*(y1-y3) - (y4-y3)*(x1-x3)) / ((y4-y3)*(x2-x1) - (x4-x3)*(y2-y1)); + float uB = ((x2-x1)*(y1-y3) - (y2-y1)*(x1-x3)) / ((y4-y3)*(x2-x1) - (x4-x3)*(y2-y1)); + + // if uA and uB are between 0-1, lines are colliding + if (uA >= 0 && uA <= 1 && uB >= 0 && uB <= 1) { + + // optionally, draw a circle where the lines meet + float intersectionX = x1 + (uA * (x2-x1)); + float intersectionY = y1 + (uA * (y2-y1)); + //fill(255,0,0); + //noStroke(); + //ellipse(intersectionX,intersectionY, 20,20); + + return true; + } + return false; +} + +boolean lineRect(float x1, float y1, float x2, float y2, float rx, float ry, float rw, float rh) { + + // check if the line has hit any of the rectangle's sides + // uses the Line/Line function below + boolean left = lineLine(x1,y1,x2,y2, rx,ry,rx, ry+rh); + boolean right = lineLine(x1,y1,x2,y2, rx+rw,ry, rx+rw,ry+rh); + boolean top = lineLine(x1,y1,x2,y2, rx,ry, rx+rw,ry); + boolean bottom = lineLine(x1,y1,x2,y2, rx,ry+rh, rx+rw,ry+rh); + + // if ANY of the above are true, the line + // has hit the rectangle + if (left || right || top || bottom) { + return true; + } + return false; +} diff --git a/StudentFolders/A1/Reilly W/dino_game/data/test.txt b/StudentFolders/A1/Reilly W/dino_game/data/test.txt new file mode 100644 index 0000000..e69de29 diff --git a/StudentFolders/A1/Reilly W/dino_game/dino.pde b/StudentFolders/A1/Reilly W/dino_game/dino.pde new file mode 100644 index 0000000..36ccb18 --- /dev/null +++ b/StudentFolders/A1/Reilly W/dino_game/dino.pde @@ -0,0 +1,48 @@ +class Dino { + PVector dinopos; + PVector gravity; + float jumpStrength; + PVector vel; + float w; + float h; + boolean canJump; + + Dino() { + dinopos = new PVector (100, 550); + vel = new PVector (0, 0); + gravity = new PVector (0, 0.67); + jumpStrength = 15; + w=25; + h=50; + canJump = true; + } + + + void update() { + dinopos.add(vel); + if (vel.y != 0 || dinopos.y < 550) { + vel.add(gravity); + canJump = false; + } + if(dinopos.y + h > height){ + dinopos.y = 550; + vel.y = 0; + canJump = true; + } + } + + void display () { + fill(0); + rect(dinopos.x, dinopos.y, w, h); + } + + void jump() { + if (canJump == true) { + vel = new PVector (0, -jumpStrength); + } + } + + boolean isTouching(Obstacle o) { + return false; + } +} diff --git a/StudentFolders/A1/Reilly W/dino_game/dino_game.pde b/StudentFolders/A1/Reilly W/dino_game/dino_game.pde new file mode 100644 index 0000000..4cbd350 --- /dev/null +++ b/StudentFolders/A1/Reilly W/dino_game/dino_game.pde @@ -0,0 +1,32 @@ +Dino d; +ArrayList obstacles = new ArrayList(); + +void setup() { + size(800, 600); + d = new Dino(); + obstacles.add(new Obstacle()); +} + + +void draw() { + background(150); + d.update(); + d.display(); + + for (int i =0; i < obstacles.size(); i++) { + Obstacle o = obstacles.get(i); + o.move(); + o.display(); + } + println(obstacles.get(0).Opos.y); +} + + +void keyPressed() { + if (key == ' ') { + d.jump(); + } + if (key == 'x') { + obstacles.add(new Obstacle()); + } +} diff --git a/StudentFolders/A1/Reilly W/dino_game/obstacle.pde b/StudentFolders/A1/Reilly W/dino_game/obstacle.pde new file mode 100644 index 0000000..a3d4a4a --- /dev/null +++ b/StudentFolders/A1/Reilly W/dino_game/obstacle.pde @@ -0,0 +1,23 @@ +class Obstacle { + PVector Opos; + PVector vel; + float w; + float h; + + Obstacle() { + + w = 20; + h = 50; + Opos = new PVector(width-w, height -h); + vel = new PVector(-2, 0); + } + + void move() { + Opos.add(vel); + } + + void display() { + fill(200, 0, 50); + rect(Opos.x, Opos.y, w, h); + } +} diff --git a/StudentFolders/A1/Reilly W/max_min/max_min.pde b/StudentFolders/A1/Reilly W/max_min/max_min.pde new file mode 100644 index 0000000..eb3af34 --- /dev/null +++ b/StudentFolders/A1/Reilly W/max_min/max_min.pde @@ -0,0 +1,14 @@ +float [] nums = new float [100]; + +void setup() { + size(800, 600); + float sum = 0; + for (int i = 0; i< nums.length; i++) { + nums[i] = random(-100, -1); + sum = sum + nums[i]; + } + println("Max:"+max(nums)); + println("Min:"+min(nums)); + println("Avg:"+sum/nums.length); + printArray(nums); +} diff --git a/StudentFolders/A1/Reilly W/my_first_bouncing_ball_using_object/bouncer.pde b/StudentFolders/A1/Reilly W/my_first_bouncing_ball_using_object/bouncer.pde new file mode 100644 index 0000000..099fd45 --- /dev/null +++ b/StudentFolders/A1/Reilly W/my_first_bouncing_ball_using_object/bouncer.pde @@ -0,0 +1,25 @@ +class Bouncer { + PVector pos; + PVector v; + int size = 50; + + Bouncer() { + pos = new PVector(random(100, 700), random(100, 500)); + v = new PVector(random(-5, 5), random(-5, 5)); + } + + void move(){ + pos.add(v); + + if (pos.x>width-size/2 || pos.xheight-size/2 || pos.yheight+75){ + y[i] = -35; + x[i] = random(-50, 850); + + } + + + } + +} + +void drawRaindrop(float x, float y, float op){ + noStroke(); + fill(0, 200, 255, op); + circle(x, y, 50); + triangle(x, y-60,x - 25, y-5, x+25, y-5); +} diff --git a/StudentFolders/A1/Reilly W/sketch_12_buildings_thing/sketch_12_buildings_thing.pde b/StudentFolders/A1/Reilly W/sketch_12_buildings_thing/sketch_12_buildings_thing.pde new file mode 100644 index 0000000..eb41859 --- /dev/null +++ b/StudentFolders/A1/Reilly W/sketch_12_buildings_thing/sketch_12_buildings_thing.pde @@ -0,0 +1,12 @@ +void setup() { + fullScreen(); +} + +void draw() { + background(120); + for (int i = 100; i< width; i += width/3) { + for (int v = 100; v