微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

启动pygame,不知道如何用鼠标与图像进行交互

如何解决启动pygame,不知道如何用鼠标与图像进行交互

我来这里是因为我在迷你游戏的一开始就陷入困境,我认为游戏本身并没有那么难,但我对 pygame 很陌生。游戏本身基本上就是他们给你看一张汽车的图片,然后,几秒钟后,会出现一些非常相似的其他图片,你必须选择正确的图片,然后它会显示它是假的还是正确的.很简单吧?

好吧,我不知道如何从一个活动“过渡”到另一个活动,我什至不知道如何从肖像游戏过渡到直接游戏,因为我有一个箭头图像,我想将其用作“下一步按钮”,以便您可以开始游戏。

所以基本上,不知道如何或是否可以制作游戏的一些示例(意思是,例如按顺序有 5 个迷你游戏),因为我想我必须“清除”或“刷新”屏幕为每个人,并且不知道如何使图像成为鼠标按下的交互式对象。

我认为这在现实中真的很容易,但我对 pygame 知之甚少,我试过在互联网上查找它,但要么我不知道该看什么,他们显示的结果不不帮我,或者我不知道我在做什么。

这是目前的代码

# Importamos las librerías necesarias
import sys,pygame,pygame.freetype
from pygame.locals import *

# Inicializamos pygame
pygame.init()

# Definimos las dimensiones de la ventana (1600 x 900px)
size = 1600,900
screen = pygame.display.set_mode(size)

# Ponemos el título e icono de la ventana
pygame.display.set_caption("Memory")
icon = pygame.image.load('icon.png')
pygame.display.set_icon(icon)

# Colours    R    G    B
GRAY     = (100,100,100)
NAVYBLUE = ( 60,60,100)
BLACK    = (  0,0)
WHITE    = (255,255,255)
RED      = (255,0)
GREEN    = (  0,0)
BLUE     = (  0,255)
YELLOW   = (255,0)
ORANGE   = (255,128,0)
PURPLE   = (127,255)
CYAN     = (  0,255)

FONT1 = PURPLE
FONT2 = BLACK

ALLCOLORS = (RED,GREEN,BLUE,YELLOW,ORANGE,PURPLE,CYAN,WHITE,BLACK)

# open cv2

# Creamos el fondo 
def fondo():
    fondoImg = pygame.image.load('fondo_memory.png')
    fondoX = 0
    fondoY = 0
    screen.blit(fondoImg,(fondoX,fondoY))   

# -------------------------------------------------------

def portada():
    
    font = pygame.font.SysFont("comicsansms",90)
    img = font.render('Memory',True,PURPLE)
    screen.blit(img,(620,400)) 
    
    flechaimg = pygame.image.load('flecha.png')
    d_flecha = screen.blit(flechaimg,(1300,600))
     
    """
    for x in range(d_flecha):
        if event.type == MOUSEBUTTONDOWN:
            fondo()
            pygame.display.update()
    """



# -------------------------------------------------------

# Comenzamos el bucle del juego
run=True
while run:
    # RGB - Red,Green,Blue
    screen.fill ((255,255))
    # Imagen fondo
    fondo()
    # Eventos del mouse 
    mousex = 0 # used to store x coordinate of mouse event
    mousey = 0 # used to store y coordinate of mouse event
    mouse_clicked = False

    # Capturamos los eventos que se han producido
    for event in pygame.event.get():
        
        # Definimos eventos:
        if event.type == pygame.QUIT: # Si el evento es salir de la ventana,terminamos
            run = False
        elif event.type == MOUSEMOTION:
            mouse_x,mouse_y = pygame.mouse.get_pos()
        elif event.type == MOUSEBUTTONDOWN:
            mouse_x,mouse_y = pygame.mouse.get_pos()
            mouse_clicked = True
            print("Click!")

    x,y = pygame.mouse.get_pos(mouse_x,mouse_y)
   # Boxx,Boxy = getBoxAtPixel(mousex,mousey)
    
    portada()
    pygame.display.update()

# Salgo de pygame
pygame.quit()
quit()

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。