im trying to get this script to draw a line from the center of the rectangle to the mouse BUT i only want it to draw about 10 pixels out. how can i find that point that is 10 pixels(or points) out?
code so far:
import pygame
from pygame.locals import *
import math
pygame.init()
screen = pygame.display.set_mode((640, 480))
red = (255,0,0)
green = (0,255,0)
blue = (0,0,255)
darkBlue = (0,0,128)
white = (255,255,255)
black = (0,0,0)
pink = (255,200,200)
x = 5
y = 5
username = "Bob"
delta = 0
print len(username)
running = 1
while running:
for event in pygame.event.get():
if event.type == QUIT:
running = 0
#elif event.type == KEYDOWN and event.key == K_w:
#print "key"
#else:
#print event
#a = 1
keystate = pygame.key.get_pressed()
if keystate[K_w]:
y-=1
if keystate[K_d]:
x+=1
elif keystate[K_a]:
x-=1
elif keystate[K_s]:
y+=1
if keystate[K_d]:
x+=1
elif keystate[K_a]:
x-=1
elif keystate[K_a]:
x-=1
elif keystate[K_d]:
x+=1
screen.fill((120, 120, 120))
myfont = pygame.font.SysFont("monospace", 12)
label = myfont.render(username, 1, (255,255,0))
screen.blit(label, (x-(len(username)*3), y-12))
mouse = pygame.mouse.get_pos()
pygame.draw.rect(screen, red, (x,y,10,10), 0)
pygame.draw.line(screen, blue, [x+5,y+5], [mouse[0],mouse[1]])
pygame.display.flip()
pygame.quit()