import pygame.freetype import sys import random pygame.init() screen = pygame.display.set_mode((640, 400)) pygame.display.set_caption('接苹果升级版') p = 0 i1 = 0 s = 0 t = 0 f1 = pygame.freetype.Font('C:/windows/fonts/msyh.ttc', 100) f2 = pygame.freetype.Font(None, 30) img = pygame.image.load("D:/py/view/res/ball.png") img = pygame.transform.scale(img, (30, 30)) wnd = pygame.display.set_mode((640, 400)) bg = pygame.image.load("./res/dusk.png") l = [] while True: pygame.time.delay(20) for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() elif event.type == pygame.MOUSEBUTTONDOWN: if p == 0: t = 0 p = 1 screen.fill((255, 255, 255)) if p == 0: wnd.blit(bg, (0, 0)) f1.render_to(screen, [120, 100], '开始游戏') if p == 1: i1 += 1 if i1 >= 50//(int(t/30)+1): i1 = 0 if t < 200: t += 1 l.append([random.randint(50, 520), 50]) if t == 200 and not l: p = 2 for i in l: screen.blit(img, [i[0], i[1]]) i[1] += int(t/30)+1 x = pygame.mouse.get_pos()[0] if x < 40: x = 40 if x > 560: x = 560 pygame.draw.rect(screen, (60, 150, 250), (x-40, 320, 80, 20)) for i in l: if i[1] >= 300: if x-70 <= i[0] <= x+40: s += 1 l.remove(i) f2.render_to(screen, [30, 30], 'score:%d' % s) if p == 2: f1.render_to(screen, [80, 130], 'score:%d' % s) pygame.display.update()改变字体大小
时间: 2023-12-26 20:04:56 浏览: 237
import random.py
这段代码中并没有修改字体大小的代码。如果你想修改字体大小,你可以使用`pygame.freetype.Font`中的`set_size`方法来设置字体大小。例如,要将字体大小设置为60,你可以这样做:
```
f1.set_size(60)
```
这将会修改`f1`这个字体对象的大小为60。你可以在适当的地方调用这个方法以修改字体大小。
阅读全文