I am trying to make a game similar to what is seen in google chrome when the internet is down for my A Level computer science course work. I have run into an issue regarding collision detection and any help would be greatly appreciated.
When i try to declare more than one platform to stop player movement (collision detection) all platforms stop stopping player movement. But when i have only one platform stopping player movement it will work.
All of my code is located here: https://github.com/VincenzoLaRoche/ComputerScienceCourseWork
Your problem is that your are handling the platforms completely separate. So if you stand on one, you are not touching the other one so it makes you fall. For this to stop, you have to modify the t1o player methods collision_detect
and do
like so:
def collision_detect(self, platform):
if self.x > platform.x and self.x < platform.x2:
if self.y + 40 == platform.y:
return True
else:
return False
def do(self):
self.keys()
self.move()
self.draw()
c1 = self.collision_detect(platform(0, 500, 800, 10))
c2 = self.collision_detect(platform(0, 480, 400, 10))
if c1 or c2:
self.yVel = 0
Constants.CANJUMP = True
else:
self.yVel = 5
Constants.CANJUMP = False
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments