-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.py
192 lines (130 loc) · 4.81 KB
/
index.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
import pygame
import os
from pygame.locals import *
from sys import exit
import mega_data
import index
bg_color = (190, 200, 255)
root = os.path.dirname(__file__)
sprites_dir = os.path.join(root, 'sprites')
sounds_dir = os.path.join(root, 'sounds')
width = 1080
height = 720
pygame.init()
clock = pygame.time.Clock()
pygame.joystick.init()
joysticks = [pygame.joystick.Joystick(i) for i in range(pygame.joystick.get_count())]
for joystick in joysticks:
print(f"Joystick novo reconhecido: {joystick.get_name()}")
main_screen = pygame.display.set_mode((width, height))
pygame.display.set_caption("Megaman")
axis_motion = [0, 0]
mbi_ss = pygame.image.load(os.path.join(sprites_dir, 'mega-basic-idle.png')).convert_alpha()
mbw_ss = pygame.image.load(os.path.join(sprites_dir, 'mega-basic-walk.png')).convert_alpha()
mbj_ss = pygame.image.load(os.path.join(sprites_dir, 'mega-basic-jump.png')).convert_alpha()
mbis_ss = pygame.image.load(os.path.join(sprites_dir, 'mega-idle-shoot.png')).convert_alpha()
mbi_rev_ss = pygame.image.load(os.path.join(sprites_dir, 'mega-basic-idle-reverse.png')).convert_alpha()
mbw_rev_ss = pygame.image.load(os.path.join(sprites_dir, 'mega-basic-walk-reverse.png')).convert_alpha()
mbj_rev_ss = pygame.image.load(os.path.join(sprites_dir, 'mega-basic-jump-reverse.png')).convert_alpha()
mbis_rev_ss = pygame.image.load(os.path.join(sprites_dir, 'mega-idle-shoot-reverse.png')).convert_alpha()
m_buster_s = pygame.image.load(os.path.join(sprites_dir, 'mega-buster.png')).convert_alpha()
ice_man_stage_song = pygame.mixer.music.load(os.path.join(sounds_dir, "ice-man-gg-cut.mp3"))
pygame.mixer.music.play(999)
all_shots = []
gravity = 0.2
shoot_sign = False
shoot_ind = 0
mega_y_limit = height - 150
all_sprites = pygame.sprite.Group()
all_bullets = pygame.sprite.Group()
m_data = mega_data.Megaman()
all_sprites.add(m_data)
while True:
clock.tick(60)
main_screen.fill(bg_color)
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
exit()
if event.type == KEYDOWN:
if event.key == K_ESCAPE:
pygame.quit()
exit()
if event.type == JOYBUTTONDOWN:
print(event.button)
if event.button == 10:
pygame.quit()
exit()
if event.button == 2:
if m_data.y > mega_y_limit:
m_data.jump = True
m_data.vy -= 8.5
else:
print("COLIDIU COM LIMITE")
if event.button == 3:
if m_data.direction == "RIGHT":
m_data.shoot = True
shoot_sign = True
shoot_ind = 0
b_data = mega_data.Megabuster()
all_shots.append(b_data)
for i in range(len(all_shots)):
all_bullets.add(all_shots[i])
elif m_data.direction == "LEFT":
m_data.shoot = True
shoot_sign = True
shoot_ind = 0
b_data = mega_data.Megabuster()
all_shots.append(b_data)
all_bullets.add(b_data)
#all_sprites.add(b_data)
#print(all_shots)
if event.type == JOYAXISMOTION:
axis_motion[event.axis] = event.value
if abs(axis_motion[0]) > 0.4:
axis_motion[event.axis] = event.value
elif abs(axis_motion[0]) < 0.4:
axis_motion[0] = 0
all_sprites.draw(main_screen)
all_sprites.update()
all_bullets.draw(main_screen)
all_bullets.update()
m_data.x += axis_motion[0] * 3.9
for i in all_shots:
if i.x + i.w <= 50:
all_bullets.remove(i)
#all_sprites.remove(i)
if shoot_sign:
shoot_ind += 0.1
if shoot_ind >= 5:
m_data.shoot = False
shoot_ind = 0
shoot_sign = False
else:
shoot_ind = 0
if axis_motion[0] == 0:
m_data.walking = False
m_data.idle = True
else:
m_data.walking = True
m_data.idle = False
if axis_motion[0] > 0.4:
m_data.direction = "RIGHT"
elif axis_motion[0] < -0.4:
m_data.direction = "LEFT"
if m_data.x < 0:
m_data.x = 0
elif m_data.x + m_data.w > width:
m_data.x = width - m_data.w
if m_data.y < 0:
m_data.y = 0
elif m_data.y + m_data.h > height:
m_data.y = height - m_data.h
m_data.vy = 0
m_data.jump = False
if m_data.y + m_data.h < height - 1:
m_data.jump = True
else:
m_data.jump = False
pygame.display.flip()
pygame.display.update()