def shoot(self): elementToShoot = self.getAggressionElement() if elementToShoot is None: return spots = self.checkForSpace(elementToShoot) if spots: from geneacrystal.gameElements import items spot = self.toAbsPos(random.choice(spots)) c = items.BulletCrystal(self._space, self._root.getParent(), spot, helpSystem=self._helpSystem) impuls = util.vectorSub(c.position, self.toAbsPos(elementToShoot.position)) impuls = util.vectorMult(impuls, 10) c._body.apply_impulse(impuls)
def _initPhysic(self, position, angle): self._body = physic.BaseBody(self, None,None) self._body.position = position self._body.angle = angle points = [(0,0), (self.size[0],0), self.size, (0,self.size[1])] points = map(lambda p: util.vectorSub(p, util.vectorMult(self.size, 0.5)), points) shape = pymunk.Poly(self._body, points) shape.collision_type = physic.CannonCollisionType shape.elasticity = 1 self._addShape(shape) sensorPoints = map(lambda p: util.vectorMult(p, 0.9), points) self._sensorShape = pymunk.Poly(self._body, sensorPoints) self._sensorShape.sensor = True self._addShape(self._sensorShape) self._addLaunchAreaDivider()
def _scorePoints(self, points): if points == 0 or self.owner.score is None: return animTime = 1500 maxTextSize = min((75 + points,500)) scoreNode = avg.WordsNode(text=str(points), fontsize=maxTextSize, parent=self._root.getParent(), alignment="center", color=self.owner.color) angle = util.getDirOfVector(util.vectorSub(self.owner.pos, self.position,)) scoreNode.angle =angle util.centerNodeOnPosition(scoreNode, self.position) anim = avg.LinearAnim(scoreNode, "pos", animTime, scoreNode.pos, self.owner.pos, False, None, lambda:scoreNode.unlink(True)) player = self.owner def addPoints(): player.score+=points textShrinkAnim = avg.LinearAnim(scoreNode, "fontsize", int(animTime*0.6), maxTextSize, maxTextSize*0.2, False, None, addPoints ) textGrowAnim = avg.LinearAnim(scoreNode, "fontsize", int(animTime*0.4), maxTextSize*0.1, maxTextSize, False, None, textShrinkAnim.start) textGrowAnim.start() anim.start()
def _getSpawnPos(self): spawnPos = util.vectorMult((self.size[0], -self.size[1]), 0.5) spawnPos = util.vectorSub(spawnPos, (util.CRYSTAL_SIZE,-util.CRYSTAL_SIZE)) spawnPos = self._root.getAbsPos(spawnPos) return spawnPos