Python pygame.mouse() Examples

The following are 6 code examples of pygame.mouse(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pygame , or try the search function .
Example #1
Source File: fig24_05.py    From PythonClassBook with GNU General Public License v3.0 8 votes vote down vote up
def createGUI( file ):

   # load movie
   movie = pygame.movie.Movie( file )
   width, height = movie.get_size()

   # initialize display window
   screen = pygame.display.set_mode( ( width, height + 100 ) )
   pygame.display.set_caption( "Movie Player" )
   pygame.mouse.set_visible( 1 )

   # play button
   playImageFile = os.path.join( "data", "play.png" )
   playImage = pygame.image.load( playImageFile ).convert()
   playImageSize = playImage.get_rect()
   playImageSize.center = width / 2, height + 50

   # copy play button to screen
   screen.blit( playImage, playImageSize )
   pygame.display.flip()

   # set arqui_recipe surface for movie's video
   movie.set_display( screen )

   return movie, playImageSize 
Example #2
Source File: fig24_05.py    From PythonClassBook with GNU General Public License v3.0 6 votes vote down vote up
def main():

   # check command line arguments
   if len( sys.argv ) != 2:
      sys.exit( "Incorrect number of arguments." )
   else:
      file = sys.argv[ 1 ]
      
   # initialize pygame
   pygame.init()

   # initialize GUI
   movie, playImageSize = createGUI( file )

   # wait until player wants to close program
   while 1:
      event = pygame.event.wait()

      # close window
      if event.type == QUIT or \
         ( event.type == KEYDOWN and event.key == K_ESCAPE ):
         break

      # click play button and play movie
      pressed = pygame.mouse.get_pressed()[ 0 ]
      position = pygame.mouse.get_pos()

      # button pressed
      if pressed:

         if playImageSize.collidepoint( position ):
            movie.play() 
Example #3
Source File: PLAYER.py    From DUGA with Mozilla Public License 2.0 6 votes vote down vote up
def __init__(self, pos):
        self.max_speed = SETTINGS.player_speed
        self.speed = 0
        self.angle = SETTINGS.player_angle
        self.health = SETTINGS.player_health

        self.real_x = pos[0]
        self.real_y = pos[1]

        self.color = SETTINGS.BLUE
        self.sprite = pygame.Surface([SETTINGS.tile_size / 12, SETTINGS.tile_size / 12])
        self.sprite.fill(self.color)
        self.rect = self.sprite.get_rect()
        self.rect.x = self.real_x
        self.rect.y = self.real_y
        SETTINGS.player_rect = self.rect
        self.last_pos_tile = None

        self.mouse = pygame.mouse
        self.sensitivity = SETTINGS.sensitivity
        self.gun = 0
        self.gunsprites_aim = []
        self.gunsprites_shoot = []

        SETTINGS.player = self
        self.collide_list = SETTINGS.all_solid_tiles + SETTINGS.npc_list
        self.update_collide_list = False
        self.solid = True
        self.dead = False
        self.last_call = 0
        self.type = 'player'
        self.hurt_sound = pygame.mixer.Sound(os.path.join('sounds', 'other', 'damage.ogg'))
        self.change_level = pygame.mixer.Sound(os.path.join('sounds', 'other', 'next_level.ogg'))

        self.current_level = SETTINGS.current_level

        #input variables
        self.mouse2 = 0
        self.inventory = 0
        self.esc_pressed = False
        self.dont_open_menu = False 
Example #4
Source File: label.py    From python-examples with MIT License 6 votes vote down vote up
def update(self, time):
        if self._can_focus:
            self._update_select_text(time)
            # Change cursor when mouse not held down
            if not pygame.mouse.get_pressed()[0]:
                if not self._over and \
                  self.rect_abs.collidepoint(pygame.mouse.get_pos()):
                    self._over = True
                    self._set_cursor(*self._cursor)
                elif self._over and \
                  not self.rect_abs.collidepoint(pygame.mouse.get_pos()):
                    self._over = False
                    self._remove_cursor()
            if self.has_focus():
                self._switch() 
Example #5
Source File: label.py    From python-examples with MIT License 6 votes vote down vote up
def update(self, time):
        if self._can_focus:
            self._update_select_text(time)
            # Change cursor when mouse not held down
            if not pygame.mouse.get_pressed()[0]:
                if not self._over and \
                  self.rect_abs.collidepoint(pygame.mouse.get_pos()):
                    self._over = True
                    self._set_cursor(*self._cursor)
                elif self._over and \
                  not self.rect_abs.collidepoint(pygame.mouse.get_pos()):
                    self._over = False
                    self._remove_cursor()
            if self.has_focus():
                self._switch() 
Example #6
Source File: visualizer.py    From gif-music-visualizer with GNU General Public License v3.0 6 votes vote down vote up
def initPygame(self):
		pygame.init()
		self.screen = pygame.display.set_mode((self.w, self.h))
		pygame.mouse.set_visible(False)
		self.clock = pygame.time.Clock()