Skip to content

lucthienphong1120/collision-pygame

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Collision Pygame

Collision Pygame library

How to use

import collision

Functions

# collision between two square objects
collision.rectCollision(rect1, rect2)

# collision between two circular objects
collision.circleCollision(center1, radius1, center2, radius2)

# collision between any two objects
collision.objCollision(surf1, pos1, surf2, pos2)

Principles

Rectangle

# x1 = x
# y1 = y
# x2 = x + width
# y2 = y + height

# x1 of rect1 is smaller x2 of rect2
# x1 of rect2 is smaller x2 of rect1
# y1 of rect1 is smaller y2 of rect2
# y1 of rect2 is smaller y2 of rect1

# rect = [x, y, width, height]

Circle

# distance between two centers is less than the sum of the two radii

# center = [x, y]
# radius = r

OBJECT

# collision between any two shapes
# check if obj1's position corresponds to obj2

# surf = surface
# pos = [x, y]

About

Collision Pygame library

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages