Rect類擁有的方法
clamp() 將矩形移動到另一個矩形當中
move(x,y) 移動矩形 xy 支持數字類型
使用方法跟屬性 目的:爲了簡便我們對圖形進行操作
第一個小遊戲—動感火車
import pygame
import time
import math
pygame.init()
screen_obj = pygame.display.set_mode((600,700))
screen_obj.fill((255,255,255))
pygame.display.set_caption('無敵碰碰球')
#pygame.draw.circle(screen_obj,(237,217,180),(300,60),60)
pygame.display.flip()
circle_y = 60
circle_x=60
speed_y = 1
speed_x=0
num=1
fps = 60
t = pygame.time.Clock()
while 1:
num += 1
t.tick(fps)
pygame.draw.circle(screen_obj,(255,255,255),(circle_x, circle_y), 60)
circle_x += speed_x
circle_y += speed_y
pygame.draw.circle(screen_obj,(237,217,180), (circle_x, circle_y), 60)
if (circle_y==640 and circle_x==60) :
# speed = -1
# 設置一下讓他向右走
speed_x=1
speed_y=0
elif (circle_y == 60 and circle_x==60):
speed_y = 1
speed_x=0
elif (circle_y==640 and circle_x==540):
speed_x=0
speed_y=-1
elif (circle_y==60 and circle_x==540):
speed_x=-1
speed_y=0
pygame.display.update()
屏幕刷新率
創建 時鐘對象
t=pygame.time.CLock()
時鐘對象調用tick()方法
t.tick(fps)