有没有办法在pygame中生成八边形-六边形-正方形-梯形网格

问题描述 投票:0回答:1

好吧,我正在尝试使用 Pygame 在 python 中制作一个游戏,我想要一个如下图所示的网格; (https://i.stack.imgur.com/MdmLZ.png)

我什至不知道如何解决这个问题,任何帮助将不胜感激。 (由于我是新手,详细的解释也会很有帮助。)

谢谢你。

我什至不知道如何解决这个问题

python pygame game-development
1个回答
0
投票

欢迎来到 Stack Overflow!我强烈建议对 pygame 进行更多研究,如果您不知道如何解决这个问题,那么这可能意味着您应该首先学习如何使用必要的工具。

如果你想构建一个游戏,我建议不要直接跳进去,在开始构建之前学习 python 和 pygame 的诀窍。如果您只想显示图像而不需要任何交互或动画(我假设您想稍后添加它?),您可以尝试以下代码:

import pygame
from sys import exit

pygame.init()

image_path = "path/to/your/image.jpg"  # Replace with the path to your image file
image = pygame.image.load(image_path)
image_rect = image.get_rect()

width, height = image_rect.width, image_rect.height
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption("Pygame Image Display")


screen.blit(image, image_rect)

pygame.display.flip()

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            exit()

这些是基本的 pygame 函数,blit 只是将图像绘制到屏幕上。 while 循环会检测您是否退出 GUI,然后循环就会结束。如果您想要或想要另一个网格,您可以尝试自定义图像尺寸。

再次,您可能应该尝试学习更多 pygame,因为这只是一个小脚本,除了您想要的显示之外没有太多功能

© www.soinside.com 2019 - 2024. All rights reserved.