File tree Expand file tree Collapse file tree 1 file changed +56
-0
lines changed
Expand file tree Collapse file tree 1 file changed +56
-0
lines changed Original file line number Diff line number Diff line change 1+ import pygame
2+
3+ pygame .init ()
4+
5+ display_width = 800
6+ display_height = 600
7+
8+ black = (0 ,0 ,0 )
9+ white = (255 ,255 ,255 )
10+ red = (255 ,0 ,0 )
11+
12+ gameDisplay = pygame .display .set_mode ((display_width ,display_height ))
13+ pygame .display .set_caption ('A bit Racey' )
14+ clock = pygame .time .Clock ()
15+
16+ carImg = pygame .image .load ('racecar.png' )
17+
18+ def car (x ,y ):
19+ gameDisplay .blit (carImg ,(x ,y ))
20+
21+
22+ x = (display_width * 0.45 )
23+ y = (display_height * 0.8 )
24+
25+ x_change = 0
26+
27+ crashed = False
28+
29+ while not crashed :
30+
31+ for event in pygame .event .get ():
32+ if event .type == pygame .QUIT :
33+ crashed = True
34+
35+ if event .type == pygame .KEYDOWN :
36+ if event .key == pygame .K_LEFT :
37+ x_change = - 5
38+ if event .key == pygame .K_RIGHT :
39+ x_change = 5
40+
41+ if event .type == pygame .KEYUP :
42+ if event .key == pygame .K_LEFT or event .key == pygame .K_RIGHT :
43+ x_change = 0
44+
45+
46+
47+ x += x_change
48+
49+ gameDisplay .fill (white )
50+ car (x ,y )
51+
52+ pygame .display .update ()
53+ clock .tick (60 )
54+
55+ pygame .quit ()
56+ quit ()
You can’t perform that action at this time.
0 commit comments