吐泡泡的小金鱼

吐泡泡的小金鱼

fish小金鱼李兴球Python

fish小金鱼李兴球Python

import random
from sprites import *

def rise(self):
    if self.ycor()<180:
        self.addy(4)
        self.screen.ontimer(self.rise,50)
    else:
        self.ht()
        
def spit_bubble(self):
    if not self.bubble.isvisible():
       self.bubble.goto(self.position())
       self.bubble.shape('circle.png')
       self.bubble.show()
       self.bubble.rise()

Sprite.rise = rise
Sprite.spit_bubble = spit_bubble

screen = Screen()
screen.setup(480,360)
screen.bgpic('underwater.png')

fish1 = Sprite('fish.png')
fish1.bubble=Sprite('blank',visible=False)

clock = Clock()
while True:
    fish1.fd(5)
    if random.randint(1,10)==1:
        fish1.spit_bubble()
    fish1.bounce_on_edge()
    fish1.right(random.randint(-20,20))
    screen.update()
    clock.tick(30)

李兴球

李兴球的博客是Python创意编程原创博客