import pygame
import time
# 遊戲初始化
pygame.init()
# 設置窗口大小 640長度 窗口寬度500
screen = pygame.display.set_mode((640, 500))
# 設置窗口標題
pygame.display.set_caption("坦福版接球遊戲")
# 文字1. 設置文字字體和大小
font = pygame.font.SysFont("SimHei", 35)
a = 200
b = 200
board_x = 400
board_y = 320
speedy = 1
speedx = 1
while 1 < 100:
# 事件:我們對電腦的物理操作,按鍵,鼠標(按鍵,移動)
for event in pygame.event.get():
# print(event)
if event.type == pygame.QUIT:
pygame.quit() # 退出遊戲
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_a:
board_x = board_x - 10
if event.key == pygame.K_d:
board_x = board_x + 10
elif event.type == pygame.MOUSEMOTION:
board_x,board_y = event.pos
screen.fill((0, 0, 0))
b = b + speedy
a = a + speedx
if a > 640:
speedx = -1
elif a< 0:
speedx = 1
if b > 640:
b = 0
if b < 0:
speedy = 1
if board_x< a<board_x + 200 and board_y < b < board_y+10:
speedy = -1
# 畫小球:屏幕,rgb三基色,座標,半徑
pygame.draw.circle(screen,(200,200,200),(a,b), 23)
# time.sleep(1)
# 畫一個長方形 pygame.draw.rect(屏幕,(r,g,b),(經度,維度,板長,板寬))
pygame.draw.rect(screen,(105,105,150),(board_x,board_y,200,10))
# 2.設置文字的內容和顏色
font2 = font.render("蔡徐坤", True, (0,255,0))
# 3.把文字放在窗口上
screen.blit(font2, (100,100))
# 刷新
pygame.display.update()
aden -接球遊戲3.0
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.