问题描述
我来这里是因为我在迷你游戏的一开始就陷入困境,我认为游戏本身并没有那么难,但我对 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 (将#修改为@)