コード例 #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
ファイル: 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))