Online Python Editor for Pokitto!

OK, it’s fixed. I had forgotten that I’d checked out the latest upstream micropython and that required a full rebuild.

2 Likes

I have today updated micropython, which is now in sync with the latest PokittoLib.

Now that I am at it, should I make a PR and merge libtilemap to PokittoLib?

Sure, go ahead. :slight_smile:

Da dum ti dum… implemented wind and steering :kissing_heart:

Animation now 4x smoother

1

9 Likes

This is AWESOME :clap::clap:

1 Like

Update:

  • Python Editor now contains a time function: umachine.time_us(), which returns current tics in milliseconds.
This is how you can implement a FPS counter with it
import upygame as upg
import framebuf
import urandom as random
import umachine

upg.display.init()
screen_sf = upg.display.set_mode() # full screen

# Set palette
upg.display.set_palette_16bit([0,4124,1984,65535]);

# pokitto picture
w2 = 16
h2 = 16
pokittoPixels = b'\
\x00\x03\x33\x33\x33\x33\x33\x00\
\x00\x32\x22\x22\x22\x22\x32\x00\
\x00\x32\x33\x33\x33\x33\x22\x00\
\x00\x32\x31\x11\x11\x11\x22\x00\
\x00\x32\x31\x13\x11\x31\x22\x00\
\x02\x32\x31\x11\x11\x11\x22\x23\
\x03\x32\x31\x13\x33\x11\x22\x30\
\x00\x32\x31\x11\x11\x11\x22\x00\
\x00\x32\x22\x22\x22\x22\x22\x00\
\x00\x32\x23\x22\x22\x23\x32\x00\
\x00\x32\x33\x32\x23\x33\x32\x00\
\x00\x32\x23\x22\x23\x32\x22\x00\
\x00\x32\x22\x23\x32\x22\x22\x00\
\x00\x32\x22\x22\x22\x22\x32\x00\
\x00\x33\x33\x33\x33\x33\x33\x00\
\x00\x32\x00\x00\x00\x00\x32\x00\
'

hero_sf = upg.surface.Surface(w2, h2, pokittoPixels)
#hero_sf.fill(2)

x=20
y=20
vx = 0;
vy = 0;
frameNum = 0
lastFpsTime = umachine.time_us()
fps = 0
while True:

    eventtype = upg.event.poll()
    if eventtype != upg.NOEVENT:
        if eventtype.type== upg.KEYDOWN:
            if eventtype.key == upg.K_RIGHT:
                vx = 1
            if eventtype.key == upg.K_LEFT:
                vx = -1
            if eventtype.key == upg.K_UP:
                vy = -1
            if eventtype.key == upg.K_DOWN:
                vy = 1
        if eventtype.type == upg.KEYUP:
            if eventtype.key == upg.K_RIGHT:
                vx = 0
            if eventtype.key == upg.K_LEFT:
                vx = 0
            if eventtype.key == upg.K_UP:
                vy = 0
            if eventtype.key == upg.K_DOWN:
                vy = 0

    for i in range(1,200):
        x2 = random.getrandbits(6) + 20
        y2 = random.getrandbits(6) + 5
        screen_sf.blit(hero_sf, x2, y2)

    x = x + vx
    y = y + vy
    screen_sf.blit(hero_sf, x, y)

    # FPS
    frameNum += 1
    if(frameNum%50 == 0): # Calculate in 50 frame intervals
        now = umachine.time_us()
        fps = 50000 // (now-lastFpsTime)
        lastFpsTime = now
    umachine.draw_text(0,0,str(fps),1)
    
    upg.display.flip()

1 Like

Anybody mind if we increase the FPS cap? I just noticed that there’s no PROJ_FPS, so it defaults to about 20. Ideally we’d have a function to set the desired cap, but for now we could just set it to something higher.

Do we need a cap at all? Practically, something like 50 FPS cap would be good as well, but there has been a discussion that the limiter is not working correctly. Would it be easiest just to set it to 100?

If somebody really wants to slow down the Python program, there is a umachine.wait() for that purpose.

Usually, the problem is too low FPS. Even 20 FPS could be challenging to achieve, if you have a lot of objects.

I wouldn’t mind removing the cap entirely.

@FManga @Hanski Bigger problem is the sudden increase of bins from ~140kB to 200+kB after latest release.

“Pyrates” is very close to playable alpha but its already 204kB

Still? It should’ve dropped back down.

Ok I haven’t checked in a moment

I’d like to point out @jonne that will be really unfair if you’re going to win… :wink:

1 Like

No chance of that :wink:

1

4 Likes

hey everyone, i’ve just started playing around with the python editor, its the first time I’ve tried making something for the pokitto so I apologise for any ignorance I may have about the hardware. When running my program on the website it eventually crashes with the error “Attempt to write to flash (0x680002a) on PC=0x1c4e0” - @Hanski can you please elaborate on what this means? thanks in advance!

2 Likes

Hi @andrewb! Can you post the code you’re working on? It’s easier to find out what’s wrong that way, especially since you’re the first to report this error.

1 Like

At the moment it is just a program that switches between different states. However, after going through the five “levels”, restarting and trying again it crashes.
I tried putting all the code in 1 file and it didn’t fix it. I also thought it was maybe something to do with memory management but I’ve tried using gc.collect() and there has still been crashes.
It could just be something silly I’ve overlooked though, or how I’m organising the code, or maybe what I’m trying isn’t possible? Any input would be great!
pokitto-mpy-project (4).zip (5.3 KB)

1 Like

It’s crashing because it’s running out of memory. Specifically, it’s a stack overflow.
The reason that happens is that you don’t exit each state before you enter the next. Each state is an endless loop that never returns.
Changing from one state to the next should be setting a variable and then returning.
pokitto-mpy-project(41).zip (5.4 KB)

2 Likes

Right, I understand now, I’ll put that fix into my code before I do anything else! Thank you for your help, it probably would have taken me a while to figure that out, its good to have another set of eyes to check over your code sometimes.

3 Likes