Skip to content

Instantly share code, notes, and snippets.

@pathunstrom
Created May 2, 2018 23:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pathunstrom/0b09eac634bf36966b7bb4fbd86236db to your computer and use it in GitHub Desktop.
Save pathunstrom/0b09eac634bf36966b7bb4fbd86236db to your computer and use it in GitHub Desktop.
import time
import pygame
WHITE = 255, 255, 255
BLACK = 0, 0, 0
whole_note_image = pygame.Surface((20, 20))
whole_note_rect = whole_note_image.get_rect()
whole_note_image.fill(WHITE)
pygame.draw.circle(whole_note_image, BLACK, whole_note_rect.center, 10, 3)
class Note(pygame.sprite.Sprite):
def __init__(self, x, y):
super().__init__()
self.image = whole_note_image
self.rect = whole_note_image.get_rect()
self.x = x
self.y = y
self.speed = 50
def update(self, time_delta):
self.x += self.speed * time_delta
self.rect.center = int(self.x), int(self.y)
def main():
pygame.init()
display = pygame.display.set_mode((400, 400))
running = True
group = pygame.sprite.Group()
note = Note(200, 200)
group.add(note)
last_frame = time.time()
while running:
this_frame = time.time()
time_delta = this_frame - last_frame
last_frame = this_frame
for e in pygame.event.get():
if e.type == pygame.QUIT:
running = False
group.update(time_delta)
display.fill(WHITE) # Fill the background
group.draw(display)
pygame.display.update()
pygame.quit()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment