<s> import pyglet , math <EOL> from pyglet . window import key <EOL> import bullet , physicalobject , resources <EOL> class Player ( physicalobject . PhysicalObject ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( Player , self ) . __init__ ( img = resources . player_image , * args , ** kwargs ) <EOL> self . engine_sprite = pyglet . sprite . Sprite ( img = resources . engine_image , * args , ** kwargs ) <EOL> self . engine_sprite . visible = False <EOL> self . thrust = <NUM_LIT> <EOL> self . rotate_speed = <NUM_LIT> <EOL> self . bullet_speed = <NUM_LIT> <EOL> self . reacts_to_bullets = False <EOL> self . key_handler = key . KeyStateHandler ( ) <EOL> self . event_handlers = [ self , self . key_handler ] <EOL> def update ( self , dt ) : <EOL> super ( Player , self ) . update ( dt ) <EOL> if self . key_handler [ key . LEFT ] : <EOL> self . rotation -= self . rotate_speed * dt <EOL> if self . key_handler [ key . RIGHT ] : <EOL> self . rotation += self . rotate_speed * dt <EOL> if self . key_handler [ key . UP ] : <EOL> angle_radians = - math . radians ( self . rotation ) <EOL> force_x = math . cos ( angle_radians ) * self . thrust * dt <EOL> force_y = math . sin ( angle_radians ) * self . thrust * dt <EOL> self . velocity_x += force_x <EOL> self . velocity_y += force_y <EOL> self . engine_sprite . rotation = self . rotation <EOL> self . engine_sprite . x = self . x <EOL> self . engine_sprite . y = self . y <EOL> self . engine_sprite . visible = True <EOL> else : <EOL> self . engine_sprite . visible = False <EOL> def on_key_press ( self , symbol , modifiers ) : <EOL> if symbol == key . SPACE : <EOL> self . fire ( ) <EOL> def fire ( self ) : <EOL> angle_radians = - math . radians ( self . rotation ) <EOL> ship_radius = self . image . width / <NUM_LIT:2> <EOL> bullet_x = self . x + math . cos ( angle_radians ) * ship_radius <EOL> bullet_y = self . y + math . sin ( angle_radians ) * ship_radius <EOL> new_bullet = bullet . Bullet ( bullet_x , bullet_y , batch = self . batch ) <EOL> bullet_vx = self . velocity_x + math . cos ( angle_radians ) * self . bullet_speed <EOL> bullet_vy = self . velocity_y + math . sin ( angle_radians ) * self . bullet_speed <EOL> new_bullet . velocity_x , new_bullet . velocity_y = bullet_vx , bullet_vy <EOL> self . new_objects . append ( new_bullet ) <EOL> resources . bullet_sound . play ( ) <EOL> def delete ( self ) : <EOL> self . engine_sprite . delete ( ) <EOL> super ( Player , self ) . delete ( ) </s>
