Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I prevent my python game from reiterating and instead carry on?
    text
    copied!<p>I've made a simple game using pygame and livewires, where a sprite has to avoid falling mushrooms. The number of mushrooms falling at a certain time is meant to increase as the score increases. Here is what I mean:</p> <pre><code>from livewires import games,color import random games.init(screen_width=633,screen_height=479,fps=50) class Stick_Man(games.Sprite): def update(self): self.x=games.mouse.x if self.left&lt;0: self.left=0 if self.right&gt;games.screen.width: self.right=games.screen.width self.check_collision() def check_collision(self): if self.overlapping_sprites: self.over_message() def over_message(self): b=games.Message(value="Game Over", size=100, color=color.red,x=games.screen.width/2,y=games.screen.height/2,lifetime=250,after_death=games.screen.quit) games.screen.add(b) class Mushroom(games.Sprite): score=0 start=200 score_required=100 level=1 total_score=0 speed=1 mushroom=games.load_image("mushroom.jpg") x_position=random.randrange(640) @staticmethod def next_level(): indicate='Level ', + Mushroom.level, ' cleared' message=games.Message(value=indicate,size=50,color=color.red,x=games.screen.width/2,y=games.screen.height/2, lifetime=150) games.screen.add(message) Mushroom().score_required+=50 Mushroom().score-=Mushroom.score_required Mushroom().start-=150 Mushroom().speed+=5 Mushroom().level+=1 if Mushroom().start==20: Mushroom().start+=10 def __init__(self): super(Mushroom,self).__init__(image=Mushroom.mushroom,x=games.mouse.x,y=0) def update(self): self.dy=Mushroom.speed self.check() self.check2() def check(self): if self.bottom==games.screen.height: self.destroy() Mushroom.score+=50 Mushroom.total_score+=Mushroom.score if Mushroom().score==Mushroom.score_required: self.next_level() def check2(self): if self.top==Mushroom.start: self.duplicate() def duplicate(self): new_mush=Mushroom() games.screen.add(new_mush) background_image=games.load_image("background.jpg", transparent=False) games.screen.background=background_image stickman_image=games.load_image("stickman.png", transparent=True) stickman=Stick_Man(image=stickman_image,left=1,bottom=480) games.screen.add(stickman) games.mouse.is_visible=False b=Mushroom() c=Mushroom() a=Mushroom() games.screen.add(b) games.screen.add(a) games.screen.add(c) games.screen.event_brab=True games.screen.mainloop() </code></pre> <p>The code is pretty self explanatory and whenever one of the mushrooms is equal to start, then a new object is created thus meaning a new mushroom comes in. However, what happens is that code doesn't function properly a second time and the mushrooms don't get faster spawn much faster either. Also, when the game first starts, the minute the first mushroom hits the bottom it says level one cleared, when it should be after two mushrooms. The sprite is just a red mushroom and also a stickman which can be found on g images if you want to simulate. </p> <p>So my question is how do i make the object's STATS carry on from where it left off whenever another mushroom appears and also display the message at the right time</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload