Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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