# Help processing 2.0 python

**URL:** <https://discourse.processing.org/t/help-processing-2-0-python/29534>\
**Category:** Processing.py\
**Created:** [April 21, 2021, 1:43am UTC](https://discourse.processing.org/t/help-processing-2-0-python/29534 "2021-04-21T01:43:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![BeastBoy3108](https://avatars.discourse-cdn.com/v4/letter/b/e0b2c6/32.png) [@BeastBoy3108](https://discourse.processing.org/u/BeastBoy3108)\
**Post date:** [April 21, 2021, 1:43am UTC](https://discourse.processing.org/t/help-processing-2-0-python/29534/1 "2021-04-21T01:43:02Z")

</div>

Hi, I am a elementary schooler, and I started collabbing with my friend in python. He would make the sprites, I would code. We are making Super Mario Brothers stage 1-1, because the whole game would take us too long time to make. When I was making the grounds, some bug, or error happened. I have tried every single thing to fix it, put over an 2 full hour to fix this but I just couldn’t. Can you help me fix this project? The code that I wrote right now goes like this-

```auto
from processing import *
from time import time

rectx = 50
recty = 300
touchingGround = False
vy = 0
sprint = False
pressed = [0, 0]
costume = 0
look = 0
timerun = 0.0
bottom = 410
noneComboStart = 0

def setup():
    global stillr, run1r, run2r, stilll, still, run1, run2, mario, block, a
    noStroke()
    stillr = loadImage("http://coder200.oyosite.com/mario/photo/still.png")
    run1r = loadImage("http://coder200.oyosite.com/mario/photo/run1.png")
    run2r = loadImage("http://coder200.oyosite.com/mario/photo/run2.png")
    jumpr = loadImage("http://coder200.oyosite.com/mario/photo/jump.png")
    stilll = loadImage("http://coder200.oyosite.com/mario/photo/still_l.png")
    run1l = loadImage("http://coder200.oyosite.com/mario/photo/run1_l.png")
    run2l = loadImage("http://coder200.oyosite.com/mario/photo/run2_l.png")
    jumpl = loadImage("http://coder200.oyosite.com/mario/photo/jump_l.png")
    block = loadImage("http://coder200.oyosite.com/mario/photo/block.png")
    a = [block, block, block, None, None, None, block, None, block, block, None, None]
    still = [stillr, stilll]
    run1 = [run1r, run1l]
    run2 = [run2r, run2l]
    jump = [jumpr, jumpl]
    mario = [still, run1, run2, jump]
    size(500, 500)

def draw():
    move()
    changeCostume()
    background(255, 255, 255)
    fill(0, 0, 0)
    image(mario[costume][look], rectx, recty, 40, 40)
    stroke(255, 255, 255)
    for i in range(len(a)):
        if not a[i] == None:
            image(a[i], i * 40, 450, 40, 40)

def keyPressed():
    global touchingGround, vy, rectx, sprint, look, timerun
    if keyboard.keyCode == 38:
        if touchingGround:
            vy += 11
            touchingGround = False
    if keyboard.keyCode == 37:
        if pressed[0] == 0:
            timerun = time()
        pressed[0] = 2
    if keyboard.keyCode == 39:
        if pressed[1] == 0:
            timerun = time()
        pressed[1] = 2
    if keyboard.keyCode == 16:
        sprint = True

def keyReleased():
    global sprint, costume
    if keyboard.keyCode == 37:
        pressed[0] = 0
    if keyboard.keyCode == 39:
        pressed[1] = 0
    if keyboard.keyCode == 16:
        sprint = False

def move():
    global recty, touchingGround, vy, rectx, noneComboStart, bottom
    for i in range(len(a)):
        if a[i] == None:
            if i - 1 >= 0:
                if a[i - 1] != None:
                    noneComboStart = i * 40
            if not i + 1 >= len(a):
                if a[i + 1] == None:
                    continue
                else:
                    if rectx >= noneComboStart and rectx <= i * 40:
                        bottom = 500
                    else:
                        bottom = 410
    if sprint:
        if pressed[0] != 0:
            pressed[0] = 4
        if pressed[1] != 0:
            pressed[1] = 4
    else:
        if pressed[0] != 0:
            pressed[0] = 2
        if pressed[1] != 0:
            pressed[1] = 2
    if not touchingGround:
        vy -= 0.5
    rectx -= pressed[0]
    rectx += pressed[1]
    recty -= vy
    if recty >= bottom:
        recty = bottom
        touchingGround = True
        vy = 0
    if rectx <= 0:
        rectx = 0

def changeCostume():
    global costume, look
    if abs(pressed[0] - pressed[1]) == 0:
        costume = 0
    elif abs(pressed[0] - pressed[1]) == 2:
        if round((time() - timerun) * 2) % 2 == 0:
            costume = 1
        else:
            costume = 2
        if pressed[0] - pressed[1] == 2:
            look = 1
        elif pressed[0] - pressed[1] == -2:
            look = 0
    elif abs(pressed[0] - pressed[1]) == 4:
        if round((time() - timerun) * 4) % 2 == 0:
            costume = 1
        else:
            costume = 2
        if pressed[0] - pressed[1] == 4:
            look = 1
        elif pressed[0] - pressed[1] == -4:
            look = 0
    if not touchingGround:
        costume = 3

run()

```

It’s very long, because this is my first time coding platformers. Also just saying I coded this from Python Mini in the coding platform called kidOYO, so it doesn’t have lots of accessibilities that we usually have.

---

<div class="post-metadata">

**Author:** ![tabreturn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tabreturn/32/3697_2.png) [@tabreturn](https://discourse.processing.org/u/tabreturn)\
**Post date:** [April 21, 2021, 2:59am UTC](https://discourse.processing.org/t/help-processing-2-0-python/29534/2 "2021-04-21T02:59:34Z")

</div>

Welcome @BeastBoy3108

I used [trinket.io](https://trinket.io) to test your code, which doesn’t report any errors when I run it. What is the bug exactly? Is it that Mario doesn’t fall through the gaps?

---

<div class="post-metadata">

**Author:** ![BeastBoy3108](https://avatars.discourse-cdn.com/v4/letter/b/e0b2c6/32.png) [@BeastBoy3108](https://discourse.processing.org/u/BeastBoy3108)\
**Post date:** [April 21, 2021, 12:46pm UTC](https://discourse.processing.org/t/help-processing-2-0-python/29534/3 "2021-04-21T12:46:28Z")

</div>

Yeah. Mario doesn’t fall into the gaps…

---

<div class="post-metadata">

**Author:** ![tabreturn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tabreturn/32/3697_2.png) [@tabreturn](https://discourse.processing.org/u/tabreturn)\
**Post date:** [April 21, 2021, 9:13pm UTC](https://discourse.processing.org/t/help-processing-2-0-python/29534/4 "2021-04-21T21:13:23Z")

</div>

You’re using this condition to detect if Mario is touching the ground:

```python
    ...
    if recty >= bottom:
        recty = bottom
        touchingGround = True

```

The variable `bottom` is equal to 410. As long as Mario’s y-coordinate has reached 410, the code assumes he’s resting on the ground. The problem is there’s no other condition to check if he’s also on a brick tile.

You could add some code that loops through the `a` list to calculate if Mario is above a `block` or a `None` item. But you’ll run into other, more complex ‘collision detection’ issues when you’re trying to complete the entire 1-1 level (walls; enemies; platforms above and below you; etc.).

I checked if [trinket.io](http://trinket.io) includes a physics library, but it [doesn’t look like it](https://trinket.io/docs/python). Perhaps kidOYO does? There are pure python physics libraries, [pypybox2d](https://github.com/pybox2d/pypybox2d); you’d have to upload/copy-paste in each py file … if that’s even possible.

You can also look around for a 2D-platform or [Mario tutorial](http://processingjs.nihongoresources.com/test/PjsGameEngine/docs/tutorial/mario.html) that doesn’t rely on a physics library, although you may have to translate that into Python.

---

<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:** [April 23, 2021, 6:09am UTC](https://discourse.processing.org/t/help-processing-2-0-python/29534/5 "2021-04-23T06:09:43Z")

</div>

> [@tabreturn](#):
>
> You can also look around for a 2D-platform or [Mario tutorial](http://processingjs.nihongoresources.com/test/PjsGameEngine/docs/tutorial/mario.html)

BtW, I’ve got a copy of that old Mario clone game in this repo: 🐙

> **[GitHub - GoSubRoutine/PjsGameEngine](https://github.com/GoSubRoutine/PjsGameEngine)**
>
> Contribute to GoSubRoutine/PjsGameEngine development by creating an account on GitHub.

You can also play it online via the link below: 🔗  
[GoSubRoutine.GitHub.io/PjsGameEngine/codebase/](http://GoSubRoutine.GitHub.io/PjsGameEngine/codebase/)
