Skip to content

Commit 4f2a67a

Browse files
committed
Thumgeon: Simplify game-over code
- Optimize code for end of game. - Remove unnecessary garbage collection. - Use Thumby API for button poling.
1 parent 13e95ea commit 4f2a67a

File tree

1 file changed

+23
-31
lines changed

1 file changed

+23
-31
lines changed

Thumgeon/Thumgeon.py

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,7 +1577,7 @@ def updateMonsters():
15771577
if(selpos >= len(player.inventory)):
15781578
selpos = len(player.inventory)-1
15791579

1580-
# Only have 3 lines to use for showing items, anyway
1580+
# Only 3 lines to use for showing items
15811581
l1 = ""
15821582
l2 = ""
15831583
l3 = ""
@@ -1619,10 +1619,10 @@ def updateMonsters():
16191619
thumby.display.drawText("eqp", 48, 32, 0)
16201620
thumby.display.update()
16211621
else:
1622-
# Clear the current message so the screen looks a little less cluttered
1622+
# Clear the current message
16231623
curMsg = ""
16241624
drawGame()
1625-
# Free all the memory we can and print some game info
1625+
16261626

16271627
thumby.display.fill(0)
16281628
thumby.display.drawText("You died!", 0, 0, 1)
@@ -1632,38 +1632,30 @@ def updateMonsters():
16321632
thumby.display.drawText("floor "+str(floorNo), 0, 32, 1)
16331633
thumby.display.update()
16341634

1635-
currentRoom.tiles.clear()
1636-
gc_collect()
1637-
1638-
while(getcharinputNew() == ' '):
1635+
while(not thumby.actionPressed()):
16391636
pass
16401637

1641-
while(swBstate == 1):
1642-
getcharinputNew()
1643-
1644-
selpos = 0
1645-
while(swBstate != 1):
1646-
thumby.display.fill(0)
1647-
thumby.display.drawText("Restart?", 0, 8, 1)
1648-
if(selpos == 0):
1649-
thumby.display.drawFilledRectangle(0, 16, 24, 8, 1)
1650-
thumby.display.drawText("yes", 0, 16, 0)
1651-
thumby.display.drawText("no", 40, 16, 1)
1652-
else:
1653-
thumby.display.drawText("yes", 0, 16, 1)
1654-
thumby.display.drawFilledRectangle(40, 16, 16, 8, 1)
1655-
thumby.display.drawText("no", 40, 16, 0)
1638+
select = 0
1639+
thumby.display.fill(0)
1640+
thumby.display.drawText("Restart?", 0, 8, 1)
1641+
thumby.actionJustPressed() # Debounce
1642+
while(not thumby.actionJustPressed()):
1643+
thumby.display.drawFilledRectangle(0, 16, 24, 8, 1-select)
1644+
thumby.display.drawText("yes", 0, 16, select)
1645+
thumby.display.drawFilledRectangle(40, 16, 16, 8, select)
1646+
thumby.display.drawText("no", 40, 16, 1-select)
16561647
thumby.display.update()
1657-
getcharinputNew()
16581648
if(thumby.buttonL.pressed()):
1659-
selpos = 0
1649+
select = 0
16601650
if(thumby.buttonR.pressed()):
1661-
selpos = 1
1651+
select = 1
16621652

1663-
if(selpos == 0):
1664-
del currentRoom
1665-
del player
1666-
curMsg = ""
1667-
gc_collect()
1668-
else:
1653+
# Free memory
1654+
del currentRoom
1655+
del player
1656+
curMsg = ""
1657+
gc_collect()
1658+
1659+
if(select == 1):
16691660
thumby.reset() # Exit game to main menu
1661+
# Else: Restart game loop

0 commit comments

Comments
 (0)