Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import processing.core.PApplet;
- import java.util.Random;
- import java.util.Scanner;
- public class Project extends PApplet {
- Random randomGenerator = new Random();
- //VARIABLES
- int xBar = 100;
- int topxBar = 100;
- // int topyBar = 800;
- public float x = 400;
- public float y = 350;
- public float speed = 7;
- public boolean moveLeft = false;
- public boolean moveRight = false;
- public boolean moveUp = false;
- public boolean moveDown = false;
- public boolean moving = false;
- //CHARACTERS
- public boolean face = false;
- public boolean snowman = false;
- public boolean ship = false;
- //bars moving
- int aBar = randomGenerator.nextInt(800);
- int bBar = randomGenerator.nextInt(800);
- int cBar = randomGenerator.nextInt(800);
- int dBar = randomGenerator.nextInt(800);
- int eBar = randomGenerator.nextInt(800);
- int zBar = randomGenerator.nextInt(70);
- int fBar = randomGenerator.nextInt(800);
- int gBar = randomGenerator.nextInt(800);
- int topzBar = randomGenerator.nextInt(400);
- int topyBar = randomGenerator.nextInt(400);
- int change=1;
- public void setup()
- {
- size(2000, 1000);
- background(0, 0, 0);
- }
- public void draw()
- {
- move();
- background(0, 0,0);
- drawBars();
- /// ABAR MOVEMENT
- if(change==1)
- {
- aBar++;
- if (aBar==800)
- change=0;
- }
- if (change==0)
- {
- aBar--;
- if(aBar==0)
- change=1;
- }
- /// BBAR MOVEMENT
- if(change==0)
- {
- bBar++;
- if (bBar==800)
- change=0;
- }
- if (change==1)
- {
- bBar--;
- if(bBar==0)
- change=1;
- }
- /// CBAR MOVEMENT
- if(change==1)
- {
- cBar++;
- if (cBar==800)
- change=0;
- }
- if (change==0)
- {
- cBar--;
- if(cBar==0)
- change=1;
- }
- /// DBAR MOVEMENT
- if(change==0)
- {
- dBar++;
- if (dBar==800)
- change=0;
- }
- if (change==1)
- {
- dBar--;
- if(dBar==0)
- change=1;
- }
- /// EBAR MOVEMENT
- if(change==1)
- {
- eBar++;
- if (eBar==800)
- change=0;
- }
- if (change==0)
- {
- eBar--;
- if(eBar==0)
- change=1;
- }
- /// FBAR MOVEMENT
- if(change==0)
- {
- fBar++;
- if (fBar==800)
- change=0;
- }
- if (change==1)
- {
- fBar--;
- if(fBar==0)
- change=1;
- }
- /// GBAR MOVEMENT
- if(change==1)
- {
- gBar++;
- if (gBar==800)
- change=0;
- }
- if (change==0)
- {
- gBar--;
- if(gBar==0)
- change=1;
- }
- translate(x, y);
- drawRocketShip();
- drawSnowMan();
- drawFace();
- }
- public void drawBars()
- {
- //bottom bars
- fill(0, 170, 190);
- rect(400, 0, xBar, aBar);
- rect(600, 0, xBar, bBar);
- rect(800, 0, xBar, cBar);
- rect(1000, 0, xBar, dBar);
- rect(1200, 0, xBar, eBar);
- rect(1400, 0, xBar, fBar);
- rect(1600, 0, xBar, gBar);
- //top bars
- fill(150, 10, 0);
- rect(400, aBar +200, topxBar, 1000);
- rect(600, bBar +200, topxBar,1000);
- rect(800, cBar +200, topxBar, 1000);
- rect(1000, dBar +200, topxBar, 1000);
- rect(1200, eBar +200, xBar, 1000);
- rect(1400, fBar +200, xBar, 1000);
- rect(1600, gBar +200, xBar, 1000);
- }
- public void drawSnowMan()
- {
- if(snowman==true)
- {
- //body
- fill(255, 255, 255);
- stroke(255, 255, 255);
- ellipse(0, 5, 40, 40);
- ellipse(0, 20, 45, 45);
- ellipse(0, 40, 55, 55);
- //head
- ellipse(0, -25, 35, 35);
- //eyes
- fill(0, 0, 0);
- ellipse(-10, -30, 5, 5);
- ellipse(10, -30, 5, 5);
- //nose
- fill(204, 102, 0);
- rect(0, -25, 15, 5);
- //Arms
- fill(153, 76, 0);
- stroke(153, 76, 0);
- rect(0, 0, 40, 4);
- rect(-40, 0, 50, 4);
- fill(255, 255, 255);
- stroke(255, 255, 255);
- ellipse(0, 5, 40, 40);
- //buttons
- fill(8, 8, 8);
- ellipse(1,20, 5, 5);
- ellipse(1, 10, 5, 5);
- ellipse(1, 0, 5, 5);
- stroke(0, 0, 0);
- }
- }
- public void drawFace()
- {
- if(face==true)
- {
- //Draw TheSmilyFace
- //Head
- stroke(0, 0, 0);
- fill(0, 0, 0);
- ellipse(0/4, 0/4, 29/4, 295/34);
- fill(255, 255, 0);
- ellipse(0/4, 0/4, 290/4, 290/4);
- //eyes
- fill(0, 0, 0);
- ellipse(-70/4, -40/4, 25/4, 25/4);
- ellipse(70/4, -40/4, 25/4, 25/4);
- fill(255, 255, 255);
- ellipse(-70/4, -40/4, 8/4, 8/4);
- ellipse(70/4, -40/4, 8/4, 8/4);
- //mouth
- fill(0, 0, 0);
- ellipse(-10/3, 50/3, 50, 20);
- fill(255, 255, 0);
- ellipse(-10/3, 50/3, 45, 15);
- fill(255, 255, 0);
- stroke(255, 255, 0);
- rect(-28, 5, 50, 10);
- stroke(0, 0, 0);
- }
- }
- public void drawRocketShip()
- {
- if(ship==true)
- {
- //wing color
- fill(70, 70, 70);
- //wings
- triangle(0, 0, 40, 10, 10, 50);
- triangle(0, 0, -40, 10, -10, 50);
- triangle(0, 0, 40, -10, 10, -50);
- triangle(0, 0, -40, -10, -10, -50);
- //Body color.
- stroke(8, 4, 2);
- fill(20, 20, 20);
- //Body
- ellipse(0, 0, 25, 25);
- //buttons
- }
- }
- public void keyPressed()
- {
- if(key == 'a')
- {
- moveLeft = true;
- moving = true;
- }
- if(key == 'd')
- {
- moveRight = true;
- moving = true;
- }
- if(key == 'w')
- {
- moveUp = true;
- moving = true;
- }
- if(key == 's')
- {
- moveDown = true;
- moving = true;
- }
- if(key == '1')
- {
- snowman=true;
- face=false;
- ship=false;
- }
- if(key == '2')
- {
- face=true;
- snowman=false;
- ship=false;
- }
- if(key=='3')
- {
- ship=true;
- snowman=false;
- face=false;
- }
- }
- public void keyReleased()
- {
- if(key =='a')
- {
- moveLeft = false;
- moving = false;
- }
- if(key == 'd')
- {
- moveRight = false;
- moving = false;
- }
- if(key == 'w')
- {
- moveUp = false;
- moving = false;
- }
- if(key == 's')
- {
- moveDown = false;
- moving = false;
- }
- // if(key == ' ')
- // {
- // snowman=false;
- // }
- }
- public void move()
- {
- if(moveUp)
- {
- y -= speed;
- }
- if(moveDown)
- { y += speed;
- }
- if(moveRight)
- { x += speed;
- }
- if(moveLeft)
- { x -= speed;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement