<reponame>chivitc1/pygamedemo
import pygame, sys
from gameobjects.vector2 import Vector2

size = w, h = 640, 320
pygame.init()
screen = pygame.display.set_mode(size, 0, 32)
background = pygame.image.load('images/sushiplate.jpg').convert()
sprite = pygame.image.load('images/intro_ball.gif').convert_alpha()
clock = pygame.time.Clock()

rect_color = 0, 255, 0
rect_size = 40, 40

position = Vector2(100.0, 100.0)
speed = 250 # pixel / second
heading = Vector2()

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()
        if event.type == pygame.MOUSEBUTTONDOWN:
            destination = Vector2(*event.pos) - (Vector2(*sprite.get_size())/2)
            heading = Vector2.from_points(position, destination)
            heading.normalize()

    screen.blit(background, (0, 0))
    screen.blit(sprite, (position.x, position.y))
    # pygame.draw.rect(screen, rect_color, pygame.Rect((x, y), rect_size))

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

    distance_moved = time_passed_seconds * speed
    position += heading * distance_moved

    pygame.display.flip()
    # pygame.time.wait(10)
import pygame, sys
from gameobjects.vector2 import Vector2

size = w, h = 640, 320
pygame.init()
screen = pygame.display.set_mode(size, 0, 32)
background = pygame.image.load('images/sushiplate.jpg').convert()
sprite = pygame.image.load('images/intro_ball.gif').convert_alpha()
clock = pygame.time.Clock()

rect_color = 0, 255, 0
rect_size = 40, 40

position = Vector2(100.0, 100.0)
speed = 250 # pixel / second
heading = Vector2()

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()
        if event.type == pygame.MOUSEBUTTONDOWN:
            destination = Vector2(*event.pos) - (Vector2(*sprite.get_size())/2)
            heading = Vector2.from_points(position, destination)
            heading.normalize()

    screen.blit(background, (0, 0))
    screen.blit(sprite, (position.x, position.y))
    # pygame.draw.rect(screen, rect_color, pygame.Rect((x, y), rect_size))

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

    distance_moved = time_passed_seconds * speed
    position += heading * distance_moved

    pygame.display.flip()
    # pygame.time.wait(10)
# pixel / second # pygame.draw.rect(screen, rect_color, pygame.Rect((x, y), rect_size)) # pygame.time.wait(10)