Skip to content

Commit 40e14d3

Browse files
committed
mouse button
1 parent a13c6fb commit 40e14d3

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

pygame/collisions/main_5_mouse.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
class Player():
1919

20-
def __init__(self, name="A", x=0, y=0, width=150, height=150, keyboard=None, mouse=False):
20+
def __init__(self, name="A", x=0, y=0, width=150, height=150, keyboard=None, mouse_button=False):
2121

2222
self.name = name
2323

@@ -54,7 +54,7 @@ def __init__(self, name="A", x=0, y=0, width=150, height=150, keyboard=None, mou
5454
self.text = "";
5555

5656
self.keyboard = keyboard
57-
self.mouse = mouse
57+
self.mouse_button = mouse_button
5858
self.mouse_move = False
5959

6060

@@ -84,20 +84,19 @@ def event_handler(self, event):
8484
elif event.key == self.keyboard['down']:
8585
self.move_y -= self.speed_y
8686

87-
if self.mouse:
87+
if self.mouse_button:
8888
if event.type == pygame.MOUSEBUTTONDOWN:
89-
if event.button == 1:
89+
if event.button == self.mouse_button:
9090
self.mouse_move = True
9191
self.rect.center = event.pos
9292
elif event.type == pygame.MOUSEBUTTONUP:
93-
if event.button == 1:
93+
if event.button == self.mouse_button:
9494
self.mouse_move = False
9595
elif event.type == pygame.MOUSEMOTION:
9696
if self.mouse_move:
9797
self.rect.center = event.pos
98-
#~ self.rect.center = event.pos
9998

100-
print event
99+
#print event
101100

102101

103102
def update(self):
@@ -178,7 +177,7 @@ def check_collision(self, sprite):
178177

179178
def render_collision_info(self):
180179

181-
text = self.name + " corners: "
180+
text = self.name + ": sides and corners: "
182181
#print "collision:",
183182

184183
if self.collision[0] or self.collision[2] or self.collision[4]:
@@ -217,7 +216,7 @@ def __init__(self):
217216
pygame.init()
218217

219218
self.screen = pygame.display.set_mode( (800,600) )
220-
pygame.display.set_caption("Collisions")
219+
pygame.display.set_caption("PyGame Collisions")
221220

222221
self.player = Player(
223222
name = "A",
@@ -227,7 +226,7 @@ def __init__(self):
227226
'up': pygame.K_UP,
228227
'down': pygame.K_DOWN,
229228
},
230-
mouse=True
229+
mouse_button=1, # left button
231230
)
232231

233232
self.enemy = Player(
@@ -237,7 +236,8 @@ def __init__(self):
237236
'right': pygame.K_d,
238237
'up': pygame.K_w,
239238
'down': pygame.K_s,
240-
}
239+
},
240+
mouse_button=3, # right button
241241
)
242242

243243
self.enemy.set_center(self.screen)
@@ -252,16 +252,16 @@ def check_collisions(self):
252252
text = 'figures: '
253253

254254
if pygame.sprite.collide_rect(self.player, self.enemy):
255-
text += 'rect'
255+
text += 'white rect'
256256

257257
if pygame.sprite.collide_rect_ratio(0.75)(self.player, self.enemy):
258-
text += ', rect_ratio(0.75)'
258+
text += ', blue rect (ratio:0.75)'
259259

260260
if pygame.sprite.collide_rect_ratio(0.5)(self.player, self.enemy):
261-
text += ', rect_ratio(0.50)'
261+
text += ', green rect (ratio:0.50)'
262262

263263
if pygame.sprite.collide_circle(self.player, self.enemy):
264-
text += ', circle'
264+
text += ', red circle'
265265

266266
self.text = self.font.render(text, 1, WHITE)
267267

0 commit comments

Comments
 (0)