• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python mouse.get_pos函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pygame.mouse.get_pos函数的典型用法代码示例。如果您正苦于以下问题:Python get_pos函数的具体用法?Python get_pos怎么用?Python get_pos使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_pos函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: start_screen

 def start_screen(self):
     exitLoop = False
     self.sfx.play_start_screen()
     while not exitLoop:
         # for i in range(0, len(self.platform.gamestart_button_list), 1):
         #      if self.platform.gamestart_button_list[i].is_mouse_over(mouse.get_pos()) and i is not constants.GAMESTART_BUTTON_TYPE["mute"]:
         #              self.sfx.play_mouseover()
         for event in pygame.event.get():
             if event.type == pygame.QUIT:
                 pygame.quit()
             if event.type == pygame.MOUSEBUTTONDOWN:
                 for i in range(0, len(self.platform.gamestart_button_list), 1):
                     if self.platform.gamestart_button_list[i].is_mouse_over(mouse.get_pos()):
                         if i == constants.GAMESTART_BUTTON_TYPE["mute"]:
                             self.sfx.play_mouseover()
                             self.platform.gamestart_mute_button.toggle_frame()
                             if self.sfx.is_muted == True:
                                 self.sfx.set_unmute()
                             else:
                                 self.sfx.set_mute()
                         elif i == constants.GAMESTART_BUTTON_TYPE["play"]:
                             self.sfx.play_mouseover()
                             exitLoop = True
                             self.sfx.stop_start_screen()
                             self.scoreboard.reset_score()
                             self.start(False)
                         elif i == constants.GAMESTART_BUTTON_TYPE["exit"]:
                             self.sfx.play_mouseover()
                             exitLoop = True
                             self.done = True
         self.platform.gamestart_screen(mouse.get_pos(), pygame.event.get())
         pygame.display.update()
         GameManager.clock.tick(constants.FPS)
开发者ID:sonlexqt,项目名称:game-programming-ass2-football-simulator-controller,代码行数:33,代码来源:game_manager.py


示例2: update

    def update(self, topmost):
        """
        Route Callbacks
        """ 
        oldMousedown = self.mousedown
        CContainer.update(self, topmost)
        CWidget.update(self, topmost)
        
        if self.moving:
            mx,my = mouse.get_pos()
            mx = mx - self.moving[0]
            my = my - self.moving[1] 
            xpos = self.position[0] + mx
            ypos = self.position[1] + my
            xpos = xpos if xpos >= 0 else 0
            ypos = ypos if ypos >= 0 else 0           
            self.position = (xpos, ypos)
            self.moving = mouse.get_pos()
                    
        if not oldMousedown and self.mousedown and self.enabled:
            #Start moving
            self.moving = mouse.get_pos()
            if self.onmove: self.onmove(self)
 
        elif oldMousedown and not self.mousedown:
            #Stop moving
            self.moving = False
            if self.onmovestop: self.onmovestop(self)
        
        if self.mousedown and self.enabled:
            self.parent.bringToFront(self)
开发者ID:geijoenr,项目名称:pyXPS,代码行数:31,代码来源:CWindow.py


示例3: gameover_screen

 def gameover_screen(self):
     exitLoop = False
     while not exitLoop:
         for event in pygame.event.get():
             if event.type == pygame.QUIT:
                 exitLoop = True
                 self.done = True
             if event.type == pygame.MOUSEBUTTONDOWN:
                 for i in range(0, len(self.platform.gameover_button_list), 1):
                     if self.platform.gameover_button_list[i].is_mouse_over(mouse.get_pos()):
                         if i == constants.GAMEOVER_BUTTON_TYPE["mute"]:
                             self.sfx.play_mouseover()
                             if self.sfx.is_muted == True:
                                 self.sfx.set_unmute()
                             else:
                                 self.sfx.set_mute()
                         elif i == constants.GAMEOVER_BUTTON_TYPE["replay"]:
                             self.sfx.play_mouseover()
                             exitLoop = True
                             self.scoreboard.reset_score()
                             self.start(False)
                         elif i == constants.GAMEOVER_BUTTON_TYPE["exit"]:
                             self.sfx.play_mouseover()
                             exitLoop = True
                             self.done = True
         self.platform.gameover_screen(mouse.get_pos(), pygame.event.get(), self.scoreboard.scores)
         pygame.display.update()
         GameManager.clock.tick(constants.FPS)
开发者ID:sonlexqt,项目名称:game-programming-ass2-football-simulator-controller,代码行数:28,代码来源:game_manager.py


示例4: update

 def update(self, topmost):
     
     oldMousedown = self.mousedown
     
     Container.update(self, topmost)
     Widget.update(self, topmost)
     
     if self.moving:
         mx,my = mouse.get_pos()
         mx = mx - self.moving[0]
         my = my - self.moving[1]
          
         self.position = (self.position[0] + mx, self.position[1] + my)
         
         self.moving = mouse.get_pos()
                 
     if not oldMousedown and self.mousedown and self.enabled:
         #Start moving
         self.moving = mouse.get_pos()
         if self.onMove: self.onMove(self)
         
     elif oldMousedown and not self.mousedown:
         #Stop moving
         self.moving = False
         if self.onMoveStop: self.onMoveStop(self)
     
     if self.mousedown and self.enabled:
         self.parent.bringToFront(self)
开发者ID:danielz360,项目名称:Maya,代码行数:28,代码来源:gui.py


示例5: update

    def update(self, topmost):
        """
        Route Callbacks
        """
        oldMousedown = self.mousedown
        CContainer.update(self, topmost)
        CWidget.update(self, topmost)

        ## handle Displacement of the drawer if click and drag
        if self.dragging_drawer:
            mx, my = mouse.get_pos()
            my = my - self.moving[1]
            ypos = self.drawerpos + my
            self.drawerpos = ypos
            if self.drawerpos < 0:
                self.drawerpos = 0
            dnbut_size_y = self.dn_button.size[1]
            dwbut_size_y = self.dw_button.size[1]
            if self.drawerpos >= self.size[1] - 2 * dnbut_size_y - dwbut_size_y:
                self.drawerpos = self.size[1] - 2 * dnbut_size_y - dwbut_size_y
            self.moving = mouse.get_pos()
            if self.onmovedrawer:
                self.onmovedrawer(self)

        self.refresh()
开发者ID:geijoenr,项目名称:pyXPS,代码行数:25,代码来源:CScrollBar.py


示例6: main

def main():
    screen, background, font = initPygame(WIDTH, HEIGHT)
    tree, deck, trash = initTriPeaks()
    lostGame = False
    deckRect = Rect(DECKLOCATION[0], DECKLOCATION[1], CARDW, CARDH)
    
    # Set background
    screen.blit(background, (0, 0))
    pygame.display.flip()

    backsideImage = loadCardImage("deck")
    cards = initCards(backsideImage)
    rects = []
    for card in cards:
        rects.append(cards[card][0])
    
    trash.add(deck.get_next())
    refreshCards(tree, cards)

    clock = pygame.time.Clock()

    while 1:
        clock.tick(60)

        for event in pygame.event.get():
            if event.type == QUIT:
                return
            elif event.type == MOUSEBUTTONDOWN:
                for rect in rects:
                    if rect.collidepoint(mouse.get_pos()):
                        checkCard(tree, trash, cards, rects, rect)
                        refreshCards(tree, cards)
                        print len(cards)
                if deckRect.collidepoint(mouse.get_pos()):
                    if loseCondition(tree, deck):
                        lostGame = True
                        break
                    drawCard(deck, trash)
                    refreshCards(tree, cards)
        if lostGame:
            while(True):
                for event in pygame.event.get():
                    if event.type == QUIT:
                        return
                            
        screen.blit(background, (0, 0))

        screen.blit(backsideImage, DECKLOCATION)
        cardsLeft = font.render(str(deck.count()), 0, (0, 0, 0))
        screen.blit(cardsLeft, DECFONTLOCATION)
        trashTop = trash.peek()
        screen.blit(loadCardImage(trashTop), TRASHLOCATION)
        for card in cards:
            screen.blit(cards[card][1], cards[card][0].topleft)

        pygame.display.flip()

        if winCondition(tree):
            print "JEI"
开发者ID:danieleldjarn,项目名称:University-of-Iceland,代码行数:59,代码来源:TriPeaks.py


示例7: handle

    def handle(self, e):
        if e.type == KEYDOWN:
            pressed = key.get_pressed()
            shifted = pressed[K_LSHIFT] or pressed[K_RSHIFT]
            scroll = 10 if shifted else 1
            
            if e.key == K_UP:
                self._scroll(1, -scroll)
                return True
                
            elif e.key == K_DOWN:
                self._scroll(1, scroll)
                return True
                
            elif e.key == K_LEFT:
                self._scroll(0, -scroll)
                return True
                
            elif e.key == K_RIGHT:
                self._scroll(0, scroll)
                return True
                    
            elif e.unicode == '>':
                self._zscroll(-1)
                return True
                
            elif e.unicode == '<':
                self._zscroll(1)
                return True

            elif e.key == K_TAB:
                self._select(self.cursor)
                mouse.set_visible(False)
                return True

        elif (e.type == MOUSEBUTTONDOWN and
              self.background and
              self.background.get_rect().collidepoint(e.pos) and
              e.button == 1):
            self._select(self._absolutetile(mouse.get_pos()))
            return True
        
        elif (e.type == MOUSEBUTTONUP and
              self.background and
              self.background.get_rect().collidepoint(e.pos) and
              e.button == 1):
            self._dragging = False
            return True

        elif (e.type == MOUSEMOTION and self.background and
            self.background.get_rect().collidepoint(e.pos) and
            1 in e.buttons):
            self._expandselection(self._absolutetile(mouse.get_pos()))
            self._dragging = True
            
        return False
开发者ID:tps12,项目名称:Dorftris,代码行数:56,代码来源:playfield.py


示例8: getPos

 def getPos(self):
     """Returns the current position of the mouse,
     in the same units as the :class:`~visual.Window` (0,0) is at centre
     """
     if usePygame:  # for pygame top left is 0,0
         lastPosPix = numpy.array(mouse.get_pos())
         # set (0,0) to centre
         lastPosPix[1] = self.win.size[1] / 2 - lastPosPix[1]
         lastPosPix[0] = lastPosPix[0] - self.win.size[0] / 2
     else:  # for pyglet bottom left is 0,0
         # use default window if we don't have one
         if self.win:
             w = self.win.winHandle
         else:
             defDisplay = pyglet.window.get_platform().get_default_display()
             w = defDisplay.get_windows()[0]
         # get position in window
         lastPosPix = numpy.array([w._mouse_x, w._mouse_y])
         # set (0,0) to centre
         if self.win.useRetina:
             lastPosPix = lastPosPix*2 - numpy.array(self.win.size) / 2
         else:
             lastPosPix = lastPosPix - numpy.array(self.win.size) / 2
     self.lastPos = self._pix2windowUnits(lastPosPix)
     return copy.copy(self.lastPos)
开发者ID:mmagnuski,项目名称:psychopy,代码行数:25,代码来源:event.py


示例9: input

    def input(self, event):
        self.x_speed = 0.0
        self.y_speed = 0.0
        x, y = mouse.get_pos()

        if event.type == MOUSEBUTTONDOWN and event.button == MOUSE.MIDDLE:
            self.x_first = x
            self.y_first = y
        elif event.type == MOUSEBUTTONUP and event.button == MOUSE.MIDDLE:
            self.x_first = None
            self.y_first = None
        elif event.type == MOUSEMOTION and mouse.get_pressed()[1] and \
            self.x_first and self.y_first:
            self.x_delta = x - self.x_first
            self.y_delta = y - self.y_first
        else:
            if mouse.get_focused():
                if x > self.w - self.scroll_width and x < self.w:
                    self.x_speed = self.speed
                elif x < self.scroll_width:
                    self.x_speed = -self.speed
                if y > self.h - self.scroll_width:
                    self.y_speed = self.speed
                elif y < self.scroll_width:
                    self.y_speed = -self.speed

            if key.get_focused():
                if key.get_pressed()[K_RIGHT]:
                    self.x_speed = self.speed
                elif key.get_pressed()[K_LEFT]:
                    self.x_speed = -self.speed
                if key.get_pressed()[K_DOWN]:
                    self.y_speed = self.speed
                elif key.get_pressed()[K_UP]:
                    self.y_speed = -self.speed
开发者ID:drtchops,项目名称:iancraft,代码行数:35,代码来源:cameras.py


示例10: update

    def update(self, topmost):
        Widget.update(self, topmost)
        oldSelectedIndex = self.selectedIndex
        if self.mouseover:
            my = mouse.get_pos()[1]
            screenPos = self.parent.getScreenPosition(self.position)[1]
            tempIndex = max(0, (my - screenPos - self.style['padding'] + self._scrolling) / self.style['item-height'])
            if tempIndex != self.overedIndex:
                self.overedIndex = tempIndex
                self.needsRefresh = True
            if self.mousedown:
                if tempIndex != self.selectedIndex:
                    self.selectedIndex = self.overedIndex
                    self.needsRefresh = True
        if self.hasFocus:
            for e in events:
                if e.type == pygame.KEYDOWN:
                    if e.key == pygame.K_DOWN:
                        self.moveDown()
                    elif e.key == pygame.K_UP:
                        self.moveUp()
                if e.type == pygame.MOUSEBUTTONDOWN:
                    if e.button == 4 and self.mouseover:
                        self._scrolling = max(0, self._scrolling - self.style['item-height'])
                    if e.button == 5 and self.mouseover:
                        self._scrolling = min(self.style['item-height'] * len(self.items) - self.size[1] + self.style['padding'] * 2, self._scrolling + self.style['item-height'])
                    self.needsRefresh = True

        if self.needsRefresh:
            self.needsRefresh = False
            self.refresh()
        if oldSelectedIndex != self.selectedIndex:
            if self.onItemSelected:
                self.onItemSelected(self)
开发者ID:249550148,项目名称:mygame,代码行数:34,代码来源:gui.py


示例11: update

    def update(self, time):
        self.time += time
        if self.time < Menu.FADEINTIME:
            ratio = self.time / Menu.FADEINTIME
            value = int(ratio * 255)
            self.color = PC.Color(value, value, value)
        position = PM.get_pos()
        if self.inrange(self.new_game, position):
            self.hover[0] = True
        else:
            self.hover[0] = False

        if self.inrange(self.volume, position):
            self.hover[1] = True
        else:
            self.hover[1] = False

        if self.inrange(self.brightness, position):
            self.hover[2] = True
        else:
            self.hover[2] = False

        if self.inrange(self.score, position):
            self.hover[3] = True
        else:
            self.hover[3] = False

        if self.inrange(self.exit, position):
            self.hover[4] = True
        else:
            self.hover[4] = False
开发者ID:davidmvp,项目名称:cryptography,代码行数:31,代码来源:Menu.py


示例12: update

    def update(self, time):
        # Move position
        self.x, self.y = self.x + (self.velocity[0] * time), self.y + (self.velocity[1] * time)

        # Check new rotation
        mouse_pos = mouse.get_pos()
        facing = mouse_pos[0] - self.x, mouse_pos[1] - self.y
        length = math.hypot(*facing)
        self.facing = facing[0] / length, facing[1] / length

        # Rotate Image
        self.image = pygame.transform.rotate(player_image, math.degrees(math.atan2(*self.facing)))
        self.rect = self.image.get_rect()
        self.rect.center = int(self.x), int(self.y)

        # If off screen, move to other side
        if self.rect.bottom < self.screen.top:
            self.rect.top = self.screen.bottom
        elif self.rect.top > self.screen.bottom:
            self.rect.bottom = self.screen.top

        if self.rect.right < self.screen.left:
            self.rect.left = self.screen.right
        elif self.rect.left > self.screen.right:
            self.rect.right = self.screen.left

        self.x, self.y = self.rect.center

        # Accelerate
        key = keyboard.get_pressed()
        if key[self.thruster]:
            x = self.velocity[0] + (self.facing[0] * self.acceleration * time)
            y = self.velocity[1] + (self.facing[1] * self.acceleration * time)
            self.velocity = x, y
开发者ID:pathunstrom,项目名称:Pygotham-Pygame,代码行数:34,代码来源:sprite.py


示例13: _blockUnderCursor

    def _blockUnderCursor(self, center=False):
        """
            returns a point in 3d space that was determined by
         reading the depth buffer value
        """
        try:
            GL.glReadBuffer(GL.GL_BACK)
        except Exception:
            logging.exception('Exception during glReadBuffer')
        ws = self.root.size
        if center:
            x, y = ws
            x //= 2
            y //= 2
        else:
            x, y = mouse.get_pos()
        if (x < 0 or y < 0 or x >= ws[0] or
                    y >= ws[1]):
            return 0, 0, 0

        y = ws[1] - y

        try:
            pixel = GL.glReadPixels(x, y, 1, 1, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT)
            newpoint = unproject(x, y, pixel[0])
        except Exception:
            return 0, 0, 0

        return newpoint
开发者ID:Dominic001,项目名称:MCEdit-Unified,代码行数:29,代码来源:camera.py


示例14: MouseClicks

def MouseClicks(collisionrects, screen, button, filled, bgc=(255, 255, 255), sq=0):
    """Handles mouse clicks"""
    i = 1
    mpos = mouse.get_pos()
    count = filled.count
    sort = filled.sort
    if button == 1:
        append = filled.append
        for sqrect in collisionrects: #Test each rectangle
            if sqrect.collidepoint(mpos): #If there is collision with the mouse pointer
                if count(i) == 0:
                    append(i)
                    sort()
                screen.fill((0, 0, 0), sqrect)
            i += 1
    elif button == 2:
        remove = filled.remove
        for sqrect in collisionrects:
            if sqrect.collidepoint(mpos):
                if count(i):
                    remove(i)
                    sort()
                screen.fill(bgc, sqrect)
            i += 1
    elif button == 3:
        remove = filled.remove
        for sqrect in collisionrects:
            if sqrect.collidepoint(mpos):
                if count(i):
                    remove(i)
                    sort()
                screen.fill(bgc, sqrect)
                screen.blit(sq, sqrect)
            i += 1
    return filled
开发者ID:Morgus,项目名称:Hanjie,代码行数:35,代码来源:gamedefs.py


示例15: event

 def event(self, event):
     # self.direction = STOP
     # create STOP event to make it work
     if event.type == KEYDOWN:
         self.control_mode = "arrows"
         self.__update_direction(event.key)
         if event.key == 280:  # PgUp
             self.speed += 1
         elif event.key == 281:  # PgDown
             self.speed -= 1
     if event.type == MOUSEBUTTONDOWN:
         self.control_mode = "mouse"
         self.goal = s2c(mouse.get_pos())
         self.screen_goal = mouse.get_pos()
         self.is_new_goal = True
         print "mouse %s %s" % (self.position, self.goal)
开发者ID:wannadie,项目名称:ideaman,代码行数:16,代码来源:hero.py


示例16: mouseLookOn

    def mouseLookOn(self):
        self.root.capture_mouse(self)
        self.focus_switch = None
        self.startingMousePosition = mouse.get_pos()

        if self.avoidMouseJumpBug == 1:
            self.avoidMouseJumpBug = 2
开发者ID:Dominic001,项目名称:MCEdit-Unified,代码行数:7,代码来源:camera.py


示例17: start_editor

    def start_editor(self):
        glyph = self.editor_info
        glyph_rect = glyph.rect
        glyph.input(PAGES['editor'])
        glyph.update()
        editor = self.editor
        editor_rect = editor.rect
        SCREEN.blit(EDITOR_BKGSCREEN, (0, 0))
        SCREEN.blit(glyph.image, glyph_rect)
        SCREEN.blit(editor.image, editor_rect)
        editor_focus = False
        while 1:
            mouse_pos = mouse.get_pos()
            link = glyph.get_collisions(mouse_pos)
            if link: mouse.set_cursor(*HAND_CURSOR)
            else: mouse.set_cursor(*DEFAULT_CURSOR)
            for ev in event.get():
                if ev.type == MOUSEBUTTONDOWN:
                    if link: pass

                    if editor.rect.collidepoint(mouse_pos): editor_focus = True

                    else: editor_focus = False

                if ev.type == KEYDOWN:
                    if ev.key == K_ESCAPE: exit()
                    if editor_focus == True: editor.input(ev)

            cursor = editor.get_cursor()
            editor.image.fill((255, 205, 0), cursor)

            SCREEN.blit(editor.image, editor_rect)
            display.update()
开发者ID:LukeMS,项目名称:glyph,代码行数:33,代码来源:example.py


示例18: event

 def event(self, event):
     if event.type == PG.KEYDOWN and event.key == PG.K_ESCAPE:
         G.Globals.STATE = Menu.Menu()
     if event.type == PG.MOUSEBUTTONDOWN:
         pos = PM.get_pos()
         if pos[0] >= 0 and pos[0] <= self.back_x:
             if pos[1] >= 0 and pos[1] <= self.back_y:
                 G.Globals.STATE = Menu.Menu()        
开发者ID:BitBallers,项目名称:GammaRayKitten,代码行数:8,代码来源:Instructions.py


示例19: mouse_hovering

 def mouse_hovering(self, mouse_pos=None):
     # pygame gets pissy if it's not initialized so we can't have x and
     # y in the initializer
     if not mouse_pos:
         mouse_pos = mouse.get_pos()
     # srsly???
     return self.surface.get_rect().move(self.x, self.y).collidepoint(
     mouse_pos)
开发者ID:B-Lock,项目名称:risk,代码行数:8,代码来源:clickable.py


示例20: get_tile

    def get_tile(self):
        x, y = mouse.get_pos()
        x += self.camera.rect.x
        y += self.camera.rect.y

        for t in self.tilemgr.tiles:
            if t.rect.collidepoint(x, y):
                self.current_tile = t.kind
                break
开发者ID:drtchops,项目名称:iancraft,代码行数:9,代码来源:editor.py



注:本文中的pygame.mouse.get_pos函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python mouse.get_pressed函数代码示例发布时间:2022-05-25
下一篇:
Python music.play函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap