Processing Project for Intro to Computer Science: Movement and Gravity
in
Programming Questions
•
10 months ago
Hey, this is my first post, and I couldn't be newer to Processing.
My final project is to have several shapes, several colors, an object that moves independent and an object that moves dependent of the user, etc. etc.
My goal is to have the man (steve) fall unless holding the mouse key, and having the cloud move to the right in the background. The code above is before I started messing around trying to get the cloud to move, and I was wondering if anyone could help me
-get the cloud to move to the right slowly
My final project is to have several shapes, several colors, an object that moves independent and an object that moves dependent of the user, etc. etc.
I have a stick man (made of three rectangles, two quadrangles, and a circle ) and a cloud (five circles, two above and three below)
Here's what I have code-wise:
- //Steve
- int xPs= 0;
- int yPs= 0;
- int rAs=0;
- int sPs=1;
- int imageNumber = 0;
- Cloud Cloud1;
- //********************************************************************************
- void setup() {
- size (500, 500);
- frameRate(15);
- background(#9CE5EA);
- Cloud1 = new Cloud(color(255,0,0),0,100,2);
- }
- //********************************************************************************
- void draw() {
- background(#9CE5EA);
- Steve(xPs, yPs, rAs, sPs, imageNumber);
- Cloud1.move();
- Cloud1.display();
- }
- //********************************************************************************
- void Steve(int xPs, int yPs, int rPs, int sPs, int i) {
- pushMatrix();
- translate(250, 250);
- scale(2);
- stroke(#000000);
- if (imageNumber == 0) {
- // first image
- quad(0, 0, 20, -20, 30, -10, 10, 10);
- quad(0, 0, -20, -20, -30, -10, -10, 10);
- rect(-12, -12, 25, 35);
- ellipse(0, -23, 30, 30);
- rect(-12, 23, 13, 20);
- rect(0, 23, 13, 20);
- imageNumber= imageNumber + 1;
- } else if (imageNumber == 4){
- //Mid image 2
- rect(-35,-5, 70, 15);
- rect(-12, -12, 25, 35);
- ellipse(0, -23, 30, 30);
- rect(-12, 23, 13, 20);
- rect(0, 23, 13, 20);
- imageNumber = 0;
- } else if (imageNumber == 1){
- //Mid image
- rect(-35,-5, 70, 15);
- rect(-12, -12, 25, 35);
- ellipse(0, -23, 30, 30);
- rect(-12, 23, 13, 20);
- rect(0, 23, 13, 20);
- imageNumber = 2;
- }else if (imageNumber == 2){
- // second image
- background(#9CE5EA);
- quad(0, 0, 10, -10, 28, 15, 18, 23);
- quad(0, 0, -10, -10, -28, 15, -18, 23);
- rect(-12, -12, 25, 35);
- ellipse(0, -23, 30, 30);
- rect(-12, 23, 13, 20);
- rect(0, 23, 13, 20);
- imageNumber = 4;
- }
- popMatrix();
- }
- //******************************************************************************
- class Cloud {
- color c;
- float xpos;
- float ypos;
- Cloud(color tempC, float tempXpos, float tempYpos, float tempXspeed){
- c = tempC;
- xpos = tempXpos;
- ypos = tempYpos;
- }
- void display (){
- pushMatrix();
- translate(100, 100);
- scale(2);
- stroke(#FFFFFF);
- ellipse(-7, -3, 25, 25);
- ellipse(7, -3, 25, 25);
- ellipse(15, 10, 20, 20);
- ellipse(0, 10, 20, 20);
- ellipse(-15, 10, 20, 20);
- popMatrix();
- }
- void move() {
- if (xpos > width) {
- xpos = xpos + 20;
- }
- }
- }
My goal is to have the man (steve) fall unless holding the mouse key, and having the cloud move to the right in the background. The code above is before I started messing around trying to get the cloud to move, and I was wondering if anyone could help me
-get the cloud to move to the right slowly
-get the man to fall if the mouse is not held
Thanks in advance!
1