//---SUNDAY DRIVE---// /* Author: Andrew Guagliano Student Number: 991405014 Class: PROG14998 Introduction to Media Computation Sept 17, 2018 Instructor: Nicolas Hesler In this game, you are the driver of a car, and you are trying to stop before the stop sign. Stop your car by pressing any button or clicking the mouse key, and a line will appear telling you how close you got. The line's color will indicate how far across the screen you are. The goal is to try to have as bright of a line as possible, while also not going past the sign's signpost. As a note, you may have to click on the screen a few times to make sure the game will pick up your button presses. Have fun! ---A GENERAL NOTE ABOUT MY MAJOR PROGRAMMING STRATEGY--- I wanted to get many shapes to move across the screen at its own rate, but also be affected by the car's movement, as if you were passing by it. I knew that affecting the movement with the car would simply be adding mouseX to the object's x value, but I was puzzled how to get objects to move across the screen, disappear, and then reappear on the other side. By studying the work done by past students, I realized that the solution to my problem was frameCount in conjunction with modulo. frameCount would allow the shape to steadily move across the screen along the x-axis, and modulo allows it to smoothly reappear on the other side when (frameCount + mouseX) can be divided into into value 2. Since it applied to so many objects, I thought it was best to put this right at the beginning. */ //---SETUP---// void setup(){ //set the size of the window size (400,400); } //---DRAW---// void draw(){ //set background color in draw to reset the window background(80,141,234); frameRate(60); rectMode(CORNER); //---BACKGROUND CLOUDS---// /*these are a gradient to create a sense of depth in the sky's background*/ noStroke(); fill(252,252,252,20); rect(0,20,400,20); fill(252,252,252,40); rect(0,40,400,20); fill(252,252,252,60); rect(0,60,400,20); fill(252,252,252,80); rect(0,80,400,20); fill(252,252,252,50); rect(0,100,400,20); fill(252,252,252,20); rect(0,120,400,20); //---SUN---// fill(252,200,0); noStroke(); /*The sun is meant to move slowly across the X-axis while being slightly impacted by MouseX. frameCount (no multipliers) + mouseX*0.01 is used to accoplish this. %650 is used to reinforce the illusion that it is moving slower than everything else.*/ ellipse(((frameCount+mouseX*0.01)%650)-40,100,65,65); //---FOREGROUND CLOUD---// fill(252,252,252); stroke(255); /*%600 means when the cloud floats off the one end of the screen, it will appear on the other. */ ellipse(((frameCount*1.3+mouseX*0.02)%600)-100,113,57,46); ellipse(((frameCount*1.3+mouseX*0.02)%600)-60,159,61,49); ellipse(((frameCount*1.3+mouseX*0.02)%600)-80,140,130,67); //---GRASS---// //a simple rectangle fill(0,200,0); noStroke(); rect(0,250,400,50); //---STOP SIGN---// rectMode(CENTER); //The signpost is just a rectangle fill(80); rect(((frameCount*-4)%2000)+1320,240,10,100); //Make the stopsign pure red fill(255,0,0); //Making the octagon required me to use 2 rectangles and 4 triangles. //%2000 is used to refresh the objects' positions infrequently. rect(((frameCount*-4)%2000)+1320,190,22,62); rect(((frameCount*-4)%2000)+1320,190,62,22); triangle(((frameCount*-4)%2000)+1310,180,((frameCount*-4)%2000)+1290,180,((frameCount*-4)%2000)+1310,160); triangle(((frameCount*-4)%2000)+1350,180,((frameCount*-4)%2000)+1330,180,((frameCount*-4)%2000)+1330,160); triangle(((frameCount*-4)%2000)+1350,200,((frameCount*-4)%2000)+1330,200,((frameCount*-4)%2000)+1330,220); triangle(((frameCount*-4)%2000)+1310,160,((frameCount*-4)%2000)+1290,200,((frameCount*-4)%2000)+1310,220); //To make the stop sign look more authentic, I added a white border to it using //lines stroke(255); strokeWeight(3); line(((frameCount*-4)%2000)+1290,180,((frameCount*-4)%2000)+1310,160); line(((frameCount*-4)%2000)+1310,160,((frameCount*-4)%2000)+1330,160); line(((frameCount*-4)%2000)+1330,160,((frameCount*-4)%2000)+1350,180); line(((frameCount*-4)%2000)+1350,180,((frameCount*-4)%2000)+1350,200); line(((frameCount*-4)%2000)+1350,200,((frameCount*-4)%2000)+1330,220); line(((frameCount*-4)%2000)+1330,220,((frameCount*-4)%2000)+1310,220); line(((frameCount*-4)%2000)+1310,220,((frameCount*-4)%2000)+1290,200); line(((frameCount*-4)%2000)+1290,200,((frameCount*-4)%2000)+1290,180); //---ROAD---// //Once again, a simple rectangle. rectMode(CORNER); noStroke(); fill(120); rect(0,300,400,100); //---DOTTED LINE---// //The dotted line is what sells the illusion that the car is moving. fill(255); rectMode(CENTER); //%500 is used to make it seem like the line is never broken. rect(((frameCount*4)+mouseX*0.2)%500,350,30,10); rect((((frameCount*4)+100)+mouseX*0.2)%500,350,30,10); rect((((frameCount*4)+200)+mouseX*0.2)%500,350,30,10); rect((((frameCount*4)+300)+mouseX*0.2)%500,350,30,10); rect((((frameCount*4)+400)+mouseX*0.2)%500,350,30,10); //---CAR---// //The car is the centerpiece of the sketch, but it was surprisingly //simple. noStroke(); //Make the car purple fill(200,0,240); rectMode(CORNER); //The mouseX and mouseY multipliers are to ensure that the car never //leaves the road, or drives off-screen. rect((0.3*mouseX)+13,(259+mouseY*0.2),250,51); rect((0.3*mouseX)+49,(212+mouseY*0.2),141,50); triangle((0.3*mouseX)+13,(mouseY*0.2)+260,(0.3*mouseX)+50,(mouseY*0.2)+212,(0.3*mouseX)+50,(mouseY*0.2)+260); triangle((0.3*mouseX)+240,(mouseY*0.2)+260,(0.3*mouseX)+189,(mouseY*0.2)+212,(0.3*mouseX)+189,(mouseY*0.2)+260); fill(0); ellipse((0.3*mouseX)+200,(312+mouseY*0.2),50,50); ellipse((0.3*mouseX)+75,(312+mouseY*0.2),50,50); } //---MOUSEPRESSED/KEYPRESSED---// void mousePressed(){ /*This line marks where the nose of your car is when you stop, so that you know if you went past the stop sign or not. It's colour changes depending on how far along the x-axis you are.*/ stroke(mouseX,mouseX,0); strokeWeight(4); line((0.3*mouseX)+263,250,(0.3*mouseX)+263,400); frameRate(1); } void keyPressed(){ /*Both mousePressed and keyPressed do the same thing. This is to allow players to use whichever control method they find most comfortable.*/ stroke(mouseX,mouseX,0); strokeWeight(4); line((0.3*mouseX)+263,250,(0.3*mouseX)+263,400); frameRate(1); }