# Super mario game help

**URL:** <https://discourse.processing.org/t/super-mario-game-help/8470>\
**Category:** Coding Questions\
**Created:** [February 17, 2019, 9:56am UTC](https://discourse.processing.org/t/super-mario-game-help/8470 "2019-02-17T09:56:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![LuciferMS666](https://avatars.discourse-cdn.com/v4/letter/l/87869e/32.png) [@LuciferMS666](https://discourse.processing.org/u/LuciferMS666)\
**Post date:** [February 17, 2019, 9:56am UTC](https://discourse.processing.org/t/super-mario-game-help/8470/1 "2019-02-17T09:56:56Z")

</div>

Hello everyone, I created this discussion because I have a job to do on processing. So I decided to create a mario game only I would like to have your help (because I’m still a beginner). I would like you to help me for example: Improve my code, rectify some bugs and even add options. But now, my first concern is that the background image of my game continues to bug and even it happens that sometimes I can not see Mario.  
Hoping that you can help me  
-Cordially

le code :

```auto
PImage bg2, coin, pipe, ground, ground2;
PImage bg, flyright, flyleft, fastleft, fastleft2;
PImage fastleft3, fastright, fastright2, fastright3;
PImage rightup, leftup, leftjump, rightjump, leftfall, rightfall;
PImage duckleft, duckright,marioleft, mariowalkleft;
PImage mariowalkleft2, marioright,mariowalkright,mariowalkright2;
PImage LtoR,RtoL;
int PointsCounter = 0,LR =0,once=1,jumpon=0,jumptime=0,onejump=0, stime=0, i=0;;
float x=100, y=670, speed=0,slow = 0, jump, g=670;
int n=415;

boolean keyup = false;
boolean keyright = false;
boolean keyleft = false;
boolean keydown = false;
boolean keyuplook = false;
boolean keyfast = false;

void setup()
{
  size(600,720);
  
   marioleft = loadImage("marioleft.png");
   mariowalkleft = loadImage("mariowalkleft.png");
   mariowalkleft2 = loadImage("mariowalkleft2.png");
   marioright = loadImage("marioright.png");
   mariowalkright = loadImage("mariowalkright.png");
   mariowalkright2 = loadImage("mariowalkright2.png");
   LtoR = loadImage("LtoR.png");
   RtoL = loadImage("RtoL.png");
   duckleft = loadImage("duckleft.png");
   duckright = loadImage("duckright.png");
   leftjump = loadImage("leftjump.png");
   rightjump = loadImage("rightjump.png");
   leftfall = loadImage("leftfall.png");
   rightfall = loadImage("rightfall.png");
   rightup = loadImage("rightup.png");
   leftup = loadImage("leftup.png");
   fastleft = loadImage("fastleft.png");
   fastleft2 = loadImage("fastleft2.png");
   fastleft3 = loadImage("fastleft3.png");
   fastright = loadImage("fastright.png");
   fastright2 = loadImage("fastright2.png");
   fastright3 = loadImage("fastright3.png");
   flyright = loadImage("flyright.png");
   flyleft = loadImage("flyleft.png");
   bg = loadImage("bg.png");
   ground = loadImage("ground.png");
   ground2 = loadImage("ground2.png");
   pipe = loadImage("pipe.png");
   coin = loadImage("coin.png");
   bg2 = loadImage("bg2.jpg");

   background(250);
   image(marioright,x, y); 
}

void draw()
{
  if (speed == -0.01) speed =0;
  if (x < 400 || x > 800)
  {
   g=670;
  }
  
   if (x > 400 && x < 800)
  {
    g=600;
  }
  
  if (speed <0.1 && speed > -0.1)
 { 
  slow = 0;
  once=0;
 }
  
  
  if (y==600 && x > 390 && x <404)
  {
  jumpon=1;
  speed = -1;
  }
  
  if (y==600 && x < 820 && x >797)
  {
  jumpon=1;
  speed = 1;
  }
  
  if(y<=600)
  if(x > 400 && x < 800)
  {
    {
  x=x+speed;
  }
  }
  
  if(x > 400 && x < 800)
  {
  }
  else
  {
  x=x+speed;
  }
 if ( x >= 400 && x <= 410 && y >600 ) x= 399;
 if ( x <= 800 && x >=790 && y >600 ) x= 801;
 
 
  y=y-jump;

  if (speed >= 0.01) speed-=0.02;
  if (speed <= -0.01) speed+=0.02;

     if (keyup)
    {
  
     jumpon=1;   
     jumptime++;
    
    }
    
    if (keyup == false)
    {
     
      onejump=0;
      jumptime=0;
    }
    
     if (keyfast)
     {
       stime++;
     }
      if (keyfast == false)
     {
       stime=0;
     }
    

   if(keydown == false)
   {
   
   if (keyleft)
   {
     once=1;
     
     
     if (keyfast)
     {
     if (speed > -2.3) speed-=0.08;
     }
     
     if (keyfast ==false)
     {
        if (speed > -1.3) speed-=0.05;
     }
     
     
    LR=0;
    
    
    
    if(keyfast)

    {
    
    
     if (frameCount%16 > 0 && frameCount%16 < 4)
  {
    background(250);
    image(marioleft,x, y);   
  } 
    
  if (frameCount%16 > 4 && frameCount%16 < 8)
{
    background(250); 
    image(mariowalkleft,x, y);
}  
  if (frameCount%16 > 8 && frameCount%16 < 12)
{
    background(250);
    image(mariowalkleft2,x, y);
}

  if (frameCount%16 > 12 && frameCount%16 < 16)
{
    background(250); 
    image(mariowalkleft,x, y);
} 
    }

  if(keyfast==false)
    {
    
    
     if (frameCount%32 > 0 && frameCount%32 < 8 )
  {
    background(250);  
    image(marioleft,x, y);   
  } 
    
  if (frameCount%32 > 8 && frameCount%32 < 16)
{
    background(250); 
    image(mariowalkleft,x, y);
}  
  if (frameCount%32 > 16 && frameCount%32 < 24)
{
    background(250); 
    image(mariowalkleft2,x, y);
}

  if (frameCount%32 > 24 && frameCount%32 < 32)
{
    background(250); 
    image(mariowalkleft,x, y);
} 
    }
    
    
        if (speed < -2.3 && stime > 200)
    {
          if (frameCount%16 > 0 && frameCount%16 < 4 )
  {
    background(250);   
    image(fastleft,x, y);   
  } 
    
  if (frameCount%16 > 4 && frameCount%16 < 8)
{
    background(250); 
    image(fastleft2,x, y);
}  
  if (frameCount%16 > 8 && frameCount%16 < 12)
{
    background(250); 
    image(fastleft3,x, y);
}

  if (frameCount%16 > 12 && frameCount%16 < 16)
{
    background(250); 
    image(fastleft2,x, y);
} 
    }

if (speed > 0 && y == g)
{
    slow=0;
    background(250); 
    image(RtoL,x, y);
}
}

   if (keyright)
   {
     once=1;
     
       
     if (keyfast)
     {
     if (speed < 2.3) speed+=0.08;
     }
     
     if (keyfast ==false)
     {
        if (speed < 1.3) speed+=0.05;
     }

LR=1;

         if(keyfast)
    {
    
    
     if (frameCount%16 > 0 && frameCount%16 < 4)
  {
    background(250); 
    image(marioright,x, y);   
  } 
    
  if (frameCount%16 > 4 && frameCount%16 < 8)
{
    background(250); 
    image(mariowalkright,x, y);
}  
  if (frameCount%16 > 8 && frameCount%16 < 12)
{
    background(250);
    image(mariowalkright2,x, y);
}

  if (frameCount%16 > 12 && frameCount%16 < 16)
{
    background(250); 
    image(mariowalkright,x, y);
} 
    }
 

  if(keyfast==false)
    {
    
    
     if (frameCount%32 > 0 && frameCount%32 < 8 )
  {
    background(250); 
    image(marioright,x, y);   
  } 
    
  if (frameCount%32 > 8 && frameCount%32 < 16)
{
    background(250); 
    image(mariowalkright,x, y);
}  
  if (frameCount%32 > 16 && frameCount%32 < 24)
{
    background(250);
    image(mariowalkright2,x, y);
}

  if (frameCount%32 > 24 && frameCount%32 < 32)
{
    background(250); 
    image(mariowalkright,x, y);
} 
    }
    
    
    if (speed > 2.3 && stime > 200)
    {
          if (frameCount%16 > 0 && frameCount%16 < 4 )
  {
    background(250);  
    image(fastright,x, y);   
  } 
    
  if (frameCount%16 > 4 && frameCount%16 < 8)
{
    background(250); 
    image(fastright2,x, y);
}  
  if (frameCount%16 > 8 && frameCount%16 < 12)
{
    background(250); 
    image(fastright3,x, y);
}

  if (frameCount%16 > 12 && frameCount%16 < 16)
{
    background(250); 
    image(fastright2,x, y);
} 
    }
   

if (speed < 0 && y == g)
{
  slow=0;
  once =0;
    background(250);
    image(LtoR,x, y);
}
   }

if (keyleft == false && keyright == false) 
{
  if (LR==1)
  {
    
    
         if (frameCount%32 > 0 && frameCount%32 < 8 )
  {
    background(250);  
    image(marioright,x, y);   
  } 
    
  if (frameCount%32 > 8 && frameCount%32 < 16)
{
    background(250);  
    image(mariowalkright,x, y);
}  
  if (frameCount%32 > 16 && frameCount%32 < 24)
{
    background(250); 
    image(mariowalkright2,x, y);
}

  if (frameCount%32 > 24 && frameCount%32 < 32)
{
    background(250);
    image(mariowalkright,x, y);
}
 
  }
  

  if (LR==0)
  {
  
    
         if (frameCount%32 > 0 && frameCount%32 < 8 )
  {
    background(250); 
    image(marioleft,x, y);   
  } 
    
  if (frameCount%32 > 8 && frameCount%32 < 16)
{
    background(250); 
    image(mariowalkleft,x, y);
}  
  if (frameCount%32 > 16 && frameCount%32 < 24)
{
    background(250); 
    image(mariowalkleft2,x, y);
}

  if (frameCount%32 > 24 && frameCount%32 < 32)
{
    background(250); 
    image(mariowalkleft,x, y);
}
    
  }
  
  
}   
   }
    

if (speed <0.1 && speed > -0.1 && LR ==0)
 { 
  background(250);
  image(marioleft,x, y);
 }
 
 
 if (speed <0.1 && speed > -0.1 && LR==1)
 { 
 background(250); 
 image(marioright,x, y);
 }
 
 if (jumpon == 1)
 {
 
    if (jump < 0) jumpon=0;
   
   
      if(y==g && jumpon == 1) 
     {
       if (onejump == 1)
       {
     if (keyfast) jump = 5;
     if (keyfast == false) jump = 4;
     } 
     }
     onejump=0;
     
   
     if (jumptime > 10) jump-=0.08;
     if (jumptime > 0 && jumptime < 10 ) jump-=0.12; 
     if (jumptime == 0) jump-=0.3;
     
        
 }
 
 
  if (jump < 0 && jump >- 3 ) jump-=0.1; 
  if (jump < 0 && y>g-5) 
  {
  jump=0;
  y=g;
  }
 
  
  
  if (jump > 0)
  {

if (LR==1)
  {
   background(250);  
   image(rightjump,x, y);
  }
  
    if (LR==0)
  {
   background(250); 
   image(leftjump,x, y);
  }
}

  if (jump < -2)
  {

if (LR==1)
  {
   background(250);
   image(rightfall,x, y);
  }
  
    if (LR==0)
  {
   background(250);
   image(leftfall,x, y);
  }
}

 if (jump != 0)
 {
   
   
   
   if(LR == 0)
   {
     if (speed < -2 && stime > 200)
    {
    background(250);  
   image(flyleft,x, y);
    }
   }
      if(LR == 1)
   {
       if (speed > 2 && stime > 200)
    {
    background(250); 
   image(flyright,x, y);
    }
    
 }
 }
 
 
 

   if (keyuplook)
   {
     
     if(LR==1)
      {
     if (speed < 0.1 && speed > -0.1)
     {
       if (y == g)
       {
     background(250); 
   image(rightup,x, y);
       }
     }
   }
   
   
   
   if(LR==0)
      {
     if (speed < 0.1 && speed > -0.1)
     {
       if (y == g)
       {
     background(250);
   image(leftup,x, y);
       }
     }
   }
   
   
   
   
   }
   
   
   
    if (keydown)
   {
      if(LR==1)
      {
      background(250);  
      image(duckright,x, y+13);
      }
      if(LR==0)
      {
      background(250); 
      image(duckleft,x, y+13);
      }
   }
   
   
   
   

   
  for(int n=415 ; n < 780; n+= 32)
   {
    image(pipe,n, 652);
   }
   
   
 
   
   for(int n=415 ; n < 780; n+= 32)
   {
    image(pipe,n, 626);
   }
   
  
   
   

 
  

  

 
 
   if (keyup == false)
    {
      onejump=1;
     
    }
 
 
 
 

/*
textSize(10);
text(slow,30,10);
text(speed,10,30);
text(x,10,50);
text(once,10,70);
text(jump,10,90);
text(y,10,110);
text(jumptime,10,130);
text(stime,10,170);
 
 
textSize(50);
text(PointsCounter,300,200);
*/

if (speed == -0.01) speed =0;
if (speed == 0.01) speed =0;

   

  
  

  
 

  for(i=0;i<700;i+=16)
  {
  image(ground,i,670+28);
  }
  for(i=0;i<700;i+=16)
  {
  image(ground2,i,670+28+16);
  }
 }
 
 
 void keyPressed() {
   if (key == 'a') keyup = true; 
   if (key == 's') keyfast = true; 
  if (key == CODED) {
    if (keyCode == UP) keyuplook = true; 
    if (keyCode == DOWN) keydown = true; 
    if (keyCode == LEFT) keyleft = true; 
    if (keyCode == RIGHT) keyright = true; 
  }
}
 
void keyReleased() {
  if (key == 'a') keyup = false;
  if (key == 's') keyfast = false;
  if (key == CODED) {
    if (keyCode == UP) keyuplook = false; 
    if (keyCode == DOWN) keydown = false; 
    if (keyCode == LEFT) keyleft = false; 
    if (keyCode == RIGHT) keyright = false; 
  }
}

```

link:  
[https://mega.nz/#!14Qy1Y7Y!uHlBpdPQfOooTgC5kD7taxUKKSRkjxL2edMeSy\_0bSM](https://mega.nz/#!14Qy1Y7Y!uHlBpdPQfOooTgC5kD7taxUKKSRkjxL2edMeSy_0bSM)

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [February 17, 2019, 11:21am UTC](https://discourse.processing.org/t/super-mario-game-help/8470/2 "2019-02-17T11:21:26Z")

</div>

pls delete and paste your code above again into the

```auto
</>

```

code formatting tag

but if someone might want to try your code, would need  
that many picture files, so possibly give a link to the full project.zip file

---

<div class="post-metadata">

**Author:** ![LuciferMS666](https://avatars.discourse-cdn.com/v4/letter/l/87869e/32.png) [@LuciferMS666](https://discourse.processing.org/u/LuciferMS666)\
**Post date:** [February 17, 2019, 5:51pm UTC](https://discourse.processing.org/t/super-mario-game-help/8470/3 "2019-02-17T17:51:41Z")

</div>

![duckleft](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/1/16a2732e725a3f4685394a59096819574f992b97.png) ![duckright](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/e/e4714572db1a424a9cb8c3e9d395bdbec1c88f40.png) ![fastleft](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/1/1232e85f7ba6ab8fbcc0cfdea4c6ef3ae1095716.png) ![fastleft2](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/b/b227697fc18572164c6dade8dcd46297c6f6b160.png) ![fastleft3](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/d/df26e4af908b7d4236f1788c5a96c8f3e74c32f6.png) ![fastright](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/7/7eec66152bdc6cecfa12430c4462cbeab3794198.png) ![fastright2](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/1/1f5f5e08da0d8c508d04ccf6cf4d43a6be2fcb92.png) ![fastright3](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/8/8a1b09a497b756ae08fe6b9fcdf6722492f827e9.png) ![flyleft](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/8/86321eb3eb00fb95a6eb00bf8bf496e0917c6cc3.png) ![flyright](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/c/c7a30d81b5eb01bbec1a771316d599f025953ea8.png) ![ground](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/e/ec105d6e3376b094f691e40140b0c01e29c0a5df.png) ![ground2](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/6/663fd13cd116224c71d9feb29333bd7d76f9b622.png) ![leftfall](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/7/7a2ff96e4b970af16ef65304e6dff955eeefc3cb.png) ![leftjump](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/4/418dba04dfc54ddc19a67f73fbbe0873e121b19b.png) ![leftup](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/e/eaeab96413493d268ffa12d5c6d834d507dea01c.png) ![LtoR](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/8/8db59e1cf769f2a4f7c9dccebbf309846c588c7b.png) ![marioleft](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/6/65a6326cb6da78816fb8ac9ba354687f9755be13.png) ![marioright](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/0/02a5a709c2c1ad40e06ea4a4c3c1edbf05c6c932.png) ![mariowalkleft](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/8/8607469ac19be632689dfadb5e385d6977959bde.png) ![mariowalkleft2](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/e/ea9af273f81cb877fd626d0f94e2796d4d01337e.png) ![mariowalkright](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/0/04997d5367b6afd6ad28946637055fc589bf2f35.png) ![mariowalkright2](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/c/c1fc029203f661b754ee1a661f061f9fe0e06246.png) ![pipe](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/4/490a4cf37fa593d3743c4b9a007329917cc71e04.png) ![rightfall](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/0/08d5774b617146dae436b71fe03f0506eb8b8835.png) ![rightjump](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/c/ca3a6af449fed60dfdc4f8df52aa106eb66ddc01.png) ![rightup](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/c/c6615f16a4c39ffc87ed4a4332b3b21abfbf1ae5.png) ![RtoL](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/6/6736437b804a8aa602d848098f348d58e59f2364.png)

 ![bg](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/8/8bd3c8f0e6ff06ee04e5506d9e57cd8acac726bc.png) ![bg2](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/b/bd56edd3476809ee5df10785504950ff04d8e3c2.png) ![coin](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/7/7038ffce3101a3909ca2bec8f64aeef84a9d4897.png)

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [February 19, 2019, 4:39am UTC](https://discourse.processing.org/t/super-mario-game-help/8470/4 "2019-02-19T04:39:25Z")

</div>

> [@Feeling ambitious!](https://discourse.processing.org/t/feeling-ambitious/1098/5):
>
> BtW, I host that Mario Engine Pjs sketch in GitHub too: smile_cat[https://GoSubRoutine.GitHub.io/PjsGameEngine/codebase/](https://GoSubRoutine.GitHub.io/PjsGameEngine/codebase/)

[ProcessingJS.NihongoResources.com/test/PjsGameEngine/docs/tutorial/mario.html](http://ProcessingJS.NihongoResources.com/test/PjsGameEngine/docs/tutorial/mario.html)

---

<div class="post-metadata">

**Author:** ![LuciferMS666](https://avatars.discourse-cdn.com/v4/letter/l/87869e/32.png) [@LuciferMS666](https://discourse.processing.org/u/LuciferMS666)\
**Post date:** [February 19, 2019, 11:46am UTC](https://discourse.processing.org/t/super-mario-game-help/8470/5 "2019-02-19T11:46:16Z")

</div>

Hello, I thank you for the code only this one does not work. There are also features that I have never seen (AddScreen addLevelLayer, etc)
