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)