platformTypeGrapevine = 2
platformTypeAfterLucky = 3
platformTypeCastle = 4
- platformTypeRaftcastle = 5
+ platformTypeWater = 5
+ platformTypeRaftcastle = 6
platformTypeFloating = platformTypeRaftcastle
- platformTypeBreaking = 6
+ platformTypeBreaking = 7
+ platformTypeTheEnd = 8
+ platformTypeWonTheGame = 9
itemTypeAccelerator = 0
itemTypeBeanie = 1
itemTypePrickly = 3
itemTypeSandcastle = 4
itemTypeFlag = 5
+ itemTypePlantSand = 6
+ itemTypePlantGrass = 7
scoreSnake = 1738
scorePrickly = 2015
scoreAfterLucky = 2315
scoreCastle = 2825
scoreRaftcastle = 3031
+ scoreWater = 3043
+ scoreTheEnd = 3089
+ scoreEpilogue = 3094
def __init__(self):
self.sx = 553
self.font = pygame.font.SysFont("xkcd,sans", 25)
self.clock = pygame.time.Clock()
self.xmovementmax = 10
- self.imgPlatformSand = pygame.image.load("assets/platformSand.png").convert_alpha()
- self.imgPlatformGrass = pygame.image.load("assets/platformGrass.png").convert_alpha()
+ self.imgPlatformSand = [ pygame.image.load("assets/platformSand1.png").convert_alpha(),
+ pygame.image.load("assets/platformSand2.png").convert_alpha(),
+ pygame.image.load("assets/platformSand3.png").convert_alpha(),
+ pygame.image.load("assets/platformSand4.png").convert_alpha() ]
+ self.imgPlatformGrass = [ pygame.image.load("assets/platformGrass1.png").convert_alpha(),
+ pygame.image.load("assets/platformGrass2.png").convert_alpha(),
+ pygame.image.load("assets/platformGrass3.png").convert_alpha(),
+ pygame.image.load("assets/platformGrass1f.png").convert_alpha(),
+ pygame.image.load("assets/platformGrass2f.png").convert_alpha(),
+ pygame.image.load("assets/platformGrass3f.png").convert_alpha() ]
+ self.imgPlatformWater = [ pygame.image.load("assets/platformWater1.png").convert_alpha(),
+ pygame.image.load("assets/platformWater2.png").convert_alpha(),
+ pygame.image.load("assets/platformWater1f.png").convert_alpha(),
+ pygame.image.load("assets/platformWater2f.png").convert_alpha() ]
self.imgPlatformAfterLucky = pygame.image.load("assets/platformAfterLucky.png").convert_alpha()
self.imgPlatformCastle = pygame.image.load("assets/platformCastle.png").convert_alpha()
self.imgPlatformRaftcastle = pygame.image.load("assets/platformRaftcastle.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.imgPlatformTheEnd = pygame.image.load("assets/platformTheEnd.png").convert_alpha()
+ self.imgPlatformWonTheGame = pygame.image.load("assets/platformWonTheGame.png").convert_alpha()
self.imgPlayerRightUp = pygame.image.load("assets/playerRightUp.png").convert_alpha()
self.imgPlayerRightDown = pygame.image.load("assets/playerRightDown.png").convert_alpha()
self.imgPlayerLeftUp = pygame.image.load("assets/playerLeftUp.png").convert_alpha()
self.imgFlagLeftDown = pygame.image.load("assets/flagLeftDown.png").convert_alpha()
self.imgFlagRight = pygame.image.load("assets/flagRight.png").convert_alpha()
self.imgFlagRightDown = pygame.image.load("assets/flagRightDown.png").convert_alpha()
+ self.imgPlantSand = [ pygame.image.load("assets/plantSand1.png").convert_alpha(),
+ pygame.image.load("assets/plantSand2.png").convert_alpha(),
+ pygame.image.load("assets/plantSand3.png").convert_alpha(),
+ pygame.image.load("assets/plantSand4.png").convert_alpha(),
+ pygame.image.load("assets/plantSand5.png").convert_alpha() ]
+ self.imgPlantGrass = [ pygame.image.load("assets/plantGrass1.png").convert_alpha(),
+ pygame.image.load("assets/plantGrass2.png").convert_alpha(),
+ pygame.image.load("assets/plantGrass3.png").convert_alpha(),
+ pygame.image.load("assets/plantGrass4.png").convert_alpha(),
+ pygame.image.load("assets/plantGrass5.png").convert_alpha(),
+ pygame.image.load("assets/plantGrass6.png").convert_alpha(),
+ pygame.image.load("assets/plantGrass7.png").convert_alpha(),
+ pygame.image.load("assets/plantGrass8.png").convert_alpha(),
+ pygame.image.load("assets/plantGrass9.png").convert_alpha(),
+ pygame.image.load("assets/plantGrass10.png").convert_alpha(),
+ pygame.image.load("assets/plantGrass11.png").convert_alpha() ]
def reset(self):
self.cameray = 0
self.hadPrickly = False
self.hadAfterLucky = False
self.hadCastle = False
- self.hadRaftcastle = False
- self.platforms = [[self.playerx, self.playery + self.sy // 6, self.platformTypeSand, False, False]]
+ self.hadTheEnd = False
+ self.raftcastleHasFlag = False
+ self.platforms = [[self.playerx, self.playery + self.sy // 6, self.platformTypeSand, 0, 0]]
self.generatePlatforms()
def updatePlayer(self):
self.xmovement -= 1
self.direction = 1
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))
+ if pygame.key.get_mods() and KMOD_CTRL:
+ self.score += 10
+ else:
+ 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] 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))
+ if pygame.key.get_mods() and KMOD_CTRL:
+ self.score -= 10
+ else:
+ 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:
if self.xmovement > 0:
self.xmovement -= 1
img = self.imgPlatformRaftcastle
else:
# all have same size
- img = self.imgPlatformSand
- rect = pygame.Rect(p[0], p[1], img.get_width(), self.imgPlatformSand.get_height())
+ img = self.imgPlatformSand[0]
+ rect = pygame.Rect(p[0], p[1], img.get_width(), self.imgPlatformSand[0].get_height())
player = pygame.Rect(self.playerx + 15, self.playery, self.imgPlayerRightUp.get_width() - 30, self.imgPlayerRightUp.get_height())
if rect.colliderect(player) and self.gravity and self.playery < (p[1] - self.cameray):
if p[2] == self.platformTypeBreaking:
else:
self.jump = self.sy // 20
self.gravity = 0
- if (p[2] == self.platformTypeAfterLucky or p[2] == self.platformTypeCastle or p[2] == self.platformTypeRaftcastle) and self.playerCarriesFlag and not p[-2]:
+ 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
+ elif p[2] == self.platformTypeRaftcastle and self.playerCarriesFlag and not self.raftcastleHasFlag:
+ self.playerCarriesFlag = False
+ self.raftcastleHasFlag = True
+ self.sandcastles += 1
if p[2] > self.platformTypeNormal and p[2] <= self.platformTypeFloating:
if p[-1]:
if p[2] == self.platformTypeAfterLucky:
p[-1] = True
def choosePlatformType(self):
- platformType = random.randint(0, 1000)
- if platformType < 800:
+ if self.score >= self.scoreTheEnd:
+ return self.platformTypeTheEnd
+ platformType = random.randint(0, 999)
+ if self.score > self.scoreWater:
+ if platformType < 900:
+ return self.platformTypeWater
+ else:
+ return self.platformTypeRaftcastle
+ elif platformType < 800:
if platformType < 1000 * self.score // self.scoreGrass:
if self.score > self.scoreAfterLucky and not self.hadAfterLucky:
self.hadAfterLucky = True
elif self.score > self.scoreCastle and not self.hadCastle:
self.hadCastle = True
return self.platformTypeCastle
- elif self.score > self.scoreRaftcastle and not self.hadRaftcastle:
- self.hadRaftcastle = True
- return self.platformTypeRaftcastle
else:
return self.platformTypeGrass
else:
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, False])
+ if platformType == self.platformTypeTheEnd:
+ if not self.hadTheEnd:
+ self.platforms.append([self.sx // 2 - self.imgPlatformTheEnd.get_width() // 2, self.platforms[-1][1] - self.sy // 4, self.platformTypeTheEnd, False, False])
+ self.platforms.append([self.sx // 2 - self.imgPlatformWonTheGame.get_width() // 2, self.platforms[-1][1] - self.sy * 2 // 3, self.platformTypeWonTheGame, False, False])
+ self.hadTheEnd = True
+ elif platformType == self.platformTypeWater or platformType == self.platformTypeRaftcastle:
+ self.platforms.append([random.randint(0, self.sx * 7 // 8), self.platforms[-1][1] - self.sy // 8, platformType, False, False])
+ else:
+ self.platforms.append([random.randint(0, self.sx * 7 // 8), self.platforms[-1][1] - self.sy // 12, platformType, False, False])
if platformType <= self.platformTypeNormal:
+ if platformType == self.platformTypeSand:
+ self.platforms[-1][-1] = random.randint(0, len(self.imgPlatformSand) - 1)
+ elif platformType == self.platformTypeGrass:
+ self.platforms[-1][-1] = random.randint(0, len(self.imgPlatformGrass) - 1)
+ else:
+ self.platforms[-1][-1] = random.randint(0, len(self.imgPlatformWater) - 1)
x = self.platforms[-1][0]
y = self.platforms[-1][1]
if platformType == self.platformTypeGrass and self.score > self.scoreSnake and not self.hadSnake:
self.items.append([x - 10, y + 9, self.itemTypeSnake, False])
self.hadSnake = True
elif platformType == self.platformTypeGrass and self.score > self.scorePrickly and not self.hadPrickly:
- self.items.append([x + self.imgPlatformSand.get_width() // 3, y + 8, self.itemTypePrickly, False])
+ self.items.append([x + self.imgPlatformSand[0].get_width() // 3, y + 8, self.itemTypePrickly, False])
self.hadPrickly = True
else:
- check = random.randint(0, 1000)
- if check > 900:
- itemType = random.randint(0,1000)
- if itemType < 100:
- self.items.append([x + self.imgPlatformSand.get_width() * 3 // 4, y + 7, self.itemTypeBeanie, False])
- elif itemType < 300 and platformType == self.platformTypeSand:
- self.items.append([x + self.imgPlatformSand.get_width() // 4, y + 6, self.itemTypeSandcastle, False])
- elif itemType < 700 and platformType == self.platformTypeSand:
- self.items.append([x + self.imgPlatformSand.get_width() // 2, y + 6, self.itemTypeFlag, False])
- elif itemType < 200 and platformType == self.platformTypeGrass:
- self.items.append([x + self.imgPlatformSand.get_width() // 2, y + 6, self.itemTypeFlag, False])
- elif itemType < 500 and platformType == self.platformTypeGrass and self.score > self.scorePrickly:
- self.items.append([x + self.imgPlatformSand.get_width() // 3, y + 8, self.itemTypePrickly, False])
- elif itemType < 800 and platformType == self.platformTypeGrass and self.score > self.scoreSnake:
+ check = random.randint(0, 999)
+ if check > 800:
+ xx = x + random.randint(0, self.imgPlatformSand[0].get_width() - 40)
+ itemType = random.randint(0,999)
+ if itemType < 50:
+ self.items.append([xx, y + 7, self.itemTypeBeanie, False])
+ elif itemType < 150 and platformType == self.platformTypeSand:
+ self.items.append([xx, y + 7, self.itemTypeSandcastle, False])
+ elif itemType < 350 and platformType == self.platformTypeSand:
+ self.items.append([xx, y + 7, self.itemTypeFlag, False])
+ elif itemType < 950 and platformType == self.platformTypeSand:
+ self.items.append([xx, y + 8, self.itemTypePlantSand, itemType % len(self.imgPlantSand)])
+ elif itemType < 100 and platformType == self.platformTypeGrass:
+ self.items.append([xx, y + 6, self.itemTypeFlag, False])
+ elif itemType < 700 and platformType == self.platformTypeGrass:
+ self.items.append([xx, y + 10, self.itemTypePlantGrass, itemType % len(self.imgPlantGrass)])
+ elif itemType < 850 and platformType == self.platformTypeGrass and self.score > self.scorePrickly:
+ self.items.append([xx, y + 8, self.itemTypePrickly, False])
+ elif itemType < 950 and platformType == self.platformTypeGrass and self.score > self.scoreSnake:
self.items.append([x - 10, y + 9, self.itemTypeSnake, False])
else:
- self.items.append([x, y + 10, self.itemTypeAccelerator, False])
+ self.items.append([xx - 5, y + 10, self.itemTypeAccelerator, False])
self.platforms.pop(0)
- self.score += 1
+ if self.score < self.scoreEpilogue:
+ self.score += 1
if p[2] == self.platformTypeSand:
- self.screen.blit(self.imgPlatformSand, (p[0], p[1] - self.cameray))
+ self.screen.blit(self.imgPlatformSand[p[-1]], (p[0], p[1] - self.cameray))
elif p[2] == self.platformTypeGrass:
- self.screen.blit(self.imgPlatformGrass, (p[0], p[1] - self.cameray))
+ self.screen.blit(self.imgPlatformGrass[p[-1]], (p[0], p[1] - self.cameray))
+ elif p[2] == self.platformTypeWater:
+ self.screen.blit(self.imgPlatformWater[p[-1]], (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:
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.platformTypeRaftcastle:
- if p[-2]:
- self.screen.blit(self.imgFlagRight, (p[0] + self.imgPlatformRaftcastle.get_width() - 115, p[1] - 10 - self.cameray))
+ if self.raftcastleHasFlag:
+ self.screen.blit(self.imgFlagRight, (p[0] + 50, p[1] - 13 - self.cameray))
self.screen.blit(self.imgPlatformRaftcastle, (p[0], p[1] - self.cameray))
elif p[2] == self.platformTypeBreaking:
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))
+ elif p[2] == self.platformTypeTheEnd:
+ self.screen.blit(self.imgPlatformTheEnd, (p[0], p[1] - self.cameray))
+ elif p[2] == self.platformTypeWonTheGame:
+ self.screen.blit(self.imgPlatformWonTheGame, (p[0], p[1] - self.cameray))
for item in self.items:
if item[2] == self.itemTypeAccelerator:
if item[-1]:
imgItem = self.imgFlagRight
else:
imgItem = None
+ elif item[2] == self.itemTypePlantSand:
+ imgItem = self.imgPlantSand[item[-1]]
+ elif item[2] == self.itemTypePlantGrass:
+ imgItem = self.imgPlantGrass[item[-1]]
if imgItem:
self.screen.blit(imgItem, (item[0], item[1] - imgItem.get_height() - self.cameray))
if not item[-1]:
self.playerWearsBeanie = True
item[-1] = True
elif item[2] == self.itemTypeSnake:
- if self.playerx + self.imgPlayerRightUp.get_width() // 2 < item[0] + self.imgPlatformGrass.get_width() // 2:
+ if self.playerx + self.imgPlayerRightUp.get_width() // 2 < item[0] + self.imgPlatformGrass[0].get_width() // 2:
self.xmovement = -self.sx // 30
self.direction = 0
self.cameray -= self.sy // 12
def generatePlatforms(self):
on = self.sy
while on > -self.sy // 6:
- x = random.randint(0,self.sx * 8 // 7)
+ x = random.randint(0, self.sx * 8 // 7)
self.platforms.append([x, on, self.choosePlatformType(), 0])
on -= self.sy // 12