I am working on a school assignment where we are making “Asteroids” in processing.py
My school uses a slightly modified version of processing.py: for example, mouseX is mouse.x. I need help with my collision detection with the asteroids, which is off
class A:
def __init__(self, x, y, r, t, vel_x, vel_y):
self.cor, self.r, self.t, self.o, self.vel, self.f = PVector(x, y), r, t, [], PVector(vel_x, vel_y), False
self.o = [randint(-15, 15) for i in range(0, self.t)]
def drawObstacle(self):
noFill()
pushMatrix()
translate(self.cor.x, self.cor.y)
beginShape()
for i in range(0, self.t):
angle = map(i, 0, self.t, 0, pi * 2)
r = self.r + self.o[i]
vertex(r * cos(angle), r * sin(angle))
endShape(CLOSE)
popMatrix()
def moveObstacle(self):
self.cor.x, self.cor.y = self.cor.x + self.vel.x * 0.01, self.cor.y + self.vel.y * 0.01
if self.cor.x > width + self.r or self.cor.x < -self.r: self.vel.x = -self.vel.x
if self.cor.y > height + self.r or self.cor.y < -self.r: self.vel.y = -self.vel.y
for a in aList:
if (self.cor.x + self.r > a.cor.x - a.r and self.cor.x + self.r < a.cor.x + a.r and self.cor.y + self.r > a.cor.y - a.r and self.cor.y + self.r < a.cor.y + a.r):
self.vel.x, self.vel.y, a.vel.x, a.vel.y = -self.vel.x, -self.vel.y, -a.vel.x, -a.vel.y
def checkRemove(self):
if self.f:
if self.r > 15:
for i in range(-1, 1): aList.append(A(self.cor.x - i * self.r, self.cor.y + i * self.r, randint(5, int(self.r * 0.75)), int(self.r * 0.25), randint(-50, 50), randint(-50, 50)))