Created
July 25, 2016 09:21
-
-
Save dazsim/1d05a0272e3df45d9e7f2f7b43c1ebe3 to your computer and use it in GitHub Desktop.
coding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
c = CollisionBox(32,32) | |
def RocketMan(self): | |
RocketMan.x = 320 | |
RocketMan.y = 200 | |
RocketMan.lastx = 320 | |
RocketMan.lasty = 200 | |
class Collider: | |
"""has Collision checks between entities like rocketman and objects in the | |
world""" | |
class CollisionBox: | |
"""this class deals with collision boxes like the rocketman and | |
walls/floors""" | |
x1,y1 = 0,0 #This is the position of the box | |
x2,y2 = 0,0 #This is the size of the box | |
def __init__(self,x,y): | |
self.x1 = 0 | |
self.y1 = 0 | |
self.x2 = x | |
self.y2 = y | |
def UpdatePos(self,x,y): | |
self.x1 = x | |
self.y1 = y | |
#This function should be called twice with self and target swapped to | |
#running into avoid edge cases where self is entirely big enough to engulf | |
#target | |
def Collide(self,target): | |
if self.x1>target.x1: | |
if self.x1<(target.x1+target.x2): | |
#handle top left corner | |
if self.y1>target.y1: | |
if self.y1<(target.y1+target.y2): | |
return True#top left corner is inside box | |
#handle bottom left corner | |
if (self.y1+self.y2)>target.y1: | |
if (self.y1+self.y2)<(target.y1+target.y2): | |
return True | |
if (self.x1+self.x2)>target.x1: | |
if (self.x1+self.x2)<(target.x1+target.x2): | |
#handle top left corner | |
if self.y1>target.y1: | |
if self.y1<(target.y1+target.y2): | |
return True#top left corner is inside box | |
#handle bottom left corner | |
if (self.y1+self.y2)>target.y1: | |
if (self.y1+self.y2)<(target.y1+target.y2): | |
return True | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment