def flameplayer(): fronttiles = [coords.sum(self.position, coords.mul(self.direction, i)) for i in range(1,4)] for tile in fronttiles: if tile in [player.position for player in world.players]: self._suggestmessage("The dragon breaths a jet of fire towards you", 5) for tile in fronttiles: self.cellmap.ignite(tile, forceignite=True) break
def get_classifications(image, width, height): global nn boxes, scores, classes, num_classes = nn.get_classification(image) classifications = [] for index in range(int(num_classes[0])): if (scores[0][index] > 0.9): box = boxes[0][index] classID = int(classes[0][index]) pt1, pt2 = split(box) pt1 = pt1[::-1] pt1 = mul(pt1, width, height) # cast normalized coords to image size pt1 = toInt(pt1) pt2 = pt2[::-1] pt2 = mul(pt2, width, height) # cast normalized coords to image size pt2 = toInt(pt2) classifications.append({'id': classID, 'points': [pt1, pt2]}) return classifications
def __init__(self, player, world, position): """Initialise instance variables""" self.player = player self.score = player.score self.world = world position = position if position else world.cellmap.startpos super(GEPlayer, self).__init__(position, world.cellmap) self.color = MAGENTA self.visibility = 15 self.direction = RIGHT self.surface = pygame.Surface(coords.mul(world.cellmap.size, images.TILESIZE)) self.surface.fill(BLACK) self.setup()
def sprite(self, player): isvisible = False tileoffset = [-1 if axis == 1 else 0 for axis in self.direction] for tile in [(0,0), (0,1), (1,0), (1,1)]: tile = coords.modsum(tile, tileoffset, self.cellmap.size) if coords.sum(self.position, tile) in player.visibletiles: isvisible = True break if isvisible: return self._pokedsprite(images.DragonRed[self.direction], layer=20, offset=coords.mul(tileoffset, images.TILESIZE)) else: return None
def rendervisible(self, geplayer, extrasprites=[]): sprites = [] sprites += extrasprites for gemgo in self.gemgos: sprite = gemgo.sprite(geplayer) if sprite is not None: sprites.append(sprite) visibleranges = ([],[]) for axis in [0, 1]: if 2*geplayer.visibility + 5 >= self.cellmap.size[axis]: visibleranges[axis].append((0, self.cellmap.size[axis])) else: rmin = (geplayer.position[axis] - geplayer.visibility - 2) % self.cellmap.size[axis] rmax = (geplayer.position[axis] + geplayer.visibility + 2) % self.cellmap.size[axis] if rmin < rmax: visibleranges[axis].append((rmin, rmax)) else: visibleranges[axis].append((rmin, self.cellmap.size[axis])) visibleranges[axis].append((0, rmax)) surface = geplayer.surface for rx in visibleranges[0]: for ry in visibleranges[1]: surface.set_clip( rx[0]*TILESIZE, ry[0]*TILESIZE, (rx[1]-rx[0])*TILESIZE, (ry[1]-ry[0])*TILESIZE) regionsprites = sprites for ix in range(rx[0]-1, rx[1]+1): for iy in range(ry[0]-1, ry[1]+1): regionsprites += self.cellmap.sprites((ix, iy)) if coords.mod((ix, iy), self.cellmap.size) not in geplayer.visibletiles: sprites.append((images.NonVisible, coords.sum(coords.mul((ix, iy), TILESIZE), (-4,-4)), 100)) regionsprites.sort(key=lambda x: x[2]) for sprite in regionsprites: surface.blit(*sprite[:2])
def vizhbond(geom, scale): # find hydrogen bonds # tol=3.0 # in angstroms # .. we should find this automagically.. lines = [] app = False c = 0 li = coords.pickspec(geom, "O") # print li # stop tol = coords.distance(li[0], li[1]) * 1.20 for g in geom: if (g[0] == "O"): hn = 0 nei = coords.find_neighbours( g, geom) # 0=the O atom, 1=H, 2=H, 3,4=hbond H # first find out the direction of covalent H bonds... h1 = nei[1][1] h2 = nei[2][1] h1 = coords.geomdiff([g, geom[h1]]) h2 = coords.geomdiff([g, geom[h2]]) uv = coords.unitvec( coords.add( h1, coords.mul(coords.add(coords.mul(h1, -1.0), h2), 0.5))) # symmetry axis n1 = nei[3][1] n2 = nei[4][1] dv1 = coords.geomdiff([g, geom[n1]]) dv2 = coords.geomdiff([g, geom[n2]]) # .. those are supposedly O that donate hydrogen bonds to us n1v = coords.dot(dv1, uv) n2v = coords.dot(dv2, uv) # .. project (neighboring hb donor - to us) vector to our symmetry axis # .. should be positive (negative?) and above some treshold sw = 2 # use sw=2, it is more sophisticated if (sw == 1): if (geom[n1][0] == "H" and n1v < 0): hn = hn + 1 if (geom[n2][0] == "H" and n2v < 0): hn = hn + 1 if (hn == 2): lines = lines + coords.tcl_plotlines( geom, c, n1, color="black", scale=scale, append=app) app = True lines = lines + coords.tcl_plotlines( geom, c, n2, color="black", scale=scale, append=app) elif (sw == 2): if ((geom[n1][0] == "H") and (n1v <= 0.01) and (coords.norm(dv1) <= tol)): lines = lines + coords.tcl_plotlines( geom, c, n1, color="black", scale=scale, append=app) app = True if ((geom[n2][0] == "H") and (n2v <= 0.01) and (coords.norm(dv2) <= tol)): lines = lines + coords.tcl_plotlines( geom, c, n2, color="black", scale=scale, append=app) app = True c = c + 1 return lines
def subtuple(a, b): return coords.sum(a, coords.mul(b, -1))