Code: Alles auswählen
class Bullet(pygame.sprite.Sprite):
def __init__(self, *groups):
Sprite.__init__(self, *groups)
self.image = pygame.image.load('images/baz.png')
self.rect = self.image.get_rect()
self.damage = 1
def update(self):
self.rect.x += 4
...
elif event.key == pygame.K_SPACE:
print(pygame.mouse.get_pos())
bullet = Bullet(sprites)
bullet.rect.x = player.rect.right - bullet.rect.width
bullet.rect.y = player.rect.y
bullets.add(bullet)
...
Code: Alles auswählen
import math
class Vector(object):
def __init__(self, x, y):
self.diff = (y[0] - x[0], y[1] - x[1])
print(self.diff)
def distance(self):
self.a = self.diff[0]
self.b = self.diff[1]
return math.sqrt(self.a**2 + self.b**2)
def unit(self):
distance = self.distance()
self.a_unit = self.a/distance
self.b_unit = self.b/distance
return self.a_unit, self.b_unit
x = (20.0, 25.0)
y = (40.0, 55.0)
thing = Vector(x, y)
print thing.distance()
print thing.unit()