[PWC7] Interactive Lines

First time submitting a challenge here, if anyone can let me know of any sites that can run my processing script instead of having everyone else copy/paste my code I would be very grateful! I do have an account with open processing, but it will not run this code for some reason. Feedback is appreciated!

Edit: Video

ParticleSystem ps; void setup() { size(640, 400); background(255); ps = new ParticleSystem(); } void draw() { background(255); ps.run(); buttons(); //GUI stroke(127); fill(200); rect(540, 0, 100, height); fill(0); text("Point1 x velocity", 540, 10); text(ps.v1.x, 570, 25); text("Point1 y velocity", 540, 50); text(ps.v1.y, 570, 65); text("Point2 x velocity", 540, 90); text(ps.v2.x, 570, 105); text("Point2 y velocity", 540, 130); text(ps.v2.y, 570, 145); text("Color r velocity", 540, 170); text(ps.v3.x, 570, 185); text("Color g velocity", 540, 210); text(ps.v3.y, 570, 225); text("Color b velocity", 540, 250); text(ps.v3.z, 570, 265); text("Life Span", 540, 290); text((int)ps.maxlife, 570, 305); fill(127); rect(545, 15, 10, 10); rect(625, 15, 10, 10); rect(545, 55, 10, 10); rect(625, 55, 10, 10); rect(545, 95, 10, 10); rect(625, 95, 10, 10); rect(545, 135, 10, 10); rect(625, 135, 10, 10); rect(545, 175, 10, 10); rect(625, 175, 10, 10); rect(545, 215, 10, 10); rect(625, 215, 10, 10); rect(545, 255, 10, 10); rect(625, 255, 10, 10); rect(545, 295, 10, 10); rect(625, 295, 10, 10); } void buttons() { // Button functionality if (mousePressed == true) { //v1 x velocity if ((mouseX > 545 && mouseX < 555) && (mouseY > 15 && mouseY < 25)) { ps.v1.x -= 0.0003; } if ((mouseX > 625 && mouseX < 635) && (mouseY > 15 && mouseY < 25)) { ps.v1.x += 0.0003; } //v1 y velocity if ((mouseX > 545 && mouseX < 555) && (mouseY > 55 && mouseY < 65)) { ps.v1.y -= 0.0003; } if ((mouseX > 625 && mouseX < 635) && (mouseY > 55 && mouseY < 65)) { ps.v1.y += 0.0003; } //v2 x velocity if ((mouseX > 545 && mouseX < 555) && (mouseY > 95 && mouseY < 105)) { ps.v2.x -= 0.0003; } if ((mouseX > 625 && mouseX < 635) && (mouseY > 95 && mouseY < 105)) { ps.v2.x += 0.0003; } //v2 y velocity if ((mouseX > 545 && mouseX < 555) && (mouseY > 135 && mouseY < 145)) { ps.v2.y -= 0.0003; } if ((mouseX > 625 && mouseX < 635) && (mouseY > 135 && mouseY < 145)) { ps.v2.y += 0.0003; } //v3 x velocity if ((mouseX > 545 && mouseX < 555) && (mouseY > 175 && mouseY < 185)) { ps.v3.x -= 0.0003; } if ((mouseX > 625 && mouseX < 635) && (mouseY > 175 && mouseY < 185)) { ps.v3.x += 0.0003; } //v3 y velocity if ((mouseX > 545 && mouseX < 555) && (mouseY > 215 && mouseY < 225)) { ps.v3.y -= 0.0003; } if ((mouseX > 625 && mouseX < 635) && (mouseY > 215 && mouseY < 225)) { ps.v3.y += 0.0003; } //v3 z velocity if ((mouseX > 545 && mouseX < 555) && (mouseY > 255 && mouseY < 265)) { ps.v3.z -= 0.0003; } if ((mouseX > 625 && mouseX < 635) && (mouseY > 255 && mouseY < 265)) { ps.v3.z += 0.0003; } //lifespan if ((mouseX > 545 && mouseX < 555) && (mouseY > 295 && mouseY < 305)) { ps.maxlife -= 0.3; } if ((mouseX > 625 && mouseX < 635) && (mouseY > 295 && mouseY < 305)) { ps.maxlife += 0.3; } } } class Line { //line's points PVector t1; // time for point 1 PVector n1;// noise for point 1 PVector pos1;// position for point 1 PVector t2;// time for point 2 PVector n2;// noise for point 2 PVector pos2; // position for point 2 //line's stroke PVector t3; // time for stroke color PVector n3; // noise for stroke color color col; // stroke color //lifespan float lifespan; // alpha for stroke color float maxlife; Line(PVector t1_, PVector t2_, PVector t3_, float lifespan_) { t1 = t1_; t2 = t2_; t3 = t3_; lifespan = lifespan_; maxlife = 255; n1 = new PVector(noise(t1.x), noise(t1.y)); n2 = new PVector(noise(t2.x), noise(t2.y)); pos1 = new PVector(map(n1.x, 0, 1, 0, width), map(n1.y, 0, 1, 0, height)); pos2 = new PVector(map(n2.x, 0, 1, 0, width), map(n2.y, 0, 1, 0, height)); n3 = new PVector(noise(t3.x), noise(t3.y), noise(t3.z)); col = color(map(n3.x, 0, 1, 0, 255), map(n3.y, 0, 1, 0, 255), map(n3.z, 0, 1, 0, 255)); } void run() { display(); lifespan -= 2; } void display() { stroke(col, map(lifespan, 0, 255, 0, maxlife)); line(pos1.x, pos1.y, pos2.x, pos2.y); } boolean isDead() { if (lifespan < 1) { return true; } else { return false; } } } class ParticleSystem { ArrayList<Line> lines; // ArrayList of Line objects PVector v1; // velocity of PVector 1 PVector v2; // velocity of PVector 2 PVector v3; // velocity of PVector 3 float maxlife; // max lifespan mapped between 0 and 255 ParticleSystem() { lines = new ArrayList<Line>(); v1 = new PVector(0.006, 0.006); v2 = new PVector(0.006, 0.006); v3 = new PVector(0.006, 0.006, 0.006); maxlife = 255; } void run() { // update and addLine methods update(); addLine(); } void addLine() { if (lines.size() < 1) { // if there are no Line objects // create random time PVectors lines.add(new Line(new PVector(random(0, 100000), random(0, 100000)), new PVector(random(0,100000), random(0, 100000)), new PVector(random(0,100000), random(0, 100000), random(0, 100000)), maxlife)); } else if (lines.size() < 500) { // else if there are less than some number // create a new Line objects with the previous line's time PVectors with added // velocity Line last = lines.get(lines.size() - 1); lines.add(new Line(last.t1.add(v1), last.t2.add(v2), last.t3.add(v3), maxlife)); } } void update() { // executes each Line object's run function and checks for dead Lines for (int i = lines.size() - 1; i >= 0; i--) { Line l = lines.get(i); l.run(); if (l.isDead()) { lines.remove(l); } } } } 
submitted by /u/DontTroubleYourself
[link] [comments]

Help with freezing certain draw functions when paused.

I'm attempting to make a simple game. Right now my problem is that I want it so that when I press a key, the bars that are reacting to the music freeze in place. I've gotten it to work where it pauses the audio but the rectangles disappear as well (since I guess there's not audio to base their heights on).

Also, I'm using the Minim Library for Audio Visualization.

Here is my code, put in any audio file to run in place of "money":

void setup() { size(1024, 200); minim = new Minim(this); money = minim.loadFile("audio.mp3", 1024); money.loop(); } void draw() { background(0); noStroke(); fill( 255, 128 ); rect( 0, 0, 512, audio.left.level()*height ); rect( 512, 0, 512, audio.right.level()*height ); } void keyPressed() { int h = height; float x1 = money.left.level()*h; float x2 = money.right.level()*h; if ( audio.isPlaying() ) { audio.pause(); rect(0,0,512,x1); rect(512,0,512,x2); } else {audio.loop();} } 
submitted by /u/pacduck
[link] [comments]

Help with converting a code I used when designing in processing to a code that will work with p5.js.

Hi, still a newbie to processing, p5.js, and the likes, and I was wondering if anyone could help me in not only converting a code to p5.js, but explaining why I make the changes I have to, haha. I feel like learning why will just help me more in the future.

Thank you very much!

Here's the code, if I'm doing this correctly:

void setup() { size(900, 600); background(50); colorMode (HSB, 100, 100, 100); } void draw() { float r = random (50); if (mousePressed==true){ fill(250,0,100); ellipse(mouseX,mouseY,50,50); } else { fill(0, 100, 100, 2); stroke (50, 100, 100, 2); strokeWeight(50); fill(0,100,100,2); ellipse(mouseX,mouseY,r,r); } } 
submitted by /u/thrsanne
[link] [comments]

Book Review: Out of Now. The Lifeworks of Tehching Hsieh

Out of Now. The Lifeworks of Tehching Hsieh (updated edition), by Tehching Hsieh and Adrian Heathfield.

Available on amazon UK and USA.

OON-cover-787x1024

Publisher MIT Press writes: In the vibrant downtown Manhattan art scene of the late 1970s and early 1980s, the Taiwanese-American artist Tehching Hsieh made a series of extraordinary performance art works. Between September 1978 and July 1986, Hsieh realized five separate one-year-long performance pieces in which he conformed to simple but highly restrictive rules throughout each entire year.

Through the course of these lifeworks, Hsieh moved from a year of solitary confinement in a sealed cell to a year in which he punched a worker’s time clock in his studio every hour on the hour to a year spent living without shelter in Manhattan to a year in which he was tied by an eight-foot rope to the artist Linda Montano and finally to a year of total abstention from all art activities and influences. In 1986 Hsieh announced that he would spend the next thirteen years making art but not showing it publicly. When this “final” lifework—an immense act of self-affirmation and self-erasure—came to a close at the turn of the millennium, he tersely and enigmatically said that during this time he had simply kept himself alive.

After years of near-invisibility, Hsieh collaborated with the British writer and curator Adrian Heathfield to create this meticulous and visually arresting documentary record of the complete body of Tehching Hsieh’s performance projects from 1978 to 1999. This milestone volume is now available again, in a paperback edition featuring the full text and all the illustrations in the hardcover, with an updated list of Hsieh’s exhibitions.

Tehching Hsieh, One Year Performance, 1978-9, 1
One Year Performance, 1978-1979

There are artworks that keep on haunting me and make me wonder “would i ever have the guts/strength/courage to do the same?” Michael Landy destroying all his possessions is a good example of that. And then there’s Tehching Hsieh. He’s the legend who to wanted to make the process of thinking about art an artwork in its own right. He did so by setting himself some simple but almost inhumanely restrictive rules that he followed, religiously, for one year. He first sat in a cell with no communication for a year. He then punched a time clock every hour on the hour for a year. He lived on the street for a year. He tied himself to a fellow artist for a year. For his last performance, he avoided engaging in any art practice. Again, for a full year.

Tehching Hsieh, One Year Performance n. 2, Time Clock Piece, 1980-81

The works took place from 1978 to 1986 in New York, a period in which he had to navigate between the growing attention from the public for his work and the necessity to remain under the radar because he was an illegal immigrant from Taiwan. If his year long performances were not radical enough, Tehching Hsieh also announced in 1986 that he would spend the next 13 years making art without showing it publicly. In the art world, this kind of crazy gesture is akin to suicide. In 1999, when he finally emerged from his voluntary cultural exile, all he said was that in that period he had ‘kept himself alive.’

Out of Now is a new and slightly updated edition of a book that’s been out of stock for the past few years. The book collects the visual documentation of the artist’s performances. The photos, maps, artist statements, etc. As well as white pages for the 13 years of artistic silence.

The introduction to the documentation consists in a series of short essays by writer and curator Adrian Heathfield who places Hsieh’s practice into the cultural context of its time while demonstrating how different it is from the ideas and concepts of that same period.

My favourite part of Out of Now is the long interview Adrian Heathfield did with Tehching Hsieh. The conversation is both deep and charming, hopping from topics as diverse as Hsieh’s mother opinion about his work to the various ways in which each piece consumed his life.

The final part of the book compiles texts written by famous and anonymous people who express the impact that Hsieh’s work had on them. There’s Tim Etchells, Santiago Sierra or Marina Abramovic writing about their admiration for his work but there’s also an unsigned letter from someone who thinks that Hsieh’s work brings ‘shame and discredit to the Chinese people”.

Out of Now documents a series of artworks but somehow manages to keep their author shrouded in mystery. Hsieh is interviewed, his work is analyzed, put into images and commented. The more you read, the less you understand the man who has pushed his emotional, physical and psychological endurance to such extreme limits. That’s probably the best homage that a book could pay to a man who is so often described as being a ‘cult figure’ in the art world.

0image2hhhhhhhhhhhhhh
One Year Performance, 1978-1979

NO.1_2_Statement
Statement for One Year Performance, 1978-1979

Tehching-Hsieh-NO.1_4
Tehching Hsieh, One Year Performance, 1978-1979. Copyright Tehching Hsieh

0sont-slide6
Tehching Hsieh, One Year Performance, 1978-79

For “Cage Piece”, Hsieh constructed a cell inside a loft in TriBeCa. The rules of his solitary confinement were listed in a curt manifesto: “I shall NOT converse, read, write, listen to the radio or watch television until I unseal myself on September 29, 1979.” Every day, a friend would bring him food and take out his waste.

hsieh_timepiece_4
Tehching Hsieh, One Year Performance n. 2, Time Clock Piece, 1980-81 (still from video)

hsieh_one-year-performance-1
Tehching Hsieh, One Year Performance, 1980-81

Tehching Tsieh, Carriageworks, Install Documentation
Tehching Hsieh, One Year Performance, 1980-81

For the “Time Piece,” the artist essentially denied himself sleep in order to punch a time clock every hour on the hour, twenty four hours a day, for one year. He apparently had to attach multiple alarm clocks to amplifiers to penetrate his foggy brain. Every time he punched the clock a movie camera would take a single movie picture shot of him.

hsieh1_1000
One Year Performance, Outdoor Piece, 1981–1982

Hsieh_One-Year-Performance_Posters-1
One Year Performance, Outdoor Piece, 1981–1982

Tehching Hsieh, One Year Performance, 1981-2, 1
One Year Performance, Outdoor Piece, 1981–1982

In his third performance piece, Hsieh spent one year living in the street, not entering buildings or shelter of any sort. He walked around New York City with a backpack and a sleeping bag and charted his wanderings on maps.

0iTehchingHsieh003
Tehching Hsieh, One Year Performance, 1983-1984

thsieh-artlife-21329004224549
Tehching Hsieh, One Year Performance, 1983-1984

Tehching Hsieh, Art Life, 1
Tehching Hsieh, One Year Performance, 1983-1984

For his next performance, he tied himself to artist Linda Montano with an 8 foot long rope. While the rope obliged them to do everything together, but any intentional bodily contact was forbidden.

Help with a hitbox

Hi there!

I am having trouble with the exam project for a short programming course and i am all out of idea so here goes.

i am having trouble with my hit detection As far as i can see the code (http://pastebin.com/5tWMwT0z) should trigger the hit mechanic every time i click inside the radius of one of the bubbels onscreen but sometimes it simply dosent trigger the code. //i know this is a lot of effort for some stranger on the internet// but any help would be greatly appreciated. Here are the picture files needed to run the code: https://drive.google.com/folderview?id=0B7uS-SB6A83rZ2x4TjVLZ2NXQ0k&usp=sharing

submitted by /u/next1759
[link] [comments]

[PWC7] Perlin Noise

Hello Everybody, this is the seventh Weekly Processing challenge, the challenges are decided just to give you a prompt to test your skills so it can be as simple or as complicated as you have time to write!

Start Date : 25-04-2016 End Date : 01-05-2016

Entries must be submitted with the [PWC7] In the Title of their post. Or post them in the comments here with the same tag. This Weeks Challenge : Perlin Noise , A good start might be to look at The Nature of Code this is a concept which can very simply make many sketches look better , apologies as it is a little vague.

Winner from last week(And thank you very much for the massive creativity in submissions!):

Winner : /u/JimmySticks2001

submitted by /u/seoceojoe
[link] [comments]

Can someone explain to me why nothing is coming up on processing

I am doing a project in college and my group member and I are almost finished it. It is an Arduino Radar. We had to modify the code so we didn't just copy/paste it so we added an led and a buzzer to it. The radar is working perfectly but the issue is we also have to use processing to display a radar on the screen. With the code I found on that website it displays the radar on the screen but when the Arduino is plugged in, processing doesn't move or do anything.

So if anyone can point me in the right direction as I have no idea what I'm doing, we haven't used processing before in class.

Forgot to mention, what is meant to happen is the radar goes from left to right and when something is in front of it, the radar in processing is meant to go from a green line to a red line. At the moment it is just staying like this all of the time.

Cheers

Arduino Code

#define echoPin 6 #define trigPin 7 #define piezoPin 4 #include <Servo.h>. Servo myServo; void setup() { Serial.begin (9600); pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); pinMode(3, OUTPUT); pinMode(piezoPin, OUTPUT); myServo.attach(2); } void loop() { for(int angle=15;angle<=165;angle++){ long duration, distance; digitalWrite(trigPin, LOW); delayMicroseconds(5); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH); distance = (duration/2) / 29.1; myServo.write(angle); delay(30); for(int angle=165;angle<=15;angle--){ myServo.write(angle); delay(30); } if (distance <= 15){ Serial.print(distance); Serial.print(" cm, "); Serial.print(angle); Serial.println(" degrees."); delay(500); digitalWrite(3, HIGH); delayMicroseconds(200); digitalWrite(3, LOW); delayMicroseconds(200); tone( 4 , 4000 , 100);} else { Serial.println("Out of range");} } 

}

Processing Code

import processing.serial.*; import java.awt.event.KeyEvent; import java.io.IOException; Serial myPort; String angle=""; String distance=""; String data=""; String noObject; float pixsDistance; int iAngle, iDistance; int index1=0; int index2=0; void setup() { size (1200, 750); smooth(); myPort = new Serial(this,"COM3", 9600); myPort.bufferUntil('.'); } void draw() { fill(98,245,31); noStroke(); fill(0,4); rect(0, 0, width, height-height*0.065); fill(98,245,31); // green color drawRadar(); drawLine(); drawObject(); drawText(); } void serialEvent (Serial myPort) { data = myPort.readStringUntil('.'); data = data.substring(0,data.length()-1); index1 = data.indexOf(","); angle= data.substring(0, index1); distance= data.substring(index1+1, data.length()); iAngle = int(angle); iDistance = int(distance); } void drawRadar() { pushMatrix(); translate(width/2,height-height*0.074); noFill(); strokeWeight(2); stroke(98,245,31); arc(0,0,(width-width*0.0625),(width-width*0.0625),PI,TWO_PI); arc(0,0,(width-width*0.27),(width-width*0.27),PI,TWO_PI); arc(0,0,(width-width*0.479),(width-width*0.479),PI,TWO_PI); arc(0,0,(width-width*0.687),(width-width*0.687),PI,TWO_PI); line(-width/2,0,width/2,0); line(0,0,(-width/2)*cos(radians(30)),(-width/2)*sin(radians(30))); line(0,0,(-width/2)*cos(radians(60)),(-width/2)*sin(radians(60))); line(0,0,(-width/2)*cos(radians(90)),(-width/2)*sin(radians(90))); line(0,0,(-width/2)*cos(radians(120)),(-width/2)*sin(radians(120))); line(0,0,(-width/2)*cos(radians(150)),(-width/2)*sin(radians(150))); line((-width/2)*cos(radians(30)),0,width/2,0); popMatrix(); } void drawObject() { pushMatrix(); translate(width/2,height-height*0.074); strokeWeight(9); stroke(255,10,10); // red color pixsDistance = iDistance*((height-height*0.1666)*0.025); if(iDistance<=15){ line(pixsDistance*cos(radians(iAngle)),-pixsDistance*sin(radians(iAngle)),(width-width*0.505)*cos(radians(iAngle)),-(width-width*0.505)*sin(radians(iAngle))); } popMatrix(); } void drawLine() { pushMatrix(); strokeWeight(9); stroke(30,250,60); translate(width/2,height-height*0.074); line(0,0,(height-height*0.12)*cos(radians(iAngle)),-(height-height*0.12)*sin(radians(iAngle))); / popMatrix(); } void drawText() { pushMatrix(); if(iDistance<15) { noObject = "Out of Range"; } else { noObject = "In Range"; } fill(0,0,0); noStroke(); rect(0, height-height*0.0648, width, height); fill(98,245,31); textSize(25); text("10cm",width-width*0.3854,height-height*0.0833); text("20cm",width-width*0.281,height-height*0.0833); text("30cm",width-width*0.177,height-height*0.0833); text("40cm",width-width*0.0729,height-height*0.0833); textSize(40); text("Object: " + noObject, width-width*0.875, height-height*0.0277); text("Angle: " + iAngle +" °", width-width*0.48, height-height*0.0277); text("Distance: ", width-width*0.26, height-height*0.0277); if(iDistance>=15) { text(" " + iDistance +" cm", width-width*0.225, height-height*0.0277); } textSize(25); fill(98,245,60); translate((width-width*0.4994)+width/2*cos(radians(30)),(height-height*0.0907)-width/2*sin(radians(30))); rotate(-radians(-60)); text("30°",0,0); resetMatrix(); translate((width-width*0.503)+width/2*cos(radians(60)),(height-height*0.0888)-width/2*sin(radians(60))); rotate(-radians(-30)); text("60°",0,0); resetMatrix(); translate((width-width*0.507)+width/2*cos(radians(90)),(height-height*0.0833)-width/2*sin(radians(90))); rotate(radians(0)); text("90°",0,0); resetMatrix(); translate(width-width*0.513+width/2*cos(radians(120)),(height-height*0.07129)-width/2*sin(radians(120))); rotate(radians(-30)); text("120°",0,0); resetMatrix(); translate((width-width*0.5104)+width/2*cos(radians(150)),(height-height*0.0574)-width/2*sin(radians(150))); rotate(radians(-60)); text("150°",0,0); popMatrix(); } 
submitted by /u/MundoOnly
[link] [comments]

Help with amateur game design!!

Hi there! My friend and I are making a game but it seems that we've run into a wall and we need your guys' expertise! First off, our game is a maze game in which the ball has to reach the check point (yellow square) and avoid the walls. if it touches the walls, it is game over. Once the check point is reach, it can advance to the next maze (ie. Maze2). What we're having trouble is: 1) getting the player to hit the checkpoint and advancing 2) changing the score to a time based. The lower the time the better! If anyone knows how to edit our code or has suggestions, please help! It'll be greatly appreciated!! :) <3

u can copy and paste our code into processing, i swear it plays better than it looks!

// The game stages // (something to keep track of what game stage we're currently in Player dude = new Player(); Maze maze; Checkpoint checkpoint;

int INTRO = 1; int RUN_GAME = 2; int GAME_OVER = 3;

// We start at the intro! int gameState = INTRO;

int score = 0;

void setup() { size(500, 500); maze = new Maze (); checkpoint = new Checkpoint (); }

//////////////////////////////////////////////////////////////// void draw() { // Run different functions according to the value of gameState if (gameState == INTRO) intro(); else if (gameState == RUN_GAME) runGame(); else if (gameState == GAME_OVER) gameOver(); }

//////////////////////////////////////////////////////////////// // Intro Screen void intro() { background(200, 0, 0); fill(255); textAlign(CENTER); text("ZOMBIE", width/2, height/2-64); text("APOCALYPSE", width/2, height/2); text("Click the circle to start", width/2, height/3*2); pushMatrix (); translate (0, 450); ellipse (30, 0, 50, 50); popMatrix (); } ////////////////////// void runGame() { background(71, 35, 105);

maze.display ();

dude.move(); dude.display();

checkpoint.display ();

if (newCollision(maze, dude, checkpoint) == true) { // a collision triggers a gameState change! gameState = GAME_OVER; }

drawScore();

score++; }

/////////////////////// void gameOver() { background(0); // draw the objects but don't animate them // (frozen screen) dude.display();

drawScore();

fill(255, 0, 0);

textAlign(CENTER); text("YOU'RE DEAD!", width/2, height/2); text("Click the circle so try again", width/2, height/3*2); pushMatrix (); translate (0, 450); ellipse (30, 0, 50, 50); popMatrix (); } //////////////////////////////////////////////////////////////// void drawScore() { textAlign(LEFT); fill(0, 255, 0);

text( nf(score, 10), 20, 30); } //////////////////////////////////////////////////////////////// void mousePressed() { if (gameState == INTRO || gameState == GAME_OVER) { gameState = RUN_GAME; score = 0; // "reset" the score } } //////////////////////////////////////////////////////////////////////

boolean newCollision(Maze m, Player p, Checkpoint c) { //A Counter for parsing int i = 0; //////////////////////OLD FUNCTION U TOLD ME TO ADD TO ALLOW COLLISION WITH CHECL POINT float d = dist(p.x, p.y, c.x, c.y); if ( d < p.radius + c.radius) {
return true; /////////////////////////////////// //////// }

//Checks the amount of lines contained in one of the arrays while (i <= m.Mx1.length - 1) { //Checks if the line at index i is horizontal if ( m.My1[i] == m.My2[i] ) { //Checks if the line is within the x values of the line at index i, and then checks if the y value is within the radius of the player if ((p.x > m.Mx1[i]) && (p.x < m.Mx2[i]) && (p.y + p.radius - 10 > m.My1[i]) && (p.y - p.radius + 10 < m.My1[i])) { //If the above is true, then the player is colliding with the line, so we return and the loop breaks return true; } } //Checks if the line is vertical else if (m.Mx1[i] == m.Mx2[i]) { //Does the same as above, but with flipped x and ys. if ((p.y > m.My1[i]) && (p.y < m.My2[i]) && (p.x + p.radius - 10 > m.Mx1[i]) && (p.x - p.radius + 10 < m.Mx1[i])) { //Again, if this is true, we are colliding return true; } } //When we get here, we have checked one line, so we increase our counter, and check the next one! i++; } //If we get through the loop, we have checked all the lines, and therefore not collided, so we return false. return false;

} class Checkpoint { float x; float y; float radius; // radius for collision

Checkpoint() {

radius = 30; 

}

void display() {

fill (248,251,4); 

rect (467,46,20, 20);

}

} class Maze { float x; float y; float radius;

//Arrays for remebering each component of each line. The length is the total amount of lines in this level. int[] Mx1 = new int[10]; int[] Mx2 = new int[10]; int[] My1 = new int[10]; int[] My2 = new int[10]; Maze () { radius = 20; }

void display () { stroke(0); fill(0); strokeWeight(4);

//This is really tedious to do. Setting each line with a unique index and putting it's components into each array. line(10, 490, 490, 490); Mx1[0] = 10; Mx2[0] = 490; My1[0] = 490; My2[0] = 490; line(490, 100, 490, 490); Mx1[1] = 490; Mx2[1] = 490; My1[1] = 100; My2[1] = 490; line(10, 10, 490, 10); Mx1[2] = 10; Mx2[2] = 490; My1[2] = 10; My2[2] = 10; line(10, 10, 10, 400); Mx1[3] = 10; Mx2[3] = 10; My1[3] = 10; My2[3] = 400; strokeJoin(MITER); beginShape(); line(10, 400, 400, 400); Mx1[4] = 10; Mx2[4] = 400; My1[4] = 400; My2[4] = 400; line(400, 300, 400, 400); Mx1[5] = 400; Mx2[5] = 400; My1[5] = 300; My2[5] = 400; line(10, 300, 400, 300); Mx1[6] = 10; Mx2[6] = 400; My1[6] = 300; My2[6] = 300; line(90, 200, 490, 200); Mx1[7] = 90; Mx2[7] = 490; My1[7] = 200; My2[7] = 200; line(90, 100, 90, 200); Mx1[8] = 90; Mx2[8] = 90; My1[8] = 100; My2[8] = 200; line(90, 100, 490, 100); //Only goes to 9 as arrays start at 0! Mx1[9] = 90; Mx2[9] = 490; My1[9] = 100; My2[9] = 100; endShape(); } } class Maze2 { float x; float y; float radius;

//Arrays for remebering each component of each line. The length is the total amount of lines in this level. int[] Mx1 = new int[11]; int[] Mx2 = new int[11]; int[] My1 = new int[11]; int[] My2 = new int[11]; Maze2 () { radius = 20; }

void display () { stroke(0); fill(0); strokeWeight(4);

 line(10, 10, 490, 10); 

Mx1 [0] = 10; Mx2 [0] = 10; My1 [0] = 490; My2 [0] = 10; line(10, 80, 400, 80); Mx1[1] = 10; Mx2[1] = 80; My1[1] = 400; My2[1] = 80; line(50, 150, 490, 150); Mx1[2] = 50; Mx2[2] = 150; My1[2] = 490; My2[2] = 150; line(10, 220, 425, 220); Mx1[3] = 10; Mx2[3] = 220; My1[3] = 425; My2[3] = 220; strokeJoin(MITER); beginShape(); line (425, 220, 425, 430); Mx1[4] = 425; Mx2[4] = 220; My1[4] = 425; My2[4] = 430; line (425, 430, 70, 430); Mx1[5] = 425; Mx2[5] = 430; My1[5] = 70; My2[5] = 430; line (70, 430, 70, 300); Mx1[6] = 70; Mx2[6] = 430; My1[6] = 70; My2[6] = 300; line (155, 220, 155,350); Mx1[7] = 155; Mx2[7] = 220; My1[7] = 155; My2[7] = 350; line (225, 300, 430, 300); Mx1[8] = 225; Mx2[8] = 300; My1[8] = 430; My2[8] = 300; line (154, 365, 360, 365); //Only goes to 9 as arrays start at 0! Mx1[9] = 154; Mx2[9] = 365; My1[9] = 360; My2[9] = 365; line(10, 490, 490, 490); //Only goes to 9 as arrays start at 0! Mx1[10] = 10; Mx2[10] = 490; My1[10] = 490; My2[10] = 490; endShape(); } } class Player { float x; float y; float radius; // radius for collision

Player() {

radius = 35; 

}

void display() { pushMatrix(); translate(x, y); fill (2,255,255); ellipse (0,0, 50, 50);
popMatrix();

}

void move() { x = mouseX; y = mouseY;

} }

submitted by /u/amayzindave
[link] [comments]