import pygame from hexxi import hexxi pygame.display.set_mode((640,640))#,pygame.NOFRAME) #pygame.display.set_icon(pygame.image.load("icon.png").convert_alpha()) ## --- Old LCD colors --- ## ##bg = pygame.Color(175,204,124,120) ##fg = pygame.Color(55,64,39) ## --- B/W LCD Colors --- ## bg = pygame.Color(255,255,255,10) fg = pygame.Color(0,0,0) class Display(): def __init__(self, dim = (96,64), scale = 10, colors = [bg,fg],padding=1): self.dim = dim self.colors = colors self.scale = scale self.padding = padding self.data = [] self.updatedPx = [] for i in range(dim[1]): self.data.append([]) for i in range(dim[0]): self.data[-1].append(0) if pygame.display.get_init() == 1: pygame.display.quit() self.screen = pygame.display.set_mode((self.dim[0]*(self.scale+self.padding),self.dim[1]*(self.scale+self.padding))) print "LCD Display initialized with buffer size of: "+str(dim[0])+"*"+str(dim[1]) def init(self): if pygame.display.get_init() == 1: pygame.display.quit() self.screen = pygame.display.set_mode((self.dim[0]*(self.scale+self.padding),self.dim[1]*(self.scale+self.padding))) pygame.display.set_icon(pygame.image.load("C:/xampp/htdocs/images/icons/large-diamond-mint.png").convert_alpha()) print "LCD Display initialized with buffer size of: "+str(self.dim[0])+"*"+str(self.dim[1]) def px(self, x, y, val = None): if val == None: return self.data[y][x] else: if x < self.dim[0] and y < self.dim[1]: self.data[y][x] = val self.updatedPx.append((x,y)) return val def fill(self,val=0,update=False): for y in range(self.dim[1]): for x in range(self.dim[0]): self.px(x,y,val) if update: self.update() return val def sprite(self,x,y,h,update=False): l = len(str(hexxi(h[0]))) for m in range(l): r = str(hexxi(h[m])) for n in range(l): c = r[n] #print c self.px(n+x,m+y,int(c)) if update: self.update() def update(self): for u in self.updatedPx: x,y = u dx = (self.scale+self.padding)*x dy = (self.scale+self.padding)*y s = self.scale r = pygame.Rect(dx,dy,s,s) self.screen.fill(self.colors[self.data[y][x]],r) self.updatedPx = [] pygame.display.update() ## --- For testing, uncomment --- ## def run_editor(): global pygame d = Display([8,8],(640/8)) d.fill() #s = hexxi("7e8181818181817e") #c = 2 #pos = (48,24) #d.colors.append(pygame.Color("Red")) #d.fill(0) #d.sprite(pos[0],pos[1],s) #d.px(10,10,c) #d.update() clock = pygame.time.Clock() max_fps = 60 running = True while running: delta = clock.tick(max_fps) events = pygame.event.get() for e in events: if e.type == pygame.MOUSEBUTTONDOWN: px_pos = [e.pos[0]/(640/8),e.pos[1]/(640/8)] px_val = d.px(px_pos[0],px_pos[1]) if px_val == 0: d.px(px_pos[0],px_pos[1],1) elif px_val < (len(d.colors)-1): d.px(px_pos[0],px_pos[1],px_val+1) else: d.px(px_pos[0],px_pos[1],0) if e.type == pygame.QUIT: running = False d.update() sprite_hex = "" for y in d.data: sprite_hex += "".join([str(x) for x in y]) shex = hexxi(sprite_hex,1).hexxi print(shex) open("dump.txt","w").write(shex) pygame.quit() return shex def test_sprite(h): s = hexxi(h) d = Display() d.fill() pos = [8,8] d.sprite(pos[0],pos[1],s) clock = pygame.time.Clock() max_fps = 60 running = True while running: delta = clock.tick(max_fps) events = pygame.event.get() for e in events: if e.type == pygame.QUIT: running = False d.update() pygame.quit() if __name__ == "__main__": sprite_name = "" sprite_data = "" sprites = {} print("\n\n\n--- Welcome to the LCD Intigrated Hex Sprite Editor ---\n\n") print('First type name of your sprite in the console.') print('Next you\'ll be promped with a point and click editor.') print('When you are done drawing your sprite you may') print('exit the editor window and you\'ll be promted through') print('the same process again\n') print('At any time you may also type:') print('"TEST" to show/test a sprite.') print('"EXIT" or "QUIT" to exit the application and dump.\n') print('Note: sprite hexes are exported to \"dump.txt\"\nfor your spriting pleasure\n\n') while sprite_name != "EXIT": sprite_name = raw_input("sprite name:") if sprite_name == "TEST": sprite_name = raw_input("sprite name:") test_sprite(sprites[sprite_name]) else: if sprite_name != "EXIT" and sprite_name != "QUIT": sprite_data = run_editor() sprites[sprite_name] = sprite_data file_data = "" for k in sprites: file_data += k+":"+sprites[k]+"\n" print(file_data) open("dump.txt","w").write(file_data)