FAQ: Python in Pokitto

Here are the gaming API functions listed: [Wiki]uPyGame & umachine library reference (for Micro Python in Pokitto)

You can only draw a filled rectangle.

1 Like

Thanks. I had checked that list but somehow missed the fill functionā€¦

My solution is to use 2 images, 1 horizontal and 1 vertical line then just draw however many you need to the screen

1 Like

Images? Thereā€™s no ā€˜draw lineā€™ function? Or is it a speed thing?

Hrm, I wonder if image rendering is faster or slower than bresenhamā€™s line algorithmā€¦

I know, I couldnā€™t find anything other than drawing images or filling rects, so I did what anyone else would do. I used images of short lines and drew as many as I needed to create a rect.

As already two people were requesting drawing primitives, I am curious what you are doing with the primitives? I almost never use them in games.

I wanted to draw some lines and mistakenly thought I could use the filled rectangle function.
I always assumed that just drawing lines would be ā€œbetterā€ in terms of ā€œperformanceā€ than having to store and draw a whole bitmap of which most pixels are transparent. I currently donā€™t really need the lines though.

1 Like

Particles, particles everywhere.
And lasers light beams.
Also debug hit box, 3d flat shaded triangles, landscapes.
If you are not a pixel artist primitives help a lot.

2 Likes

Yes laser light beams!

3 Likes

I usually use primitives for drawing UI elements.
Boxes to draw text on come in very handy.
(Fill a rect in a background colour, draw an outline of a foreground colour,
put text in the resulting empty space.)

Also shape drawing is dynamically scalable, bitmaps arenā€™t (unless you repeat part of the image).

And shapes are good placeholders for when you canā€™t be bothered to do art.

I second this, although with a rectangle primitive I could manage.

Drawpixel would be most important for me

@Hanski is it possible to not get always the same random numbers?

Now thatā€™s interesting, a random number generator not generating random numbers. Maybe you need a function to reset it?

Yeah I need a way to set the seed based on the time or something

Just use a splash screen to seed your random numbers:


def splashScreen():
    while True:
        random.getrandbits(30)
        eventtype = upygame.event.poll()
        if eventtype != upygame.NOEVENT and eventtype.type == upygame.KEYUP:
            return
        screen.blit( splash.bmp, 0, 0 )       
        upygame.display.flip()

This calls random.getrandbits every frame, until the player presses a button. Since the amount of time until that happens isnā€™t constant, you get a different sequence of random numbers from then on.

7 Likes

Deviously clever. I love it.

2 Likes

This also has the advantage to open a predictable way to control the RNG, which is really interesting for speedrunning :slight_smile:

1 Like

Exactly how I do it in Noggin. A very good method.

1 Like

@spinal the goal in Noggin is to flip all tiles right? Also is it possible to make so that the game knows when thereā€™s no moves possible and display a game over? My guess is that it would be a bit complicated but I had to ask. I am enjoying the game a lot either way.

Thatā€™s the goal alright. As for detecting no further moves, I had though about that, but I really canā€™t think of a way to do it. I would imagine some sort of flood-fill or path-finding routine might be involved, but Iā€™m not sure how possible it could be.