Beispiel #1
0
 def load(self,sp):
     for object in sp:
         if object=="":
             break
         spp=object.split('|')
         if spp[0]=="F":
             self.foodList.append(classes.Food(classes.Location(int(spp[1]),int(spp[2])),int(spp[3]),5))
         if spp[0]=="EC":
             self.cellEggs.append(classes.Egg(classes.Location(int(spp[1]),int(spp[2])),int(spp[3]),int(spp[4]),6,int(spp[5]),False))
         if spp[0]=="EP":
             self.cellEggs.append(classes.Egg(classes.Location(int(spp[1]),int(spp[2])),int(spp[3]),int(spp[4]),6,int(spp[5]),True))
         if spp[0]=="C":
             #self,cell,angle,carnivore,eggwithdraw,foodLeft,foodWithdraw,ID,lifeTime,location,speed,rad,lifewithdraw,timeToLay,AI,vision,eggHatchTime,strength=0):
             self.cellList.append(classes.baseCell(None,int(spp[3]),int(spp[4]),int(spp[5]),int(spp[6]),int(spp[7]),int(spp[8]),int(spp[9]),classes.Location(int(spp[1]),int(spp[2])),int(spp[10]),10,int(spp[11]),int(spp[12]),int(spp[13]),int(spp[14]),int(spp[15]),int(spp[16])))
         if spp[0]=="CP":
             self.myCell=classes.baseCell(None,int(spp[3]),int(spp[4]),int(spp[5]),int(spp[6]),int(spp[7]),int(spp[8]),int(spp[9]),classes.Location(int(spp[1]),int(spp[2])),int(spp[10]),10,int(spp[11]),int(spp[12]),int(spp[13]),int(spp[14]),int(spp[15]),int(spp[16]))
         if spp[0]=="T":
             consts.counter=int(spp[1])*consts.framerate
             self._counter=int(spp[1])*consts.framerate
Beispiel #2
0
 def __init__(self,height,width,lvl): #temp
     print "Load game? " + str(consts.loadedGame)
     if consts.loadedGame==False: ##new game ##change true to 'consts.loadedGame==False'
         ##(cell,angle,carnivore,eggwithdraw,food,foodWithdraw,ID,lifeTime,location,speed,rad,lifewithdraw,timeToLay,AI,vision,eggHatchTime,strength=0):
         self.screenheight=height
         self.screenwidth=width
         """
         self.myCell = classes.baseCell(None, angle, carnivor, eggwithdraw, p_food, foodWithdraw, 0, p_lifetime,
                                            classes.Location(400, 400), speed, rad, lifewithdraw, timeToLay, AI,
                                            vision, eggHatchTime, strength)
         """
         if lvl==1:#easy
             self.myCell = classes.baseCell(None, 0, 1, consts.framerate, 40, consts.framerate, 0, 40,
                                            classes.Location(400, 400), 3, 10, consts.framerate, 15, 2,
                                            200, 3, 10)
         if lvl==2:#lil harder
             self.myCell = classes.baseCell(None, 0, 0, consts.framerate, 40, consts.framerate, 0, 40,
                                            classes.Location(400, 400), 2, 10, consts.framerate, 20, 2,
                                            200, 3, 10)
         if lvl==3:#normal
             self.myCell = classes.baseCell(None, 0, 0, consts.framerate, 30, consts.framerate, 0, 40,
                                            classes.Location(400, 400), 1, 10, consts.framerate, 20, 2,
                                            200, 3, 5)
         if lvl==4:#hard
             self.myCell = classes.baseCell(None, 0, 0, consts.framerate, 20, consts.framerate, 0, 30,
                                            classes.Location(400, 400), 1, 10, consts.framerate, 25, 2,
                                            200, 3, 1)
         angle = 4
         lifewithdraw = consts.framerate
         carnivore = 0
         eggwithdraw = consts.framerate
         food = 30
         foodWithdraw = consts.framerate
         rad = 10
         AI = 2
         vision = 200
         lifeTime = 40
         p_lifetime = lifeTime
         p_food = food
         speed = 1
         timeToLay = 20
         eggHatchTime = 3
         strength = 5
         #                            cell,angle,carnivore,eggwithdraw,foodleft,foodwithdraw,ID,Lifetime,location,speed,rad,lifewithdeaw,timetolay,AI,vision,eggHatchtime,strngth
         #self.myCell=classes.baseCell(None,angle,1,eggwithdraw,p_food,foodWithdraw,0,p_lifetime,classes.Location(400,400),speed,rad,lifewithdraw,timeToLay,AI,vision,eggHatchTime,strength)
         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
         self.cellList.append(classes.baseCell(None, angle, carnivore, eggwithdraw, food, foodWithdraw, 1, lifeTime,classes.Location(random.randint(0, self.screenwidth),random.randint(0, self.screenheight)), speed, rad,lifewithdraw, timeToLay, AI, vision, eggHatchTime, strength))
         self.cellList.append(classes.baseCell(None,angle,carnivore,eggwithdraw,food,foodWithdraw,2,lifeTime,classes.Location(random.randint(0,self.screenwidth),random.randint(0,self.screenheight)),speed,rad,lifewithdraw,timeToLay,AI,vision,eggHatchTime,strength))
         self.cellList.append(classes.baseCell(None,angle,carnivore,eggwithdraw,food,foodWithdraw,3,lifeTime,classes.Location(random.randint(0,self.screenwidth),random.randint(0,self.screenheight)),speed,rad,lifewithdraw,timeToLay,AI,vision,eggHatchTime,strength))
         self.cellList.append(classes.baseCell(None,angle,carnivore,eggwithdraw,food,foodWithdraw,4,lifeTime,classes.Location(random.randint(0,self.screenwidth),random.randint(0,self.screenheight)),speed,rad,lifewithdraw,timeToLay,AI,vision,eggHatchTime,strength))
         self.cellList.append(classes.baseCell(None,angle,carnivore,eggwithdraw,food,foodWithdraw,5,lifeTime,classes.Location(random.randint(0,self.screenwidth),random.randint(0,self.screenheight)),speed,rad,lifewithdraw,timeToLay,AI,vision,eggHatchTime,strength))
         self.cellList.append(classes.baseCell(None,angle,carnivore,eggwithdraw,food,foodWithdraw,6,lifeTime,classes.Location(random.randint(0,self.screenwidth),random.randint(0,self.screenheight)),speed,rad,lifewithdraw,timeToLay,AI,vision,eggHatchTime,strength))
         self.cellList.append(classes.baseCell(None,angle,carnivore,eggwithdraw,food,foodWithdraw,7,lifeTime,classes.Location(random.randint(0,self.screenwidth),random.randint(0,self.screenheight)),speed,rad,lifewithdraw,timeToLay,AI,vision,eggHatchTime,strength))
         self.cellList.append(classes.baseCell(None,angle,carnivore,eggwithdraw,food,foodWithdraw,8,lifeTime,classes.Location(random.randint(0,self.screenwidth),random.randint(0,self.screenheight)),speed,rad,lifewithdraw,timeToLay,AI,vision,eggHatchTime,strength))
         self.cellList.append(classes.baseCell(None,angle,carnivore,eggwithdraw,food,foodWithdraw,9,lifeTime,classes.Location(random.randint(0,self.screenwidth),random.randint(0,self.screenheight)),speed,rad,lifewithdraw,timeToLay,AI,vision,eggHatchTime,strength))
         self.cellList.append(classes.baseCell(None,angle,carnivore,eggwithdraw,food,foodWithdraw,10,lifeTime,classes.Location(random.randint(0,self.screenwidth),random.randint(0,self.screenheight)),speed,rad,lifewithdraw,timeToLay,AI,vision,eggHatchTime,strength))
         ##self.cellEggs[0].mixPlayerCells(self.myCell,self.myCell)
         #self.cellEggs.append(classes.Egg((100,100),self.cellList[0],None,6,0))
         self.putFood()
     else: ##later code goes here
         onlyfiles = [f for f in listdir("src/SAV") if isfile(join("src/SAV", f))]
         choice=easygui.multchoicebox("Pick savefile:","",onlyfiles)
         file_path = path.relpath("src/SAV/"+choice)
         file = open(file_path,"r")
         sp=file.read()
         spp=base64.urlsafe_b64decode(sp).split('\n')
         self.load(spp)
         file.close()
         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
     self.p2spaceLimiter=classes.spaceLimited(consts.screenwidth/2,0.05)
Beispiel #3
0
def sandbox():
    angle=4
    lifewithdraw=consts.framerate
    carnivore=0
    eggwithdraw=consts.framerate
    food=15
    foodWithdraw=consts.framerate
    rad=10
    AI=2
    vision=500
    lifeTime=20
    p_lifetime=lifeTime
    p_food=food
    speed=1
    timeToLay=10
    eggHatchTime=3
    strength=5
    x=400
    y=400
     #                   cell,angle,carnivore,eggwithdraw,foodleft,foodwithdraw,ID,Lifetime,location,speed,rad,lifewithdeaw,timetolay,AI,vision,eggHatchtime,strngth
    sPl=classes.baseCell(None,angle,carnivore,eggwithdraw,p_food,foodWithdraw,0,p_lifetime,classes.Location(x,y),speed,rad,lifewithdraw,timeToLay,AI,vision,eggHatchTime,strength)
    sPl.base90, sPl.base45 = pygame.image.load('src/IMG/HeadD.png'),pygame.image.load('src/IMG/HeadUL.png')
    sPl.image=sPl.base90
    attstr=["None","angle","carnivore","eggWithdraw","food","foodWithdraw","ID","lifetime","x","y","speed","rad","lifeWithdraw","timeToLay","AI","Vision","eggHatchTime","str"]
    idA=1
    while(True):
        screen.fill((255,255,0))
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                return False,"End"
            if event.type == pygame.KEYDOWN:
                if event.key==pygame.K_p:
                    exit()
                if event.key==pygame.K_m:
                    save_rawtext=algorithm.save(sPl,sCellList,sFoodList)
                    pygame.quit()
                    filename=easygui.enterbox("Enter save name: ","","Save001")
                    file_path = path.relpath("src/SAV/"+filename+".sav")
                    file = open(file_path,"wb")
                    file.write(save_rawtext)
                    file.close()
                    exit()
                if event.key==pygame.K_a:
                    print "Making cell"
                    x=pygame.mouse.get_pos()[0]
                    y=pygame.mouse.get_pos()[1]
                    attlist=[None,angle,carnivore,eggwithdraw,p_food,foodWithdraw,idA,p_lifetime,x,y,speed,rad,lifewithdraw,timeToLay,AI,vision,eggHatchTime,strength]
                    idA+=1
                    rt=easygui.multenterbox("Make Cell","",attstr,attlist)
                    print rt
                    rt[0]="0"
                    for index in xrange(0,len(rt)):
                        rt[index]=int(rt[index])
                    sCellList.append(classes.baseCell(None,rt[1],rt[2],rt[3],rt[4],rt[5],rt[6],rt[7],classes.Location(rt[8],rt[9]),rt[10],rt[11],rt[12],rt[13],rt[14],rt[15],rt[16],rt[17]))
                if event.key==pygame.K_s:
                    x=pygame.mouse.get_pos()[0]
                    y=pygame.mouse.get_pos()[1]
                    sFoodList.append(classes.Food(classes.Location(x,y),1,5))
                if event.key==pygame.K_d:
                    x=pygame.mouse.get_pos()[0]
                    y=pygame.mouse.get_pos()[1]
                    sPl.location.x=x
                    sPl.location.y=y
        for cell in sCellList:
                if cell.timeToHurt%2==0:
                    ##pygame.draw.circle(screen,(255,0,0),(cell.location.getTupple()),cell.rad)
                    ##pygame.draw.circle(screen,(10,255,10),(cell.location_compensated()),2)
                    screen.blit(cell.image,(cell.location.x-cell.rad,cell.location.y-cell.rad))
                    ##draw IDs:
                    color=(0,0,0)
                    if cell.mode=="c":
                        color=(255,0,0)
                    label = myfont2.render(str(cell.ID), 1, color)
                    screen.blit(label,(cell.location.x+5,cell.location.y))
                    ##draw life:
                    label = myfont2.render(str(cell.lifeTimeLeft), 1, (0,0,0))
                    screen.blit(label,(cell.location.x-15,cell.location.y))
                    pygame.draw.rect(screen,(255,0,0),(cell.location.x-10,cell.location.y-15,(30*(cell.lifeTimeLeft/float(cell.lifeTime))),6))
                    ##draw foodbar
                    pygame.draw.rect(screen,(0,255,0),(cell.location.x-10,cell.location.y-6-15,(30*(cell.foodLeft/float(cell.lifeTime))),6))
        if sPl.timeToHurt%2==0:
            screen.blit(sPl.image,(sPl.location.x-sPl.rad,sPl.location.y-sPl.rad))
            pygame.draw.rect(screen,(255,0,0),(sPl.location.x-10,sPl.location.y-15,(30*(sPl.lifeTimeLeft/float(sPl.lifeTime))),6))
            ##draw player ID
            label = myfont2.render(str(sPl.ID), 1, (255,255,0))
            screen.blit(label,(sPl.location.x,sPl.location.y))
            #foodbar
            pygame.draw.rect(screen,(0,255,0),(sPl.location.x-10,sPl.location.y-6-15,(30*(sPl.foodLeft/float(sPl.lifeTime))),6))
        for food in sFoodList:
            #pygame.draw.circle(screen,(80,255,80),(food.location.getTupple()),food.rad)
            screen.blit(food.image,(food.location.x-food.rad,food.location.y-food.rad))

        clock.tick(consts.framerate)
        pygame.display.flip()