【发布时间】:2015-06-01 17:48:54
【问题描述】:
嗨,我正在制作一个基本的光线投射引擎,所以我认为从小地图开始会很好,但问题是我的类地图在构造函数中要求一个 mapGrid,当我通过它时,python 给了我这个错误@ 987654321@
这是代码: 主要部分
import pygame
def map(object):
def __init__(self,grid,scale):
self.grid= grid
self.mapWidth= len(grid[0]) #Number of map blocks
self.mapHeight= len(grid)
self.miniMapScale= scale #How many pixels to draw a map block
self.miniWidth= self.mapWidth * self.miniMapScale #Size of the minimap
self.miniHeight= self.mapHeight * self.miniMapScale
self.rectGrid= grid
for y in range(self.mapHeight):
for x in range(self.mapWidth):
self.rectGrid[y][x]= pygame.Rect(x,y,self.miniWidth,self.miniHeight)
def blitMiniMap():
pass
数据文件
mapGrid= [
[1,1,1,1],
[1,0,0,1],
[1,0,0,1],
[1,1,1,1]
]
size = [640, 480]
地图类
import pygame
def map(object):
def __init__(self,grid,scale):
self.grid= grid
self.mapWidth= len(grid[0]) #Number of map blocks
self.mapHeight= len(grid)
self.miniMapScale= scale #How many pixels to draw a map block
self.miniWidth= self.mapWidth * self.miniMapScale #Size of the minimap
self.miniHeight= self.mapHeight * self.miniMapScale
self.rectGrid= grid
for y in range(self.mapHeight):
for x in range(self.mapWidth):
self.rectGrid[y][x]= pygame.Rect(x,y,self.miniWidth,self.miniHeight)
def blitMiniMap():
pass
谢谢。
【问题讨论】:
-
你确定你必须两次发布相同的代码吗?有一个名为
map的内置函数,it 有两个参数要传递给它
标签: python list arguments pygame iteration