I'm re-making the Chrome Dino Game in Pygame, and can't get the cactus to spawn randomly while never overlapping each other. I don't know what method / math equation to use and where, any idea ?
def __init__(self) :
self.type = random.randint(0, 2)
self.image = SMALLCACTUSIMG[self.type]
self.rect = self.image.get_rect()
self.placer = random.randint(12, 20)
self.rect.x = ((win_rect.width*self.placer) / 10)
self.rect.y = 590
def update(self):
self.rect.x -= game_speed
if self.rect.x < - self.rect.width :
obstacles.remove(self)
def draw(self):
win.blit(self.image, (self.rect.x, self.rect.y))
class LargeCactus :
# Same thing, except that the image isn't the same
def redraw():
for obstacle in obstacles :
obstacle.draw()
obstacle.update()
pygame.display.update()
while gamerunning:
while len(obstacles) < 3 :
if random.randint(0, 1) == 0 :
cactus = SmallCactus()
elif random.randint(0, 1) == 1 :
cactus = LargeCactus()
cactus.append(obstacles)
Aucun commentaire:
Enregistrer un commentaire