[Release & Competition] Online Python Editor for Pokitto!


#1

PLEASE NOTE - competition rules in post #2 !! - admin

Hi,

I am happy to announce an online Python Editor for Pokitto, made by @fmanga ! It is a free tool which enables you to write and test Micro Python programs online, and finally create the binary for Pokitto. No installation or login needed :slight_smile:

The editor has some unique and advanced features, like:

  • An inline pixel editor that enables you to draw bitmaps inside the text editor!
  • An integrated Pokitto emulator to immediately see your program in action
  • An integrated builder to make a binary packet for flashing to Pokitto.
  • Ready-made example projects to immediately run in the emulator and Pokitto

This really is the easiest way to develop simple games for Pokitto!

Click on the link below to try the editor:
https://pyinsky.herokuapp.com/

Look at the video for a quick overview of the features of the editor:

Below are some links to help you with the Python development on Pokitto:


#2

Python Coding Competition!

compo

First of all, a very big thank you to @Hanski and @FManga for their hard work on the incredible Python IDE and the tutorials and wikis. These will make Python coding on Pokitto much easier!

To celebrate this, the Batcomputer has decided to host a small competition to encourage people to try out Python coding on Pokitto and give to feedback and ideas about the tools.

RULES

  • make a Pokitto game / app using our Python editor pyinsky.herokuapp.com

  • and submit it in this thread by 30.3.2019 or by sending to python@pokitto.com

  • entry must include
    – .py source code
    – game binary saved from our python editor
    – license information for graphics or other resources that you have not made yourself

  • if you need help in getting up and running with the tools, come here to this thread to ask for help

  • the game must be “complete” in the sense that it can be loaded on Pokitto, played and enjoyed

  • game code has to be open-source so other can benefit from your wisdom!

  • game can not use images / other copyrighted material that the author does not own

  • author gives permission for game to be put on next gamedisk compilation

  • winners shall be chosen by the almighty Batcomputer and @Hanski the boy wonder. We citizens of Gotham can trust them to be fair judges

  • this competition will also be announced on Twitter

  • I reserve the right to amend rules if the situation requires it! Nobody will be cheated but if something happens, I will simply deal with it.

  • warning: rude, offensive or impolite stuff will get deleted

PRIZES

Fully kitted Pokitto + Pokitto logo T-shirt for THREE best entries:

  • best beginner
  • best mid range
  • best advanced coder
    Everyone has a chance! The jury won’t just give prizes to old experienced coders. We will look at the submissions and we can see the effort of the individual submissions.

… and ofcourse the admiration of Pokitto community to prize winners and participants!

COMPETITION ENTRIES

Here are competition entries (in release order). You can post your entry to this thread, and we will add it here.


Entry: Mandelbrot set
Author: @drummyfish
Sources:

Here
# Drummyfish, CC0

import upygame as upg
import framebuf

upg.display.init()
screen_sf = upg.display.set_mode()

RESOLUTION = (40,25)
ITERATIONS = 100
PIXEL_SIZE = 3

SUBDIV = 1000

COLORS = 5

center = [-500,0]
view_width = 2500

step = view_width // RESOLUTION[0]

top_left = (center[0] - RESOLUTION[0] // 2 * step, center[1] - RESOLUTION[1] // 2 * step)

def mandelbrot(point):
  z = [0,0]   # complex number to iterate

  color = 0

  try: 
    for n in range(ITERATIONS):
      # Mandelbrot formula: f_c(z) = z^2 + c
      z = ((z[0] * z[0] - (z[1] * z[1])) // SUBDIV + point[0],
           (2 * z[0] * z[1]) // SUBDIV             + point[1])

      abs1 = z[0] if z[0] >= 0 else -1 * z[0]
      abs2 = z[1] if z[1] >= 0 else -1 * z[1]

      length = abs1 if abs1 >= abs2 else abs2

      if length > 1000000000 or length != length:
        return 1
  except Exception:
    return 1

  return 0

point = [top_left[0], top_left[1]]

fractal = []

for y in range(RESOLUTION[1]):
  for x in range(RESOLUTION[0]):
    fractal.append(mandelbrot(point))

    point[0] += step

  point[0] = top_left[0]
  point[1] += step

while True:
  eventtype = upg.event.poll()

  i = 0
  
  for y in range(RESOLUTION[1]):
    for x in range(RESOLUTION[0]):
      screen_sf.fill(fractal[i],upg.Rect(x * PIXEL_SIZE,y * PIXEL_SIZE,PIXEL_SIZE,PIXEL_SIZE))
      i += 1
  
  upg.display.flip()

Binary:
Screenshot or video:

image


Entry: Bounce!
Author: @wuuff
Sources:

Here
# Welcome to Python on Pokitto!
import upygame as pygame

import umachine as pok

pygame.display.init()
screen = pygame.display.set_mode() # full screen
screenRect = screen.get_rect()
screenW = screenRect.width
screenH = screenRect.height

ballPixels = b'\
\x01\x70\
\x17\xcf\
\x7c\xcf\
\x0f\xf0\
'

ball2Pixels = b'\
\x01\x60\
\x16\xae\
\x6a\xae\
\x0e\xe0\
'

ballSurface = pygame.surface.Surface(4,4,ballPixels)
ball2Surface = pygame.surface.Surface(4,4,ball2Pixels)

#pok.draw_text(0,10,"hello", 1)
pygame.display.flip()

balls = [{'x':0,'y':44,'vy':5},{'x':0,'y':44,'vy':5},{'x':0,'y':44,'vy':5},{'x':0,'y':44,'vy':5},{'x':0,'y':44,'vy':5},\
         {'x':0,'y':44,'vy':5},{'x':0,'y':44,'vy':5},{'x':0,'y':44,'vy':5},{'x':0,'y':44,'vy':5},{'x':0,'y':44,'vy':5},{'x':0,'y':44,'vy':5}]
    
currBall = 0
ballTimer = 0
bounce = 'bounce!'
    
while True:
    ballTimer += 2
    if ballTimer == 10 and currBall < len(balls):
        ballTimer = 0
        currBall += 1
    #pok.draw_text(myX,10,"hello", 1)
    #screen.blit( ballSurface, myX, myY, 0 )
    for b in range(0,currBall):
        ball = balls[b]
        if b < 7:
            pok.draw_text(ball['x'],ball['y']-10,bounce[6-b], 1)
        ball['x'] += 2
        if ball['x'] > 110:
            ball['x'] = 0
        if ball['y'] < 44:
            ball['vy'] += 1
        else:
            ball['vy'] -= 1
        ball['y'] += ball['vy']
        screen.blit( ballSurface, ball['x'], ball['y'], 0 )
        screen.blit( ball2Surface, ball['y'], ball['x'], 0 )
    pygame.display.flip()

Binary:
Screenshot or video:
image


Entry: Rexitto
Author: @HomineLudens
Source: rexitto.zip (25.9 KB)
Binary: rexitto.bin (140.8 KB)
Screenshot or video:
rex


Entry: You shall not pass
Author: @FManga
Source: pokitto-mpy-project(20).zip (153.3 KB)
Binary: build(48).bin (175.3 KB)

Instructions or other info

How to play:

You’re a knight on an important quest… but a pesky lizard is in your way.
Left : Sword attack. Effective against attempts to heal.
Up : Heal yourself. Makes you vulnerable to sword attacks.
Right : Block. Reflects sword damage back to opponent.

Screenshot or video:
1


Entry: Dr Mriller
Author: @fmanga
Source: pokitto-mpy-project(49).zip (81.4 KB)
Binary: build(79).bin (155.8 KB)
Screenshot or video:
1


Entry: Noggin
Author: @spinal
Source: NogginSource.zip (151.0 KB)
Binary:Noggin.bin (188.8 KB)

Instructions and other info

Each tile gives you a number, make that many moves without crossing your path then hit A.
Wildcards are as follows,
Jack - swap a tile from the spares pile.
Queen - choose any tile horizontally or vertically, but all tiles in that line will flip.
King - Same as Queen, but only your selected tile will flip.
! - Move one tile, but reserve the ability to move anywhere by pressing B when on your starting tile.

A - Turn a tile
B - return to start tile
C - start fresh game
01 02

Screenshot or video:
03 04


Entry: KameraKatze
Author: @ServalKatze
Source: KameraKatze.zip (22.8 KB)
Binary: kamerakatze.bin (139.7 KB)

Instructions and other info

You are a kitty. :cat2:

Take pictures of the sleeping lion to score points. Note how the environment changes as your score increases. Don’t get noticed by the scary lion. :lion:

start ingame


Entry: Pyrates
Author: @jonne
Source: pyrates.zip (60.2 KB)
Binary:pyrates.bin (154.3 KB)

Instructions and other info

Objective of the game

For a pirate,

a fate far worse than the treacherous rocks ripping the ship to shreds, far worse than the raging seas, the howling winds, or the mystical sea-monster Kraken

… is running out of Grog

Sailing the dangerous waters of the Spanish Main, you as a captain have to take care of your ship and crew. Your goal is to sail to different islands, land on the ports and make sure your ship stays brimmed with Grog.

Instructions

  • you are sailing. In sailing you go with the wind, you do not just “point the ship”. Learn to navigate!
  • if you get lost at sea, just press ‘C’ to restart the challenge
  • PRESS A several times in the beginning to start
  • if you are Landed you can jiggle your boat to get loose
  • if you wish to exit a port, turn your ship and press A to give it a push
  • the ship’s mast watch will call “Land Ahoy” when he sights land. You can then try to sail in that direction. It is easy to miss the islands!
  • not all islands are safe to land - the port may be in an impossible place. Sail away to another island

Now go learn the ropes, ya miserable landlubber!!

1


Entry: **Tor’s Game Gallery **
Author: @torbuntu
Source:TorsGameGallery.zip (97.8 KB)
Binary:tgg.bin (173.3 KB)
Binary:

Instructions and other info

Mecha Narwhal
Explore the ocean depths as the Mecha Narwhal! Dodge shark poky coral, avoid or dash through dangerous jellyfish, and keep an eye out for those pesky sharks!
The farther you explore, the faster you’ll go! Keep your eyes open.

Angry space toast
Just a simple avoidance game where you’re objective is to not get clobbered by the angry space toast. You have a shield, but it can only take so much buttery angst. Once that is depleted you have minimal health remaining before you’re toast.
A is the button to start the round. Movement is with D-pad but thrust is either UP or A. No other controls yet.

mechaNarwhal ast


Entry: Big Blue
Author: @andrewb
Source: BigBlue.zip (32.2 KB)
Binary: file.bin (156.5 KB)

Instructions and other info

Your goal in it is to guide the astronaut home, avoiding aliens, comets and rockets across 5 different levels of increasing difficulty.

gameplay


#3

Amazing, looks like a huge leap in accessibility for the beginners. Going to test!

And a coding competition ahead! It’s a good day today :slight_smile:


#4

Just go for it :slight_smile: The prizes are very, very nice also!
Just ask here if you have any questions or comments about the editor, uPyGame, Micro Python, etc.


#5

TIP: The speed of the Python program on Pokitto HW is actually significantly faster than in the integrated emulator.


#6

Question… is Pokitto Python for 110x88 only? of is 220x176 possible?


#7

For simplicity, the online editor supports only 110x88 with 16 colors. It is also for memory usage reasons, as there is not too much free RAM left for Python programs.


#8

Does float work? It doesn’t want to compile with float numbers and float(2) gives me unknown name.


#9

Floats are not supported.
Here you can get hints what MP features are supported, and which aren’t: https://github.com/haviital/micropython/blob/master/ports/pokitto/mpconfigport.h


#10

Floats are not supported.

Okay, switched to integers. Here is Mandelbrot set :slight_smile:

image

Summary
# Drummyfish, CC0

import upygame as upg
import framebuf

upg.display.init()
screen_sf = upg.display.set_mode()

RESOLUTION = (40,25)
ITERATIONS = 100
PIXEL_SIZE = 3

SUBDIV = 1000

COLORS = 5

center = [-500,0]
view_width = 2500

step = view_width // RESOLUTION[0]

top_left = (center[0] - RESOLUTION[0] // 2 * step, center[1] - RESOLUTION[1] // 2 * step)

def mandelbrot(point):
  z = [0,0]   # complex number to iterate

  color = 0

  try: 
    for n in range(ITERATIONS):
      # Mandelbrot formula: f_c(z) = z^2 + c
      z = ((z[0] * z[0] - (z[1] * z[1])) // SUBDIV + point[0],
           (2 * z[0] * z[1]) // SUBDIV             + point[1])

      abs1 = z[0] if z[0] >= 0 else -1 * z[0]
      abs2 = z[1] if z[1] >= 0 else -1 * z[1]

      length = abs1 if abs1 >= abs2 else abs2

      if length > 1000000000 or length != length:
        return 1
  except Exception:
    return 1

  return 0

point = [top_left[0], top_left[1]]

fractal = []

for y in range(RESOLUTION[1]):
  for x in range(RESOLUTION[0]):
    fractal.append(mandelbrot(point))

    point[0] += step

  point[0] = top_left[0]
  point[1] += step

while True:
  eventtype = upg.event.poll()

  i = 0
  
  for y in range(RESOLUTION[1]):
    for x in range(RESOLUTION[0]):
      screen_sf.fill(fractal[i],upg.Rect(x * PIXEL_SIZE,y * PIXEL_SIZE,PIXEL_SIZE,PIXEL_SIZE))
      i += 1
  
  upg.display.flip()

#11

Ooh! First entry. It’s game on!!!


#12

I’ve never even looked at python before, but I’m going to try something. Why not :slight_smile:


#13

Is there a reason that my images don’t do that re-colour thing that the examples do?


#14

yes, something I have forgot to mention. There has to be “pixels” in the variable name.


#15

cool, I don’t suppose image arrays are a thing? I want to use a 14 frame sprite sheet.


#16

you have to use a separate surface for each frame


#17

This looks really nice, and the image editing in the code reminds me of fantasy consoles like the Pico-8, where all the development tools are integrated together. This should make it a lot easier for people to start developing for the Pokitto. I definitely want to find some time to try this out.


#18

I think it would make more sense to put that in a comment above rather than restricting the programmer’s word choice.
Unless that’s too much extra effort?


#19

Hi,
I made a FAQ about all questions related to Python in Pokitto: FAQ: Python in Pokitto

I will collect all the information in this discussion thread to there.


#20

I wanted to try something really quick with this and I hadn’t done any demoscene-style stuff before, so I put something simple together. I’m amazed how fast this runs on the Pokitto! It’s super smooth, even without trying to do any optimizations. Hoping to be able to do more later.

image

Code
# Welcome to Python on Pokitto!
import upygame as pygame

import umachine as pok

pygame.display.init()
screen = pygame.display.set_mode() # full screen
screenRect = screen.get_rect()
screenW = screenRect.width
screenH = screenRect.height

ballPixels = b'\
\x01\x70\
\x17\xcf\
\x7c\xcf\
\x0f\xf0\
'

ball2Pixels = b'\
\x01\x60\
\x16\xae\
\x6a\xae\
\x0e\xe0\
'

ballSurface = pygame.surface.Surface(4,4,ballPixels)
ball2Surface = pygame.surface.Surface(4,4,ball2Pixels)

#pok.draw_text(0,10,"hello", 1)
pygame.display.flip()

balls = [{'x':0,'y':44,'vy':5},{'x':0,'y':44,'vy':5},{'x':0,'y':44,'vy':5},{'x':0,'y':44,'vy':5},{'x':0,'y':44,'vy':5},\
         {'x':0,'y':44,'vy':5},{'x':0,'y':44,'vy':5},{'x':0,'y':44,'vy':5},{'x':0,'y':44,'vy':5},{'x':0,'y':44,'vy':5},{'x':0,'y':44,'vy':5}]
    
currBall = 0
ballTimer = 0
bounce = 'bounce!'
    
while True:
    ballTimer += 2
    if ballTimer == 10 and currBall < len(balls):
        ballTimer = 0
        currBall += 1
    #pok.draw_text(myX,10,"hello", 1)
    #screen.blit( ballSurface, myX, myY, 0 )
    for b in range(0,currBall):
        ball = balls[b]
        if b < 7:
            pok.draw_text(ball['x'],ball['y']-10,bounce[6-b], 1)
        ball['x'] += 2
        if ball['x'] > 110:
            ball['x'] = 0
        if ball['y'] < 44:
            ball['vy'] += 1
        else:
            ball['vy'] -= 1
        ball['y'] += ball['vy']
        screen.blit( ballSurface, ball['x'], ball['y'], 0 )
        screen.blit( ball2Surface, ball['y'], ball['x'], 0 )
    pygame.display.flip()