八大行星_星球大爆炸_turtle eight planet solar system

"""
   星球大爆炸.py
   这是用海龟画图模块制作的一个八大行星动画。不过,有一天闯入
   了一个流浪星球,它不受太阳引力,莽撞地随机移动,碰到行星就把
   它吞噬掉。为了拯救太阳系,你需要尽快用鼠标指针单击它,然后它就会
   爆炸,否则如果太阳系只剩下三颗行星的活,整个恒星系将会发生大爆炸。
"""

import math
import pygame
from turtle import *
from random import randint,choice

class Demon(Turtle):
    def __init__(self,images,pos,bomb):
        Turtle.__init__(self, shape='d.gif',visible=False)
        self.bomb = bomb
        self.screen_width = self.screen.window_width()
        self.screen_height = self.screen.window_height()
        self.set_speed()
        self.images = images
        self.images_amounts = len(images)
        self.penup()
        self.goto(pos)
        self.onclick(self.explode)
        self.count=0
        self.dead = False
        self.setheading(randint(1,360))
        self.st()
        self.move()

    def move(self):
        if not self.dead:
            if randint(1,30) == 1 : self.set_speed()
            x =  self.xcor() + self.xspeed
            y =  self.ycor() + self.yspeed
            self.goto(x,y)
            if abs(x) > self.screen_width//2 - 50:
                self.xspeed = - self.xspeed
                
            if abs(y) > self.screen_height//2 - 50:
                self.yspeed = - self.yspeed
            self.screen.ontimer(self.move,7)
        

You must log in to read the rest of this article. Please log in or register as a user.