Skip to content

Commit

Permalink
Make things a bit cleaner, possibly.
Browse files Browse the repository at this point in the history
  • Loading branch information
Francis Herne committed Nov 23, 2014
1 parent 57a74fb commit 9f2d55f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
9 changes: 7 additions & 2 deletions Map.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,16 @@ def __init__(self, mapdict):

groundimage = pygame.image.load(terrainfilepath).convert()
groundarray = pygame.surfarray.pixels2d(groundimage)
if not all(color in terrain.colorlist(groundimage) for color in numpy.unique(groundarray)):
wronggroundcolours = numpy.setdiff1d(groundarray, terrain.colorlist(groundimage))
if wronggroundcolours.size:
print wronggroundcolours
raise Exception("Unexpected value in "+terrainfilepath)
collectablesimage = pygame.image.load(itemfilepath).convert()
collectablesarray = pygame.surfarray.pixels2d(collectablesimage)
if not all(color in collectables.colorlist(collectablesimage) for color in numpy.unique(collectablesarray)):
collectablescolorsflat = pygame.surfarray.map_array(collectablesimage, numpy.array(collectables.mapcolor.keys()))
wrongcollectablecolors = numpy.setdiff1d(collectablesarray, collectablescolorsflat)
if wrongcollectablecolors.size:
print wrongcollectablecolors
raise Exception("Unexpected value in "+itemfilepath)
self.size = groundimage.get_rect().size

Expand Down
4 changes: 0 additions & 4 deletions collectables.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import numpy
import pygame.surfarray
from colors import *

NONE = 0
Expand All @@ -13,8 +11,6 @@
BROWN: CHOCOLATE,
RED: DYNAMITE
}
def colorlist(surface):
return [pygame.surfarray.map_array(surface, numpy.array([color])) for color in mapcolor.keys()]

value = {
NONE: 0,
Expand Down
2 changes: 1 addition & 1 deletion terrain.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
typeslist = types.tolist()

def colorlist(surface):
return [pygame.surfarray.map_array(surface, numpy.array([type[0:3]])) for type in typeslist]
return pygame.surfarray.map_array(surface, types[['r','g','b']].view(numpy.uint8).reshape(-1, 3))
def color_typeindex(surface):
return zip(colorlist(surface), range(len(typeslist)))

Expand Down

0 comments on commit 9f2d55f

Please sign in to comment.