VIDEO I wrote a script that allows these white squares to follow my mouse position depending on where the mouse is the idea is I want it to look like aiming dots where eventually the blue square would be able to move at that direction of where the dots are aimed towards and then fall back down but I want to make it better it seems a bit off right now and not accurate how would I improve it and also how would I then make the blue square get thrown towards that direction and fall back down
this is how it works I get the mouse position and when I click space if my mouse_y is less then 300 the dots x and y move up there at certain speed
mouse_x, mouse_y = pygame.mouse.get_pos() if keys[pygame.K_SPACE]: if mouse_y <= 300: dot1.x -= 2 dot1.y -= 3 dot2.x -= 4 dot2.y -= 4 dot3.x -= 5 dot3.y -= 5 dot4.x -= 6 dot4.y -= 6 dot5.x -= 7 dot5.y -= 7 if mouse_y >= 300: dot1.x += 2 dot1.y += 3 dot2.x += 4 dot2.y += 4 dot3.x += 5 dot3.y += 5 dot4.x += 6 dot4.y += 6 dot5.x += 7 dot5.y += 7 my full code
import pygamepygame.init()window = pygame.display.set_mode((500,500))# the playerclass player: def __init__(self,x,y,height,width,color): self.x = x self.y = y self.width = width self.height = height self.color = color self.rect = pygame.Rect(x,y,height,width) self.isJump = False self.JumpCount = 10 self.fall = 0 def draw(self): self.rect.topleft = (self.x,self.y) pygame.draw.rect(window,self.color,self.rect)color = (55,255,255)player1 = player(50,400,50,50,color)# the bottom rect the player collides withbottom1 = player(0,450,550,40,(145,215,15))# aiming dots classclass dots: def __init__(self,x,y,height,width,color): self.x = x self.y = y self.width = width self.height = height self.color = color self.rect = pygame.Rect(x,y,height,width) self.isJump = False self.JumpCount = 10 self.fall = 0 def draw(self): self.rect.topleft = (self.x,self.y) pygame.draw.rect(window,self.color,self.rect)color1 = (255,255,255)dot1 = player(100,370,20,20,color1)dot2 = player(165,340,20,20,color1)dot3 = player(235,310,20,20,color1)dot4 = player(300,300,20,20,color1)dot5 = player(365,320,20,20,color1)dots = [dot1,dot2,dot3,dot4,dot5]speed = 1# main looprun = Truewhile run: pygame.time.delay(50) for event in pygame.event.get(): if event.type == pygame.QUIT: run = False keys = pygame.key.get_pressed() mouse_x, mouse_y = pygame.mouse.get_pos() if keys[pygame.K_SPACE]: if mouse_y <= 300: dot1.x -= 2 dot1.y -= 3 dot2.x -= 4 dot2.y -= 4 dot3.x -= 5 dot3.y -= 5 dot4.x -= 6 dot4.y -= 6 dot5.x -= 7 dot5.y -= 7 if mouse_y >= 300: dot1.x += 2 dot1.y += 3 dot2.x += 4 dot2.y += 4 dot3.x += 5 dot3.y += 5 dot4.x += 6 dot4.y += 6 dot5.x += 7 dot5.y += 7 window.fill((28, 40, 51)) # player jumping # draw the player player1.draw() bottom1.draw() for dot in dots: dot.draw() pygame.display.update()pygame.quit()