两个矩形碰撞原理演示程序_跟随鼠标移动的矩形

"""
   两个矩形碰撞原理演示程序_跟随鼠标移动的矩形.py
"""
import pygame
from pygame.locals import *

WIDTH,HEIGHT = 480,360
screen = pygame.display.set_mode((WIDTH,HEIGHT))

r1 = pygame.Rect(0,0,100,100)
r1.center = (WIDTH//2,HEIGHT//2) # r1在屏幕中央,宽高为100

r2 = pygame.Rect(0,0,50,50)      # r2先在左上角的位置

running = True
while running :
    event = pygame.event.poll()  # 从事件队列中取一个事件
    if event.type == QUIT:running = False

    x,y = pygame.mouse.get_pos()
    r2.center = x,y              # 跟随鼠标移动的矩形

You must log in to read the rest of this article. Please log in or register as a user.