Created
November 15, 2015 23:13
-
-
Save AndyNovo/df851ca4754c96489952 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 pygame | |
import random | |
BLACK = (0,0,0) | |
RED = (255, 0, 0) | |
WHITE = (255, 255, 255) | |
pygame.init() | |
WIDTH = 450 | |
HEIGHT = 600 | |
screen = pygame.display.set_mode([WIDTH, HEIGHT]) | |
another_loop = True | |
clock = pygame.time.Clock() | |
font = pygame.font.Font(None, 36) #Make a font | |
textx = 100 | |
texty = 400 | |
circle_x = 50 | |
circle_y = 50 | |
while another_loop: | |
# --- Basic Event Processing | |
for event in pygame.event.get(): | |
if event.type == pygame.QUIT: | |
another_loop = False | |
# Every loop we will wipe the screen and redraw images | |
screen.fill(BLACK) | |
text = font.render("Hi there", 1, WHITE) #Use font to generate text image | |
#Draw the new screen here: | |
screen.blit(text, (100, 100)) #stick that image on screen | |
screen.blit(text, (textx, texty)) #possibly in multiple places | |
textx = (textx + random.randint(-5, 5)) % WIDTH #make updates | |
texty = (texty + random.randint(-5, 5)) % HEIGHT | |
pygame.draw.circle(screen, RED, (circle_x, circle_y), 30) | |
if( pygame.key.get_pressed()[pygame.K_LEFT] != 0 ): | |
circle_x = (circle_x - 5) % WIDTH | |
if( pygame.key.get_pressed()[pygame.K_RIGHT] != 0 ): | |
circle_x = (circle_x + 5) % WIDTH | |
circle_y = (circle_y + 5) % HEIGHT | |
#This sets the frames per second | |
clock.tick(60) | |
#This puts the new stuff you've drawn on screen | |
pygame.display.flip() | |
#When we've left the while loop exit pygame | |
pygame.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment