-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintro6.py
More file actions
33 lines (26 loc) · 693 Bytes
/
intro6.py
File metadata and controls
33 lines (26 loc) · 693 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import pygame
from pygame.locals import *
size = 640, 320
width, height = size
GREEN = (150, 255, 150)
RED = (255, 0, 0)
pygame.init()
screen = pygame.display.set_mode(size)
running = True
ball = pygame.image.load("ball.gif")
rect = ball.get_rect()
speed = [2, 2]
while running:
for event in pygame.event.get():
if event.type == QUIT:
running = False
rect = rect.move(speed)
if rect.left < 0 or rect.right > width:
speed[0] = -speed[0]
if rect.top < 0 or rect.bottom > height:
speed[1] = -speed[1]
screen.fill(GREEN)
pygame.draw.rect(screen, RED, rect, 1)
screen.blit(ball, rect)
pygame.display.update()
pygame.quit()