pygame module - pie game

main.py

import sys
import pygame
from pygame.locals import *
from draw_circle4 import draw_circle4

pygame.init()
# 设置屏幕大小
screen = pygame.display.set_mode((1200, 800))
# 设置字体
myFont = pygame.font.Font(None, 60)

# 颜色信息
forum_gold = 255, 227, 132
light_yellow = 255, 222, 179
deep_dark = 41, 36, 33
white = 255, 255, 255
blue = 0, 0, 255

# 公共参数
width = 10

# 圆的参数
center_circle = 300, 500
radius = 80

# 方形的参数信息
center_square = 0, 500
pos_x = 0
pos_y = 500
vel_x = 0.2
vel_y = 1
# .render()三个参数:渲染的文本、是否抗锯齿,颜色
# textImage = myFont.render("Ruthless Defender", False, deep_dark)

# 动作状态
action_flag = 0

while True:
    for event in pygame.event.get():
        # if event.type in (QUIT, KEYDOWN) or event.type == KEYDOWN and event.key == K_SPACE:
        if event.type == QUIT:
            sys.exit()
        elif event.type == KEYDOWN and event.key == pygame.K_1 and action_flag == 0:
            action_flag = 1
        elif event.type == KEYDOWN and event.key == pygame.K_2 and action_flag == 1:
            action_flag = 2
        elif event.type == KEYDOWN and event.key ==pygame.K_3 and action_flag == 2:
            action_flag = 3
        elif event.type == KEYDOWN and event.key ==pygame.K_4 and action_flag == 3:
            action_flag = 4
    pos_x += vel_x
    if pos_x >= 1050 or pos_x <= 0:
        vel_x = -vel_x
    pos = pos_x, pos_y, 150, 100
    screen.fill(light_yellow)
    # screen.blit(textImage, (400, 0))
    # pygame.draw.circle(screen, deep_dark, center_circle, radius, width)
    # pygame.draw.rect(screen, deep_dark, pos, width)
    draw_circle4(screen, deep_dark, width, action_flag)
    if action_flag == 4:
        draw_circle4(screen, blue, width, action_flag)
    pygame.display.update()


draw_circle4

import pygame
import math
def draw_circle4(screen, deep_dark, width, action_flag):
    # 弧的参数
    arc_pos = 450, 250, 300, 300
    start_angle = math.radians(0)
    end_angle = math.radians(90*action_flag)
    # 线的参数
    start_poi1 = 600 - 1 / 2 * width, 400
    start_poi2 = 600, 400 + 1 / 2 * width
    if action_flag == 0:
        width = 0
    elif action_flag == 1:
        width = 10
    elif action_flag == 2:
        start_poi1 = 450, 400
    elif action_flag > 2:
        start_poi2 = 600, 550
        start_poi1 = 450, 400
    end_poi1 = 750, 400
    end_poi2 = 600, 250
    # 文字的参数
    text = [1, 2, 3, 4]
    position = [(650, 325), (550, 325), (550, 475), (650, 475)]
    myFont = pygame.font.Font(None, 60)
    for i in range(4):
        textImage = myFont.render(str(text[i]), False, deep_dark)
        screen.blit(textImage, position[i])
    # 进行绘制
    pygame.draw.line(screen, deep_dark, start_poi1, end_poi1, width)
    pygame.draw.line(screen, deep_dark, start_poi2, end_poi2, width)
    pygame.draw.arc(screen, deep_dark, arc_pos, start_angle, end_angle, width)


猜你喜欢

转载自blog.csdn.net/Alexandra_Zero/article/details/132856425
pie