]> bicyclesonthemoon.info Git - ott/molpy-up/commitdiff
sand, sandcastles, and flags
authorPeter Gerwinski <peter.gerwinski@hs-bochum.de>
Thu, 29 Mar 2018 23:25:10 +0000 (01:25 +0200)
committerPeter Gerwinski <peter.gerwinski@hs-bochum.de>
Thu, 29 Mar 2018 23:25:10 +0000 (01:25 +0200)
assets/flagLeft.png [new file with mode: 0644]
assets/flagRight.png [new file with mode: 0644]
assets/platformGrass.png [moved from assets/platformNormal.png with 100% similarity]
assets/platformSand.png [new file with mode: 0644]
assets/sandcastle.png [new file with mode: 0644]
molpyup.py

diff --git a/assets/flagLeft.png b/assets/flagLeft.png
new file mode 100644 (file)
index 0000000..344f46e
Binary files /dev/null and b/assets/flagLeft.png differ
diff --git a/assets/flagRight.png b/assets/flagRight.png
new file mode 100644 (file)
index 0000000..b1755f6
Binary files /dev/null and b/assets/flagRight.png differ
diff --git a/assets/platformSand.png b/assets/platformSand.png
new file mode 100644 (file)
index 0000000..c0655c6
Binary files /dev/null and b/assets/platformSand.png differ
diff --git a/assets/sandcastle.png b/assets/sandcastle.png
new file mode 100644 (file)
index 0000000..b4f075f
Binary files /dev/null and b/assets/sandcastle.png differ
index 04482c59e901cdaa723f367b025995b090554e9d..8dec6d6f4339be363f2ef52895533d9d4eaf822c 100644 (file)
@@ -47,12 +47,16 @@ class MolpyUp:
         pygame.font.init()
         self.font = pygame.font.SysFont("xkcd,sans", 25)
         self.xmovementmax = 10
-        self.platformTypeNormal = 0
-        self.platformTypeFloating = 1
-        self.platformTypeBreaking = 2
+        self.platformTypeSand = 0
+        self.platformTypeGrass = 1
+        self.platformTypeFloating = 2
+        self.platformTypeBreaking = 3
         self.itemTypeAccelerator = 0
         self.itemTypeBeanie = 1
-        self.imgPlatformNormal = pygame.image.load("assets/platformNormal.png").convert_alpha()
+        self.itemTypeSandcastle = 2
+        self.itemTypeFlag = 3
+        self.imgPlatformSand = pygame.image.load("assets/platformSand.png").convert_alpha()
+        self.imgPlatformGrass = pygame.image.load("assets/platformGrass.png").convert_alpha()
         self.imgPlatformFloating = pygame.image.load("assets/platformFloating.png").convert_alpha()
         self.imgPlatformBreaking = pygame.image.load("assets/platformBreaking.png").convert_alpha()
         self.imgPlatformBroken = pygame.image.load("assets/platformBroken.png").convert_alpha()
@@ -67,10 +71,14 @@ class MolpyUp:
         self.imgAccelerator = pygame.image.load("assets/accelerator.png").convert_alpha()
         self.imgAcceleratorUsed = pygame.image.load("assets/acceleratorUsed.png").convert_alpha()
         self.imgBeanie = pygame.image.load("assets/beanie.png").convert_alpha()
+        self.imgSandcastle = pygame.image.load("assets/sandcastle.png").convert_alpha()
+        self.imgFlagLeft = pygame.image.load("assets/flagLeft.png").convert_alpha()
+        self.imgFlagRight = pygame.image.load("assets/flagRight.png").convert_alpha()
     
     def reset(self):
         self.cameray = 0
         self.score = 0
+        self.sandcastles = 0
         self.items = []
         self.playerx = self.sx // 2
         self.playery = self.sy * 3 // 4
@@ -79,7 +87,8 @@ class MolpyUp:
         self.gravity = 0
         self.xmovement = 0
         self.playerWearsBeanie = False
-        self.platforms = [[self.playerx, self.playery + self.sy // 6, self.platformTypeNormal, False]]
+        self.playerCarriesFlag = False
+        self.platforms = [[self.playerx, self.playery + self.sy // 6, self.platformTypeSand, False]]
         self.generatePlatforms()
 
     def updatePlayer(self):
@@ -122,6 +131,8 @@ class MolpyUp:
                     self.screen.blit(self.imgPlayerRightUpBeanie, (self.playerx, self.playery - self.cameray))
                 else:
                     self.screen.blit(self.imgPlayerRightUp, (self.playerx, self.playery - self.cameray))
+            if self.playerCarriesFlag:
+                self.screen.blit(self.imgFlagLeft, (self.playerx + 25, self.playery - 10 - self.cameray))
         else:
             if self.jump:
                 if self.playerWearsBeanie:
@@ -133,54 +144,70 @@ class MolpyUp:
                     self.screen.blit(self.imgPlayerLeftUpBeanie, (self.playerx, self.playery - self.cameray))
                 else:
                     self.screen.blit(self.imgPlayerLeftUp, (self.playerx, self.playery - self.cameray))
+            if self.playerCarriesFlag:
+                self.screen.blit(self.imgFlagRight, (self.playerx + 10, self.playery - 10 - self.cameray))
 
     def updatePlatforms(self):
         for p in self.platforms:
-            rect = pygame.Rect(p[0], p[1], self.imgPlatformNormal.get_width() - 10, self.imgPlatformNormal.get_height())
+            rect = pygame.Rect(p[0], p[1], self.imgPlatformSand.get_width() - 10, self.imgPlatformSand.get_height())
             player = pygame.Rect(self.playerx, self.playery, self.imgPlayerRightUp.get_width() - 10, self.imgPlayerRightUp.get_height())
             if rect.colliderect(player) and self.gravity and self.playery < (p[1] - self.cameray):
-                if p[2] != 2:
+                if p[2] != self.platformTypeBreaking:
                     self.jump = self.sy // 20
                     self.gravity = 0
                 else:
                     p[-1] = 1
-            if p[2] == 1:
+            if p[2] == self.platformTypeFloating:
                 if p[-1] == 1:
                     p[0] += self.extrax // 10
-                    if p[0] > self.sx + self.extrax:
+                    if p[0] + self.imgPlatformFloating.get_width() > self.sx + self.extrax:
                         p[-1] = 0
                 else:
                     p[0] -= self.extrax // 10
                     if p[0] <= 0:
                         p[-1] = 1
 
+    def choosePlatformType(self):
+        platformType = random.randint(0, 1000)
+        if platformType < 800:
+            if platformType < self.score:
+                return self.platformTypeGrass
+            else:
+                return self.platformTypeSand
+        elif platformType < 900:
+            return self.platformTypeFloating
+        else:
+            return self.platformTypeBreaking
+
     def drawPlatforms(self):
         for p in self.platforms:
             check = self.platforms[1][1] - self.cameray
             if check > self.sy:
-                platformType = random.randint(0, 1000)
-                if platformType < 800:
-                    platformType = 0
-                elif platformType < 900:
-                    platformType = 1
-                else:
-                    platformType = 2
+                platformType = self.choosePlatformType()
                 self.platforms.append([random.randint(0, self.sx * 7 // 8), self.platforms[-1][1] - self.sy // 12, platformType, False])
                 check = random.randint(0, 1000)
-                if check > 900 and platformType == 0:
+                if check > 900 and platformType <= self.platformTypeGrass:
                     x = self.platforms[-1][0]
                     y = self.platforms[-1][1]
                     itemType = random.randint(0,1000)
-                    if itemType < 900:
+                    if itemType < 100:
+                        itemType = self.itemTypeBeanie
+                        self.items.append([x + self.imgPlatformSand.get_width() * 3 // 4, y + 6, itemType, False])
+                    elif itemType < 300 and platformType == self.platformTypeSand:
+                        itemType = self.itemTypeSandcastle
+                        self.items.append([x + self.imgPlatformSand.get_width() // 4, y + 6, itemType, False])
+                    elif itemType < 800 and platformType == self.platformTypeSand:
+                        itemType = self.itemTypeFlag
+                        self.items.append([x + self.imgPlatformSand.get_width() // 2, y + 6, itemType, False])
+                    else:
                         itemType = self.itemTypeAccelerator
                         self.items.append([x, y + 10, itemType, False])
-                    else:
-                        itemType = self.itemTypeBeanie
-                        self.items.append([x + self.imgPlatformNormal.get_width() * 3 // 4, y + 6, itemType, False])
                 self.platforms.pop(0)
                 self.score += 1
-            if p[2] == self.platformTypeNormal:
-                self.screen.blit(self.imgPlatformNormal, (p[0], p[1] - self.cameray))
+            if p[2] == self.platformTypeSand:
+                self.screen.blit(self.imgPlatformSand, (p[0], p[1] - self.cameray))
+            elif p[2] == self.platformTypeGrass:
+                self.screen.blit(self.imgPlatformGrass, (p[0], p[1] - self.cameray))
             elif p[2] == self.platformTypeFloating:
                 self.screen.blit(self.imgPlatformFloating, (p[0], p[1] - self.cameray))
             elif p[2] == self.platformTypeBreaking:
@@ -199,6 +226,15 @@ class MolpyUp:
                     imgItem = self.imgBeanie
                 else:
                     imgItem = None
+            elif item[2] == self.itemTypeSandcastle:
+                imgItem = self.imgSandcastle
+                if item[-1]:
+                    self.screen.blit(self.imgFlagRight, (item[0] + 4, item[1] - imgItem.get_height() + 2 - self.imgFlagRight.get_height() - self.cameray))
+            elif item[2] == self.itemTypeFlag:
+                if not item[-1]:
+                    imgItem = self.imgFlagRight
+                else:
+                    imgItem = None
             if imgItem:
                 self.screen.blit(imgItem, (item[0], item[1] - imgItem.get_height() - self.cameray))
             if not item[-1]:
@@ -207,22 +243,22 @@ class MolpyUp:
                         self.jump = self.sy // 12
                         self.cameray -= self.sy // 12
                         item[-1] = True
-                    elif item[2] == self.itemTypeBeanie:
+                    elif item[2] == self.itemTypeBeanie and not self.playerWearsBeanie:
                         self.playerWearsBeanie = True
                         item[-1] = True
+                    elif item[2] == self.itemTypeSandcastle and self.playerCarriesFlag:
+                        self.playerCarriesFlag = False
+                        item[-1] = True
+                        self.sandcastles += 1
+                    elif item[2] == self.itemTypeFlag and not self.playerCarriesFlag:
+                        self.playerCarriesFlag = True
+                        item[-1] = True
 
     def generatePlatforms(self):
         on = self.sy
         while on > -self.sy // 6:
             x = random.randint(0,self.sx * 8 // 7)
-            platformType = random.randint(0, 1000)
-            if platformType < 800:
-                platformType = self.platformTypeNormal
-            elif platformType < 900:
-                platformType = self.platformTypeFloating
-            else:
-                platformType = self.platformTypeBreaking
-            self.platforms.append([x, on, platformType, 0])
+            self.platforms.append([x, on, self.choosePlatformType(), 0])
             on -= self.sy // 12
 
     def drawGrid(self):
@@ -256,7 +292,7 @@ class MolpyUp:
         self.reset()
         while True:
             self.screen.fill((255,255,255))
-            clock.tick(60)
+            clock.tick(40)
             for event in pygame.event.get():
                 if event.type == QUIT:
                     sys.exit()
@@ -265,6 +301,8 @@ class MolpyUp:
             self.updatePlayer()
             self.updatePlatforms()
             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.playery - self.cameray > self.sy * 7 // 6:
                 self.showScore()
                 self.reset()