Created
May 2, 2018 23:56
-
-
Save pathunstrom/0b09eac634bf36966b7bb4fbd86236db to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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