1. 程式人生 > >12月1日課堂筆記及作業

12月1日課堂筆記及作業

課前回顧
eg:申明變數age,為age賦值自己的年齡,並且打印出來
age = 18
print(age)

計算機英語
font 字型 render 表達

本週知識點
pygame.font.SysFont() 方法
-設定遊戲中的字型和字型大小的方法
-pygame 工具箱
-font 工具
-SysFont() 需要怎麼使用工具

課堂練習
while True:
#建立變數tf設定文字的字型和大小
tf = pygame.font.SysFont("微軟雅黑",40)
st = pygame.font.SysFont("宋體",50)
hello = tf.render('hello',False,(255,0,0))
#螢幕的傳輸方法
screen.blit(hello,(200,200))
# 更新螢幕內容
pygame.display.update()
#處理關閉遊戲
handleEvent()

while True:
screen.blit(bg, (0, 0))
#設定文字的字型和大小
tf = pygame.font.SysFont('幼圓',50)
#在背景中新增生命值
life = tf.render("LIFE:99",True,(255,0,0))
screen.blit(life,(350,5))
#在背景中新增分數
score = tf.render("SCORE:100000",False,(0,255,0))
screen.blit(score,(10,5))
# 更新螢幕內容
pygame.display.update()
#處理關閉遊戲
handleEvent()

作業:設定紅色的hello和綠色的python傳輸到螢幕上.

while True:
#繫結文字設定字型及大小
tf = pygame.font.SysFont("微軟雅黑",40)

#繫結hello變數
hello = tf.render("hello",False,(255,0,0))

#傳輸hello到螢幕
screen.blit(hello,(300,200))
#繫結python 變數
python =tf.render("python",True,(0,255,0))
#傳輸python 到螢幕
screen.blit(python,(300,300))
# 更新螢幕內容
pygame.display.update()
#處理關閉遊戲
handleEvent()