17
17
18
18
class Player ():
19
19
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 ):
21
21
22
22
self .name = name
23
23
@@ -54,7 +54,7 @@ def __init__(self, name="A", x=0, y=0, width=150, height=150, keyboard=None, mou
54
54
self .text = "" ;
55
55
56
56
self .keyboard = keyboard
57
- self .mouse = mouse
57
+ self .mouse_button = mouse_button
58
58
self .mouse_move = False
59
59
60
60
@@ -84,20 +84,19 @@ def event_handler(self, event):
84
84
elif event .key == self .keyboard ['down' ]:
85
85
self .move_y -= self .speed_y
86
86
87
- if self .mouse :
87
+ if self .mouse_button :
88
88
if event .type == pygame .MOUSEBUTTONDOWN :
89
- if event .button == 1 :
89
+ if event .button == self . mouse_button :
90
90
self .mouse_move = True
91
91
self .rect .center = event .pos
92
92
elif event .type == pygame .MOUSEBUTTONUP :
93
- if event .button == 1 :
93
+ if event .button == self . mouse_button :
94
94
self .mouse_move = False
95
95
elif event .type == pygame .MOUSEMOTION :
96
96
if self .mouse_move :
97
97
self .rect .center = event .pos
98
- #~ self.rect.center = event.pos
99
98
100
- print event
99
+ # print event
101
100
102
101
103
102
def update (self ):
@@ -178,7 +177,7 @@ def check_collision(self, sprite):
178
177
179
178
def render_collision_info (self ):
180
179
181
- text = self .name + " corners: "
180
+ text = self .name + ": sides and corners: "
182
181
#print "collision:",
183
182
184
183
if self .collision [0 ] or self .collision [2 ] or self .collision [4 ]:
@@ -217,7 +216,7 @@ def __init__(self):
217
216
pygame .init ()
218
217
219
218
self .screen = pygame .display .set_mode ( (800 ,600 ) )
220
- pygame .display .set_caption ("Collisions" )
219
+ pygame .display .set_caption ("PyGame Collisions" )
221
220
222
221
self .player = Player (
223
222
name = "A" ,
@@ -227,7 +226,7 @@ def __init__(self):
227
226
'up' : pygame .K_UP ,
228
227
'down' : pygame .K_DOWN ,
229
228
},
230
- mouse = True
229
+ mouse_button = 1 , # left button
231
230
)
232
231
233
232
self .enemy = Player (
@@ -237,7 +236,8 @@ def __init__(self):
237
236
'right' : pygame .K_d ,
238
237
'up' : pygame .K_w ,
239
238
'down' : pygame .K_s ,
240
- }
239
+ },
240
+ mouse_button = 3 , # right button
241
241
)
242
242
243
243
self .enemy .set_center (self .screen )
@@ -252,16 +252,16 @@ def check_collisions(self):
252
252
text = 'figures: '
253
253
254
254
if pygame .sprite .collide_rect (self .player , self .enemy ):
255
- text += 'rect'
255
+ text += 'white rect'
256
256
257
257
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)'
259
259
260
260
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)'
262
262
263
263
if pygame .sprite .collide_circle (self .player , self .enemy ):
264
- text += ', circle'
264
+ text += ', red circle'
265
265
266
266
self .text = self .font .render (text , 1 , WHITE )
267
267
0 commit comments