コード例 #1
0
ファイル: hare.py プロジェクト: svuolli/coldworld
 def process(self, time_passed):
     self.frame_timer -= time_passed
     self.amount_ran += time_passed * self.max_speed
     if self.frame_timer < 0:
         self.frame_timer = FRAME_TIME
         self.current_frame += 1
         if self.current_frame >= len(self.images_lf) or self.current_frame >= len(self.images_rf):
                 self.current_frame = 0
     
     x, y = self.location
     
     GameEntity.process(self, time_passed)
     if self.heading.x < 0.0:
         self.left_facing = True
     elif self.heading.x > 0.0:
         self.left_facing = False
コード例 #2
0
ファイル: hare.py プロジェクト: svuolli/coldworld
 def __init__(self, world, images_lf, images_rf):
     GameEntity.__init__(self, world, "hare", None)
     # self.dead_image = pygame.transform.flip(image, 0, 1)
     self.health = 25
     self.max_speed = 0
     self.current_frame = 0
     self.frame_timer = FRAME_TIME
     self.images_lf = images_lf
     self.images_rf = images_rf
     self.left_facing = False
     
     self.human_chasing = None
     self.amount_ran = 0.0
     
     exploring_state = HareStateExploring(self)
     fleeing_state = HareStateFleeing(self)
     
     self.brain.add_state(exploring_state)
     self.brain.add_state(fleeing_state)
     
     self.brain.set_state("exploring")
コード例 #3
0
ファイル: human.py プロジェクト: svuolli/coldworld
    def __init__(self, world, playernumber):
        
        GameEntity.__init__(self, world, "human_red", None)

        fmt = "images/davy%i.png" if playernumber == 1 else "images/aslak%i.png"
        image_files = map(lambda i: fmt%(i+1), xrange(2))
        self.images_lf = map(lambda f: loadImage(f), image_files)
        self.images_rf = map(lambda i: pygame.transform.flip(i, 1, 0), self.images_lf)

        self.current_frame = 0
        self.frame_timer = FRAME_TIME
        self.left_facing = False

        self.carry_image = None
        self.max_speed = 180.        
        self.player_number = playernumber

        self.hunger = 100.0
        self.hunger_image_index = 0
        self.thirst = 100.0
        self.thirst_image_index = 0
        self.heat = 100.0
        self.heat_image_index = 0

        self.age = 0.0

        self.sounds = {"walk":pygame.mixer.Sound("audio/running_in_snow.wav"),
                "eat":pygame.mixer.Sound("audio/eat.wav"),
                }
        
        self.x_heading = 0
        self.y_heading = 0

        if(pygame.joystick.get_count() > self.world.joystick_in_use):
            self.setup_joystick()
        else:
            self.joycontrol = -1
            self.init_keymap(self.player_number)
コード例 #4
0
ファイル: main.py プロジェクト: CatsAreEvil/Warriors-game
warriors = 0
WindClan = Clan("WindClan",warriors,EveryCat)
#WindClan.AddCat(kitty,"Apprentice",EveryCat)
#WindClan.SayCats()
#WindClan.ChooseMentor(kitty)
#ThunderClan = Clan("ThunderClan",warriors,EveryCat)
#ThunderClan.SayCats()
#ShadowClan = Clan("ShadowClan",warriors,EveryCat)
#ShadowClan.SayCats()
#RiverClan = Clan("RiverClan",warriors,EveryCat)
#RiverClan.SayCats()
#SkyClan isn't a real clan

# Create the player
player = GameEntity(6,'kit',RandomFur(),isAI = False)
player.Setup()
player.CreateSprite()

#player.Setup()
#print(player.SayName())


#level_list.append(levels.ForestCamp(player))
level_list.append(levels.Level_01(player))
level_list.append(levels.Level_02(player))



active_sprite_list = pygame.sprite.Group()
コード例 #5
0
ファイル: human.py プロジェクト: svuolli/coldworld
    def process(self, time_passed):
        self.hunger -= time_passed*2.5
        self.thirst -= time_passed*2.5
        self.heat -= time_passed*2.5
        self.age += time_passed
    
        pressed = pygame.key.get_pressed()
        move_vector = (0, 0)
        if(self.joycontrol == -1):
            for m in (self.key_map[key] for key in self.key_map if pressed[key]):
                move_vector = map(sum, zip(move_vector, m))
        else:
            x = self.joystick.get_axis(0)
            y = self.joystick.get_axis(1)

            if math.fabs(x) < 0.1:
                x = 0.
            if math.fabs(y) < 0.1:
                y = 0.
                
            move_vector = Vector2(x,y)
            

        self.heading = Vector2(move_vector)
        if move_vector[0] < 0.0:
            self.left_facing = True
        elif move_vector[0] > 0.0:
            self.left_facing = False

        if self.heading.get_length() > 0.0:
            self.frame_timer -= time_passed
            if self.frame_timer < 0.0:
                self.frame_timer = FRAME_TIME
                self.current_frame += 1
                if self.current_frame >= len(self.images_rf):
                    self.current_frame = 0
    
        GameEntity.process(self, time_passed)
        hare = self.world.get_close_entity("hare", self.location, 80)
        if hare:
            self.hunger = min(self.hunger+20.0, 120.0)
            self.world.remove_entity(hare)
            self.world.hare_count -= 1
            self.sounds["eat"].play()
        fire = self.world.get_close_entity("fire", self.location, 80)
        if fire:
            self.heat = min(self.heat+time_passed*20.0, 120)
        water = self.world.get_close_entity("water", self.location, 80)
        if water:
            self.thirst = min(self.thirst+time_passed*20.0, 120)

        if self.hunger < 0.0 or self.heat < 0.0 or self.thirst < 0.0:
            self.world.remove_entity(self)
            self.world.human_count -= 1
            tomb_stone = Block(self.world, loadImage("images/tomb.png"))
            tomb_stone.location = self.location
            self.world.add_entity(tomb_stone)
        
        self.hunger_image_index = min(5,int(6.0*self.hunger/120.0))
        self.thirst_image_index = min(5,int(6.0*self.thirst/120.0))
        self.heat_image_index = min(5,int(6.0*self.heat/120.0))
コード例 #6
0
ファイル: fire.py プロジェクト: svuolli/coldworld
 def __init__(self, world, images):
     GameEntity.__init__(self, world, "fire", None)
     self.images = images
     self.current_frame = randint(0,2)
     self.frame_timer = randint(0, 100)/100.0
     self.life_time = 30.0 + randint(1, 15)
コード例 #7
0
ファイル: water.py プロジェクト: svuolli/coldworld
 def __init__(self, world, images):
     GameEntity.__init__(self, world, "water", None)
     self.images = images
     self.current_frame = randint(0,1)
     self.frame_timer = randint(0, 100)/100.0
コード例 #8
0
class Clan():
    def __init__(self, name, warriors, worldCats):
        self.name = name
        self.allCats = []
        self.warriors = []
        self.apprentices = []
        self.elders = []
        self.leadership = []

        self.CreateCat("Leader", worldCats)  #create leader
        self.CreateCat("Deputy", worldCats)  #create deputy
        self.CreateCat("Medicine Cat", worldCats)  #create medicine cat
        I = 0
        while I < warriors:  #create warriors
            self.CreateCat("Warrior", worldCats)
            I = I + 1
        I = 0

        while I < warriors * 0.15:  #create apprentices

            self.CreateCat("Apprentice", worldCats)
            I = I + 1
        I = 0
        while I < warriors * 0.2:  #create elders
            self.CreateCat("Elder", worldCats)
            I = I + 1

    def SayCats(self):
        print(self.name + "!")
        I = 0
        while I < len(self.allCats):
            print(self.allCats[I].SayRank() + ": " + self.allCats[I].SayName())
            I = I + 1

    def CreateCat(self, rank, worldcats):
        if rank == "Leader":
            tempname = (RandomName(True) + "star")
            if SearchName(tempname,
                          worldcats) == True or AvoidName(tempname) == True:
                self.CreateCat("Leader", worldcats)  #try again
            else:  #create cat
                self.leader = GameEntity(randint(30, 120), "Leader",
                                         RandomFur())  #create leader
                self.leader.NPCSetup(tempname, self.name)
                self.leader.CreateSprite()
                self.allCats.append(self.leader)
                self.leadership.append(self.leader)
                worldcats.append(self.leader)
        elif rank == "Deputy":
            tempname = GenerateName()
            if SearchName(tempname,
                          worldcats) == True or AvoidName(tempname) == True:
                self.CreateCat("Leader", worldcats)  #try again
            else:
                self.deputy = GameEntity(randint(25, 120), "Deputy",
                                         RandomFur())
                self.deputy.NPCSetup(tempname, self.name)
                self.deputy.CreateSprite()
                self.allCats.append(self.deputy)
                self.leadership.append(self.deputy)
                worldcats.append(self.deputy)
        elif rank == "Medicine Cat":
            tempname = GenerateName()
            if SearchName(tempname,
                          worldcats) == True or AvoidName(tempname) == True:
                self.CreateCat("Leader", worldcats)  #try again
            else:
                self.medCat = GameEntity(randint(35, 120), "Medicine Cat",
                                         RandomFur())
                self.medCat.NPCSetup(tempname, self.name)
                self.medCat.CreateSprite()
                self.allCats.append(self.medCat)
                self.leadership.append(self.medCat)
                worldcats.append(self.medCat)
        elif rank == "Warrior":
            tempname = GenerateName()
            if SearchName(tempname,
                          worldcats) == True or AvoidName(tempname) == True:
                self.CreateCat("Leader", worldcats)  #try again
            else:
                self.newwarrior = GameEntity(randint(20, 120), "Warrior",
                                             RandomFur())
                self.newwarrior.NPCSetup(tempname, self.name)
                self.newwarrior.CreateSprite()
                self.allCats.append(self.newwarrior)
                self.warriors.append(self.newwarrior)
                worldcats.append(self.newwarrior)
        elif rank == "Apprentice":
            tempname = RandomName(True) + 'paw'
            if SearchName(tempname,
                          worldcats) == True or AvoidName(tempname) == True:
                self.CreateCat("Leader", worldcats)  #try again
            else:
                self.newbie = GameEntity(randint(6, 22), "Apprentice",
                                         RandomFur())
                self.newbie.NPCSetup(tempname, self.name)
                self.newbie.CreateSprite()
                self.allCats.append(self.newbie)
                self.apprentices.append(self.newbie)
                worldcats.append(self.newbie)
        elif rank == "Elder":
            tempname = GenerateName()
            if SearchName(tempname,
                          worldcats) == True or AvoidName(tempname) == True:
                self.CreateCat("Leader", worldcats)  #try again
            else:
                self.elder = GameEntity(randint(105, 140), "Elder",
                                        RandomFur())
                self.elder.NPCSetup(tempname, self.name)
                self.elder.CreateSprite()
                self.allCats.append(self.elder)
                self.elders.append(self.elder)
                worldcats.append(self.elder)

    def AddCat(self, newcat, rank,
               worldcats):  #adds an existing cat to the clan
        self.allCats.append(newcat)
        worldcats.append(newcat)
        if newcat.SayRank() == "Leader" or newcat.SayRank(
        ) == "Deputy" or newcat.SayRank() == "Medicine Cat":
            self.leadership.append(newcat)
        elif newcat.SayRank() == "Warrior":
            self.warriors.append(newcat)
        elif newcat.SayRank() == "Apprentice":
            self.apprentices.append(newcat)
        elif newcat.SayRank() == "Elder":
            self.elders.append(newcat)

    def ChooseMentor(self, apprentice):
        self.newmentor = (self.warriors[randint(0, len(self.warriors) - 1)])
        apprentice.MakeApprentice(self.newmentor)
        self.newmentor.MakeMentor(apprentice)

    def SayLeader(self):
        return self.leader
コード例 #9
0
 def CreateCat(self, rank, worldcats):
     if rank == "Leader":
         tempname = (RandomName(True) + "star")
         if SearchName(tempname,
                       worldcats) == True or AvoidName(tempname) == True:
             self.CreateCat("Leader", worldcats)  #try again
         else:  #create cat
             self.leader = GameEntity(randint(30, 120), "Leader",
                                      RandomFur())  #create leader
             self.leader.NPCSetup(tempname, self.name)
             self.leader.CreateSprite()
             self.allCats.append(self.leader)
             self.leadership.append(self.leader)
             worldcats.append(self.leader)
     elif rank == "Deputy":
         tempname = GenerateName()
         if SearchName(tempname,
                       worldcats) == True or AvoidName(tempname) == True:
             self.CreateCat("Leader", worldcats)  #try again
         else:
             self.deputy = GameEntity(randint(25, 120), "Deputy",
                                      RandomFur())
             self.deputy.NPCSetup(tempname, self.name)
             self.deputy.CreateSprite()
             self.allCats.append(self.deputy)
             self.leadership.append(self.deputy)
             worldcats.append(self.deputy)
     elif rank == "Medicine Cat":
         tempname = GenerateName()
         if SearchName(tempname,
                       worldcats) == True or AvoidName(tempname) == True:
             self.CreateCat("Leader", worldcats)  #try again
         else:
             self.medCat = GameEntity(randint(35, 120), "Medicine Cat",
                                      RandomFur())
             self.medCat.NPCSetup(tempname, self.name)
             self.medCat.CreateSprite()
             self.allCats.append(self.medCat)
             self.leadership.append(self.medCat)
             worldcats.append(self.medCat)
     elif rank == "Warrior":
         tempname = GenerateName()
         if SearchName(tempname,
                       worldcats) == True or AvoidName(tempname) == True:
             self.CreateCat("Leader", worldcats)  #try again
         else:
             self.newwarrior = GameEntity(randint(20, 120), "Warrior",
                                          RandomFur())
             self.newwarrior.NPCSetup(tempname, self.name)
             self.newwarrior.CreateSprite()
             self.allCats.append(self.newwarrior)
             self.warriors.append(self.newwarrior)
             worldcats.append(self.newwarrior)
     elif rank == "Apprentice":
         tempname = RandomName(True) + 'paw'
         if SearchName(tempname,
                       worldcats) == True or AvoidName(tempname) == True:
             self.CreateCat("Leader", worldcats)  #try again
         else:
             self.newbie = GameEntity(randint(6, 22), "Apprentice",
                                      RandomFur())
             self.newbie.NPCSetup(tempname, self.name)
             self.newbie.CreateSprite()
             self.allCats.append(self.newbie)
             self.apprentices.append(self.newbie)
             worldcats.append(self.newbie)
     elif rank == "Elder":
         tempname = GenerateName()
         if SearchName(tempname,
                       worldcats) == True or AvoidName(tempname) == True:
             self.CreateCat("Leader", worldcats)  #try again
         else:
             self.elder = GameEntity(randint(105, 140), "Elder",
                                     RandomFur())
             self.elder.NPCSetup(tempname, self.name)
             self.elder.CreateSprite()
             self.allCats.append(self.elder)
             self.elders.append(self.elder)
             worldcats.append(self.elder)
コード例 #10
0
ファイル: grass.py プロジェクト: svuolli/coldworld
 def __init__(self, world, image):
     GameEntity.__init__(self, world, "grass", image)
コード例 #11
0
ファイル: block.py プロジェクト: svuolli/coldworld
 def __init__(self, world, image):
     GameEntity.__init__(self, world, "block", image)