|

楼主 |
发表于 2020-4-28 22:56:49
|
显示全部楼层
本帖最后由 weiter 于 2020-4-28 23:01 编辑
如下是源代码(因为是改写……所以有一些不同的地方)
- import pygame
- import sys
- from pygame.locals import *
- from random import *
- #import console
- class Ball(pygame.sprite.Sprite):
- def __init__(self, image, position, speed):
- pygame.sprite.Sprite.__init__(self)
- self,image = pygame.image.load(image).convert_alpha()
- self.rect = self.image.get_rect()
- self.rect.left, self.rect.top = position
- self.speed = speed
- def main():
- pygame.init()
- ball_image = "healthy.png"
- bg_image = "bg.png"
- running = True
- bg_size = width, height = 1024, 681
- screen = pygame.display.set_mode(bg_size)
- pygame.display.set_caption("感染模拟器")
- backgruond = pygame.image.load(bg_image).convert_alpha()
- balls = []
- #输入的变量
- for i in range(2):
- position = randint(0, width-96), randint(0, height-96)
- speed = [randint(-10, 10), randint(-10, 10)]
- ball = Ball(ball_image, position, speed)
- balls.append(ball)
- clock = pygame.time.Clock()
-
- while running:
- for event in pygame.event.get():
- if event.type == QUIt:
- sys.exit()
- screen.blit(background (0, 0))
- for each in balls:
- screen.blit(each.image, each.rect)
- pygame.display.flip()
- clock.tick(30)
- if __name__ == "__main__":
- main()
复制代码 |
|