Drawing a line using Pygame
I'm realising I badly need to brush up on my maths if I'm going to do game stuff, but would appreciate some help on this atm.
I'm trying to draw a line in pygame from the bottom corner of this rectangle to the "e" point. The line will represent the distance and angle between the mouse cursor position when it was pressed down "s" and released "e". The line should be drawn relative to the rectangle, regardless of where the click started and ended on the screen. This is what I've got so far, but it seems convoluted and I don't think I've got the equation right. Any guidance?
if pg.mouse.get_pressed()[0] == True:
pg.draw.line(self.screen, BLACK, self.player.rect.bottomleft, (self.player.rect.bottomleft[1] + find_slope(self.player.rect.bottomleft, pg.mouse.get_pos()) * pg.mouse.get_pos()[0]- self.player.rect.bottomleft[0]), 2)
def find_slope(start, end):
a = start[1] - end[1]
b = start[0] - end[0]
return np.divide(a,b)
0 comments · 76% upvoted · other discussions