Skip to content

Commit

Permalink
Play with micropython examples
Browse files Browse the repository at this point in the history
  • Loading branch information
polldo committed May 25, 2022
1 parent 6a6b38c commit eb2d01f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 32 deletions.
8 changes: 4 additions & 4 deletions examples/micropython/animation/animation.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import dolp

explosion1 = bytearray(b'\x10\x10\x00\x00\x00\x00\x90\x40\x40\x20\x40\x40\x84\x00\x10\x00\x00\x00\x00\x00\x04\x00\x00\x05\x01\x02\x01\x21\x00\x04\x00\x00\x00\x00')
explosion2 = bytearray(b'\x10\x10\x00\x00\x00\x00\x88\x60\x24\x10\x20\x60\x80\x00\x12\x00\x00\x00\x00\x40\x02\x00\x00\x03\x02\x24\x02\x03\x00\x00\x00\x44\x00\x00')
explosion3 = bytearray(b'\x10\x10\x00\x00\x60\x44\x84\x40\xa6\x14\x10\x20\x42\x82\x00\x08\x40\x00\x00\x08\x00\x08\x01\x22\x04\x4b\x48\x05\x02\x01\x00\x60\x06\x00')
explosion4 = bytearray(b'\x10\x10\x00\x00\x00\x18\xa8\xc8\xf0\xf0\xf0\xe0\xe8\xb8\x08\x00\x00\x00\x00\x00\x00\x30\x39\x17\x17\x1f\x0f\x17\x13\x21\x78\x20\x00\x00')
explosion1 = bytearray([0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x90, 0x40, 0x40, 0x20, 0x40, 0x40, 0x84, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x05, 0x01, 0x02, 0x01, 0x21, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00])
explosion2 = bytearray([0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x88, 0x60, 0x24, 0x10, 0x20, 0x60, 0x80, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x03, 0x02, 0x24, 0x02, 0x03, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00])
explosion3 = bytearray([0x10, 0x10, 0x00, 0x00, 0x60, 0x44, 0x84, 0x40, 0xa6, 0x14, 0x10, 0x20, 0x42, 0x82, 0x00, 0x08, 0x40, 0x00, 0x00, 0x08, 0x00, 0x08, 0x01, 0x22, 0x04, 0x4b, 0x48, 0x05, 0x02, 0x01, 0x00, 0x60, 0x06, 0x00])
explosion4 = bytearray([0x10, 0x10, 0x00, 0x00, 0x00, 0x18, 0xa8, 0xc8, 0xf0, 0xf0, 0xf0, 0xe0, 0xe8, 0xb8, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x39, 0x17, 0x17, 0x1f, 0x0f, 0x17, 0x13, 0x21, 0x78, 0x20, 0x00, 0x00])
explosion = dolp.Animation([explosion1, explosion2, explosion3, explosion4], [150, 200, 200, 300])

dolp.begin()
Expand Down
24 changes: 9 additions & 15 deletions examples/micropython/collision_demo/collision_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import dolp

# Particle vars
particleImg = bytearray(b'\x08\x08\xf7\xbe\xff\xf7\x5f\xfe\xf7\xbd')
particleImg = bytearray([0x08, 0x08, 0xf7, 0xbe, 0xff, 0xf7, 0x5f, 0xfe, 0xf7, 0xbd])
PARTICLE_LIVE = 0

def updateParticle(particle):
Expand Down Expand Up @@ -53,18 +53,12 @@ def spawnMonster():
monsterCounter += 1


def setup():
print("Start")
dolp.begin()
dolp.begin()

def loop():
spawnTimeout = dolp.new_timeout()
dolp.set_timeout(spawnTimeout, 500, True)
while True:
dolp.loop_begin()
if (dolp.check_timeout(spawnTimeout)):
spawnMonster()
dolp.loop_end()

setup()
loop()
spawnTimeout = dolp.new_timeout()
dolp.set_timeout(spawnTimeout, 500, True)
while True:
dolp.loop_begin()
if (dolp.check_timeout(spawnTimeout)):
spawnMonster()
dolp.loop_end()
4 changes: 2 additions & 2 deletions examples/micropython/logo/logo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import dolp

arduinoImg = bytearray(b'\x0F\x08\x3c\x66\xc2\x92\xd2\x46\x6c\x38\x6c\x46\xd2\x92\xc2\x66\x3c')
maskImg = bytearray(b'\x0F\x08\x3c\x66\xc2\x92\xd2\x46\x6c\x38\x6c\x46\xd2\x92\xc2\x66\x3c')
arduinoImg = bytearray([0x0F, 0x08, 0x3c, 0x66, 0xc2, 0x92, 0xd2, 0x46, 0x6c, 0x38, 0x6c, 0x46, 0xd2, 0x92, 0xc2, 0x66, 0x3c])
maskImg = bytearray([0x0F, 0x08, 0x3c, 0x66, 0xc2, 0x92, 0xd2, 0x46, 0x6c, 0x38, 0x6c, 0x46, 0xd2, 0x92, 0xc2, 0x66, 0x3c])

dolp.begin()

Expand Down
34 changes: 23 additions & 11 deletions examples/micropython/space/space.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,25 @@
import dolp

# Images
spaceship = bytearray(b'\x10\x10\x00\x00\xb4\x00\x00\xc0\xfc\x15\x15\xfc\xc0\x00\x00\xb4\x00\x00\x40\xfc\x7f\x20\x38\x98\x49\xef\xef\x49\x98\x38\x20\x7f\xfc\x40')
enemy1 = bytearray(b'\x10\x10\x00\x80\xc0\x60\xf5\x35\x60\xc8\xc8\x60\x35\xf5\x60\xc0\x80\x00\x00\x36\x02\x00\x1d\x26\x4c\x93\x93\x4c\x26\x1d\x00\x02\x36\x00')
enemy1mask = bytearray(b'\x10\x10\x00\x80\xc0\x60\xff\xff\xf0\xf8\xf8\xf0\xff\xff\x60\xc0\x80\x00\x00\x3f\x03\x00\x1d\x3f\x7f\xff\xff\x7f\x3f\x1d\x00\x03\x3f\x00')
enemy2 = bytearray(b'\x10\x10\x00\xfc\x46\x23\x16\xdc\xa1\x6e\x6e\xa1\xdc\x16\x23\x46\xfc\x00\x00\x55\x10\x0a\x00\x02\x08\x10\x10\x08\x02\x00\x0a\x10\x55\x00')
enemy2mask = bytearray(b'\x10\x10\x00\xfc\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xfc\x00\x00\x7f\x1f\x0f\x07\x07\x0f\x1f\x1f\x0f\x07\x07\x0f\x1f\x7f\x00')
explosion1 = bytearray(b'\x10\x10\x00\x00\x00\x00\x90\x40\x40\x20\x40\x40\x84\x00\x10\x00\x00\x00\x00\x00\x04\x00\x00\x05\x01\x02\x01\x21\x00\x04\x00\x00\x00\x00')
explosion2 = bytearray(b'\x10\x10\x00\x00\x00\x00\x88\x60\x24\x10\x20\x60\x80\x00\x12\x00\x00\x00\x00\x40\x02\x00\x00\x03\x02\x24\x02\x03\x00\x00\x00\x44\x00\x00')
explosion3 = bytearray(b'\x10\x10\x00\x00\x60\x44\x84\x40\xa6\x14\x10\x20\x42\x82\x00\x08\x40\x00\x00\x08\x00\x08\x01\x22\x04\x4b\x48\x05\x02\x01\x00\x60\x06\x00')
explosion4 = bytearray(b'\x10\x10\x00\x00\x00\x18\xa8\xc8\xf0\xf0\xf0\xe0\xe8\xb8\x08\x00\x00\x00\x00\x00\x00\x30\x39\x17\x17\x1f\x0f\x17\x13\x21\x78\x20\x00\x00')
spaceship = bytearray([0x10, 0x10, 0x00, 0x00, 0xb4, 0x00, 0x00, 0xc0, 0xfc, 0x15, 0x15, 0xfc, 0xc0, 0x00, 0x00, 0xb4, 0x00, 0x00, 0x40, 0xfc, 0x7f, 0x20, 0x38, 0x98, 0x49, 0xef, 0xef, 0x49, 0x98, 0x38, 0x20, 0x7f, 0xfc, 0x40])

enemy1 = bytearray([0x10, 0x10, 0x00, 0x80, 0xc0, 0x60, 0xf5, 0x35, 0x60, 0xc8, 0xc8, 0x60, 0x35, 0xf5, 0x60, 0xc0, 0x80, 0x00, 0x00, 0x36, 0x02, 0x00, 0x1d, 0x26, 0x4c, 0x93, 0x93, 0x4c, 0x26, 0x1d, 0x00, 0x02, 0x36, 0x00])
enemy1mask = bytearray([0x10, 0x10, 0x00, 0x80, 0xc0, 0x60, 0xff, 0xff, 0xf0, 0xf8, 0xf8, 0xf0, 0xff, 0xff, 0x60, 0xc0, 0x80, 0x00, 0x00, 0x3f, 0x03, 0x00, 0x1d, 0x3f, 0x7f, 0xff, 0xff, 0x7f, 0x3f, 0x1d, 0x00, 0x03, 0x3f, 0x00])
enemy2 = bytearray([0x10, 0x10, 0x00, 0xfc, 0x46, 0x23, 0x16, 0xdc, 0xa1, 0x6e, 0x6e, 0xa1, 0xdc, 0x16, 0x23, 0x46, 0xfc, 0x00, 0x00, 0x55, 0x10, 0x0a, 0x00, 0x02, 0x08, 0x10, 0x10, 0x08, 0x02, 0x00, 0x0a, 0x10, 0x55, 0x00])
enemy2mask = bytearray([0x10, 0x10, 0x00, 0xfc, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xfc, 0x00, 0x00, 0x7f, 0x1f, 0x0f, 0x07, 0x07, 0x0f, 0x1f, 0x1f, 0x0f, 0x07, 0x07, 0x0f, 0x1f, 0x7f, 0x00])

explosion1 = bytearray([0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x90, 0x40, 0x40, 0x20, 0x40, 0x40, 0x84, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x05, 0x01, 0x02, 0x01, 0x21, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00])
explosion2 = bytearray([0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x88, 0x60, 0x24, 0x10, 0x20, 0x60, 0x80, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x03, 0x02, 0x24, 0x02, 0x03, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00])
explosion3 = bytearray([0x10, 0x10, 0x00, 0x00, 0x60, 0x44, 0x84, 0x40, 0xa6, 0x14, 0x10, 0x20, 0x42, 0x82, 0x00, 0x08, 0x40, 0x00, 0x00, 0x08, 0x00, 0x08, 0x01, 0x22, 0x04, 0x4b, 0x48, 0x05, 0x02, 0x01, 0x00, 0x60, 0x06, 0x00])
explosion4 = bytearray([0x10, 0x10, 0x00, 0x00, 0x00, 0x18, 0xa8, 0xc8, 0xf0, 0xf0, 0xf0, 0xe0, 0xe8, 0xb8, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x39, 0x17, 0x17, 0x1f, 0x0f, 0x17, 0x13, 0x21, 0x78, 0x20, 0x00, 0x00])
explosionAnim = dolp.Animation([explosion1, explosion2, explosion3, explosion4], [100, 100, 100, 100])

# Entity types
BULLET_TYPE = 0
ENEMY_TYPE = 1

################
# Explosion
LIVE_TIMEOUT = 0
def update_explosion(obj):
t = obj.get_timeout(LIVE_TIMEOUT)
Expand All @@ -31,6 +35,8 @@ def explosion(x, y):
obj.set_animation(explosionAnim)
obj.update(update_explosion)

################
# Bullet
def update_bullet(obj):
if not obj.is_moving():
dolp.delete_entity(obj)
Expand All @@ -44,6 +50,8 @@ def spawn_bullet(x, y):
obj.collision()
obj.update(update_bullet)

################
# Space ship
def update_ship(obj):
w, h = 16, 16
if dolp.pressed(dolp.BUTTON_A):
Expand All @@ -55,6 +63,8 @@ def spawn_ship():
obj.set_image(spaceship)
obj.update(update_ship)

################
# Enemy
class Enemy:
ENEMY_HIT_STATE = 0
w, h = 16, 16
Expand Down Expand Up @@ -91,13 +101,15 @@ def spawn():
obj.collision(Enemy.collision)
obj.set_state(Enemy.ENEMY_HIT_STATE, 0)

# setup
################
# Setup
dolp.begin()
spawn_timeout = dolp.new_timeout()
dolp.set_timeout(spawn_timeout, 1000, True)
spawn_ship()

# loop
################
# Loop
while True:
dolp.loop_begin()
if dolp.check_timeout(spawn_timeout):
Expand Down

0 comments on commit eb2d01f

Please sign in to comment.