Created
April 19, 2012 14:15
-
-
Save youngershen/2421224 to your computer and use it in GitHub Desktop.
你妹的,晚上就敲了这几行,pygame还老假死,去你妹
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import pygame | |
from pygame.locals import * | |
import pygame.surfarray as surfarray | |
def init(): | |
pygame.init() | |
screen = pygame.display.set_mode((500,500)) | |
def initPlayerPosition(): | |
position =[] | |
for i in range(4): | |
for n in range(4): | |
position.append((i*100,n*130)) | |
return position | |
def loadImage(path,name = None): | |
if name == None: | |
fullPath = os.path.join(path) | |
else : | |
fullPath = os.path.join(path,name) | |
try: | |
image = pygame.image.load(fullPath) | |
except pygame.error,message: | |
print 'cannot load your images',fullname | |
raise SystemExit,message | |
#image = image.convert() | |
return image,image.get_rect() | |
def loadImages(*path): | |
images = [] | |
if len(path) == 0: | |
return | |
for file in path: | |
images.append(loadImage(file)) | |
return images | |
def initPlayerSurface(image,position): | |
buffer2d = surfarray.pixels2d(image) | |
print len(buffer2d[0]) | |
buffer = [] | |
print position | |
for i in position: | |
x = i[0] | |
y = i[1] | |
for n in range(0,130): | |
for m in range(0,100): | |
temp = buffer2d[x+m][y+n] | |
buffer.append(temp) | |
return buffer | |
def eventLine(): | |
try: | |
while 1: | |
event = pygame.event.wait() | |
if event.type == pygame.QUIT: | |
break | |
if event.type == pygame.KEYDOWN: | |
if event.key == pygame.K_ESCAPE or event.unicode == 'q': | |
break | |
pygame.display.flip() | |
finally: | |
pygame.quit() | |
if __name__ == '__main__': | |
init() | |
pos = initPlayerPosition(); | |
player = loadImage('./resources/images/loli/','loli.png') | |
sur = initPlayerSurface(player[0],pos) | |
player[0].convert() | |
print sur | |
eventLine() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment