Ball.py
ball.py
—
Python Source,
1 KB (1284 bytes)
Dateiinhalt
from visual import *
from bricks import *
widthr = 14.125+10
heightd = 7.875
widthl = -widthr+20
heightu = -heightd
class ball(frame):
def __init__(self):
frame.__init__(self)
self.body = sphere(frame=self, pos = (-10,0,0), radius=0.2, color = color.white, material = materials.emissive)
self.v = vector(1,0,0) #Richtungsvektor
self.speedb = 0.05
def collision(self, player, world):
if (self.pos.y >= heightd or self.pos.y <= heightu):
self.v.y = -self.v.y
if (self.pos.x >= widthr or self.pos.x <= widthl-25):
self.v.x = -self.v.x
if (self.x > widthl):
if (self.v.x<0 and (self.pos.x <= widthl+0.5 and (self.y > player.y-((player.body.height/2)) and self.y < player.y+((player.body.height/2))))):
self.v.x = -self.v.x
self.v = self.v + vector(0,((self.pos.y-player.y)*0.2),0)
self.v = self.v * (1/sqrt((self.v.x)*(self.v.x)+(self.v.y)*(self.v.y)))
self.pos += self.v * self.speedb
for brick in world.bricklist:
if(math.fabs((self.pos.x - 10) - brick.x_) < 0.8 and math.fabs((-self.pos.y) + brick.y_) < 0.8):
self.v.x = -self.v.x
brick.hit()
break