Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mario;
- import java.awt.Image;
- import processing.core.PApplet;
- import processing.core.PImage;
- import java.util.Random;
- public class Mario extends PApplet {
- Random randomGenerator = new Random();
- PImage background;
- PImage background2;
- PImage youwin;
- public boolean moveCircle = false;
- public boolean moveCircleRight= false;
- public boolean moveCircleLeft = false;
- public boolean moveCircleDown = false;
- public int startX = 0+25;
- public int startY = 1000-173;
- public int bulletX=2000, bulletY=500;
- public int jump, wallpaper=1;
- public int xPipe2=910;
- public int yPipe2=755;
- public int level;
- public boolean drawCircle = true;
- public void setup() {
- size(2000,1000);
- background = loadImage("background.jpg");
- background2 = loadImage("background 2.png");
- youwin = loadImage("you win!.png");
- }
- public void draw() {
- drawBackground();
- if(wallpaper==1){
- image(background, 0, 0);
- level = 1;
- }
- if(wallpaper==2){
- image(background2, 0, 0);
- level = 2;
- }
- move();
- circle();
- bullet();
- //System.out.println("mouse x " +mouseX + " mouse y " +mouseY);
- }
- public void circle(){
- if (drawCircle){
- stroke(255,0,0);
- fill(255,0,0);
- ellipse(startX, startY, 50,50);
- }
- }
- public void bullet(){
- fill(0,0,0);
- ellipse(bulletX, bulletY, 20,20);
- if(bulletX >100)
- bulletX-=30;
- else
- {
- bulletY=randomGenerator.nextInt(270)+600;
- bulletX=2000;
- }
- //////////////////////
- ////BULLET PHYSICS
- /////////////////////////////////
- if(startX>=bulletX && (startY+25 >= bulletY && startY-25<= bulletY))
- {
- startX=50;
- background(255,0,0);
- }
- }
- public void keyPressed(){
- if(key == 'w' && jump == 0){
- moveCircle = true;
- }
- if(key == 'd'){
- moveCircleRight = true;
- }
- if(key == 'a'){
- moveCircleLeft = true;
- }
- if(key == 's'){
- moveCircleDown = true;
- }
- }
- public void keyReleased(){
- if(key == 'w'){
- moveCircle=false;
- jump++;
- }
- if(key == 'd'){
- moveCircleRight = false;
- }
- if(key == 'a'){
- moveCircleLeft = false;
- }
- if(key == 's'){
- moveCircleDown = false;
- }
- }
- public void move(){
- if(level == 1){
- if(moveCircle){
- if(startY >600){
- startY -= 13 ;
- }
- else{
- startY -= 0;
- }
- }
- else{
- if(startY< 1000-173){
- startY+=10;
- }
- else{
- startY -=0;
- jump=0;
- }
- }
- if(moveCircleRight){
- if((startX> 873 && startY > 755 && startX < 950) || (startX + 25 > 573 && (startX - 25 < 573 + 75) && startY + 25 > 783)
- || (startX > 1480 && startX< 1550 && startY> 650) || (startX > 1125 && startY> 620 && startX <1200)){
- startX += 0;
- }
- else{
- startX +=15;
- }
- }
- if(moveCircleLeft){
- if(startX<50 || ( (startX+25 > 590 && startX - 25<585+75 && startY+25> 783) || (startX> 900 && startY > 755 && startX < 1010)
- ||(startX > 1550 && startX< 1645 && startY> 650)||(startX > 1150 && startY> 620 && startX <1280))){
- startX -=0;
- }
- else{
- startX -=15;
- }
- }
- }
- if(level == 2){
- if(moveCircle){
- if(startY >400){
- startY -= 13 ;
- }
- else{
- startY -= 0;
- }
- }
- else{
- if(startY< 950){
- startY+=10;
- }
- else{
- startY -=0;
- jump=0;
- }
- }
- if(moveCircleRight){
- if(startX>1425 && startY> 850){
- image(background2,0,0 );
- startX += 0;
- }
- else if(startX< 1890){
- startX +=15;
- }
- }
- if(moveCircleLeft){
- if(startX<50){
- startX -=0;
- }
- else{
- startX -=15;
- }
- }
- if(level==2 && startX>1425 && startY>850){
- drawCircle=false;
- image(youwin,200,75);
- }
- }
- // if(moveCircleDown){
- // if(startY<1000-173){
- // startY +=25;
- // }
- // else{
- // startY-=0;
- // }
- // }
- }
- public void drawBackground(){
- if(startX >1900){
- wallpaper=2;
- startX =0;
- startY= 950;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement