简体   繁体   中英

pygame drawing items in inverse direction

The question is:

I'm trying to make platform generator for my pygame project but the problem is when I create platforms the positioning in the pygame is inverse how could I solve that problem?

The code in my settings.py

#Platform Generator
#Platforms(x, y, w, h)
PLATFORMS_LIST = []

for i in range(WIDTH):
    MAX_HEIGHT = random.randint(100, 120)
    PLATFORMS_LIST.append((i * 20, 300, 20, MAX_HEIGHT))

The code in sprites.py

class Platforms(pygame.sprite.Sprite):
    def __init__(self, x, y, w, h):
        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.Surface((w, h))
        self.image.fill(GREEN)
        self.rect = self.image.get_rect()
        self.rect.x = x
        self.rect.y = y

代码输出

But I want the inverse of that green platforms.

If the maximum height is 120, then you have to shift the items by the difference 120-MAX_HEIGHT to the bottom:

MAX_HEIGHT = random.randint(100, 120)
# PLATFORMS_LIST.append((i * 20, 300, 20, MAX_HEIGHT))
PLATFORMS_LIST.append((i * 20, 300+120-MAX_HEIGHT, 20, MAX_HEIGHT))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM