Created
December 13, 2016 16:04
-
-
Save IanMcT/b6eee010bdf9cdd2016a03ce822c7dc4 to your computer and use it in GitHub Desktop.
sample animated rectangle
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 random, os.path | |
import pygame | |
from pygame.locals import * | |
SCREENRECT = Rect(0, 0, 370, 720) | |
class Ball: | |
def __init__(self): | |
self.location = (50,50,50,50) | |
self.y = 50 | |
def update(self): | |
self.y = self.y + 1 | |
print(self.y) | |
self.location = (self.location[0],self.y,self.location[2],self.location[3]) | |
print(self.location) | |
def draw(self,s): | |
pygame.draw.rect(s,(255,255,255), self.location) | |
def main(winstyle = 0): | |
# Initialize pygame | |
pygame.init() | |
bestdepth = pygame.display.mode_ok(SCREENRECT.size, winstyle, 32) | |
screen = pygame.display.set_mode(SCREENRECT.size, winstyle, bestdepth) | |
background = pygame.Surface(SCREENRECT.size) | |
pygame.display.flip() | |
clock = pygame.time.Clock() | |
b = Ball() | |
while True: | |
for event in pygame.event.get(): | |
if event.type == QUIT or \ | |
(event.type == KEYDOWN and event.key == K_ESCAPE): | |
return | |
pygame.display.update() | |
#all.clear(screen,background) | |
screen.fill((0,0,0)) | |
b.update() | |
#b.clear() | |
b.draw(screen) | |
clock.tick(40) | |
if __name__ == '__main__': main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment