+# -*- coding: utf-8 -*-
# Molpy Up!
#
# Based on Max00355's version of DoodleJump, <https://github.com/Max00355/DoodleJump>
# OTTified in about 120 minutes.
#
# Copyright (C) 2018, 2026 by Balthasar SzczepaĆski
-# edited to add arrow, AI, and a flag save mode - balthasar_s
+# add arrow, AI, flag save mode,
+# remove off-screen space,
+# some optimisation
#
# This program is Free Software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License (GNU GPL), version 3,
class MolpyUp:
- platformTypeSand = 0
- platformTypeGrass = 1
- platformTypeNormal = platformTypeGrass
- platformTypeGrapevine = 2
- platformTypeAfterLucky = 3
- platformTypeCastle = 4
- platformTypeWater = 5
- platformTypeRaftcastle = 6
- platformTypeFloating = platformTypeRaftcastle
- platformTypeLucky = 7
- platformTypeBreaking = 8
- platformTypeTheEnd = 9
+ platformTypeSand = 0
+ platformTypeGrass = 1
+ platformTypeNormal = platformTypeGrass
+ platformTypeGrapevine = 2
+ platformTypeAfterLucky = 3
+ platformTypeCastle = 4
+ platformTypeWater = 5
+ platformTypeRaftcastle = 6
+ platformTypeFloating = platformTypeRaftcastle
+ platformTypeLucky = 7
+ platformTypeBreaking = 8
+ platformTypeTheEnd = 9
platformTypeWonTheGame = 10
itemTypeAccelerator = 0
- itemTypeBeanie = 1
- itemTypeSnake = 2
- itemTypePrickly = 3
- itemTypeSandcastle = 4
- itemTypeFlag = 5
- itemTypePlantSand = 6
- itemTypePlantGrass = 7
+ itemTypeBeanie = 1
+ itemTypeSnake = 2
+ itemTypePrickly = 3
+ itemTypeSandcastle = 4
+ itemTypeFlag = 5
+ itemTypePlantSand = 6
+ itemTypePlantGrass = 7
- scoreSnake = 1738
- scorePrickly = 2015
- scoreGrass = 2193
+ scoreSnake = 1738
+ scorePrickly = 2015
+ scoreGrass = 2193
scoreAfterLucky = 2315
- scoreCastle = 2825
- scoreLucky = 2976
+ scoreCastle = 2825
+ scoreLucky = 2976
scoreRaftcastle = 3031
- scoreWater = 3043
- scoreTheEnd = 3089
- scoreEpilogue = 3094
+ scoreWater = 3043
+ scoreTheEnd = 3089
+ scoreEpilogue = 3094
def __init__(self):
self.relativeX=0
self.eternalFlag = False
self.ai = False
self.aiDebag = False
- 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.imgPlatformLuckySleeping = pygame.image.load("assets/platformLuckySleeping.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.imgPlatformLuckySleeping = pygame.image.load("assets/platformLuckySleeping.png").convert_alpha()
self.imgPlatformLuckyAttacking = pygame.image.load("assets/platformLuckyAttacking.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.imgPlayerLeftDown = pygame.image.load("assets/playerLeftDown.png").convert_alpha()
- self.imgPlayerRightUpBeanie = pygame.image.load("assets/playerRightUpBeanie.png").convert_alpha()
- self.imgPlayerRightDownBeanie = pygame.image.load("assets/playerRightDownBeanie.png").convert_alpha()
- self.imgPlayerLeftUpBeanie = pygame.image.load("assets/playerLeftUpBeanie.png").convert_alpha()
- self.imgPlayerLeftDownBeanie = pygame.image.load("assets/playerLeftDownBeanie.png").convert_alpha()
- 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.imgSnake = pygame.image.load("assets/snake.png").convert_alpha()
- self.imgSnakeLeft = pygame.image.load("assets/snakeLeft.png").convert_alpha()
- self.imgSnakeRight = pygame.image.load("assets/snakeRight.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()
- 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() ]
- self.imgMolpArrow = pygame.image.load("assets/molpArrow.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.imgPlayerLeftDown = pygame.image.load("assets/playerLeftDown.png").convert_alpha()
+ self.imgPlayerRightUpBeanie = pygame.image.load("assets/playerRightUpBeanie.png").convert_alpha()
+ self.imgPlayerRightDownBeanie = pygame.image.load("assets/playerRightDownBeanie.png").convert_alpha()
+ self.imgPlayerLeftUpBeanie = pygame.image.load("assets/playerLeftUpBeanie.png").convert_alpha()
+ self.imgPlayerLeftDownBeanie = pygame.image.load("assets/playerLeftDownBeanie.png").convert_alpha()
+ 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.imgSnake = pygame.image.load("assets/snake.png").convert_alpha()
+ self.imgSnakeLeft = pygame.image.load("assets/snakeLeft.png").convert_alpha()
+ self.imgSnakeRight = pygame.image.load("assets/snakeRight.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()
+ 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() ]
+ self.imgMolpArrow = pygame.image.load("assets/molpArrow.png").convert_alpha()
+ self.playerHeight = self.imgPlayerRightUp.get_height()
+ self.playerWidth = self.imgPlayerRightUp.get_width()
+ self.playerHalfWidth = self.playerWidth // 2
+ self.platformSpeed = self.extrax // 10
+ self.platformSandHeight = self.imgPlatformSand[0].get_height()
+ self.platformSandWidth = self.imgPlatformSand[0].get_width()
+ self.showArrow = True
+
def reset(self):
self.cameray = 0
self.score = 0
self.sandcastles = 0
self.speed = 30
- self.showArrow = True
+ self.showSpeed = False
self.playerx = self.sx // 2
self.playery = self.sy * 3 // 4
self.direction = 0
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.imgPlatformSand[0].get_width()]]
+ self.platforms = [[self.playerx, self.playery + self.sy // 6, self.platformTypeSand, 0, 0, -1, False, self.platformSandWidth]]
self.generateInitialPlatforms()
self.items = []
self.aiNextPlatformOk = False
return True
except FileNotFoundError:
return False
-
+
def findNextPlatform(self):
- # bestDistance=float("Inf")
- # for p in self.platforms:
- # if not self.jump:
- # distance = abs(p[0]-self.playerx) * 0.5 - p[1]
- # else:
- # distance = abs(p[0]-self.playerx) * 0.5 + abs(p[1]-self.playery)
- # if p[1]>self.playery:
- # distance += 900
- # if p[2] > self.platformTypeNormal and p[2] <= self.platformTypeFloating:
- # distance += 290
- # if p[2] == self.platformTypeBreaking:
- # distance = float("Inf")
- # p[6]=distance
- # if distance<bestDistance:
- # bestDistance = distance
- # self.aiNextPlatform=p
- # self.aiNextPlatformOk = True
-
bestPlatformScore = float("-Inf")
- actualY=self.playery+self.imgPlayerRightUp.get_height()
- actualX=self.playerx+self.imgPlayerRightUp.get_width()//2
+ actualY = self.playery + self.playerHeight
+ actualX = self.playerx + self.playerHalfWidth
self.aiNextPlatform = self.platforms[0]
if self.jump > 0:
- maxY = actualY - (self.jump * (self.jump+1) // 2)
+ maxY = actualY - (self.jump * (self.jump + 1 ) // 2)
framesUp = self.jump
else:
maxY = actualY
if (platformY < maxY) or (p[2] == self.platformTypeBreaking):
platformScore = float("-Inf")
- p[6]=platformScore
+ p[6] = platformScore
continue
distY = actualY - platformY
else:
framesDown = int(math.floor(math.sqrt(2*distDown)))
- speedX=9;
+ speedX = 9;
if p[2] > self.platformTypeNormal and p[2] <= self.platformTypeFloating:
- if (p[4] and platformX>actualX) or (not p[4] and platformX<actualX):
- speedX -= self.extrax // 10
+ if (p[4] and platformX > actualX) or (not p[4] and platformX < actualX):
+ speedX -= self.platformSpeed
else:
- speedX += self.extrax // 10
+ speedX += self.platformSpeed
- platformScore += framesUp + framesDown - distX//speedX
+ platformScore += framesUp + framesDown - distX // speedX
- if platformX-actualX>2*self.xmovementmax and self.xmovement < 0:
- platformScore -= (self.xmovementmax-self.xmovement)*(self.xmovementmax-self.xmovement)//4
- elif actualX-platformX>2*self.xmovementmax and self.xmovement > 0:
- platformScore -= (-self.xmovementmax-self.xmovement)*(-self.xmovementmax-self.xmovement)//4
+ if platformX - actualX > 2 * self.xmovementmax and self.xmovement < 0:
+ platformScore -= (self.xmovementmax - self.xmovement) * (self.xmovementmax - self.xmovement) // 4
+ elif actualX - platformX > 2 * self.xmovementmax and self.xmovement > 0:
+ platformScore -= (-self.xmovementmax - self.xmovement) * (-self.xmovementmax - self.xmovement) // 4
if platformScore < 0:
platformScore = float("-Inf")
- platformScore *=4
+ platformScore *= 4
- if distY>16:
- platformScore += distY + distX//2
+ if distY > 16:
+ platformScore += distY + distX // 2
else:
- platformScore += 2*distY - 200 + distX
+ platformScore += 2 * distY - 200 + distX
if p[2] > self.platformTypeNormal and p[2] <= self.platformTypeFloating:
platformScore -= 50 #100
bestPlatformScore = platformScore
self.aiNextPlatform = p
self.aiNextPlatformOk = True
-
-
-
-
-
+
def updatePlayer(self):
if ((not self.jump) and (self.playery > self.aiNextPlatform[1])) or (self.aiNextPlatform[1] - self.cameray > self.sy):
self.aiNextPlatformOk = False
-
+
if not self.aiNextPlatformOk and self.ai:
self.findNextPlatform()
-
+
if not self.jump:
self.playery += self.gravity
self.gravity += 1
self.playery -= self.jump
self.jump -= 1
key = pygame.key.get_pressed()
-
+
+ xdir = 0;
+ actualX = self.playerx + self.playerHalfWidth
if key[K_RIGHT]:
- if self.xmovement < self.xmovementmax:
- self.xmovement += 1
- self.direction = 0
+ xdir = 1
+ self.showSpeed = False
elif key[K_LEFT]:
- if self.xmovement > -self.xmovementmax:
- self.xmovement -= 1
- self.direction = 1
+ xdir = -1
+ self.showSpeed = False
elif key[K_PLUS] or key[K_KP_PLUS]:
if pygame.key.get_mods() & 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))
+ self.showSpeed = True
elif key[K_MINUS] or key[K_KP_MINUS]:
if pygame.key.get_mods() & 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.ai:
- actualX=self.playerx+self.imgPlayerRightUp.get_width()//2
- platformX = self.aiNextPlatform[0] + self.aiNextPlatform[7] //2
- if self.aiNextPlatform[2] > self.platformTypeNormal and self.aiNextPlatform[2] <= self.platformTypeFloating:
- if self.aiNextPlatform[4] == True:
- self.relativeX = self.xmovement - self.extrax // 10
- else:
- self.relativeX = self.xmovement + self.extrax // 10
+ self.showSpeed = True
+ elif self.ai:
+ platformX = self.aiNextPlatform[0] + self.aiNextPlatform[7] // 2
+ if self.aiNextPlatform[2] > self.platformTypeNormal and self.aiNextPlatform[2] <= self.platformTypeFloating:
+ if self.aiNextPlatform[4] == True:
+ self.relativeX = self.xmovement - self.platformSpeed
else:
- self.relativeX = self.xmovement
-
- if actualX<platformX -2.5*self.relativeX:
- if self.xmovement < self.xmovementmax:
- self.xmovement += 1
- self.direction = 0
- elif actualX>platformX -2.5*self.relativeX:
- if self.xmovement > -self.xmovementmax:
- self.xmovement -= 1
- self.direction = 1
- else:
- if self.xmovement > 0:
- self.xmovement -= 1
- elif self.xmovement < 0:
- self.xmovement += 1
+ self.relativeX = self.xmovement + self.platformSpeed
else:
- if self.xmovement > 0:
- self.xmovement -= 1
- elif self.xmovement < 0:
- self.xmovement += 1
-
- if self.playerx > self.sx + self.extrax:
- self.playerx = -self.extrax
+ self.relativeX = self.xmovement
+
+ if actualX < platformX - 2.5 * self.relativeX:
+ xdir = 1
+ elif actualX > platformX - 2.5 * self.relativeX:
+ xdir = -1
+
+ if xdir > 0:
+ if self.xmovement < self.xmovementmax:
+ self.xmovement += 1
+ elif self.xmovement > self.xmovementmax:
+ self.xmovement -= 1
+ self.direction = 0
+ elif xdir < 0:
+ if self.xmovement > -self.xmovementmax:
+ self.xmovement -= 1
+ elif self.xmovement < -self.xmovementmax:
+ self.xmovement += 1
+ self.direction = 1
+ elif self.xmovement > 0:
+ self.xmovement -= 1
+ elif self.xmovement < 0:
+ self.xmovement += 1
+
+ self.playerx += self.xmovement
+ actualX += self.xmovement
+
+ while actualX < 0:
+ self.playerx += self.sx
+ actualX += self.sx
self.aiNextPlatformOk = False
- elif self.playerx < -self.extrax:
- self.playerx = self.sx + self.extrax
+ while actualX >= self.sx:
+ self.playerx -= self.sx
+ actualX -= self.sx
self.aiNextPlatformOk = False
- self.playerx += self.xmovement
+
if self.playery - self.cameray <= self.sy // 3:
self.cameray -= self.sy // 60
- if (self.playery - self.cameray + self.imgPlayerRightUp.get_height()) < 0:
- if self.showArrow:
- self.screen.blit(self.imgMolpArrow, (self.playerx, 2))
+ drawX = self.playerx % self.sx
+ if drawX > self.sx - self.playerWidth:
+ drawX = [drawX, drawX - self.sx]
else:
- if not self.direction:
- if self.jump:
- if self.playerWearsBeanie:
- self.screen.blit(self.imgPlayerRightDownBeanie, (self.playerx, self.playery - self.cameray))
- else:
- self.screen.blit(self.imgPlayerRightDown, (self.playerx, self.playery - self.cameray))
- if self.playerCarriesFlag:
- self.screen.blit(self.imgFlagLeft, (self.playerx + 24, self.playery - 10 - self.cameray))
- else:
- if self.playerWearsBeanie:
- 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.imgFlagLeftDown, (self.playerx + 22, self.playery - 10 - self.cameray))
+ drawX = [drawX]
+ drawY = self.playery - self.cameray
+
+ for x in drawX:
+ if (drawY + self.playerHeight) < 0:
+ if self.showArrow:
+ self.screen.blit(self.imgMolpArrow, (x, 2))
else:
- if self.jump:
- if self.playerWearsBeanie:
- self.screen.blit(self.imgPlayerLeftDownBeanie, (self.playerx, self.playery - self.cameray))
+ if not self.direction:
+ if self.jump:
+ if self.playerWearsBeanie:
+ self.screen.blit(self.imgPlayerRightDownBeanie, (x, drawY))
+ else:
+ self.screen.blit(self.imgPlayerRightDown, (x, drawY))
+ if self.playerCarriesFlag:
+ self.screen.blit(self.imgFlagLeft, (x + 24, drawY - 10))
else:
- self.screen.blit(self.imgPlayerLeftDown, (self.playerx, self.playery - self.cameray))
- if self.playerCarriesFlag:
- self.screen.blit(self.imgFlagRight, (self.playerx + 13, self.playery - 10 - self.cameray))
+ if self.playerWearsBeanie:
+ self.screen.blit(self.imgPlayerRightUpBeanie, (x, drawY))
+ else:
+ self.screen.blit(self.imgPlayerRightUp, (x, drawY))
+ if self.playerCarriesFlag:
+ self.screen.blit(self.imgFlagLeftDown, (x + 22, drawY - 10))
else:
- if self.playerWearsBeanie:
- self.screen.blit(self.imgPlayerLeftUpBeanie, (self.playerx, self.playery - self.cameray))
+ if self.jump:
+ if self.playerWearsBeanie:
+ self.screen.blit(self.imgPlayerLeftDownBeanie, (x, drawY))
+ else:
+ self.screen.blit(self.imgPlayerLeftDown, (x, drawY))
+ if self.playerCarriesFlag:
+ self.screen.blit(self.imgFlagRight, (x + 13, drawY - 10))
else:
- self.screen.blit(self.imgPlayerLeftUp, (self.playerx, self.playery - self.cameray))
- if self.playerCarriesFlag:
- self.screen.blit(self.imgFlagRightDown, (self.playerx + 11, self.playery - 10 - self.cameray))
-
-
+ if self.playerWearsBeanie:
+ self.screen.blit(self.imgPlayerLeftUpBeanie, (x, drawY))
+ else:
+ self.screen.blit(self.imgPlayerLeftUp, (x, drawY))
+ if self.playerCarriesFlag:
+ self.screen.blit(self.imgFlagRightDown, (x + 11, drawY - 10))
def choosePlatformType(self):
if self.score >= self.scoreTheEnd:
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, 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()]
self.hadTheEnd = True
elif platformType == self.platformTypeWater or platformType == self.platformTypeRaftcastle:
- platform=[random.randint(0, self.sx * 7 // 8), self.platforms[-1][1] - self.sy // 8, platformType, False, False, -1, False, self.imgPlatformSand[0].get_width()]
+ platform = [random.randint(0, self.sx - self.platformSandWidth), self.platforms[-1][1] - self.sy // 8, platformType, False, False, -1, False, self.platformSandWidth]
elif platformType == self.platformTypeLucky:
- platform=[0, self.platforms[-1][1] - self.sy // 12, platformType, False, False, -1, False, self.imgPlatformSand[0].get_width()]
+ platform = [0, self.platforms[-1][1] - self.sy // 12, platformType, False, False, -1, False, self.platformSandWidth]
else:
- platform=[random.randint(0, self.sx * 7 // 8), self.platforms[-1][1] - self.sy // 12, platformType, False, False, -1, False, self.imgPlatformSand[0].get_width()]
+ platform = [random.randint(0, self.sx - self.platformSandWidth), self.platforms[-1][1] - self.sy // 12, platformType, False, False, -1, False, self.platformSandWidth]
if platformType <= self.platformTypeNormal:
if platformType == self.platformTypeSand:
platform[4] = random.randint(0, len(self.imgPlatformSand) - 1)
elif self.score > 0:
check = random.randint(0, 999)
if check > 800:
- xx = x + random.randint(0, self.imgPlatformSand[0].get_width() - 40)
+ xx = x + random.randint(0, self.platformSandWidth - 40)
itemType = random.randint(0,999)
if itemType < 50:
platform[5]=self.itemTypeBeanie
if self.score < self.scoreEpilogue:
self.score += 1
for p in self.platforms:
- if p[2] == self.platformTypeGrapevine:
- img = self.imgPlatformGrapevine
- elif p[2] == self.platformTypeAfterLucky:
- img = self.imgPlatformAfterLucky
- elif p[2] == self.platformTypeCastle:
- img = self.imgPlatformCastle
- elif p[2] == self.platformTypeRaftcastle:
- img = self.imgPlatformRaftcastle
- else:
- # all have same size
- 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):
+ rect = pygame.Rect(p[0], p[1], p[7], self.platformSandHeight)
+ 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:
+ 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):
if p[2] == self.platformTypeBreaking:
p[4] = True
else:
self.sandcastles += 1
if p[2] > self.platformTypeNormal and p[2] <= self.platformTypeFloating:
if p[4]:
- 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] + img.get_width() > self.sx:# + self.extrax:
+ p[0] += self.platformSpeed
+ if p[0] + p[7] >= self.sx:# + self.extrax:
p[4] = False
else:
- p[0] -= self.extrax // 10
+ p[0] -= self.platformSpeed
if p[0] <= 0:
p[4] = True
-
-
-
def drawPlatforms(self):
for p in self.platforms:
if p[2] == self.platformTypeSand:
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))
- # print (str(p))
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))
if self.aiDebag:
- self.screen.blit(self.imgMolpArrow, (self.aiNextPlatform[0] + (self.imgPlatformSand[0].get_width()-self.imgMolpArrow.get_width())//2, self.aiNextPlatform[1] - self.cameray + 16))
-
-
+ self.screen.blit(self.imgMolpArrow, (self.aiNextPlatform[0] + (self.platformSandWidth-self.playerWidth)//2, self.aiNextPlatform[1] - self.cameray + 16))
def drawAndUpdateItems(self):
while self.items and self.items[0][1] - self.cameray > self.sy + self.sy // 12:
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: