飞机大战制作笔记4

1.显示分数(显示特殊文字方法)
Font方法:(用于载入字体,一般写在游戏主循环外)
score_font = pygame.font.Font("font/font.ttf", 36) ##括号的第一个参数是字体的路径(ttf格式),第二的参数是字体的大小

render方法:(把字体(text)变成surface对象,一般写在有序主循环内)
score_text = score_font.render("Score : %s" % str(score), True,WHITE)  ##第一个参数是text(以字符串的形式),第二个参数是"是否消除锯齿",第三个参数是字体颜色


2.暂停按钮

#游戏暂停按钮
paused = False
paused_nor_image = pygame.image.load("Images/shoot/game_pause_nor.png").convert_alpha() #载入浅色暂停按钮
paused_pressed_image = pygame.image.load("Images/shoot/game_pause_pressed.png").convert_alpha()	#载入深色暂停按钮
resume_nor_image = pygame.image.load("Images/shoot/game_resume_nor.png").convert_alpha() #载入浅色开始按钮
resume_pressed_image = pygame.image.load("Images/shoot/game_resume_pressed.png").convert_alpha() #载入深色开始按钮
paused_rect = paused_nor_image.get_rect() #获取图片矩形位置
paused_rect.left, paused_rect.top = width - paused_rect.width - 10, 10
paused_image = paused_nor_image #pause按钮的默认初始状态
	
	
...while中...
    for event in pygame.event.get():
			
        ...
			
        elif event.type == MOUSEBUTTONDOWN:
             if event.button == 1 and paused_rect.collidepoint(event.pos):
                 paused = not paused

        elif event.type == MOUSEMOTION:
            if paused_rect.collidepoint(event.pos): #判断鼠标的位置是否在paused_rect这个位置上,如果是就显示“深 色”图标
                if paused:
                    paused_image = resume_pressed_image #如果在暂停的情况下,图片变成“深 色 继 续”图片
                else:
                    paused_image = paused_pressed_image #如果在继续的情况下,图片变成“深 色 暂 停”图片
            else: #如果鼠标没在paused_rect上方的话,就显示 “浅 色” 图标
                if paused:
                    paused_image = resume_nor_image
                else:
                    paused_image = paused_nor_image						
		...
	
     #绘制暂停按钮
     screen.blit(paused_image, paused_rect)


3.难度的设置
在游戏主循环中,通过对玩家得分进行简单的if...else...判断即可实现

4.全屏炸弹

炸弹图片载入

爆炸效果:清除正在屏幕中的飞机



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章