File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55
66
77def check_keyup_event (event , ship ):
8- """检测按键释放 """
8+ """按键释放事件响应 """
99 ship .stop ()
1010
1111def check_keydown_event (event , ship ):
12- """检测按键按下 """
12+ """按键按下事件响应 """
1313 if pygame .K_RIGHT == event .key :
1414 # 向右移动飞船
1515 ship .moving ('right' )
16- ship .update ()
1716 if pygame .K_LEFT == event .key :
1817 # 向左移动飞船
1918 ship .moving ('left' )
20- ship .update ()
2119
2220def check_event (ship ):
23- #监视键盘和鼠标事件
21+ """检测按键事件"""
2422 for event in pygame .event .get ():
2523 if pygame .QUIT == event .type :
2624 sys .exit ()
Original file line number Diff line number Diff line change 44
55
66class Ship ():
7-
87 def __init__ (self , scrren ):
98 """初始化飞船并设置其初始位置"""
109 self .scrren = scrren
@@ -28,7 +27,6 @@ def blitme(self):
2827
2928 def update (self ):
3029 """根据移动标志调整飞船的位置"""
31-
3230 if True == self .__moving_riht and self .rect .right < self .scrren_rect .right :
3331 self .self_center += self .speed_factor
3432
@@ -38,10 +36,12 @@ def update(self):
3836 self .rect .centerx = self .self_center
3937
4038 def moving (self , direction ):
39+ """移动飞船"""
4140 if 'left' == direction :
4241 self .__moving_left = True
4342 elif 'right' == direction :
4443 self .__moving_riht = True
44+ self .update ()
4545
4646 def stop (self ):
4747 """停止移动,将移动标志位都设置为FALSE"""
You can’t perform that action at this time.
0 commit comments