美文网首页
pygame绘图应用-Pie Game

pygame绘图应用-Pie Game

作者: 进击的鸭子 | 来源:发表于2017-07-01 01:47 被阅读0次

结合上一章应用pygame绘图的知识点,做一个简单的小游戏开发。Pie游戏,是一款非常简单的游戏,没有什么难度,但是又有几本的游戏逻辑,玩家任意顺序按下的键盘1、2、3、4随着按下去的键来绘制或隐藏相应的饼块。

#pie game
import pygame
from pygame.locals import *
import sys
import math

pygame.init()
screen = pygame.display.set_mode((600,500))
pygame.display.set_caption("Pie Game")

#color && font
font_color = 255,255,255
bg_color = 0,0,200
line_color = 255,255,200
myfont = pygame.font.Font(None,60)

#position && radius
pos_x = 300
pos_y = 250
radius = 200
position = pos_x - radius,pos_y - radius,radius*2,radius*2
line_width = 4
arc_width= 4

piece1 = False
piece2 = False
piece3 = False
piece4 = False

while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            sys.exit()
        elif event.type == KEYUP:
            if event.key == pygame.K_ESCAPE:
                sys.exit()
            elif event.key == pygame.K_1:
                if piece1:
                    piece1 = False
                else:
                    piece1 = True
            elif event.key == pygame.K_2:
                if piece2:
                    piece2 = False
                else:
                    piece2 = True
            elif event.key == pygame.K_3:
                if piece3:
                    piece3 = False
                else:
                    piece3 = True
            elif event.key == pygame.K_4:
                if piece4:
                    piece4 = False
                else:
                    piece4 = True

            screen.fill(bg_color)
            # draw font

            
            #draw Arc
            if piece1:
                pygame.draw.line(screen,line_color,(pos_x,pos_y),(pos_x,pos_y-radius),line_width)
                pygame.draw.line(screen,line_color,(pos_x,pos_y),(pos_x+radius,pos_y),line_width)
                pygame.draw.arc(screen,line_color,position,math.radians(0),math.radians(90),arc_width)
                textImage1 = myfont.render("1",True,font_color)
                screen.blit(textImage1,(pos_x+radius/2,pos_y-radius/2))
            if piece2:
                pygame.draw.line(screen,line_color,(pos_x,pos_y),(pos_x,pos_y-radius),line_width)
                pygame.draw.line(screen,line_color,(pos_x,pos_y),(pos_x - radius,pos_y),line_width)
                pygame.draw.arc(screen,line_color,position,math.radians(90),math.radians(180),arc_width)
                textImage2 = myfont.render("2",True,font_color)
                screen.blit(textImage2,(pos_x - radius/2,pos_y-radius/2))
            if piece3:
                pygame.draw.line(screen,line_color,(pos_x,pos_y),(pos_x-radius,pos_y),line_width)
                pygame.draw.line(screen,line_color,(pos_x,pos_y),(pos_x,pos_y+radius),line_width)
                pygame.draw.arc(screen,line_color,position,math.radians(180),math.radians(270),arc_width)
                
                textImage3 = myfont.render("3",True,font_color)
                screen.blit(textImage3,(pos_x - radius/2,pos_y+radius/2))
            if piece4:
                pygame.draw.line(screen,line_color,(pos_x,pos_y),(pos_x,pos_y+radius),line_width)
                pygame.draw.line(screen,line_color,(pos_x,pos_y),(pos_x+radius,pos_y),line_width)
                pygame.draw.arc(screen,line_color,position,math.radians(270),math.radians(360),arc_width)
                textImage4 = myfont.render("4",True,font_color)
                screen.blit(textImage4,(pos_x+radius/2,pos_y+radius/2))
            
            #refresh
            pygame.display.update()
            
            
            

效果:

屏幕快照 2017-07-01 上午1.47.13.png

相关文章

  • pygame绘图应用-Pie Game

    结合上一章应用pygame绘图的知识点,做一个简单的小游戏开发。Pie游戏,是一款非常简单的游戏,没有什么难度,但...

  • PYGAME EXAMPLE

    Pie Game import mathimport pygameimport sysfrom pygame.lo...

  • alphabet input game

    pygame for alphabet input game common process for random ...

  • Mac pygame踩坑(1)

    初次使用pygame实现绘图功能就踩坑 直接上代码 import pygame pygame.init() # 创...

  • day 11

    01 pygame 事件 02 pygame 鼠标事件 03 py game键盘事件 04 动画效果 05 多球效果

  • 2019-05-05《R语言绘图》之饼图 Pie Charts

    《R语言绘图》之饼图 Pie Charts 自学笔记 语法:pie(x, labels = names(x), e...

  • pygame事件

    pygame事件 鼠标事件的应用 pygame动画 ballgame 小球游戏

  • pygame初识-绘图

    在上一章中已经向大家介绍了pygame的开发基础,了解怎么安装pygame并且熟悉了一下它的窗口程序创建,接下来,...

  • pygame应用

    一、pygame事件 二、鼠标键盘应用 效果如下: 三、鼠标事件应用2 要求:先在屏幕上显示一张图片,鼠标按下移动...

  • 学习笔记----python绘图pie

    # python 绘制饼状图 #-*- coding:utf-8 –*- import matplotlib.py...

网友评论

      本文标题:pygame绘图应用-Pie Game

      本文链接:https://www.haomeiwen.com/subject/fakwcxtx.html