1 def show_menu(): 2 global game_state,screen 3 font_name = pygame.font.match_font('arial') 4 font = pygame.font.Font(font_name,40) 5 screen.blit(background_img3,background_rect) 6 7 # rect1 = pygame.draw.rect(screen,(255,255,255),(WIDTH/20,80, 550, 100), 10) 8 # screen.blit(font.render('SPACE SHOOTER',True,(0,255,0)), (150, 100)) 9 draw_text('SPACE SHOOTER',screen,(0,255,0),70,WIDTH/2,100) 10 rect2 = pygame.draw.rect(screen,(0,255,0),(WIDTH/7 + 80,350, 400, 50), 10) 11 screen.blit(font.render('Press Space key to start',True,(255,255,0)), (220, 350)) 12 rect3 = pygame.draw.rect(screen,(0,255,0),(WIDTH/7 + 80,450, 400, 50), 10) 13 screen.blit(font.render('Press Esc key to quit',True,(255,255,0)), (220, 450))
时间: 2024-04-28 19:23:57 浏览: 156
这段代码是用来显示游戏菜单的,使用了Python中的Pygame库。在第3行中,使用了match_font方法来获取字体名字,然后在第4行中创建了一个字体对象。在第5行中,使用blit方法将一张背景图片绘制到屏幕上。在第9行中,使用了自定义的draw_text函数将"SPACE SHOOTER"字样绘制到屏幕上。在第10和12行中,使用了draw.rect方法绘制了两个矩形框,并在里面分别绘制了"Press Space key to start"和"Press Esc key to quit"的字样。
阅读全文