From a218160fd64f45ed0759855294ad509364b54981 Mon Sep 17 00:00:00 2001 From: Peter Gerwinski Date: Sat, 31 Mar 2018 10:00:51 +0200 Subject: [PATCH] cleaned up, fixed busy-waiting mustard, enabled numpad, introduced AfterLucky, Castle, and Prickly --- assets/platformAfterLucky.png | Bin 0 -> 1837 bytes assets/platformCastle.png | Bin 0 -> 1733 bytes ...formFloating.png => platformGrapevine.png} | Bin assets/prickly.png | Bin 0 -> 1005 bytes assets/pricklyCurled.png | Bin 0 -> 993 bytes molpyup.py | 118 +++++++++++++----- 6 files changed, 88 insertions(+), 30 deletions(-) create mode 100644 assets/platformAfterLucky.png create mode 100644 assets/platformCastle.png rename assets/{platformFloating.png => platformGrapevine.png} (100%) create mode 100644 assets/prickly.png create mode 100644 assets/pricklyCurled.png diff --git a/assets/platformAfterLucky.png b/assets/platformAfterLucky.png new file mode 100644 index 0000000000000000000000000000000000000000..c42ddb8aed9a4f00c64f84e154016d03444cec2c GIT binary patch literal 1837 zcmV+|2h#Y7P)P*hUn9^@Dq5gDbxex8Aiftdje5|fJy90LM;KxTd zhXgqT*)0qVOgts26(GF~&iMtEMVaXtB?^X?mX->RDfvmM3c;1dC8@c^3Z8k%`9%f! zMTsS;DL}PQJ3xTfCBH<$Jux#+!N@?BM0XPepm2n+5aELmLxAMcqA~~ztVn=Cfx&>m zfgyk)k)fVp0mD&-H;m$pE{vs&D;V!Fi7^E+O<=mfEX*9qypZ_~izQ13%Pm$t)>hVg zY?f@(*uJrcv+w3m;^^Y|!kNfFNw(Qwf(Vw1#;#IHzHNXkhblggKtmOddeXk zJ*BtGYgGzVO;mrX9aQhq2-Q^5{GfF}dy-D7u9cpk-Yfkh1`7;pjbe;#P2^3PO<$T_ zFyCph#BzdFopr8FoNb_;tG%^@v7?TYnzNFNf~&lng1fSZx~Hy}iMNf9yKk^xf`5KM zec;5PrNO&GE{47gXNr)Ew2F#|u85f#yC?2J0$ZYPQdn|B%9_-h=^PmrnVDI0voGed z=h^316l^MdSFB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Q^5{GfF}dy-D7u9cpk-Yfkh1`7;pjbe;#P2^3PO<$T_ zFyCph#BzdFopr8FoNb_;tG%^@v7?TYnzNFNf~&lng1fSZx~Hy}iMNf9yKk^xf`5KM zec;5PrNO&GE{47gXNr)Ew2F#|u85f#yC?2J0$ZYPQdn|B%9_-h=^PmrnVDI0voGed z=h^316l^MdSFBxb7qP0ll{*!Ux>Us_&Wcs{JRSunm(C+e)V<1_wb(rzfS#W z{pa}qKL8B?4>W(M#f<;}00Lr5M??VshmXv^00009a7bBm006Nn006Nn0b!>s?*IS* z2XskIMF-*o9u+Jx5~h2jB_qWt?AkbmXg;hfI*p1S;**qcwP$UE3SgUCa(DyoXgMg|t9Hm{S0 zwW}bwI2daxJz>{O_}IDJ9p#+9P_R;$h@v3=^JtKiB5wH83;HtBQD+@3HAg!=ZA-z~ bM6kU9njSebDIGO300000NkvXXu0mjfy6E9L literal 0 HcmV?d00001 diff --git a/assets/pricklyCurled.png b/assets/pricklyCurled.png new file mode 100644 index 0000000000000000000000000000000000000000..1a5430478959b7a28f27e952a6f39f46341636c8 GIT binary patch literal 993 zcmV<710MW|P)P*hUn9^@Dq5gDbxex8Aiftdje5|fJy90LM;KxTd zhXgqT*)0qVOgts26(GF~&iMtEMVaXtB?^X?mX->RDfvmM3c;1dC8@c^3Z8k%`9%f! zMTsS;DL}PQJ3xTfCBH<$Jux#+!N@?BM0XPepm2n+5aELmLxAMcqA~~ztVn=Cfx&>m zfgyk)k)fVp0mD&-H;m$pE{vs&D;V!Fi7^E+O<=mfEX*9qypZ_~izQ13%Pm$t)>hVg zY?f@(*uJrcv+w3m;^^Y|!kNfFNw(Qwf(Vw1#;#IHzHNXkhblggKtmOddeXk zJ*BtGYgGzVO;mrX9aQhq2-Q^5{GfF}dy-D7u9cpk-Yfkh1`7;pjbe;#P2^3PO<$T_ zFyCph#BzdFopr8FoNb_;tG%^@v7?TYnzNFNf~&lng1fSZx~Hy}iMNf9yKk^xf`5KM zec;5PrNO&GE{47gXNr)Ew2F#|u85f#yC?2J0$ZYPQdn|B%9_-h=^PmrnVDI0voGed z=h^316l^MdSFBxb7qP0ll{*!Ux>Us_&Wcs{JRSunm(C+e)V<1_wb(rzfS#W z{pa}qKL8B?4>W(M#f<;}00Lr5M??VshmXv^00009a7bBm006Nn006Nn0b!>s?*IS* z2XskIMF-*o9u+SW>~T_k0001hNklbr=?LDZ0ww;xsszCS!oiZc=qaE+d P00000NkvXXu0mjfmrvOK literal 0 HcmV?d00001 diff --git a/molpyup.py b/molpyup.py index 5b2b40d..9edbf62 100644 --- a/molpyup.py +++ b/molpyup.py @@ -39,6 +39,27 @@ import sys import random class MolpyUp: + + platformTypeSand = 0 + platformTypeGrass = 1 + platformTypeNormal = platformTypeGrass + platformTypeGrapevine = 2 + platformTypeAfterLucky = 3 + platformTypeCastle = 4 + platformTypeFloating = platformTypeCastle + platformTypeBreaking = 5 + + itemTypeAccelerator = 0 + itemTypeBeanie = 1 + itemTypePrickly = 2 + itemTypeSandcastle = 3 + itemTypeFlag = 4 + + #scoreSnake = 600 # m1738 + scorePrickly = 696 # m2015 + scoreAfterLucky = 800 # m2315 + scoreCastle = 976 # m2825 + def __init__(self): self.sx = 553 self.sy = 395 @@ -46,18 +67,13 @@ class MolpyUp: self.screen = pygame.display.set_mode((self.sx, self.sy)) pygame.font.init() self.font = pygame.font.SysFont("xkcd,sans", 25) + self.clock = pygame.time.Clock() self.xmovementmax = 10 - self.platformTypeSand = 0 - self.platformTypeGrass = 1 - self.platformTypeFloating = 2 - self.platformTypeBreaking = 3 - self.itemTypeAccelerator = 0 - self.itemTypeBeanie = 1 - 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.imgPlatformAfterLucky = pygame.image.load("assets/platformAfterLucky.png").convert_alpha() + self.imgPlatformCastle = pygame.image.load("assets/platformCastle.png").convert_alpha() + self.imgPlatformGrapevine = pygame.image.load("assets/platformGrapevine.png").convert_alpha() self.imgPlatformBreaking = pygame.image.load("assets/platformBreaking.png").convert_alpha() self.imgPlatformBroken = pygame.image.load("assets/platformBroken.png").convert_alpha() self.imgPlayerRightUp = pygame.image.load("assets/playerRightUp.png").convert_alpha() @@ -71,6 +87,8 @@ 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.imgPrickly = pygame.image.load("assets/prickly.png").convert_alpha() + self.imgPricklyCurled = pygame.image.load("assets/pricklyCurled.png").convert_alpha() self.imgSandcastle = pygame.image.load("assets/sandcastle.png").convert_alpha() self.imgFlagLeft = pygame.image.load("assets/flagLeft.png").convert_alpha() self.imgFlagLeftDown = pygame.image.load("assets/flagLeftDown.png").convert_alpha() @@ -91,7 +109,9 @@ class MolpyUp: self.xmovement = 0 self.playerWearsBeanie = False self.playerCarriesFlag = False - self.platforms = [[self.playerx, self.playery + self.sy // 6, self.platformTypeSand, False]] + self.hadAfterLucky = False + self.hadCastle = False + self.platforms = [[self.playerx, self.playery + self.sy // 6, self.platformTypeSand, False, False]] self.generatePlatforms() def updatePlayer(self): @@ -110,10 +130,10 @@ class MolpyUp: if self.xmovement > -self.xmovementmax: self.xmovement -= 1 self.direction = 1 - elif key[K_PLUS]: + elif key[K_PLUS] or key[K_KP_PLUS]: self.speed += 1 self.screen.blit(self.font.render("Speed: " + str(self.speed), -1, (0, 0, 0)), (self.sx // 32, self.sy - self.sy // 12)) - elif key[K_MINUS]: + elif key[K_MINUS] or key[K_KP_MINUS]: self.speed -= 1 self.screen.blit(self.font.render("Speed: " + str(self.speed), -1, (0, 0, 0)), (self.sx // 32, self.sy - self.sy // 12)) else: @@ -161,33 +181,50 @@ class MolpyUp: def updatePlatforms(self): for p in self.platforms: - rect = pygame.Rect(p[0], p[1], self.imgPlatformSand.get_width() - 10, self.imgPlatformSand.get_height()) + rect = pygame.Rect(p[0], p[1], self.imgPlatformSand.get_width(), 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] != self.platformTypeBreaking: + if p[2] == self.platformTypeBreaking: + p[-1] = True + else: self.jump = self.sy // 20 self.gravity = 0 - else: - p[-1] = 1 - if p[2] == self.platformTypeFloating: - if p[-1] == 1: + if (p[2] == self.platformTypeAfterLucky or p[2] == self.platformTypeCastle) and self.playerCarriesFlag and not p[-2]: + self.playerCarriesFlag = False + p[-2] = True + self.sandcastles += 1 + if p[2] > self.platformTypeNormal and p[2] <= self.platformTypeFloating: + if p[-1]: + if p[2] == self.platformTypeAfterLucky: + img = self.imgPlatformAfterLucky + elif p[2] == self.platformTypeCastle: + img = self.imgPlatformCastle + else: + img = self.imgPlatformGrapevine p[0] += self.extrax // 10 - if p[0] + self.imgPlatformFloating.get_width() > self.sx + self.extrax: - p[-1] = 0 + if p[0] + img.get_width() > self.sx + self.extrax: + p[-1] = False else: p[0] -= self.extrax // 10 if p[0] <= 0: - p[-1] = 1 + p[-1] = True def choosePlatformType(self): platformType = random.randint(0, 1000) if platformType < 800: if platformType < self.score: - return self.platformTypeGrass + if self.score > self.scoreAfterLucky and not self.hadAfterLucky: + self.hadAfterLucky = True + return self.platformTypeAfterLucky + elif self.score > self.scoreCastle and not self.hadCastle: + self.hadCastle = True + return self.platformTypeCastle + else: + return self.platformTypeGrass else: return self.platformTypeSand elif platformType < 900: - return self.platformTypeFloating + return self.platformTypeGrapevine else: return self.platformTypeBreaking @@ -196,15 +233,21 @@ class MolpyUp: check = self.platforms[1][1] - self.cameray if check > self.sy: platformType = self.choosePlatformType() - self.platforms.append([random.randint(0, self.sx * 7 // 8), self.platforms[-1][1] - self.sy // 12, platformType, False]) + self.platforms.append([random.randint(0, self.sx * 7 // 8), self.platforms[-1][1] - self.sy // 12, platformType, False, False]) check = random.randint(0, 1000) - if check > 900 and platformType <= self.platformTypeGrass: + if check > 900 and platformType <= self.platformTypeNormal: x = self.platforms[-1][0] y = self.platforms[-1][1] itemType = random.randint(0,1000) if itemType < 100: itemType = self.itemTypeBeanie self.items.append([x + self.imgPlatformSand.get_width() * 3 // 4, y + 6, itemType, False]) + elif itemType < 200 and platformType == self.platformTypeGrass: + itemType = self.itemTypeFlag + self.items.append([x + self.imgPlatformSand.get_width() // 2, y + 6, itemType, False]) + elif itemType < 600 and platformType == self.platformTypeGrass and self.score > self.scorePrickly: + itemType = self.itemTypePrickly + self.items.append([x + self.imgPlatformSand.get_width() // 3, y + 8, 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]) @@ -220,10 +263,18 @@ class MolpyUp: 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.platformTypeGrapevine: + self.screen.blit(self.imgPlatformGrapevine, (p[0], p[1] - self.cameray)) + elif p[2] == self.platformTypeAfterLucky: + if p[-2]: + self.screen.blit(self.imgFlagRight, (p[0] + 47, p[1] - 12 - self.cameray)) + self.screen.blit(self.imgPlatformAfterLucky, (p[0], p[1] - self.cameray)) + elif p[2] == self.platformTypeCastle: + if p[-2]: + self.screen.blit(self.imgFlagRight, (p[0] + self.imgPlatformCastle.get_width() - 16, p[1] - 4 - self.cameray)) + self.screen.blit(self.imgPlatformCastle, (p[0], p[1] - self.cameray)) elif p[2] == self.platformTypeBreaking: - if not p[3]: + if not p[-1]: self.screen.blit(self.imgPlatformBreaking, (p[0], p[1] - self.cameray)) else: self.screen.blit(self.imgPlatformBroken, (p[0], p[1] - self.cameray)) @@ -238,6 +289,11 @@ class MolpyUp: imgItem = self.imgBeanie else: imgItem = None + elif item[2] == self.itemTypePrickly: + if not item[-1]: + imgItem = self.imgPrickly + else: + imgItem = self.imgPricklyCurled elif item[2] == self.itemTypeSandcastle: imgItem = self.imgSandcastle if item[-1]: @@ -258,6 +314,8 @@ class MolpyUp: elif item[2] == self.itemTypeBeanie and not self.playerWearsBeanie: self.playerWearsBeanie = True item[-1] = True + elif item[2] == self.itemTypePrickly: + item[-1] = True elif item[2] == self.itemTypeSandcastle and self.playerCarriesFlag: self.playerCarriesFlag = False item[-1] = True @@ -281,6 +339,7 @@ class MolpyUp: def waitForIt(self, its): run = False while not run: + self.clock.tick(self.speed) event = pygame.event.poll() if event.type == KEYDOWN: key = pygame.key.get_pressed() @@ -305,11 +364,10 @@ class MolpyUp: self.waitForIt([K_RETURN]) def run(self): - clock = pygame.time.Clock() self.reset() while True: self.screen.fill((255,255,255)) - clock.tick(self.speed) + self.clock.tick(self.speed) for event in pygame.event.get(): if event.type == QUIT: sys.exit() -- 2.30.2