0

Im writing a basic mouse dodge game and i need to blit little stars to dodge. i made it so that once one star leaves the screen it blits it again at the top> that works but it blits it in the same x position

Here is the update code that moves the star:

def update(self):
    self.mouse_pos = pygame.mouse.get_pos()
    (self.player_r.x, self.player_r.y) = self.mouse_pos

    self.star_r.x = ran_x
    self.star_r.y += 2
    if self.star_r.y > 640:
        self.star_r.y = 0

Here is where the star gets blitted:

def blitPlayer(self, screen):
    screen.blit(background,(0,0))
    screen.blit(self.player,(self.mouse_pos))
    screen.blit(self.star,(ran_x, self.star_r.y))

I define ran_x outside the class at the top like this:

ran_x = random.randint(10,470)

What i think is happening is that when i run it ran_x is being defined by one random number and then keeping that number but i want it to change each time the star leaves the screen

Thanks in Advance!!

-ChristianCareaga

Serial
  • 7,925
  • 13
  • 52
  • 71

1 Answers1

1

Then why not recompute ran_x here:

if self.star_r.y > 640:
    self.star_r.y = 0
    ran_x = new random number
Patashu
  • 21,443
  • 3
  • 45
  • 53
  • yeah that should do it do you think there is an easy way to blit like 2 or 3 at a time instead of one – Serial Jun 04 '13 at 04:21
  • 1
    @Christian Careaga Make `ran_x` an instance variable, not static or global. e.g. each star should be associated with its own value for x co-ordinate, so `star.ran_x` – Patashu Jun 04 '13 at 04:45