def _makeKeyboards(self, finishedCB, parent): self._namesToEnter = len(self._players) playerScores = [] for player in self._players: playerScores.append(player.score) for player in self._players: heading = avg.WordsNode( color="FFFFFF", fontsize=25, sensitive=False, angle=player.angle, alignment="center", ) hsen = HighscoreEntryNode(self._highscore, player.score, playerScores, finishedCB, parent=parent, size=(util.WINDOW_SIZE[0]//3,util.WINDOW_SIZE[0]//9)) hsen.angle = player.angle hsen.appendChild(heading) if player in self.remainaingPlayers: designation = "WINNER" else: designation = "LOSER" heading.text= "{}<br/>{} Points".format(designation, player.score) util.centerNodeOnPosition(hsen, player.pos) util.centerNodeOnPosition(heading, util.vectorAdd((0,0), (hsen.size[0]/2, -heading.getMediaSize()[1])))
def checkForSpace(self, element): radius = element.shape.radius + util.CRYSTAL_RADIUS + 1 availablePositions = [] stepsize = 360 // 4 maxNeigbors = 0 for alpha in range(0, 360, stepsize): alpha += random.randint(0, stepsize - 1) # alpha+= random.randrange(stepsize) angle = (2 * math.pi) * (alpha / 360.0) vector = util.getVectotInDirection(angle, radius) posToCheck = util.vectorAdd(self.toAbsPos(element.position), vector) testBody = pymunk.Body() testBody.position = posToCheck shapeToTestInner = pymunk.Circle(body=testBody, radius=util.CRYSTAL_SIZE / 2) shapeToTestOuter = pymunk.Circle( body=testBody, radius=(util.CRYSTAL_SIZE / 2) * self.neighbourhoodThreshold ) intersectionsInner = self._space.shape_query(shapeToTestInner) # dnode = avg.CircleNode(parent=self._root.getParent(), pos=posToCheck, r=util.CRYSTAL_SIZE/2,fillcolor="00FFFF", strokewidth=0) if len(intersectionsInner) == 0 or (len(intersectionsInner) == 1 and element.shape in intersectionsInner): intersectionsOuter = self._space.shape_query(shapeToTestOuter) neighborCount = len(intersectionsOuter) # dnode.fillopacity=0.5 if neighborCount > maxNeigbors: maxNeigbors = neighborCount availablePositions = [self.toRelPos(posToCheck)] elif neighborCount == maxNeigbors: availablePositions.append(self.toRelPos(posToCheck)) return availablePositions
def structureCollision(self, space, arbiter): assert(len(arbiter.shapes) == 2) assert(len(arbiter.contacts) == 1) incommingShape, structureShape = self.getShapesByType(arbiter.shapes, CrystalCollisionType, StructureCollisionType) incomming, structure = incommingShape.body, structureShape.body offset = util.vectorGetDirWithLength(structure.position, incomming.position, arbiter.contacts[0].distance) incomming.position = util.vectorAdd(incomming.position, offset) incomming.update() structure.onCrystalCollision(incomming, structureShape) incomming.onStructureCollision(structure) return False
def getOffscreenPosForElement(self, pos): return util.vectorAdd(pos, util.vectorMult(self._canvasRoot.size, 0.5))
def _getSpawnPos(self): spawnPos = 0, -self.size[1]/2 spawnPos = util.vectorAdd(spawnPos, (0,util.CRYSTAL_SIZE)) spawnPos = self._root.getAbsPos(spawnPos) return spawnPos