本文整理汇总了Python中pygame.MOUSEBUTTONDOWN属性的典型用法代码示例。如果您正苦于以下问题:Python pygame.MOUSEBUTTONDOWN属性的具体用法?Python pygame.MOUSEBUTTONDOWN怎么用?Python pygame.MOUSEBUTTONDOWN使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类pygame
的用法示例。
在下文中一共展示了pygame.MOUSEBUTTONDOWN属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: startInterface
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import MOUSEBUTTONDOWN [as 别名]
def startInterface(screen):
screen.fill(Config.get('bg_color'))
clock = pygame.time.Clock()
while True:
button_1 = BUTTON(screen, (95, 150), '开始游戏')
button_2 = BUTTON(screen, (95, 305), '退出游戏')
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
if button_1.collidepoint(pygame.mouse.get_pos()):
return
elif button_2.collidepoint(pygame.mouse.get_pos()):
quitGame()
clock.tick(60)
pygame.display.update()
示例2: start_interface
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import MOUSEBUTTONDOWN [as 别名]
def start_interface(screen):
clock = pygame.time.Clock()
while True:
button_1 = BUTTON(screen, (330, 190), '单人模式')
button_2 = BUTTON(screen, (330, 305), '双人模式')
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
if button_1.collidepoint(pygame.mouse.get_pos()):
return 1
elif button_2.collidepoint(pygame.mouse.get_pos()):
return 2
clock.tick(60)
pygame.display.update()
示例3: end_interface
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import MOUSEBUTTONDOWN [as 别名]
def end_interface(screen):
clock = pygame.time.Clock()
while True:
button_1 = BUTTON(screen, (330, 190), '重新开始')
button_2 = BUTTON(screen, (330, 305), '退出游戏')
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
if button_1.collidepoint(pygame.mouse.get_pos()):
return
elif button_2.collidepoint(pygame.mouse.get_pos()):
pygame.quit()
sys.exit()
clock.tick(60)
pygame.display.update()
示例4: switchInterface
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import MOUSEBUTTONDOWN [as 别名]
def switchInterface(screen):
screen.fill(Config.get('bg_color'))
clock = pygame.time.Clock()
while True:
button_1 = BUTTON(screen, (95, 150), '进入下关')
button_2 = BUTTON(screen, (95, 305), '退出游戏')
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
if button_1.collidepoint(pygame.mouse.get_pos()):
return
elif button_2.collidepoint(pygame.mouse.get_pos()):
quitGame()
clock.tick(60)
pygame.display.update()
示例5: endInterface
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import MOUSEBUTTONDOWN [as 别名]
def endInterface(screen, color, is_win):
screen.fill(color)
clock = pygame.time.Clock()
if is_win:
text = 'VICTORY'
else:
text = 'FAILURE'
font = pygame.font.SysFont('arial', 30)
text_render = font.render(text, 1, (255, 255, 255))
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if (event.type == pygame.KEYDOWN) or (event.type == pygame.MOUSEBUTTONDOWN):
return
screen.blit(text_render, (350, 300))
clock.tick(60)
pygame.display.update()
示例6: startInterface
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import MOUSEBUTTONDOWN [as 别名]
def startInterface(screen):
clock = pygame.time.Clock()
while True:
screen.fill((41, 36, 33))
button_1 = Button(screen, (150, 175), '1 Player')
button_2 = Button(screen, (150, 275), '2 Player')
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
if button_1.collidepoint(pygame.mouse.get_pos()):
return 1
elif button_2.collidepoint(pygame.mouse.get_pos()):
return 2
clock.tick(10)
pygame.display.update()
示例7: handleEvents
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import MOUSEBUTTONDOWN [as 别名]
def handleEvents(self):
self.mouse = self.get(MOUSE)
for event, pos in self.context.events:
self.mouse = pos
handled = self.mode.handleEvent((event, pos))
if not handled:
if event.type == pygame.MOUSEBUTTONDOWN:
self.handleMouseDown(event, pos)
elif event.type == pygame.MOUSEMOTION:
self.handleMouseMotion(pos)
elif event.type == pygame.MOUSEBUTTONUP:
self.handleMouseUp(pos)
if self.mouse:
self.set(MOUSE, self.mouse)
示例8: prompt
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import MOUSEBUTTONDOWN [as 别名]
def prompt(win):
pygame.draw.rect(win, (0, 0, 0), (110, 160, 280, 130))
pygame.draw.rect(win, (255, 255, 255), (110, 160, 280, 130), 4)
win.blit(SF.PROMPT[0], (130, 170))
win.blit(SF.PROMPT[1], (130, 205))
win.blit(SF.YES, (145, 240))
win.blit(SF.NO, (305, 240))
pygame.draw.rect(win, (255, 255, 255), (140, 240, 60, 28), 2)
pygame.draw.rect(win, (255, 255, 255), (300, 240, 45, 28), 2)
pygame.display.flip()
while True:
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONDOWN:
if 240 < event.pos[1] < 270:
if 140 < event.pos[0] < 200:
return True
elif 300 < event.pos[0] < 345:
return False
# This shows the installation guide screen
示例9: main
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import MOUSEBUTTONDOWN [as 别名]
def main(win):
pth = os.path.join("res", "stockfish", "path.txt")
configured = os.path.exists(pth)
clock = pygame.time.Clock()
while True:
clock.tick(24)
showScreen(win, configured)
for event in pygame.event.get():
if event.type == pygame.QUIT:
return False
elif event.type == pygame.MOUSEBUTTONDOWN:
x, y = event.pos
if 120 < x < 370 and 320 < y < 350:
if configured:
os.remove(pth)
if guideMain(win):
return True
else:
configured = os.path.exists(pth)
pygame.display.update()
示例10: prompt
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import MOUSEBUTTONDOWN [as 别名]
def prompt(win):
rounded_rect(win, (255, 255, 255), (110, 160, 280, 130), 4, 4)
win.blit(PREF.PROMPT[0], (130, 165))
win.blit(PREF.PROMPT[1], (130, 190))
win.blit(PREF.YES, (145, 240))
win.blit(PREF.NO, (305, 240))
pygame.draw.rect(win, (255, 255, 255), (140, 240, 60, 28), 2)
pygame.draw.rect(win, (255, 255, 255), (300, 240, 45, 28), 2)
pygame.display.flip()
while True:
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONDOWN:
if 240 < event.pos[1] < 270:
if 140 < event.pos[0] < 200:
return True
elif 300 < event.pos[0] < 350:
return False
# This function shows the screen
示例11: main
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import MOUSEBUTTONDOWN [as 别名]
def main(win):
prefs = load()
clock = pygame.time.Clock()
while True:
clock.tick(24)
showScreen(win, prefs)
for event in pygame.event.get():
if event.type == pygame.QUIT and prompt(win):
return
elif event.type == pygame.MOUSEBUTTONDOWN:
if 200 < event.pos[0] < 285 and 450 < event.pos[1] < 490:
save(*prefs)
return
for cnt in range(5):
if 100 + cnt*60 < event.pos[1] < 140 + cnt*60:
if 250 < event.pos[0] < 330:
prefs[cnt] = True
if 360 < event.pos[0] < 430:
prefs[cnt] = False
pygame.display.update()
示例12: prompt
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import MOUSEBUTTONDOWN [as 别名]
def prompt(win):
rounded_rect(win, (255, 255, 255), (110, 160, 280, 130), 10, 4)
win.blit(LOADGAME.MESSAGE[0], (116, 160))
win.blit(LOADGAME.MESSAGE[1], (118, 190))
win.blit(LOADGAME.YES, (145, 240))
win.blit(LOADGAME.NO, (305, 240))
pygame.draw.rect(win, (255, 255, 255), (140, 240, 60, 28), 2)
pygame.draw.rect(win, (255, 255, 255), (300, 240, 46, 28), 2)
pygame.display.flip()
while True:
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONDOWN:
if 240 < event.pos[1] < 270:
if 140 < event.pos[0] < 200:
return True
elif 300 < event.pos[0] < 350:
return False
# This function shows the screen
示例13: getChoice
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import MOUSEBUTTONDOWN [as 别名]
def getChoice(win, side):
win.blit(CHESS.CHOOSE, (130, 10))
win.blit(CHESS.PIECES[side]["q"], (250, 0))
win.blit(CHESS.PIECES[side]["b"], (300, 0))
win.blit(CHESS.PIECES[side]["r"], (350, 0))
win.blit(CHESS.PIECES[side]["n"], (400, 0))
pygame.display.update((0, 0, 500, 50))
while True:
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONDOWN:
if 0 < event.pos[1] < 50:
if 250 < event.pos[0] < 300:
return "q"
elif 300 < event.pos[0] < 350:
return "b"
elif 350 < event.pos[0] < 400:
return "r"
elif 400 < event.pos[0] < 450:
return "n"
# This function draws the board
示例14: mainViewerLoop
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import MOUSEBUTTONDOWN [as 别名]
def mainViewerLoop(self):
while not self._receivedUpdate: # Wait for first update
time.sleep(0.5)
self._initViewier()
while self._runPygame:
for event in pygame.event.get(): # User did something
if event.type == pygame.QUIT: # User clicked quit
self._runPygame = False # Flag done
elif event.type == pygame.MOUSEBUTTONDOWN: # Mouse Click
self._handleClick(pygame.mouse.get_pos())
elif event.type == pygame.KEYDOWN: # Key Press Down
self._handleKeypress(event.key)
if self._receivedUpdate:
self._drawViewer()
self._receivedUpdate = False
time.sleep(0.2)
pygame.quit() # Done. Quit pygame.
示例15: handle
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import MOUSEBUTTONDOWN [as 别名]
def handle(self, event):
gd.BoardGame.handle(self, event) # send event handling up
if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
active = self.board.active_ship
if active == 0:
self.change_fract_btn(self.numbers, -1, 0)
elif active == 1:
self.change_fract_btn(self.numbers, 1, 0)
elif active == 2:
self.change_fract_btn(self.numbers, 0, -1)
elif active == 3:
self.change_fract_btn(self.numbers, 0, 1)
elif active == 4:
self.change_fract_btn(self.numbers2, -1, 0)
elif active == 5:
self.change_fract_btn(self.numbers2, 1, 0)
elif active == 6:
self.change_fract_btn(self.numbers2, 0, -1)
elif active == 7:
self.change_fract_btn(self.numbers2, 0, 1)
self.auto_check_reset()
elif event.type == pygame.KEYDOWN and (event.key == pygame.K_RETURN or event.key == pygame.K_KP_ENTER):
self.check_result()
elif event.type == pygame.KEYDOWN:
self.auto_check_reset()