-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
82 lines (67 loc) · 2.49 KB
/
Copy pathmain.py
File metadata and controls
82 lines (67 loc) · 2.49 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
import pygame
pygame.init()
win = pygame.display.set_mode((600,400))
pygame.display.set_caption('Mario')
img_path = './assets/'
bg = pygame.image.load(img_path+'bg.png')
mario_right = [pygame.image.load(img_path+"w_0.png").convert_alpha(),
pygame.image.load(img_path+"w_0.png").convert_alpha(),
pygame.image.load(img_path+"w_1.png").convert_alpha(),
pygame.image.load(img_path+"w_1.png").convert_alpha(),
pygame.image.load(img_path+"w_2.png").convert_alpha(),
pygame.image.load(img_path+"w_2.png").convert_alpha(),
pygame.image.load(img_path+"w_3.png").convert_alpha(),
pygame.image.load(img_path+"w_3.png").convert_alpha()]
mario_left = [pygame.image.load(img_path+"wl_0.png").convert_alpha(),
pygame.image.load(img_path+"wl_0.png").convert_alpha(),
pygame.image.load(img_path+"wl_1.png").convert_alpha(),
pygame.image.load(img_path+"wl_1.png").convert_alpha(),
pygame.image.load(img_path+"wl_2.png").convert_alpha(),
pygame.image.load(img_path+"wl_2.png").convert_alpha(),
pygame.image.load(img_path+"wl_3.png").convert_alpha(),
pygame.image.load(img_path+"wl_3.png").convert_alpha()]
rindex = 0
lindex = 0
is_right = True
vel = 5
FPS = 30 #Change if you want to speed up the animation
run = True
x = 0
y = 323
hitbox = mario_right[0].get_rect() #All images have the same dimensions
def commands():
global run, x, y, rindex, lindex, is_right
keys = pygame.key.get_pressed()
for events in pygame.event.get():
if events.type == pygame.QUIT:
run = False
if keys[pygame.K_RIGHT]:
is_right = True
x += vel
rindex += 1
if not keys[pygame.K_RIGHT]:
rindex = 0
if keys[pygame.K_LEFT]:
is_right = False
x -= vel
lindex += 1
if not keys[pygame.K_LEFT]:
lindex = 0
def render():
global rindex, lindex
win.blit(bg,(0, 0))
if is_right:
win.blit(mario_right[rindex], (x,y))
if rindex >= len(mario_right) - 1:
rindex = 0
else:
win.blit(mario_left[lindex], (x,y))
if lindex >= len(mario_left) - 1:
lindex = 0
while run:
pygame.time.Clock().tick(FPS)
commands()
render()
#print(hitbox)
pygame.display.update()
pygame.quit()