MCPcopy Index your code
hub / github.com/geekcomputers/Python / checkSlabCollision

Method checkSlabCollision

PingPong/Ball.py:35–46  ·  view source on GitHub ↗
(self, slabPos)

Source from the content-addressed store, hash-verified

33 self.pos = [self.pos[0] + self.vel[0], self.pos[1] + self.vel[1]]
34
35 def checkSlabCollision(self, slabPos): # slab pos = [xmin, ymin, xmax, ymax]
36 if (
37 self.pos[0] + self.rad > slabPos[0]
38 and self.pos[0] - self.rad < slabPos[2]
39 and self.pos[1] + self.rad > slabPos[1]
40 and self.pos[1] - self.rad < slabPos[3]
41 ):
42 # Handle collision here (e.g., reverse ball's direction)
43 if self.pos[0] < slabPos[0] or self.pos[0] > slabPos[2]:
44 self.vel[0] *= -1
45 if self.pos[1] < slabPos[1] or self.pos[1] > slabPos[3]:
46 self.vel[1] *= -1

Callers 1

main.pyFile · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected