"""
Pygame 模板程式
"""
# 匯入pygame模組
import pygame
# 定義一些會用到的顏色
# 常數使用大寫
BLACK = ( 0, 0, 0)
WHITE = ( 255, 255, 255)
GREEN = ( 0, 255, 0)
RED = ( 255, 0, 0)
SKIN_COLOR = (247, 208, 160)
NOSE_COLOR = (198, 171, 135)
def face():
pygame.draw.ellipse(screen,SKIN_COLOR,(200,50,300,450))
def left_eye():
pygame.draw.ellipse(screen,WHITE,(230,160,100,50))
def right_eye():
pygame.draw.ellipse(screen,WHITE,(370,160,100,50))
def left_eye_ball():
pygame.draw.ellipse(screen,BLACK,(265,170,20,30))
def right_eye_ball():
pygame.draw.ellipse(screen,BLACK,(410,170,20,30))
def nose():
pygame.draw.polygon(screen,NOSE_COLOR,[[350, 250], [325,300], [375, 300]])
def mouth():
pygame.draw.arc(screen,RED, (300,350,250,100), 50, 80,1)
# 初始化pygame
pygame.init()
# 創造一個pygame視窗並設定大小及標題
size = (700, 500)
screen = pygame.display.set_mode(size)
pygame.display.set_caption("我的遊戲")
# 設定一個開關供迴圈使用
done = False
# 創造一個clock控制畫面更新速度
clock = pygame.time.Clock()
# -------- 主要的程式迴圈 -----------
while not done:
# --- 事件迴圈 event loop
for event in pygame.event.get(): # 從事件list中抓取事件
if event.type == pygame.QUIT: # 當使用者按下結束
done = True # 將done變數設為True-->while迴圈將會結束
# --- 程式的運算與邏輯
# --- 繪圖的程式碼
# 先將畫面塗滿底色(將原有畫面清掉)
# 繪圖的程式要寫在這行後面,不然會被這行清掉
screen.fill(WHITE)
face()
left_eye()
right_eye()
left_eye_ball()
right_eye_ball()
nose()
mouth()
pygame.display.flip()
# --- 每秒鐘60個frame
clock.tick(60)
# 關閉式窗並離開程式
pygame.quit()