-
Notifications
You must be signed in to change notification settings - Fork 0
/
Movement.py
124 lines (110 loc) · 3.67 KB
/
Movement.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import pygame
import spritesheet
pygame.init()
display_width = 1200
display_height = 600
gameDisplay = pygame.display.set_mode((display_width,display_height))
black = (0,0,0)
white = (255,255,255)
clock = pygame.time.Clock()
crashed = False
ss = spritesheet.spritesheet('pacman.png')
pacmanImg = ss.image_at((0, 0, 16, 16))
pacmanImg1 = ss.image_at((0, 0, 16, 16))
player_rect = pacmanImg.get_rect()
def pacman(x,y):
gameDisplay.blit(pacmanImg, (x,y))
def pacman1(x, y):
gameDisplay.blit(pacmanImg1, (x1,y1))
x = (display_width * 0.45)
y = (display_height * 0.8)
x1 = (display_width * 0.45)
y1 = (display_height * 0.4)
x_change = 0
y_change = 0
x1_change = 0
y1_change = 0
pacman_speed = 0
pacman1_speed = 0
while not crashed:
for event in pygame.event.get():
if event.type == pygame.QUIT:
crashed = True
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
pacmanImg = ss.image_at((0, 16, 16, 16))
player_rect = pacmanImg.get_rect()
gameDisplay.blit(pacmanImg, player_rect)
x_change = -3
y_change = 0
if x == 0:
x = display_width
elif event.key == pygame.K_RIGHT:
pacmanImg = ss.image_at((0, 0, 16, 16))
player_rect = pacmanImg.get_rect()
gameDisplay.blit(pacmanImg, player_rect)
x_change = 3
y_change = 0
if x == display_width:
x = 0
elif event.key == pygame.K_UP:
pacmanImg = ss.image_at((0, 32, 16, 16))
player_rect = pacmanImg.get_rect()
gameDisplay.blit(pacmanImg, player_rect)
y_change = -3
x_change = 0
if y = display_height:
y = 0
elif event.key == pygame.K_DOWN:
pacmanImg = ss.image_at((0, 48, 16, 16))
player_rect = pacmanImg.get_rect()
gameDisplay.blit(pacmanImg, player_rect)
y_change = 3
x_change = 0
if y == 0:
y = display_height
elif event.key == pygame.K_a:
pacmanImg1 = ss.image_at((0, 16, 16, 16))
player_rect = pacmanImg.get_rect()
gameDisplay.blit(pacmanImg, player_rect)
x1_change = -3
y1_change = 0
if x == 0:
x = display_width
elif event.key == pygame.K_d:
pacmanImg1 = ss.image_at((0, 0, 16, 16))
player_rect = pacmanImg.get_rect()
gameDisplay.blit(pacmanImg, player_rect)
x1_change = 3
y1_change = 0
if x == display_width:
x = 0
elif event.key == pygame.K_w:
pacmanImg1 = ss.image_at((0, 32, 16, 16))
player_rect = pacmanImg.get_rect()
gameDisplay.blit(pacmanImg, player_rect)
y1_change = -3
x1_change = 0
if y = display_height:
y = 0
elif event.key == pygame.K_s:
pacmanImg1 = ss.image_at((0, 48, 16, 16))
player_rect = pacmanImg.get_rect()
gameDisplay.blit(pacmanImg, player_rect)
y1_change = 3
x1_change = 0
if y == 0:
y = display_height
x += x_change
y += y_change
x1 += x1_change
y1 += y1_change
player_rect.x += x_change
player_rect.y += y_change
gameDisplay.fill(black)
pacman(x,y)
pacman1(x1,y1)
pygame.display.update()
clock.tick(60)
pygame.quit()
quit()