]> bicyclesonthemoon.info Git - ott/molpy-up/commitdiff
moved bottom condition to update player; add more game mode messages
authorb <rowerynaksiezycu@gmail.com>
Thu, 26 Mar 2026 21:36:37 +0000 (22:36 +0100)
committerb <rowerynaksiezycu@gmail.com>
Thu, 26 Mar 2026 21:37:44 +0000 (22:37 +0100)
molpyup.py

index c8ea1131d0bb799577fa4cd6954bbf8077f02b6e..3e0a268c5908ed2ed6915fb3f74f957388e3de16 100644 (file)
@@ -11,6 +11,7 @@
 # Copyright (C) 2018, 2026 by Balthasar SzczepaƄski
 # add arrow, AI, flag save mode,
 # remove off-screen space,
+# gmae mode messages,
 # some optimisation
 #
 # This program is Free Software: you can redistribute it and/or modify it
@@ -159,6 +160,7 @@ class MolpyUp:
                                          pygame.image.load("assets/plantGrass11.png").convert_alpha() ]
         self.imgMolpArrow              = pygame.image.load("assets/molpArrow.png").convert_alpha()
         self.playerHeight = self.imgPlayerRightUp.get_height()
+        # self.playerHalfHeight = self.playerHeight // 2
         self.playerWidth = self.imgPlayerRightUp.get_width()
         self.playerHalfWidth = self.playerWidth // 2
         self.platformSpeed = self.extrax // 10
@@ -171,7 +173,7 @@ class MolpyUp:
         self.score = 0
         self.sandcastles = 0
         self.speed = 30
-        self.showSpeed = False
+        self.modeText = ''
         self.playerx = self.sx // 2
         self.playery = self.sy * 3 // 4
         self.direction = 0
@@ -187,11 +189,13 @@ class MolpyUp:
         self.hadLucky = False
         self.hadTheEnd = False
         self.raftcastleHasFlag = False
-        self.platforms = [[self.playerx, self.playery + self.sy // 6, self.platformTypeSand, 0, 0, -1, False, self.platformSandWidth]]
+        self.platforms = [[self.playerx, self.playery + self.sy // 6, self.platformTypeSand, 0, 0, -1, 0, self.platformSandWidth]]
         self.generateInitialPlatforms()
         self.items = []
         self.aiNextPlatformOk = False
         self.aiNextPlatform=[self.playerx,self.playery]
+        self.oops = False
+        self.pause = False
         if self.filename:
             self.restoreGame (self.filename)
 
@@ -350,28 +354,42 @@ class MolpyUp:
         else:
             self.playery -= self.jump
             self.jump -= 1
+            
+        if self.playery - self.cameray > self.sy * 7 // 6:
+            if self.eternal or (self.eternalFlag and self.sandcastles > 0):
+                if self.eternalFlag:
+                    self.sandcastles -= 1
+                self.jump = self.gravity
+                self.gravity = 0
+                self.aiNextPlatformOk = False
+                self.playery = self.cameray + self.sy + self.playerHeight
+            else:
+                self.oops = True
+        
         key = pygame.key.get_pressed()
         
         xdir = 0;
         actualX = self.playerx + self.playerHalfWidth
         if key[K_RIGHT]:
             xdir = 1
-            self.showSpeed = False
+            self.modeText = ''
         elif key[K_LEFT]:
             xdir = -1
-            self.showSpeed = False
+            self.modeText = ''
         elif key[K_PLUS] or key[K_KP_PLUS]:
             if pygame.key.get_mods() & KMOD_CTRL:
                 self.score += 10
+                self.modeText = "Score +10: " + str(self.score)
             else:
                 self.speed += 1
-                self.showSpeed = True
+                self.modeText = "Speed: " + str(self.speed)
         elif key[K_MINUS] or key[K_KP_MINUS]:
             if pygame.key.get_mods() & KMOD_CTRL:
                 self.score -= 10
+                self.modeText = "Score -10: " + str(self.score)
             else:
                 self.speed -= 1
-                self.showSpeed = True
+                self.modeText = "Speed: " + str(self.speed)
         elif self.ai:
             platformX = self.aiNextPlatform[0] + self.aiNextPlatform[7] // 2
             if self.aiNextPlatform[2] > self.platformTypeNormal and self.aiNextPlatform[2] <= self.platformTypeFloating:
@@ -497,15 +515,15 @@ class MolpyUp:
         platformType = self.choosePlatformType()
         if platformType == self.platformTypeTheEnd:
             if not self.hadTheEnd:
-                platform2 = [self.sx // 2 - self.imgPlatformTheEnd.get_width() // 2, self.platforms[-1][1] - self.sy // 4, self.platformTypeTheEnd, False, False, -1, False, self.imgPlatformTheEnd.get_width()]
-                platform = [self.sx // 2 - self.imgPlatformWonTheGame.get_width() // 2, platform2[1] - self.sy * 2 // 3, self.platformTypeWonTheGame, False, False, -1, False, self.imgPlatformWonTheGame.get_width()]
+                platform2 = [self.sx // 2 - self.imgPlatformTheEnd.get_width() // 2, self.platforms[-1][1] - self.sy // 4, self.platformTypeTheEnd, False, False, -1, 0, self.imgPlatformTheEnd.get_width()]
+                platform = [self.sx // 2 - self.imgPlatformWonTheGame.get_width() // 2, platform2[1] - self.sy * 2 // 3, self.platformTypeWonTheGame, False, False, -1, 0, self.imgPlatformWonTheGame.get_width()]
                 self.hadTheEnd = True
         elif platformType == self.platformTypeWater or platformType == self.platformTypeRaftcastle:
-            platform = [random.randint(0, self.sx - self.platformSandWidth), self.platforms[-1][1] - self.sy // 8, platformType, False, False, -1, False, self.platformSandWidth]
+            platform = [random.randint(0, self.sx - self.platformSandWidth), self.platforms[-1][1] - self.sy // 8, platformType, False, False, -1, 0, self.platformSandWidth]
         elif platformType == self.platformTypeLucky:
             platform = [0, self.platforms[-1][1] - self.sy // 12, platformType, False, False, -1, False, self.platformSandWidth]
         else:
-            platform = [random.randint(0, self.sx - self.platformSandWidth), self.platforms[-1][1] - self.sy // 12, platformType, False, False, -1, False, self.platformSandWidth]
+            platform = [random.randint(0, self.sx - self.platformSandWidth), self.platforms[-1][1] - self.sy // 12, platformType, False, False, -1, 0, self.platformSandWidth]
         if platformType <= self.platformTypeNormal:
             if platformType == self.platformTypeSand:
                 platform[4] = random.randint(0, len(self.imgPlatformSand) - 1)
@@ -571,7 +589,7 @@ class MolpyUp:
             colX = self.playerx % self.sx
             player = pygame.Rect(colX + 15, self.playery, self.playerWidth - 30, self.playerHeight)
             collision = rect.colliderect(player)
-            if colX >= self.sx - self.playerWidth:
+            if colX > self.sx - self.playerWidth:
                 player = pygame.Rect(colX - self.sx + 15, self.playery, self.playerWidth - 30, self.playerHeight)
                 collision = rect.colliderect(player) or collision
             if collision and self.gravity and self.playery < (p[1] - self.cameray):
@@ -644,7 +662,7 @@ class MolpyUp:
             elif p[2] == self.platformTypeWonTheGame:
                 self.screen.blit(self.imgPlatformWonTheGame, (p[0], p[1] - self.cameray))
             if self.aiDebag:
-                self.screen.blit(self.font.render(str(p[2])+" "+str(p[5])+" "+str(p[6]), -1, (0, 0x57, 0xaf)), (p[0], p[1] - self.cameray + 16))
+                self.screen.blit(self.font.render(str(p[2])+" "+str(p[5])+" "+str(p[6]), -1, (0, 0x57, 0xaf) if self.ai else (0xbb, 0x66, 0x22)), (p[0], p[1] - self.cameray + 16))
         if self.aiDebag:
             self.screen.blit(self.imgMolpArrow, (self.aiNextPlatform[0] + (self.platformSandWidth-self.playerWidth)//2, self.aiNextPlatform[1] - self.cameray + 16))
 
@@ -777,30 +795,38 @@ class MolpyUp:
                         if pygame.key.get_mods() & KMOD_CTRL:
                             self.ai = not self.ai
                             self.aiNextPlatformOk = False
+                            self.modeText = "AI " + ('enabled' if self.ai else 'disabled')
                     elif key[K_d]:
                         if pygame.key.get_mods() & KMOD_CTRL:
                             self.aiDebag = not self.aiDebag
+                            self.modeText = "AI debug " + ('enabled' if self.aiDebag else 'disabled')
                     elif key[K_e]:
                         if pygame.key.get_mods() & KMOD_CTRL:
                             self.eternal = not self.eternal
                             self.eternalFlag = False
+                            self.modeText = "Eternal mode " + ('enabled' if self.eternal else 'disabled')
                     elif key[K_g]:
                         if pygame.key.get_mods() & KMOD_CTRL:
                             self.eternalFlag = not self.eternalFlag
                             self.eternal = False
+                            self.modeText = "Eternal (flag) mode " + ('enabled' if self.eternalFlag else 'disabled')
                     elif key[K_f]:
                         if pygame.key.get_mods() & KMOD_CTRL:
                             self.playerCarriesFlag = not self.playerCarriesFlag
+                            self.modeText = "Flag " + ('added' if self.playerCarriesFlag else 'removed')
                     elif key[K_b]:
                         if pygame.key.get_mods() & KMOD_CTRL:
                             self.playerWearsBeanie = not self.playerWearsBeanie
+                            self.modeText = "Beanie " + ('added' if self.playerWearsBeanie else 'removed')
                     elif key[K_SPACE]:
-                        while self.waitForIt([K_SPACE, K_s]) == K_s:
-                            self.saveGame()
+                        self.modeText = "Wait for it."
+                        self.pause = True
                     elif key[K_s]:
                         self.saveGame()
+                        self.modeText = "Saved"
                     elif key[K_a]:
                         self.showArrow = not self.showArrow
+                        self.modeText = "Arrow " + ('enabled' if self.showArrow else 'disabled')
             self.drawGrid()
             self.drawPlatforms()
             self.drawAndUpdateItems()
@@ -809,22 +835,19 @@ class MolpyUp:
             self.screen.blit(self.font.render(str(self.score), -1, (0, 0, 0)), (self.sx // 32, self.sy // 24))
             for i in range(0, self.sandcastles):
                 self.screen.blit(self.imgFlagRight, (self.sx // 32 + 10 * i, self.sy // 8))
-            if self.showSpeed:
-                self.screen.blit(self.font.render("Speed: " + str(self.speed), -1, (0, 0, 0)), (self.sx // 32, self.sy - self.sy // 12))
-           
-            if self.playery - self.cameray > self.sy * 7 // 6:
-                if self.eternal:
-                    self.jump = self.gravity
-                    self.gravity = 0
-                    self.aiNextPlatformOk = False
-                elif self.eternalFlag and self.sandcastles > 0:
-                    self.sandcastles -= 1
-                    self.jump = self.gravity
-                    self.gravity = 0
-                    self.aiNextPlatformOk = False
-                else:
-                    self.showScore()
-                    self.reset()
+            if self.modeText != '':
+                self.screen.blit(self.font.render(self.modeText, -1, (0, 0, 0)), (self.sx // 32, self.sy - self.sy // 12))
+            
+            if self.oops:
+                self.showScore()
+                self.reset()
             pygame.display.flip()
+            
+            if self.pause:
+                self.modeText = "RUN!"
+                while self.waitForIt([K_SPACE, K_s]) == K_s:
+                    self.saveGame()
+                    self.modeText = "Saved"
+                self.pause = False
 
 MolpyUp().run()
\ No newline at end of file