Beispiel #1
0
 def delete_level(self, x, y):
     r = Rect(self.delete_level_label.x, self.delete_level_label.y, 130, 20)
     if r.contains(x, y):
         status = True
         self.yes_label.visible = status
         self.no_label.visible = status
         self.delete_is_press = status
     if self.delete_is_press:
         yes = Rect(self.yes_label.x, self.yes_label.y, 15, 20)
         no = Rect(self.no_label.x, self.no_label.y, 15, 20)
         status = False
         if yes.contains(x, y):
             path = 'levelfile/level'+str(self.save_as)+'.txt'
             if os.path.exists(path):
                 os.remove(path)
             self.save_as = self.get_all_level()[-1]
             self.yes_label.visible = status
             self.no_label.visible = status
             self.delete_is_press = status
             self.reset_blocks()
             self.reset_level_select()
         elif no.contains(x, y):
             self.delete_is_press = status
             self.yes_label.visible = status
             self.no_label.visible = status
Beispiel #2
0
 def delete_level(self, x, y):
     r = Rect(self.delete_level_label.x, self.delete_level_label.y, 130, 20)
     if r.contains(x, y):
         status = True
         self.yes_label.visible = status
         self.no_label.visible = status
         self.delete_is_press = status
     if self.delete_is_press:
         yes = Rect(self.yes_label.x, self.yes_label.y, 15, 20)
         no = Rect(self.no_label.x, self.no_label.y, 15, 20)
         status = False
         if yes.contains(x, y):
             path = 'levelfile/level' + str(self.save_as) + '.txt'
             if os.path.exists(path):
                 os.remove(path)
             self.save_as = self.get_all_level()[-1]
             self.yes_label.visible = status
             self.no_label.visible = status
             self.delete_is_press = status
             self.reset_blocks()
             self.reset_level_select()
         elif no.contains(x, y):
             self.delete_is_press = status
             self.yes_label.visible = status
             self.no_label.visible = status
Beispiel #3
0
 def on_mouse_release(self, x, y, buttons, modifiers):
     print('$global', x, y)
     
     from cocos.rect import Rect
     aabb2 = self.explosion2.get_AABB()
     global_2_bl = self.explosion.point_to_world(aabb2.bottomleft)
     global_2_tr = self.explosion.point_to_world(aabb2.topright)
     rect2 = Rect(*global_2_bl, *(global_2_tr - global_2_bl))
     print('%local_rect2', self.explosion2.get_rect())
     print('%aabb2', self.explosion2.get_AABB())
     print('%rect2', rect2)
     print('Contains:', rect2.contains(x, y))
     print()
Beispiel #4
0
    def on_mouse_release(self, x, y, buttons, modifiers):
        print('$global', x, y)

        from cocos.rect import Rect
        aabb2 = self.explosion2.get_AABB()
        global_2_bl = self.explosion.point_to_world(aabb2.bottomleft)
        global_2_tr = self.explosion.point_to_world(aabb2.topright)
        rect2 = Rect(*global_2_bl, *(global_2_tr - global_2_bl))
        print('%local_rect2', self.explosion2.get_rect())
        print('%aabb2', self.explosion2.get_AABB())
        print('%rect2', rect2)
        print('Contains:', rect2.contains(x, y))
        print()
Beispiel #5
0
    def find_facing(self, entity, with_behavior=None):
        # Find nearby things that respond to use
        # TODO really need to figure out where this kind of code goes.  surely
        # in the entity layer.
        # TODO also, goddamn, Rect blows.
        # XXX the idea here is that the "activation" rectangle is a fixed size
        # in front of the searching entity, extended inwards to touch the
        # entity's center.  this could probably be improved or better-commented
        # or something.
        # TODO this makes poor use of the concept of "shape".  luckily that
        # isn't implemented yet.
        # TODO seems the search area should be round, and yet, it is not.  eh?
        target = Rect(
            0,
            0,
            SEARCH_DISTANCE + abs(entity._angle.vector[0]) * entity.entity_type.shape,
            SEARCH_DISTANCE + abs(entity._angle.vector[1]) * entity.entity_type.shape,
        )
        if entity._angle is flora.util.direction.UP:
            target.midbottom = entity.position
        elif entity._angle is flora.util.direction.DOWN:
            target.midtop = entity.position
        elif entity._angle is flora.util.direction.LEFT:
            target.midright = entity.position
        elif entity._angle is flora.util.direction.RIGHT:
            target.midleft = entity.position

        for z, other in self.children_names["entities"].children:
            if other is entity:
                continue

            if with_behavior is not None and with_behavior not in other.behaviors:
                continue

            # TODO again, Rect sucks
            if target.contains(*other.position):
                # OK, within range
                # TODO need to, like, pick more cleverly than just the first
                return other
Beispiel #6
0
 def new_level(self, x, y):
     r = Rect(self.new_level_label.x, self.new_level_label.y, 70, 20)
     if r.contains(x, y):
         self.create_new_level()
Beispiel #7
0
 def has_point(self, x, y):
     px, py = self.position
     px -= self.width // 2
     py -= self.height // 2
     r = Rect(px, py, self.width, self.height)
     return r.contains(x, y)
Beispiel #8
0
 def new_level(self, x, y):
     r = Rect(self.new_level_label.x, self.new_level_label.y, 70, 20)
     if r.contains(x, y):
         self.create_new_level()