Skip to content

Instantly share code, notes, and snippets.

@spiiin
Created August 2, 2016 22:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spiiin/dfabd3cd7554c1bc0bdb1c0133e723b4 to your computer and use it in GitHub Desktop.
Save spiiin/dfabd3cd7554c1bc0bdb1c0133e723b4 to your computer and use it in GitHub Desktop.
from operator import itemgetter
NAME_TABLE_SIZE = 960
def getAllScreenBlocks(tiles):
#функция выбора индексов блока
def getNextItem2x2(firstIndex, maxIndex):
i = firstIndex
while i < maxIndex:
for x in xrange(16):
yield i
i += 2
i += 32
#ограничиваем генератор индексов размером Name Table
getNextFromPage = lambda fi : getNextItem2x2(fi, NAME_TABLE_SIZE)
#начальные индексы тайлов в блоке
startIndexes = (0,1,32,33)
#создаём генератор индексов блоков
blockIndexesIters = [getNextFromPage(x) for x in startIndexes]
#выбираем индексы блоков
blocksIndexes = zip(*blockIndexesIters)
#получаем номера тайлов блоков по их индексам
blocks = [itemgetter(*b)(tiles) for b in blocksIndexes]
return blocks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment