Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_test.py
More file actions
Latest commit
102 lines (84 loc) · 2.2 KB
/
Copy pathmain_test.py
File metadata and controls
102 lines (84 loc) · 2.2 KB
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
importpygame
pygame.init()
win_width=480
win_height=480
win=pygame.display.set_mode((win_width, win_height))
pygame.display.set_caption('First Game')
sprite_sheet=pygame.image.load('Game/blue_woman_sprite.png') # 594 * 261 (9 * 4)
clock=pygame.time.Clock()
x=50
y=200
width=594//9
height=261//4
vel=6
left=False
right=False
up=False
down=False
walkcount=0
walk_R= []
walk_L= []
walk_U= []
walk_D= []
char_sheet= [walk_U, walk_L, walk_D, walk_R]
bg=pygame.image.load('Game/bg.jpg')
# char = sprite_sheet.subsurface((0, 0, width, height))
foriinrange(4):
forjinrange(9):
char_sheet[i].append(sprite_sheet.subsurface((width*j, height*i, width, height)))
char=char_sheet[2][0]
defredrawGameWindow():
globalwalkcount
win.blit(bg, (0, 0))
ifwalkcount+1>=20:
walkcount=0
ifleft:
win.blit(walk_L[walkcount//5], (x, y))
walkcount+=1
elifright:
win.blit(walk_R[walkcount//5], (x, y))
walkcount+=1
elifup:
win.blit(walk_U[walkcount//5], (x, y))
walkcount+=1
elifdown:
win.blit(walk_D[walkcount//5], (x, y))
walkcount+=1
else:
win.blit(char, (x, y))
pygame.display.update()
# main loop
run=True
whilerun:
clock.tick(27)
foreventinpygame.event.get():
ifevent.type==pygame.QUIT:
run=False
keys=pygame.key.get_pressed()
print("l", left, "r", right, "u", up, "d", down, "key_a", keys[pygame.K_a])
ifkeys[pygame.K_a] andx>0:
x-=vel
left=True
right=False
elifkeys[pygame.K_d] andx<win_width-width:
x+=vel
right=True
left=False
ifkeys[pygame.K_w] andy>0:
y-=vel
up=True
down=False
elifkeys[pygame.K_s] andy<win_height-height:
y+=vel
down=True
up=False
ifkeys[pygame.K_a] ==0andkeys[pygame.K_d] ==0andkeys[pygame.K_s] ==0andkeys[pygame.K_w] ==0:
right=False
left=False
down=False
up=False
walkcount=0
ifkeys[pygame.K_q]:
run=False
redrawGameWindow()
pygame.quit()