示例#1
0
文件: ia.py 项目: leofrozen/Mutuca
    def check_conditions(self):

        if self.got_safe:
            self.entity.running = False
            return "roaming"

        target = self.entity.stage.get_entity(self.entity.target_id)

        # If the target has been killed the return to exploring state
        if target is None:
            self.entity.target_id = None
            return "roaming"

        # If the target gets far enough away, return to exploring state
        if Vector2(target.rect.center).get_distance_to(
                self.entity.rect.center) > 150:
            return "roaming"

        if self.entity.life <= 0:
            return "dead"

        return None
示例#2
0
文件: ia.py 项目: leofrozen/Mutuca
    def check_conditions(self):

        if self.got_kill:
            print "morre ai troxa"
            return "exploring"

        target = self.entity.stage.get_entity(self.entity.target_id)

        # If the target has been killed the return to exploring state
        if target is None:
            self.entity.target_id = None
            return "exploring"

        # If the target gets far enough away, return to exploring state
        if Vector2(target.rect.center).get_distance_to(
                self.entity.rect.center) > self.entity.vision:
            return "exploring"

        if self.entity.life <= 0:
            return "dead"

        return None
示例#3
0
文件: ia.py 项目: leofrozen/Mutuca
 def random_destination(self, surface):
     w, h = surface
     self.entity.destination = Vector2(randint(w - 500, w + 500),
                                       randint(h - 500, h + 500))
示例#4
0
 def __init__(self, stage, sprite, position):
     GameElement.__init__(self, stage, sprite, "lapide", position)
     self.position = Vector2(position)
     self.rect.center = self.position
示例#5
0
    def process(self):
        
        mouse_pos = (x, y) = pygame.mouse.get_pos()
        
        self.key_direction = Vector2(0,0)
        self.action = None

        #self.direction = self.last_direction
        if self.rect_up.collidepoint(mouse_pos):
            self.key_direction.y = -1
            #self.last_direction = self.direction
        elif self.rect_down.collidepoint(mouse_pos):
            self.key_direction.y = +1
            #self.last_direction = self.direction
        
        elif self.rect_right.collidepoint(mouse_pos):
            self.key_direction.x = +1
            #self.last_direction = self.direction
        elif self.rect_left.collidepoint(mouse_pos):
            self.key_direction.x = -1
            #self.last_direction = self.direction
        
        # Diagonal movements
#         elif rect_top_right.collidepoint(mouse_pos):
#             self.direction = "up_right"
#             self.last_direction = self.direction
#             
#         elif rect_top_left.collidepoint(mouse_pos):
#             self.direction = "up_left"
#             self.last_direction = self.direction
#             
#         elif rect_down_right.collidepoint(mouse_pos):
#             self.direction = "down_right"
#             self.last_direction = self.direction
#             
#         elif rect_down_left.collidepoint(mouse_pos):
#             self.direction = "down_left"
#             self.last_direction = self.direction
        
        else:
            self.direction = None
        
#         if direction: 
#             return self.direction
        
        mouse_pos = (x, y) = pygame.mouse.get_pos()
        self.action = None
        #print "action button on (%i,%i)" %mouse_pos
        if self.rect_actionA.collidepoint(mouse_pos):
            self.action = "action1"

            #self.direction = self.last_direction
        elif self.rect_actionB.collidepoint(mouse_pos):
            self.action = "action2"

            #self.direction = self.last_direction
        elif self.rect_actionC.collidepoint(mouse_pos):
            self.action = "action3"

            #self.direction = self.last_direction
        elif self.rect_actionD.collidepoint(mouse_pos):
            self.action = "action4"
示例#6
0
    def process(self):
        
        self.key_direction = Vector2(0,0)
        self.action = None
        
        # get direction
#         if self.joystick.get_numhats() > 0:
#             axis_x, axis_y = self.joystick.get_hat(0)
#             print "pegando as paradas"
#  
#             if axis_x < 0:
#                 self.key_direction.x = -1
#             elif axis_x > 0:
#                 self.key_direction.x = +1
#             
#             if axis_y > 0:
#                 self.key_direction.y = -1
#             elif axis_y < 0:
#                 self.key_direction.y = +1
#             
#             
#         print "Hats values: ________________ (%f, %f)" %(axis_x, axis_y)
        
        
        if self.joystick.get_numaxes() >= 2:
            axis_x = self.joystick.get_axis(0)
            axis_y = self.joystick.get_axis(1)
            
        # solving joystick deadzones
        if abs(axis_x) < 0.1:
            axis_x = 0.
        if abs(axis_y) < 0.1:
            axis_y = 0.
            
        if axis_x < 0:
            self.key_direction.x = -1
        elif axis_x > 0:
            self.key_direction.x = +1
        
        if axis_y > 0:
            self.key_direction.y = +1
        elif axis_y < 0:
            self.key_direction.y = -1
        
 
#         if axis_x < 0:
#                 self.direction = LEFT
#         elif axis_x > 0:
#             self.direction = RIGHT
#         
#         elif axis_y > 0:
#             self.direction = DOWN
#         elif axis_y < 0:
#             self.direction = UP
        self.key_direction.normalize()
        
        
        # get action_buttons
        for button_no in xrange(self.joystick.get_numbuttons()):
            if self.joystick.get_button(button_no):
                if button_no == 0:
                    self.action = "action1"
                if button_no == 1:
                    self.action = "action2"
                if button_no == 2:
                    self.action = "action3"
                if button_no == 3:
                    self.action = "action4"
示例#7
0
 def __init__(self):
     self.key_direction = Vector2(0,0)
     self.action = None