-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmoving_box.py
More file actions
40 lines (27 loc) · 824 Bytes
/
moving_box.py
File metadata and controls
40 lines (27 loc) · 824 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
34
35
36
37
38
39
40
import pygame
pygame.init()
clock = pygame.time.Clock()
WHITE_COLOR = (255, 255, 255)
BLUE_COLOR = (30, 144, 255)
SCREEN_WIDTH = 1100
SCREEN_HEIGHT = 700
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
screen.fill(WHITE_COLOR)
pygame.display.set_caption('Moving Box')
box_x, box_y = 40, 350
box_width, box_height = 50, 50
box = pygame.rect.Rect((box_x, box_y), (box_width, box_height))
def move_box(current_box):
current_box.move_ip(5, 0)
if current_box.x > SCREEN_WIDTH:
current_box.center = (box_x, box_y)
while True:
events = pygame.event.get()
for event in events:
if event.type == pygame.QUIT:
pygame.quit()
screen.fill(WHITE_COLOR)
pygame.draw.rect(screen, BLUE_COLOR, box)
move_box(box)
pygame.display.flip()
clock.tick(45)