感谢您花时间阅读本文。我正在尝试用pygame创建一个非常基本的游戏系统。我不是pygame最好的,所以我可能会错过一些相当明显的东西。到目前为止,我已将所有内容都放在一个文件中我现在所看到的似乎很渺茫,可能有更高效的方法,但现在我只是使用2d数组,其数字等同于特定类型的瓦片(草,水等)。为此,我正在使用numpy,因为这是有人推荐给我的。虽然我不知道我是否喜欢这种方法,因为如果将来我有一些不是简单的图形,而且具有更多特定的属性呢?像宝箱一样或陷阱?你将如何构造这个?使用pygame问题/问题的基于Tile的游戏
但无论如何,我的问题是现在的屏幕只是黑色的,并没有绘制草地砖。
下面是代码:
import numpy
import pygame
import sys
from pygame.locals import *
pygame.init()
fpsClock = pygame.time.Clock()
windowWi = 800
windowHi = 608
mapWi = 50 # *16 = 800, etc
mapHi = 38
# ----- all of the images ------------------------------
grass1 = pygame.image.load('pictures\(Grass\grass1.png')
#-------------------------------------------------------
screen = pygame.display.set_mode((windowWi, windowHi))
pygame.display.set_caption("Tile Testing!")
gameRunning = True
groundArray = numpy.ones((mapWi,mapHi))
def drawMapArray(maparray):
for x in range(mapWi,1):
for y in range(mapHi,1):
#Determines tile type.
if maparray[y,x] == 1:
screen.blit(grass1, (x*16, y*16))
else:
print "Nothing is here!"
while gameRunning:
drawMapArray(groundArray)
for event in pygame.event.get():
if event.type == "QUIT":
pygame.quit()
sys.exit()
#Updates display and then sets FPS to 30 FPS.
pygame.display.update()
fpsClock.tick(30)
请随时引导我,因为我很新的游戏设计,并希望任何反馈,更好的结构方向!
感谢, 瑞安
编辑: 我曾经尝试这样做,这是有道理的逻辑,但我得到一个索引超出范围的错误。可能会扩展为您增加更多的瓷砖类型更好
def drawMapArray(maparray):
for x in range(0,mapWi,1):
for y in range(0,mapHi,1):
#Determines tile type.
if maparray[y,x] == 1:
screen.blit(grass1, (x*16, y*16))
else:
print "Nothing is here!"
你的意思是有一个“(”文件名'图片\(草\ grass1.png'? – 2012-08-09 00:02:01
我想你'范围()'调用可能是走错了路周围,试图为' x在范围内(1,mapWi):'。 – Marius 2012-08-09 00:04:43
这就是如何命名文件哈哈,这些只是一些开源的16位瓦片图像,我用于测试目的,我很快就会改变它,因为它看起来很混乱 – Ryan 2012-08-09 00:07:02