vendredi 17 juin 2016

Moving sprites by vectors

I want to move some sprites for my Pygame over the display. Its a given route and I want to move them with vectors. So I got the positions of my route and so I got the magnitude and the heading. You can see the formulas and how I want to change the way of the spirts (with "if"). I put the vectors in tuples and I think thats not correctly. I get an error

TypeError: can't multiply sequence by non-int of type 'float' line 51

I think that is the way I mutliply the tuples. But I hope you get my idea behind this and you can help me

clock = pygame.time.Clock()

speed = 25.
position = (30.0,50.0)
magnitude = [509, 141, 128, 409, 293, 330, 251, 532]
heading = [(0.7,0.73),(0.71,0.71),(0.78,0.63),(-0.52,0.65),(0.97,0.24),(0.58,-0.82),(-0.88,-0.48),(0.08,-0.99)]





while True:

for event in pygame.event.get():
    if event.type == QUIT:
        exit()

screen.blit(background, (0.0,0.0))
screen.blit(lachmann, position)
screen.blit(oertel, (300,30))
screen.blit(festerling, (500,30))
screen.blit(tonnenanwalt,(800,30))

time_passed = clock.tick()
time_passed_seconds = time_passed / 1000.0



route = time_passed_seconds * speed
position += heading * route

if route == magnitude[0]:
      route1 = time_passed_seconds * speed
      position += heading[1] * route1
      if route == magnitude[1]:
          route2 = time_passed_seconds * speed

Aucun commentaire:

Enregistrer un commentaire