Example #1
0
 def growCellEggs(self):
     for egg in self.cellEggs:
         if egg.timeToHatch==0:
             newCell=egg.Hatch()
             self.cellList.append(newCell)
             self.cellEggs.remove(egg)
             ##egg hatch practicle
             graphics.practicleList.append(classes.practicle(egg.location,(163,213,230),practicle_radius))
Example #2
0
    def growPlayerEggs(self):
        for egg in self.myEggs:
            if egg.timeToHatch==0:
                advance,newCell=egg.Hatch()
                if advance:
                    self.myCell.base90, self.myCell.base45 = pygame.image.load('src/IMG/e_HeadD.png'),pygame.image.load('src/IMG/e_HeadUL.png')
                    self.myCell.image=self.myCell.base90

                    self.cellList.append(self.myCell)
                    self.myEggs.remove(egg)
                    self.myCell=newCell

                    self.myCell.base90, self.myCell.base45 = pygame.image.load('src/IMG/HeadD.png'),pygame.image.load('src/IMG/HeadUL.png')
                    self.myCell.image=self.myCell.base90
                else:
                    self.cellList.append(newCell)
                    self.myEggs.remove(egg)
                ##egg hatch practicle
                graphics.practicleList.append(classes.practicle(egg.location,(163,213,230),practicle_radius))
Example #3
0
    def nextStep(self,text):
        if consts.godmode:
            self.myCell.lifeTimeLeft=self.myCell.lifeTime
            self.myCell.foodLeft=self.myCell.food
        if text!="Empty":
            consts.askingQuestion=False
            ##parse input
        self._counter+=1

        ##change season

        if not consts.recording:
            if self._counter%(consts.framerate*60)==0:
                consts.season=(consts.season+1)%4
        ##handle input
        inputlist=self.getInput()
        for item in inputlist:
            if (item=="Left" or item=="Right") and (("Left" in self.__kinput) or ("Right" in self.__kinput)):
                continue
            elif (item=="c" and ("c" in self.__kinput)):
                continue
            elif (item=="m" and ("m" in self.__kinput)):
                continue
            else:
                self.__kinput.append(item)
        for item in self.__kinput:
            if not consts.mouse_control:
                if item=="Left" or item=="OLeft":
                    self.myCell.changeAngle(-1)
                if item=="Right" or item=="ORight":
                    self.myCell.changeAngle(1)
        self.myCell.changeAngle(0)
        if "Up" in self.__kinput:
            self.myCell.move()
        ##handle food and life
        self.myCell.checkTarget()
        self.myCell.checkEat(self.foodList)
        self.myCell.consumeFood(self._counter)
        self.myCell.consumeLife(self._counter)
        self.myCell.consumeEggTime(self._counter)
        self.myCell.checkRIP()
        if self.myCell.timeToHurt!=0:
            self.myCell.timeToHurt-=1
        input=[]
        for cell in self.cellList:
            input=AI.nextStep(self.myCell,self.cellList,self.foodList,cell)
            for item in input:
                if item=="OLeft":
                    cell.changeAngle(-1)
                if item=="ORight":
                    cell.changeAngle(1)
                if "Up" == item:
                    cell.move()
                if "a" == item:
                    if cell.timeToLayLeft==0 and cell.lastMother!=None:
                        self.cellEggs.append(cell.layEgg())
                        cell.lastMother=None
                        cell.target=None
                if "c" ==item:
                    if cell.mode=="m":
                        cell.mode="c"
                    else:
                        cell.mode="m"

            cell.checkEat(self.foodList)
            cell.consumeFood(self._counter)
            cell.consumeLife(self._counter)
            cell.consumeEggTime(self._counter)
            cell.checkTarget()
            cell.checkRIP()
            if cell.timeToHurt!=0:
                cell.timeToHurt-=1
            if cell.dead:
                self.cellList.remove(cell)


        if "a" in inputlist:
            if self.myCell.timeToLayLeft==0 and self.myCell.lastMother!=None:
                self.myEggs.append(self.myCell.layEgg(True))
                self.myCell.lastMother=None

        if "c" in inputlist: ##carnivore or mating
            if self.myCell.mode=='m':
                self.myCell.mode='c'
            else:
                self.myCell.mode='m'
        if "m" in inputlist: ##load/save menu
            self.LoadSaveMenu()
        ##check egg hatching
        for egg in self.cellEggs:
            egg.consumeHatch(self._counter)
        for egg in self.myEggs:
            egg.consumeHatch(self._counter)
        self.growCellEggs()
        self.growPlayerEggs()



        ##check for carnivore eating and mating
        allCells=[]
        noCollision=True
        for cell in self.cellList:
            allCells.append(cell)
        allCells.append(self.myCell)
        for cell in allCells:
            for otherCell in allCells:
                collision=math.sqrt(((cell.location.x-otherCell.location.x)**2)+((cell.location.y-otherCell.location.y)**2))<cell.rad+otherCell.rad
                if (cell.ID!=otherCell.ID) and (collision): ##not the same cell
                    noCollision=False
                    if cell.mode=='c': ##carnivore
                        if otherCell.timeToHurt<=0:
                            otherCell.timeToHurt=consts.framerate
                            otherCell.lifeTimeLeft-=cell.strength
                            if otherCell.lifeTimeLeft<=0: ##only eat if you killed him
                                cell.foodLeft+=otherCell.foodLeft
                                otherCell.lifeTimeLeft=0
                                otherCell.dead=True
                                print str(cell.ID), "Ate", str(otherCell.ID)
                            else: ##cant eat
                                print str(cell.ID), "hurt", str(otherCell.ID), "but did not kill him."
                            ##cell eat practicle
                            if cell.lastCollision!=otherCell and otherCell.lastCollision!=cell: ##only if its not a false collision
                                graphics.practicleList.append(classes.practicle(cell.location,(240,165,36),practicle_radius))
                                cell.lastCollision=otherCell
                    if cell.mode=='m': ##mate
                        if otherCell.mode=='m': ##mate too
                            cell.lastMother=otherCell
                            otherCell.lastMother=cell
                            ##cell eat practicle
                            if cell.lastCollision!=otherCell and otherCell.lastCollision!=cell: ##only if its not a false collision
                                graphics.practicleList.append(classes.practicle(cell.location,(240,36,131),practicle_radius))
                                cell.lastCollision=otherCell
            if noCollision: ##the cell has not colided, reset the last collision
                cell.lastCollision=cell.ID+self._counter


        ##check if its phase 2
        if consts.counter/consts.framerate>consts.timeUntilPhase2 and self.p2spaceLimiter.active==False:
            self.p2spaceLimiter.activate()
        self.p2spaceLimiter.grow()
        if self.p2spaceLimiter.active:
            completeCellList=[]
            for cell in self.cellList:
                completeCellList.append(cell)
            completeCellList.append(self.myCell)
            for cell in completeCellList:
                if  not math.sqrt(((cell.location.x-self.p2spaceLimiter.loc.x)**2)+((cell.location.y-self.p2spaceLimiter.loc.y)**2))<cell.rad+self.p2spaceLimiter.radius:
                    cell.lifeTimeLeft-=self.p2spaceLimiter.hurt
                    graphics.practicleList.append(classes.practicle(cell.location,(255,0,0),7))

        #grow more food
        """
        0-Summer 75%
        1-Autumn 50%
        2-winter 25%
        3-spring 100%
        """

        if consts.season==0:
            if self._counter%(consts.framerate/6)==0:
                self.putFood()
        elif consts.season==1:
            if self._counter%(consts.framerate/4)==0:
                self.putFood()
        elif consts.season==2:
            if self._counter%(consts.framerate/2)==0:
                self.putFood()
        elif consts.season==3:
            if self._counter%(consts.framerate/8)==0:
                self.putFood()

        consts.counter=self._counter
        self.__kinput=[]

        if self.myCell.dead:
            choice=None
            while choice!="Okay":
                choice = graphics.askBoard("Prompt","You have died :(\n\nYou lived " + str(consts.counter/consts.framerate)+" seconds.")
            pygame.event.post(pygame.event.Event(pygame.QUIT))

        ##deduct practicle time
        if (self._counter%(consts.framerate*0.125)):
            for practicle in graphics.practicleList:
                if practicle.radius==1:
                    graphics.practicleList.remove(practicle)
                else:
                    practicle.radius-=1
        import requests
        testdata=""
        if self._counter%30==0:
            for cell in self.cellList:
                #print cell.location.x
                #print cell.location.y
                testdata+=str(cell.location.x/float(consts.screenwidth)*100)+"@"+str(cell.location.y/float(consts.screenheight)*100)+"|";
            r = requests.post("http://www.avuka.net/P_live.php", data={"cells":testdata})