简体   繁体   English

在新的x位置Pygame发条

[英]Blitting in new x position Pygame

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 我做到了,一旦一颗星星离开屏幕,它就会再次在顶部将其变亮>起作用,但它会在相同的x位置变亮它

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 ,如下所示:

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 我认为正在发生的是,当我运行ran_x时,它是由一个随机数定义的,然后保留该数字,但是我希望每次星星离开屏幕时它都会更改

Thanks in Advance!! 提前致谢!!

-ChristianCareaga -克里斯蒂安·卡雷加(ChristianCareaga)

Then why not recompute ran_x here: 那为什么不在这里重新计算ran_x:

if self.star_r.y > 640:
    self.star_r.y = 0
    ran_x = new random number

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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