//Help the skeleton get big and strong by drinking milk! //----MADE BY: JEREMY LEUNG----// //(Sometimes the milk container will go offscreen. Sometimes it comes back but try restarting and that might fix it) //used for the milk drop float gravity=.05; float MilkDropYSpeed; float milkdropX, milkdropY; float milkdropSY; //For the movement of the milk container float x; float y; boolean right = false; boolean left = false; //For the movement of the skull float skullX; //Colors Used color white; color black; //This is call to make the milk container go back and forth randomly void flipMilkDirection() { } void setup() { size(400, 400); frameRate(60); milkdropX = 110; milkdropY = 100; milkdropSY = 5; white = color(255, 255, 255); black = color(0, 0, 0); } void draw() { background(black); stroke(white); skull(); line(0, 0, 0, 400); line(400, 0, 400, 400); //-UPDATE-// // Updates the milk drops Y position // Credit: Professor Nicolas Hesler (Rover Lander Example) updateMilkDropPosition(); milkdropY = milkdropY+milkdropSY; if (milkdropY>height) { milkdropX = x; milkdropY = 100; } updateskullX(); { } //Hit Box for the skull so the mlk drops resets to its spawn point if (milkdropX > skullX-5 && milkdropX < skullX+85 && milkdropY > 300 && milkdropY < 400) { milkdropX = x; milkdropY = 100; } } //-SKULL-// void skull () { if (left) { x=x-2; } else { x=x+2; } } // Credit: Professor Nicolas Hesler (Gone Fishing Example) // Pressing the left or right arrow keys will make the skull move in those directions void updateskullX () { if (keyPressed) { if (keyCode == LEFT) { skullX--; } else if (keyCode == RIGHT) { skullX++; } } //upper jaw fill(white); quad(40+skullX, 303, 60+skullX, 297, 65+skullX, 325, 25+skullX, 320); constrain(100, 5, 5); //bottom jaw quad(90+skullX, 350, 70+skullX, 360, 85+skullX, 305, 95+skullX, 310); //head ellipse(40+skullX, 350, 75, 75); //eye hole fill(black); ellipse(30+skullX, 325, 20, 15); //-MILK BOTTLE-// //This make the milk container go left or right randomly { flipMilkDirection(); float r = random(400); if (r > 325) { if (left == true) { left = false; } else { left = true; } } } //Milk Body fill(white); quad(x+100, 70, x+20, 70, x+20, 120, x+100, 120); //Milk Neck fill(white); quad(x+20, 70, x, 85, x, 105, x+20, 120); //Milk Head fill(white); quad(x, 85, x-10, 90, x-10, 100, x, 105); //Milk Drop fill(white); ellipse(milkdropX, milkdropY, 15, 15); //-"MILK"-// //"M" stroke(black, 200); fill(black); line(x+30, 113, x+50, 113); line(x+30, 113, x+40, 108); line(x+40, 108, x+30, 103); line(x+30, 103, x+50, 103); //"I" line(x+30, 98, x+50, 98); //"L" line(x+30, 93, x+50, 93); line(x+50, 93, x+50, 88); //"K" line(x+30, 83, x+50, 83); line(x+40, 83, x+30, 76); line(x+40, 83, x+50, 76); //println(mouseX, mouseY); } void updateMilkDropPosition() { milkdropY= milkdropY + milkdropSY; milkdropY = milkdropY + milkdropSY; } //Coding is actually very hard and a lot of help was given by other students //Major credit goes to ZACHARY MACLEOD for explaining a majority of the code used in this assignment //1. Every time draw() is executed, so every frame, the program generates a random number from 0 to whatever number you want. //2. This random number (which is stored in a variable) is checked to see if it is above/below the halfway mark between 0 and the number you picked as the maximum. //3. If it is above, reverse the direction of the milk carton. This also works for below, you choose whichever. //4. There is a chance that the milk carton will hit the sides of the screen, so you'll have to check the carton's position and reverse regardless of the number generated that frame if this occurs. //random(min, max); //Basically you want 2 states //One the adds x, and one that subtracts x //that can labeled //int direction = 0 //0 being left //1 being right //And you need something that switches the states randomly //But it depends on how often you want it to switch //Cus using just random(min,max) is going to make just freak out and spazz out //Than you just constrain x to 0 and 400 and your good