游戏编程基础day8

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)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值