Ejemplo n.º 1
0
def mouse_click(x, y):
    global object
    if object == 'Ball':
        balls.add(Ball(x, y, random_angle()))
    elif object == "Floater":
        balls.add(Floater(x, y, random_angle()))
    elif object == "Black_Hole":
        simu.add(Black_Hole(x, y))
    elif object == "Pulsator":
        simu.add(Pulsator(x, y))
    elif object == "Remove":
        g = balls
        h = set()
        k = set()
        for f in g:
            if f.contains((x, y)):
                h.add(f)
        for s in simu:
            if s.contains((x, y)):
                k.add(s)
        for l in h:
            remove(l)
        for b in k:
            simu.remove(b)
        pass
    elif object == "Hunter":
        simu.add(Hunter(x, y, random_angle()))
 def update(self, model):
     if len(Black_Hole.update(self, model)) != 0:
         for i in range(len(Black_Hole.update(self, model))):
             for a in range(10):
                 choice = randint(1, 2)
                 dx = randint(-10, 10)
                 dy = randint(-10, 10)
                 if choice == 1:
                     model.simuls.add(Ball(self._x + dx, self._y + dy))
                 elif choice == 2:
                     model.simuls.add(Floater(self._x + dx, self._y + dy))
         self.eaten = set()
         model.remove(self)
Ejemplo n.º 3
0
    def _floater_open(self, parent, *args):
        if not self._floater:
            self._floater = Floater(parent, parent)
            self._floater.size_min_set(
                self._floater_min_w, self._floater_min_h)

            self._floater_title_init()
            self._floater_actions_init()
            self._floater_content_init()

        self._floater_update()

        self._floater.show()
Ejemplo n.º 4
0
def mouse_click(x, y):
    if button == 'Ball':
        simulation.add(Ball(x, y))
    elif button == 'Floater':
        simulation.add(Floater(x, y))
    elif button == 'Black_Hole':
        simulation.add(Black_Hole(x, y))
    elif button == 'Pulsator':
        simulation.add(Pulsator(x, y))
    elif button == 'Hunter':
        simulation.add(Hunter(x, y))
    elif button == 'Special':
        simulation.add(Special(x, y))
    elif button == 'Remove':
        for i in simulation.copy():
            if i.distance((x, y)) < i.radius:
                remove(i)
Ejemplo n.º 5
0
def mouse_click(x,y):
    global selection, simultons
    if selection == 'Remove': #Need to finish
        for sim in simultons.copy():
            if sim.contains( (x,y) ):
                remove(sim)
    elif selection == 'Ball':
        add( Ball(x,y,5,5,0,5) )
    elif selection == 'Floater':
        add( Floater(x,y,5,5,0,5) )
    elif selection == 'Black_Hole':
        add( Black_Hole(x,y,20,20) )
    elif selection == 'Pulsator':
        add( Pulsator(x,y,20,20) )
    elif selection == 'Hunter':
        add( Hunter(x,y,20,20,0,5) )
    elif selection == 'Special':
        add( Special(x,y,5,5,0,10) )
Ejemplo n.º 6
0
def mouse_click(x,y):
    try:
        if object_name == 'Ball':
            balls.add(Ball(x,y))
        elif object_name == 'Floater':
            balls.add(Floater(x,y))
        elif object_name == 'Black_Hole':
            balls.add(Black_Hole(x,y))
        elif object_name == 'Pulsator':
            balls.add(Pulsator(x,y))
        elif object_name == 'Hunter':
            balls.add(Hunter(x,y))  
        elif object_name == 'Special':
            balls.add(Special(x,y))
  
        elif object_name == 'Remove':
            for i in find(lambda a: a.contains((x,y))):
                balls.remove(i)      
        
    except:
        pass
Ejemplo n.º 7
0
def mouse_click(x, y):
    global balls
    if select_kind == 'Remove':
        for b in balls:
            coor = b.get_location()
            if coor[0] - 5 < x and x < coor[0] + 5 and coor[
                    1] - 5 < y and y < coor[1] + 5:
                remove(b)
                break
    elif select_kind == 'Ball':
        add(Ball(x, y))
    elif select_kind == 'Floater':
        add(Floater(x, y))
    elif select_kind == 'Black_Hole':
        add(Black_Hole(x, y))
    elif select_kind == 'Pulsator':
        add(Pulsator(x, y))
    elif select_kind == 'Hunter':
        add(Hunter(x, y))
    elif select_kind == 'Special':
        add(Special(x, y))
Ejemplo n.º 8
0
def mouse_click(x,y):
    global balls, click, remove_set
    if str(click) == "Remove":
        try:
            for ele in balls:
                if ele.contains((x,y)):
                    remove(ele) 
        except:
            pass
    else:
        if str(click) == "Ball":
            add(Ball(x,y))
        elif str(click) == 'Black_Hole':
            add(Black_Hole(x,y))
        elif str(click) == 'Floater':
            add(Floater(x,y))
        elif str(click) == 'Hunter':
            add(Hunter(x,y))
        elif str(click) == 'Pulsator':
            add(Pulsator(x,y))
        elif str(click) == "Special":
            add(Special(x,y))
Ejemplo n.º 9
0
 def update(self, model):
     self.time_count += 1
     target_simu = model.find(
         lambda x: isinstance(x, Prey) == False and self.distance(
             x.get_location()) <= Special.safe_distance)
     if target_simu != set():
         for target in target_simu:
             position_target = target.get_location()
             position_hunter = self.get_location()
             self.set_angle(pi -
                            atan2(position_target[1] -
                                  position_hunter[1], position_target[0] -
                                  position_hunter[0]))
         self.rs = self.get_speed() + random()
         self.set_speed(self.rs)
     if self.time_count > 30:
         model.simulton_module.add(
             Floater(self.get_location()[0],
                     self.get_location()[1]))
         model.simulton_module.add(
             Ball(self.get_location()[0],
                  self.get_location()[1]))
         self.time_count = 0
     self.move()
Ejemplo n.º 10
0
    def open(self):
        if not self._pop:
            self._pop = Floater(self.button, self.obj)
            self.pager = Naviframe(self._pop)
            self.pager.style_set("editje.rightwards")
            self.states = List(self._pop)
            self.states.size_hint_weight_set(evas.EVAS_HINT_EXPAND,
                                             evas.EVAS_HINT_EXPAND)
            self.states.size_hint_align_set(-1.0, -1.0)
            self.states.show()
            self.pager.item_simple_push(self.states)
            self._pop.content_set(self.pager)
            self._pop.size_min_set(self.pop_min_w, self.pop_min_h)
            self._pop.title_set("States selection")
            self._pop.action_add("New", self._state_add_new_cb)
            self._pop.action_add("Close", self._cancel_clicked)

            self._edit_grp.part.callback_add("states.changed",
                                             self._list_populate)
            self._edit_grp.part.state.callback_add("state.changed",
                                                   self._list_populate)

        self._list_populate()
        self._pop.show()
Ejemplo n.º 11
0
    def loadFloaters(self, config, allowedSections):
        """Load objects floating in the water.

        Args:
            config:          Parsed level config object.
                             configparser.ConfigParser object.
            allowedSections: List or tuple of names used in configuration
                             files to specify configuration for a track
                             section.
        """
        riverTracks = []
        floatingObjects = []
        for trackSection in allowedSections:

            if not config[trackSection].getboolean('enabled'):
                continue

            cfg = config[trackSection]

            gaps = []
            for amount in cfg.get('gaps').replace(' ', '').split(','):
                gaps.append(int(amount))

            track = {
                'top': cfg.getint('top'),
                'bottom': cfg.getint('bottom'),
                'direction': cfg.get('direction'),
                'speed': cfg.getint('speed'),
                'gaps': gaps,
            }
            riverTracks.append(track)

            # Get names of config files for the floaters for the level.
            configFilenames = cfg.get('floaters').replace(' ', '').split(',')

            # Load specified water objects.
            waterObjects = []
            for idx, configName in enumerate(configFilenames):
                configPath = os.path.join(self.configDir, configName)
                if idx == len(gaps):
                    msg = (f"No gap defined for floater '{configPath}' in "
                           f"section '{trackSection}'.")
                    print(msg)
                    raise ValueError(msg)
                stuff = Floater(configPath,
                                roadDirection=track['direction'],
                                screenWidth=self.screenWidth,
                                screenHeight=self.screenHeight,
                                roadTop=track['top'],
                                roadBottom=track['bottom'],
                                gapInFront=gaps[idx],
                                speed=track['speed'])

                # Calculate and set starting position of the floater.
                if idx == 0:
                    carWidth = stuff.carWidth

                    if stuff.direction == 'to_left':
                        initPos = stuff.initPos = stuff.gap
                    else:
                        initPos = stuff.initPos = self.screenWidth - stuff.gap

                    stuff.gap = 0
                    stuff.calcPositions()

                else:
                    if stuff.direction == 'to_left':
                        stuff.initPos = initPos + carWidth + stuff.gap
                    else:
                        stuff.initPos = initPos - stuff.carWidth - stuff.gap
                    stuff.calcPositions()

                    initPos = stuff.initPos
                    carWidth = stuff.carWidth

                waterObjects.append(stuff)

            floatingObjects += waterObjects

        return (riverTracks, floatingObjects)