def checkCollision(self):
for entity in self.Entities:
ox = entity.x
oy = entity.y
for block in self.Blocks:
if block.y < entity.y and entity.y < block.y + block.size:
if (entity.x < block.x and block.x < entity.x+entity.width) or (entity.x+entity.width > block.x+block.size and block.x+block.size > entity.x):
print ("Hit Bottom")
entity.tpEntity(ox, oy+0.5)
elif entity.y < block.y and block.y < entity.y+entity.height:
if (entity.x < block.x and block.x < entity.x+entity.width) or (entity.x+entity.width > block.x+block.size and block.x+block.size > entity.x):
print ("Hit Top")
entity.tpEntity(ox, oy-self.gravity)
elif entity.x < block.x and block.x < entity.x+entity.width:
if (block.y < entity.y and entity.y < block.y + block.size) or (entity.y < block.y and block.y < entity.y+entity.height):
print("Hit Left")
entity.tpEntity(ox-0.5,oy)
elif entity.x+entity.width > block.x+block.size and block.x+block.size > entity.x:
if (block.y < entity.y and entity.y < block.y + block.size) or (entity.y < block.y and block.y < entity.y+entity.height):
print("Hit Right")
entity.tpEntity(ox+0.5,oy)
i have this odd bug, if i walk to a wall, it always registers it as if its on top of it. can anyone explain to me why this happens, and how i should/could fix it? Thank you :)
EDIT: The self.gravity variable is the gravity on the planet/map, as its supposed to be diffrent on each planet/map. By default(here) its on 0.2.
item.x + item.width
can be simplified and made much more readable and understandable so you can easily identify your problem. any rect object has attributes for topleft, topright, bottomleft, etc. Check out the rect page pygame.org/docs/ref/rect.html – Keatinge