0

Is there an algorithm to change a set of coordinates to make it move towards another set of coordinates? Like, if I have ax,ay=(20,30) a

#fonctions 
import pygame, sys
from pygame.locals import *
pygame.init()
fpsClock = pygame.time.Clock()
windows= pygame.display.set_mode((1200,500), 0, 32)
pygame.display.set_caption('testing')

size = width, height = (32, 32)
PNGImg = pygame.Surface(size)

sob_X=575
sob_Y=250
FPS = 15 # frames per second setting
RED= (255, 0, 0)  #red color

while True:
    windows.fill((54, 141, 197))     
    pygame.draw.circle(windows, RED, (70, 80), 20, 0)
    windows.blit(PNGImg, (sob_X,sob_Y))

    dis_X=sob_X-600 #cicle X_Cordinate
    dis_Y=sob_X-870  #cicle Y_Cordinate
    if dis_X<0:
        sob_X=sob_X+ dis_X
        if sob_X==70 and dis_Y<0:
            sob_Y=sob_X+dis_Y
        elif sob_X==70 and dis_Y>0:
                sob_Y=sob_Y-dis_Y
    elif dis_X>0:
        sob_X=sob_X -dis_X
        if sob_X==70 and dis_Y<0:
            sob_Y=sob_Y+dis_Y
        elif sob_X==70 and dis_Y>0:
            sob_Y=sob_Y-dis_Y

    windows.blit(PNGImg, (sob_X,sob_Y))
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
    pygame.display.update()
    fpsClock.tick(FPS)



pygame.quit()

nd bx,by=(40,60)

How can I change ax and ay (coordinate of the image"surface") to equal bx and by? (Preferably an algorithm achievable in python.) i tried to make algorithme but in the end don't work thanks you

  • Does this answer your question? [Pygame: Move object towards position](https://stackoverflow.com/questions/19747856/pygame-move-object-towards-position) – Matiiss Jul 06 '23 at 09:23

1 Answers1

0

Replying here as I can't comment yet, but from the question itself, do you mean to do ax, ay = bx, by ? You can simply do that, or even individual ones like ax = by.

With an example from the terminal:

>>> ax,ay=(20,30)
>>> bx,by=(40,60)
>>> ax, ay = bx, by
>>> ax, ay
(40, 60)
Andre
  • 47
  • 7