1
這就是我現在正在做的事情,我知道一定有更好的辦法,一直在尋找幾天。我所做的基本上是強制檢查if/elif在哪裏開始新行。 'imgblock'是一個16x16像素的精靈,屏幕上保存着一個16x10的網格。下面在lolgrid()部分中,我已經定義了圖像名稱,並且儘管在網格中的每個塊都希望它顯示出來。任何人都可以請給我一些關於如何讓這更優雅的信息?我只待了一個禮拜,我真的很感激它對我在這裏糟糕的嘗試的經驗。如何創建一個網格來將精靈粘貼到?
由於一噸
import pygame, sys, os, random
from pygame.locals import *
pygame.init()
#print help(pygame.transform)
resmulti=3
spritesize=16*resmulti
resolution=(256*resmulti,224*resmulti)
framerate=60
## OBJECTS ##
clock=pygame.time.Clock()
screen=pygame.display.set_mode(resolution)
## TEST STUFF ##
test = [random.randint(1,10) for i in range(20)]
print test
## MAIN ##
def pngLoad(imgloc, size, flipx, flipy):
img = pygame.image.load(imgloc).convert_alpha()
if size > 1:
#pygame.transform.scale(Surface, (width, height), DestSurface = None): return Surface
img = pygame.transform.scale(img, (img.get_width()*size, img.get_height()*size))
if flipx == 1:
#pygame.transform.flip(Surface, xbool, ybool)
img = pygame.transform.flip(img, True, False)
if flipy == 1:
img = pygame.transform.flip(img, False, True)
return img
################################################
# GRID = 16x16 pixel blocks. 16x10.5 block grid
################################################
def lolGrid(imgBlock,*gridz):
#print list(gridz)
Grid = range(177)
for i in gridz:
if i < 16:
Grid[i] = screen.blit(imgBlock, (i*spritesize,resmulti*56))
elif i > 15 and i < 32:
Grid[i] = screen.blit(imgBlock, ((i-16)*spritesize,spritesize+resmulti*56))
elif i > 31 and i < 48:
Grid[i] = screen.blit(imgBlock, ((i-32)*spritesize,spritesize*2+resmulti*56))
elif i > 47 and i < 64:
Grid[i] = screen.blit(imgBlock, ((i-48)*spritesize,spritesize*3+resmulti*56))
elif i > 63 and i < 80:
Grid[i] = screen.blit(imgBlock, ((i-64)*spritesize,spritesize*4+resmulti*56))
elif i > 79 and i < 96:
Grid[i] = screen.blit(imgBlock, ((i-80)*spritesize,spritesize*5+resmulti*56))
elif i > 95 and i < 112:
Grid[i] = screen.blit(imgBlock, ((i-96)*spritesize,spritesize*6+resmulti*56))
elif i > 111 and i < 128:
Grid[i] = screen.blit(imgBlock, ((i-112)*spritesize,spritesize*7+resmulti*56))
elif i > 127 and i < 144:
Grid[i] = screen.blit(imgBlock, ((i-128)*spritesize,spritesize*8+resmulti*56))
elif i > 143 and i < 160:
Grid[i] = screen.blit(imgBlock, ((i-144)*spritesize,spritesize*9+resmulti*56))
elif i > 159 and i < 176:
Grid[i] = screen.blit(imgBlock, ((i-160)*spritesize,spritesize*10+resmulti*56))
############
#LOL IMAGES
############
tanback = pngLoad("tanback.png", resmulti,0,0)
longblackback = pngLoad("blackbacklong.png", resmulti,0,0)
link1 = pngLoad("link1.png", resmulti,1,0)
shrub1 = pngLoad("shrub_01.png", resmulti,0,0)
grnwall1 = pngLoad("greenwall_01.png", resmulti,0,0)
grnwall2 = pngLoad("greenwall_02.png", resmulti,0,0)
grnwall3 = pngLoad("greenwall_03.png", resmulti,0,0)
#background = pngLoad("back.png")
#mous = pngLoad("link001.png")
#bif="back.png"
#mif="link001.png"
#background=pygame.image.load(bif).convert_alpha()
#mous=pygame.image.load(mif).convert_alpha()
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
screen.blit(tanback,(0,0))
screen.blit(longblackback,(0,resmulti*3*-56))
#screen.fill((255,218,144), rect=None, special_flags=0)
lolGrid(grnwall1,0,1,16,17,32,33,48,112,128,129,144,145,160,161)
lolGrid(grnwall2,49,64)
lolGrid(grnwall3,96,113)
lolGrid(shrub1,2, 4, 6, 9, 11, 13, 15,18,20,22,25,27,29,31,54,57,59,61, 66, 68,86,89,91,98,100,118,121,123,125,146,147,148,149,150,151,152,153,154,155,156,157,158,159,162,163,164,165,166,167,168,169,170,171,172,173,174,175)
print clock.get_fps()
clock.tick(framerate)
pygame.display.update()
你就不能圓座標最近的網格邊界? – martineau
我不確定你在做什麼。像這樣? http://i.stack.imgur.com/utDaA.png – ninMonkey
我認爲即時通訊術語錯誤。我試圖採取代表瓦片配置的地圖,並將它們放在網格上。是的,猴子,它看起來有點像這樣,每個矩形都是它自己的圖塊,放置在某個地圖文件中用於該「級別」或任何它將被調用的地圖文件。 馬蒂諾im不是100%確定如何id做 –