The class Ship () :
"" "once upon a time there was a mountain, the mountain there is a old monk... "" "
Def __init__ (self, screen, ai_setting) :
The self. The screen=screen
Self. Ai_setting=ai_setting
The self. The image=pygame. Image. The load (' images/ship. BMP)
Self. New_image=pygame. Transform. Scale (self image, (\
Ai_setting. Big, ai_setting. Small)) # zoom
The self. The rect=self. New_image. Get_rect ()
Self. Screen_rect=screen. Get_rect ()
the self. The rect. Centerx=self. Screen_rect. Centerx # is the location of the craft X coordinate location?
The self. The rect. Bottom=self. Screen_rect. Bottom
Self. Zuoy=float (self. The rect. Centery) # write centerx or centery are the same effect?
Self. Sx=float (self. The rect. Centerx) # why it doesn't matter that the control of the attribute is not set up and down float?
Sign #
Self. Moving_right=False
Self. Moving_left=False
Self. Moving_up=False
Self. Moving_down=False #!!!!!!!!!! Up and down????????
Def move (self) :
If self. Moving_right and self. The rect. Right & lt; 800:
# self. Screen_rect. Right:
Self. Zuoy +=self. Ai_setting. Ship_speed
If self. Moving_left and self. The rect. Left & gt; 0:
# self. Screen_rect. Left:
Self. Zuoy -=self. Ai_setting. Ship_speed
If self. Moving_up and self. The rect. Top> Self. Screen_rect. Top:
Self. Sx +=- self. Ai_setting. Ship_speed # self. The sx=self. The rect. Centery
If self. Moving_down and self. The rect. Bottom & lt; Self. Screen_rect. Bottom:
The self. The sx +=self. Ai_setting. Ship_speed
The self. The rect. Centerx=self. Zuoy
The self. The rect. Centery=self. Sx
CodePudding user response:
Will ship the abscissa is defined as the middle of the screen, that is to say, can realize the shuttle's horizontal position in the middle of the screen