Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- class MapChunk(object):
- def __init__(self, chunkVal):
- """
- chunkVal = 4digit int 1010 minimum value 7474 maximum value
- """
- try:
- self.tileArray=np.load(str(chunkVal/100)+"."+str(chunkVal%100)+".npy")
- except IOError as errorInfo:
- print("IOError: ", errorInfo)
- self.tileArray=np.zeros([64,64])
- def getTileArray(self):
- return self.tileArray
- def getTile(self,x,y):
- return self.tileArray[x,y]
- def setTileArray(self, tileArray):
- self.tileArray=tileArray
- def setTile(self,x,y,val):
- self.tileArray[x,y]=val
- class Map(object):
- def __init__(self, offsetX, offsetY): # Offset 0 to 61 (61 limit bc 3x3 grid)
- self.mapArray=np.empty(shape=(3,3), dtype=MapChunk) # Create chunk map (64x64)
- self.currentX=offsetX
- self.currentY=offsetY
- if offsetX<0: # out of bounds management
- offsetX=0
- print "Map OffsetX < 0, setting to 0. Map.__init__"
- if offsetX>61:
- offsetX=61
- print "Map OffsetX > 61, setting to 61. Map.__init__"
- if offsetY<0:
- offsetY=0
- print "Map OffsetY < 0, setting to 0. Map.__init__"
- if offsetY>61:
- offsetY=61
- print "Map OffsetY > 61, setting to 61. Map.__init__"
- for x in range(3): # Fill with data from file
- for y in range(3):
- chunkVal=1010+100*(offsetX+x)+offsetY+y
- self.mapArray[x,y]=MapChunk(chunkVal)
- # print x, " ", y, " ",chunkVal
- def getMap(self): # very much doubt you'd want to use this but psshhhhhh y-knot
- return self.mapArray
- def getMapChunkExact(self, x, y):
- if x>=self.currentX and x<=self.currentX+2: # Check value is in mem
- if y>=self.currentY and y<=self.currentY+2:
- return self.mapArray[x-self.currentX,y-self.currentY]
- print "Offset out of bounds in Map.getMapChunkExact"
- def getMapChunkByOffset(self, offsetX, offsetY): # range 0-2
- if offsetX>=0 and offsetX<=2: # Check value is in mem
- if offsetY>=0 and offsetY<=2:
- return self.mapArray[self.currentX+offsetX,self.currentY+offsetY]
- print "Offset out of bounds in Map.getMapChunkByOffset"
- x=Map(0,0)
- x.getMapChunkByOffset(2,2)
- """tileArray=np.zeros([64,64])
- for i in range(10,74):
- for j in range(10,74):
- np.save(str(i)+"."+str(j),tileArray)"""
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement