I need help please! Mario

int gameMode=0;//0 - menu, 1 - play game, 2 - instructions, 3 - character selection
int selChar=1;//default character is "character 1"
int level=1;
color red=color(255, 0, 0);
color green=color(0, 255, 0);
color blue=color(0, 0, 255);

boolean moveRight=false;
boolean moveLeft=false;
boolean moveDown=false;
boolean moveUp=false;

int x=50;
boolean[] keys=new boolean[128];

int[] v={4, 0};//horizontal and vertical velocity

int[] g1={0, 0, -968};
int[] g2={968, 0, -968};

PImage pic1;
PImage pic2;
int speed=-5;

int[] g3={0, 0, -108};
int[] g4={108, 0, -108};

PImage pic3;
PImage pic4;

PImage a;
PImage b;
PImage c;
  
import processing.sound.*;
SoundFile file;

void setup() {
   file = new SoundFile(this,"supermario.mp3");
    file.play();
  size(800, 600);
  a = loadImage("mario.png");
  b = loadImage("luigi.png");
  c = loadImage("Yoshi.png");
  pic1=loadImage("back.png");
  pic2=loadImage("back1.png");
  pic3=loadImage("ground1.png");
  pic4=loadImage("ground2.png");
}

void draw() {//runs forever
  background(red);
  if (gameMode==0){
    mainMenu();
  }
  else if (gameMode==1){
      playL1();
  }
  else if (gameMode==2)
    controls();
  else if (gameMode==3)
    select();
}//end draw

void playL1(){
  image(pic1, g1[0], g1[1]);
  image(pic2, g2[0], g2[1]);

//g1[0] = g1[0] + speed;//moving left
  //if (g1[0] + speed < g1[2]) { 
  //  g1[0] = -g2[2];
  //}
  //g2[0] = g2[0] + speed;//moving left
  //if (g2[0] + speed < g2[2]) {
  //  g2[0] = -g1[2];
  //}
  
  image(pic3, g3[0], g3[1]);
  image(pic4, g4[0], g4[1]);
  
   g3[0] = g3[0] + speed;//moving left
  if (g3[0] + speed < g3[2]) { 
    g3[0] = -g4[2];
  }
  g4[0] = g4[0] + speed;//moving left
  if (g4[0] + speed < g4[2]) {
    g4[0] = -g3[2];
  }
  
} //end playL1


void controls() {
  textSize(35);
  fill(255);
  text("press spacebar to jump",150,150);
  text("move you characters", 150, 250);
  text("collect coins",150,350);
  text("avoid the enemies",150,450);
  backToMain();
}

void select() {//character select
  textAlign(LEFT);
  textSize(20);
  fill(0);//black
  //displaying all characters
  rect(200, 50, 100, 100);
  rect(350, 50, 100, 100);
  rect(500, 50, 100, 100);

  if (mouseIn(200, 50, 100, 100)) {
    fill(blue);
    rect(200, 50, 100, 100);
    if (mousePressed) {
      selChar=1;//1 could mean Mario
      gameMode=0;//main menu
    }
  }

  if (mouseIn(350, 50, 100, 100)) {
    fill(blue);
    rect(350, 50, 100, 100);
    if (mousePressed) {
      selChar=2;//2 could mean Luigi
      gameMode=0;
    }
  }

  if (mouseIn(500, 50, 100, 100)) {
    fill(blue);
    rect(500, 50, 100, 100);
    if (mousePressed) {
      selChar=3;//3 could be Yoshi
      gameMode=0;
    }
  }

  fill(255);
  text("Char 1", 210, 100);
  text("Char 2", 360, 100);
  text("Char 3", 510, 100);

  backToMain();
}//end select

void mainMenu() {
  textAlign(LEFT);
  textSize(35);
  fill(blue);
  text("START", 350, 430);
  text("INSTRUCTIONS", 290, 490);
  text("CHARACTERS", 295, 555);
  
  image(a, 200, 0, 150, 200);
  image(b, 80, 250, 200, 250);
  image(c,600,200,150,200);
  
  if (mouseIn(330, 400, 150, 35)) {//"play"
    fill(0);
    text("START", 350, 430);
    if (mousePressed) {
      gameMode=1;
    }
  }
  if (mouseIn(280, 460, 270, 35)) {//"instructions"
    fill(0);
    text("INSTRUCTIONS", 290, 490);
    if (mousePressed) {
      gameMode=2;
    }
  }
  if (mouseIn(285, 525, 240, 35)) {//"characters"
    fill(0);
    text("CHARACTERS", 295, 555);
    if (mousePressed) {
      gameMode=3;
    }
  }
  fill(255);
  textSize(60);
  text("Super Mario ", 230, 300);
}//end mainMenu

void backToMain() {
  textAlign(LEFT);
  textSize(20);
  fill(green);
  rect(20, 550, 120, 40);
  fill(blue);
  text("Menu", 50, 580);

  if (mouseIn(20, 550, 120, 40)) {//"back to menu"
    fill(0);
    text("Menu", 50, 580);
    if (mousePressed) {
      gameMode=0;
    }
  }
}//end backToMain


void keyPressed() {
  //println(keyCode+" was pressed");
  //keys[keyCode]=true;
}

void keyReleased() {
  //println(keyCode+" was released");
  //keys[keyCode]=false;
}

//The function returns true if the mouse pointer is INSIDE the rectangle, otherwise returns false
boolean mouseIn(int left, int top, int w, int h) {
  return (mouseX > left && mouseX < left+w && mouseY > top && mouseY < top+h);
}//end mouseIn

I have this code but I dont know how to make the background image and the ground image move in the direction that the character is moving

basically when you say image(ground, 0,0);

make the first 0 a variable and decrease it:

image(ground, groundX, groundY);

groundX--;

  • ground moves left.

  • ground image must be wider than screen

Chrisir

thank you. I’m going to try that

We can’t run your code because we don’t have your images… :wink:


this is the background

still hard to read

what is pic a , b , c?

what is pic pic3, pic4??

what is the difference between back and back1 ?

Please format your code:
https://discourse.processing.org/faq#format-your-code

its the same picture. My teacher said to do that so the background would look like it was moving

pic a,b,c are on the main menu screen

pic 1,2 are the 2 background pictures

pic 3,4 are the 2 ground pictures

What they are getting at is, it would be beneficial to you and to those you wish to get help from if your variables and functions had a better naming convention. Keep it short and sweet but as descriptive as possible so it is easy to read and there is no question as to what the code does.

Like this. Next time, figure it out yourself…


PImage pic;

void setup(){
  fullScreen();
  pic=loadImage("earth.jpg");
}

void draw(){
  scale(1.0*height/pic.height);
  int ofs=frameCount%pic.width;
  image(pic,-ofs,0);
  image(pic,pic.width-ofs,0);
}

My guess is that you are trying to create a parallax scrolling effect?