Пример #1
0
 def on_mouse_motion( self, x, y, dx, dy ):
     (x,y) = director.get_virtual_coordinates(x,y)
     for idx,i in enumerate( self.children):
         item = i[1]
         if item.is_inside_box( x, y) and not item.is_disabled:
             self._select_item( idx )
             break
Пример #2
0
    def on_mouse_press (self, x, y, buttons, modifiers):
        """This function is called when any mouse button is pressed

        (x, y) are the physical coordinates of the mouse
        'buttons' is a bitwise or of pyglet.window.mouse constants LEFT, MIDDLE, RIGHT
        'modifiers' is a bitwise or of pyglet.window.key modifier constants
           (values like 'SHIFT', 'OPTION', 'ALT')
        """
        self.posx, self.posy = director.get_virtual_coordinates (x, y)
        if(self.isChosen):
            print(self.board[self.chosenTile].moves(self.chosenTile))
            tile = self.get_tile(self.posx, self.posy)

            if tile in self.board[self.chosenTile].moves(self.chosenTile):
                self.board[self.chosenTile].position=(self.get_pos(*self.get_tile(x,y)))
                self.board[tile]=self.board[self.chosenTile]
                del self.board[self.chosenTile]
                self.isChosen=False
            if tile == self.chosenTile:
                self.isChosen=False
        else:
            try:
                print(None)
                self.board[self.get_tile(x,y)]
                self.isChosen=True
                self.chosenTile=self.get_tile(x,y)
            except KeyError:
                pass
Пример #3
0
    def screen_to_world(self, x, y):
        """Translates screen coordinates to world coordinates.

        Account for viewport, layer and screen transformations.

        Arguments:
            x (int): x coordinate in screen space
            y (int): y coordinate in screen space

        Returns:
            tuple[int, int]: coordinates in world-space
        """
        # director display scaling
        if director.autoscale:
            x, y = director.get_virtual_coordinates(x, y)

        # normalise x,y coord
        ww, wh = director.get_window_size()
        sx = x / self.view_w
        sy = y / self.view_h

        # get the map-space dimensions
        vx, vy = self.childs_ox, self.childs_oy

        # get our scaled view size
        w = int(self.view_w / self.scale)
        h = int(self.view_h / self.scale)

        # convert screen pixel to map pixel
        return int(vx + sx * w), int(vy + sy * h)
Пример #4
0
 def move_chess(self, x, y):
     if x <= (400 - 20) / 4:
         if y <= (400 - 20) / 4:
             a, b = 20, 20
         else:
             a, b = 20, 400
     elif x >= 3 * (400 - 20) / 4:
         if y <= (400 - 20) / 4:
             a, b = 400, 20
         else:
             a, b = 400, 400
     else:
         c = (400 - 20) / 2
         a, b = c, c
     aa = []
     for i in self.spt:
         aa.append(i.position)
     cc = self.can_move_place()
     for i in aa:
         if i in cc:
             cc.remove(i)
     if (a, b) not in cc:
         self.text.element.text = '移动错误'
     else:
         self.chess.position = director.get_virtual_coordinates(a, b)
     self.pos = [(20, 20), (20, 400), (400, 20), (400, 400), (190, 190)]
Пример #5
0
    def on_pointer_motion(self, x, y):
        "Simula el evento de movimiento de puntero."
        x, y = director.get_virtual_coordinates(x, y)

        for index, item in enumerate(self.items):
            if item.includes(x, y):
                self._set_hover(index)
Пример #6
0
    def pixel_from_screen(self, x, y):
        '''Look up the Layer-space pixel matching the screen-space pixel.

        Account for viewport, layer and screen transformations.
        '''
        # director display scaling
        if not director.do_not_scale_window:
            x, y = director.get_virtual_coordinates(x, y)

        # normalise x,y coord
        ww, wh = director.get_window_size()
        sx = x / self.view_w
        sy = y / self.view_h

        # get the map-space dimensions
        vx, vy = self.childs_ox, self.childs_oy
        
        # get our scaled view size
        w = int(self.view_w / self.scale)
        h = int(self.view_h / self.scale)

        #print (int(x), int(y)), (vx, vy, w, h), int(vx + sx * w), int(vy + sy * h)

        # convert screen pixel to map pixel
        return int(vx + sx * w), int(vy + sy * h)
Пример #7
0
    def on_mouse_press(self, x, y, buttons, modifiers):
        # This next line seems a bit odd, and that's because it is!
        self.position_x, self.position_y = director.get_virtual_coordinates(x, y)
        # It introduces a new topic, virtual coordinates
        # If I had used default coordinates, the position might be updated in the OS's coordinates rather than the scene
        # The director provides us with the appropriate coordinates within our "virtual" window

        self.update_text(x, y)
Пример #8
0
 def on_mouse_release(self, x, y, button, modifiers):
     vx, vy = director.get_virtual_coordinates(x, y)
     for c in self.model.player_choices:
         rect = c.get_rect()
         print rect
         if c.contains(vx, vy):
             self.model.set_choice(c)
             return
Пример #9
0
 def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
     """ Обработчик события  - таскание мышью
         x, y - физические координаты курсора
         buttons - нажатые кнопки. Опытным путем установлено: 1 - левая, 4 - правая, 2 - средняя
     """
     if self.is_dragged:  # если именно эту строчку таскают - таскаемся =)
         x, y = director.get_virtual_coordinates(x, y)
         self.do(Place((x - self.w/2, y - self.h/2)))  # за серединку
Пример #10
0
 def on_mouse_motion(self, x, y, dx, dy):
     if y < 150 or interface.modal_window:
         return
     x, y = director.get_virtual_coordinates(*self.scroller.pixel_from_screen(x, y))
     cell = self.find_cell(x, y)
     if not cell:
         return
     self.highlight.tile_highlight.position = cell.position
Пример #11
0
    def on_mouse_press(self, x, y, buttons, modifiers):
        ''' invoked when the mouse button is pressed
            x, y the coordinates of the clicked point
        '''
        mouse_x, mouse_y = director.get_virtual_coordinates(x, y)

        for bug in self.collision_manager.objs_touching_point(mouse_x,
                                                              mouse_y):
            kill_bug(bug)
Пример #12
0
 def update_mouse_mark(self, x, y):
     x, y = director.get_virtual_coordinates (x, y)
     self.mouse_mark.position = (x-5, y-5)
     rect = self.sprite1.get_rect()
     # mouse hit ?
     if rect.contains(x, y):
         self.mouse_mark.color = (255, 0, 0)
     else:
         self.mouse_mark.color = (0, 0, 255)
Пример #13
0
    def on_mouse_press (self, x, y, buttons, modifiers):
        """This function is called when any mouse button is pressed

        (x, y) are the physical coordinates of the mouse
        'buttons' is a bitwise or of pyglet.window.mouse constants LEFT, MIDDLE, RIGHT
        'modifiers' is a bitwise or of pyglet.window.key modifier constants
           (values like 'SHIFT', 'OPTION', 'ALT')
        """
        self.posx, self.posy = director.get_virtual_coordinates (x, y)
        self.update_text (x,y)
Пример #14
0
    def on_mouse_press(self, point_x, point_y, buttons, modifiers):
        ''' invoked when the mouse button is pressed
            x, y the coordinates of the clicked point
        '''
        mouse_x, mouse_y = director.get_virtual_coordinates(point_x, point_y)

        for bug in self.collision_manager.objs_touching_point(mouse_x,
                                                              mouse_y):
            self.shake()
            self.player.add_points(bug.value)
            kill_bug(bug)
Пример #15
0
 def on_mouse_press(self, x, y, button, modifiers):
     if self.proto and self.proto.ingame:
         x, y = director.get_virtual_coordinates(x, y)
         if button == pyglet.window.mouse.MIDDLE:
             #self.send_mouse()
             self.proto.send_shoot()
             return True
         elif button == pyglet.window.mouse.RIGHT:
             #self.send_mouse()
             self.proto.send_split()
             return True
Пример #16
0
 def on_mouse_press(self, x, y, buttons, modifiers):
     x, y = director.get_virtual_coordinates(x, y)
     if buttons & LEFT and self.money>=75:
         self.money -= 75
         t = Tower(x,y)
         self.towers.append(t)
         self.add(t)
     if buttons & RIGHT :
         for t in self.towers:
             b = t.shoot(x,y)
             self.bullets.append(b)
             self.add(b)
Пример #17
0
    def on_mouse_drag (self, x, y, dx, dy, buttons, modifiers):
        """Called when the mouse moves over the app window with some button(s) pressed

        (x, y) are the physical coordinates of the mouse
        (dx, dy) is the distance vector covered by the mouse pointer since the
          last call.
        'buttons' is a bitwise or of pyglet.window.mouse constants LEFT, MIDDLE, RIGHT
        'modifiers' is a bitwise or of pyglet.window.key modifier constants
           (values like 'SHIFT', 'OPTION', 'ALT')
        """
        self.posx, self.posy = director.get_virtual_coordinates (x, y)
        self.update_text (x, y)
Пример #18
0
    def on_mouse_press(self, x, y, m_button, modifiers):
        x, y = director.get_virtual_coordinates(x, y)
        if self.modal_window:
            button_set = self._modal_buttons
            x, y = x-self.modal_window.x, y-self.modal_window.y
        else:
            button_set = self._switchers + self._active_buttons

        for button in button_set:
            if button.contains(x, y):
                self._pressed_button = button
                button.on_press()
                break
Пример #19
0
 def on_mouse_press(self, x, y, buttons, modifiers):
     """ Обработчик события  - нажатие кнопки мыши
     x, y - физические координаты курсора
     buttons - нажатые кнопки. Опытным путем установлено: 1 - левая, 4 - правая, 2 - средняя
     """
     if buttons == 1:
         x, y = director.get_virtual_coordinates(x, y)  # перевод из физических координат в виртуальные
         posx = self.x
         posy = self.y
         posx2 = self.x + self.w
         posy2 = self.y + self.h
         if (x >= posx) and (y >= posy) and (x <= posx2) and (y <= posy2) and self.is_active:
             self.rectangle.layer_color = self.color_pressed
 def on_mouse_press (self, x, y, buttons, modifiers):
     self.posx, self.posy = director.get_virtual_coordinates (x, y)
     
     for x in self.logic.arena:
         pos, hunter, sprite = x
         if abs(sprite.x - self.posx) < col_radious or abs(sprite.y - self.posy) < col_radious:
             hunter[1][1] -= 1
             if hunter[1][1] <= 0:
                 self.logic.arena.remove(x)
                 self.logic.hunter_each[hunter[0]] -= 1
                 self.logic.arena_grid[pos] = True
                 self.logic.death_sounds[hunter[0]].play()
                 sprite.kill()
                 self.logic.corpses += 1
Пример #21
0
    def on_mouse_press(self, x, y, button, modifiers):
        if y < 150 or interface.modal_window:
            return
        x, y = director.get_virtual_coordinates(*self.scroller.pixel_from_screen(x, y))
        if shared_data.mode == Modes.NORMAL:
            buildings = [(building.z, building) for building in self.object_layer.buildings if building.contains(x, y)]
            obj = min(buildings)[1]
            interface.show_infocard(obj)
        else:
            cell = self.find_cell(x, y)
            if cell:
                self.start_cell = cell
                if shared_data.mode == Modes.DELETE:
                    self.mark_cells(cell)
                elif shared_data.mode == Modes.TREE:
                    self.object_layer.add_object(cell, Tree)
                elif shared_data.mode == Modes.ROAD:
                    if cell.passable:
                        cell.add_road()
                elif shared_data.mode == Modes.HOUSING:
                    self.object_layer.add_object(cell, House, building=True)
                elif shared_data.mode == Modes.PILLAR:
                    if not self.pillar_cell:
                        if self.object_layer.add_object(cell, Pillar):
                            self.pillar_cell = cell
                            cell.type = Cell.ROAD
                elif shared_data.mode in Modes.WALL:
                    self.object_layer.add_wall(cell, int(shared_data.mode[-1]))
                elif shared_data.mode == Modes.STAIRS:
                    self.object_layer.add_object(cell, Stairs)

                    # Place road at bottom of the stairs, so stairs will have correct road continuation.
                    top_cell = self.cells[cell.i+1][cell.j+1]
                    top_cell.add_road()
                    cell.add_road()

                    # Set cells at bottom and at top of the stairs to neighbours of each other,
                    # so they will be connected when finding path.
                    right_cell = self.cells[cell.i-1][cell.j]
                    left_cell = self.cells[cell.i+2][cell.j+1]
                    right_cell.neighbours.append(left_cell)
                    left_cell.neighbours.append(right_cell)
                    right_cell.level = -1
                elif shared_data.mode in Modes.LEVEL:
                    if shared_data.mode == Modes.LEVEL[0]:
                        cell.level += 1
                    if shared_data.mode == Modes.LEVEL[1]:
                        cell.level -= 1
                    self.object_layer.add(c.text.Label(str(cell.level), position=cell.position))
Пример #22
0
    def on_mouse_release(self, x, y, m_button, modifiers):
        x, y = director.get_virtual_coordinates(x, y)
        if self.modal_window:
            button_set = self._modal_buttons
            x, y = x-self.modal_window.x, y-self.modal_window.y
        else:
            button_set = self._switchers + self._active_buttons

        for button in button_set:
            if button.contains(x, y) and button == self._pressed_button:
                button.restore_image()
                button.on_release()
                break

        self._pressed_button = None
Пример #23
0
    def on_mouse_drag(self, x, y, dx, dy, m_button, modifiers):
        x, y = director.get_virtual_coordinates(x, y)
        if self.modal_window:
            button_set = self._modal_buttons
            x, y = x-self.modal_window.x, y-self.modal_window.y
        else:
            button_set = self._switchers + self._active_buttons

        for button in button_set:
            if button.contains(x, y) and self._pressed_button == button:
                button.on_press()
                break
            elif (not button.contains(x, y)) and self._pressed_button == button:
                button.restore_image()
                break
Пример #24
0
 def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
     """ Обработчик события  - таскание мышью
         x, y - физические координаты курсора
         buttons - нажатые кнопки. Опытным путем установлено: 1 - левая, 4 - правая, 2 - средняя
     """
     x, y = director.get_virtual_coordinates(x, y)  # перевод из физических координат в виртуальные
     posx = self.x
     posy = self.y
     posx2 = self.x + self.w
     posy2 = self.y + self.h
     # проверяем, попадает ли курсор в позицию, если да - изменяем цвет прямоугольника
     if (x >= posx) and (y >= posy) and (x <= posx2) and (y <= posy2) and not self.is_occupied:
         self.rectangle.layer_color = (0.2, 1, 0.2, 1)  # зелёненький
     else:
         self.rectangle.layer_color = (1, 0.2, 0.2, 1)  # красненький
    def on_mouse_press(self, x, y, buttons, modifiers):
        """This function is called when any mouse button is pressed

        (x, y) are the physical coordinates of the mouse
        'buttons' is a bitwise or of pyglet.window.mouse constants LEFT, MIDDLE, RIGHT
        'modifiers' is a bitwise or of pyglet.window.key modifier constants
           (values like 'SHIFT', 'OPTION', 'ALT')

        cocos has 2 coordinates systems, a physical one and a virtual one.
        pyglet sends physical coordinates, as we want to map it in a virtual context,
        director.get_virtual_coordinates(x, y) does the correct mapping for us
        doing it with self.posx, self.posy = x,y will work too but as soon
        as we change the window size the mapping is off-set
        """
        self.posx, self.posy = director.get_virtual_coordinates(x, y)
        self.update_text(x, y)
Пример #26
0
 def on_mouse_press(self, x, y, buttons, modifiers):
     vx, vy = director.get_virtual_coordinates(x,y)
     grid_cell = get_cell_from_point(vx, vy)
     
     if buttons == mouse.RIGHT:
         world_obj = self.level.world.grid.get_at(grid_cell)
         # remove tower:
         if world_obj is not None and isinstance(world_obj, Tower):
             self.level.remove_tower(world_obj)
     
     elif buttons == mouse.LEFT:
         world_obj = self.level.world.grid.get_at(grid_cell)
         # activate or deactivate tower:
         if world_obj is not None and isinstance(world_obj, Tower):
             self.level.world.activate_tower(world_obj)
         else:
             self.level.world.deactivate_tower()
Пример #27
0
    def on_mouse_press(self, x, y, buttons, modifiers):
        #debug stuff
        #self.score = 10
        #self.showResults()
        #end debug stuff

        if self.isGameOver or self.isAnimating:
            pass
        else:
            #handle the mouse click to activate the powerup.
            for item in self.powerMenu:
                if item.contains(x, y):
                    self.sound_effects['powerup'].play()
                    item.activate()

            self.posx, self.posy = director.get_virtual_coordinates(x, y)
            #make the bits toggle when the mouse is clicked.
            if self.bitpattern.handleClick(x, y):
                self.sound_effects['click'].play()
Пример #28
0
    def pixel_from_screen(self, x, y):
        '''Look up the Layer-space pixel matching the screen-space pixel.

        Account for viewport, layer and screen transformations.
        '''
        # director display scaling
        x, y = director.get_virtual_coordinates(x, y)

        # normalise x,y coord
        ww, wh = director.get_window_size()
        sx = x / ww
        sy = y / wh

        # get the map-space dimensions
        vx, vy, w, h = self.view_x, self.view_y, self.view_w, self.view_h

        #print (int(x), int(y)), (vx, vy, w, h), int(vx + sx * w), int(vy + sy * h)

        # convert screen pixel to map pixel
        return int(vx + sx * w), int(vy + sy * h)
Пример #29
0
 def on_mouse_drag(self, x, y, dx, dy, button, modifiers):
     if y < 150 or interface.modal_window:
         return
     x, y = director.get_virtual_coordinates(*self.scroller.pixel_from_screen(x, y))
     cell = self.find_cell(x, y)
     if not cell:
         return
     self.highlight.tile_highlight.position = cell.position
     if shared_data.mode == Modes.ROAD:
         if self.start_cell and self.start_cell.passable and cell.passable:
             if cell != self.current_cell:
                 self.current_cell = cell
                 self.draw_road_path(cell)
     elif shared_data.mode == Modes.TREE:
         self.object_layer.add_object(cell, Tree)
     elif shared_data.mode == Modes.HOUSING:
         self.object_layer.add_object(cell, House, building=True)
     elif shared_data.mode == Modes.DELETE:
         if self.start_cell:
             self.mark_cells(cell)
Пример #30
0
 def on_mouse_motion(self, x, y, dx, dy):
     self.draging = director.get_virtual_coordinates(x,y)
     grid_pos = get_cell_from_point(self.draging[0], self.draging[1])
     
     # TODO this call is ugly, so loong:
     is_out = self.menu.level.world.grid.is_out_at(self.tower_class, grid_pos)
     if is_out:
         self.rect_layer.visible = False
     else:
         self.rect_layer.visible = True
     
     # TODO this call is ugly, so loong:
     can_fit = self.menu.level.world.grid.can_fit_at(self.tower_class, grid_pos)
     self.rect_layer.position = (grid_pos[0]*GRID_CELL,
                                 grid_pos[1]*GRID_CELL)
     if can_fit:
         self.rect_layer.color = 0, 255, 0
     else:
         self.rect_layer.color = 255, 0, 0
         
     self.sprite.position = self.draging
Пример #31
0
 def on_mouse_press(self, x, y, buttons, modifiers):
     self.mouse_action = 'press'
     self.mouse_modifiers = modifiers
     self.posx, self.posy = director.get_virtual_coordinates(x, y)
     self.update_mouse_label(x, y)
Пример #32
0
 def on_mouse_motion(self, x, y, dx, dy):
     if not autotest:
         vh, vy = director.get_virtual_coordinates(x, y)
         self.move_label(vh, vy)
Пример #33
0
 def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
     (x, y) = director.get_virtual_coordinates(x, y)
     x, y = self.sun.position
     self.sun.position = (x + dx, y + dy)
Пример #34
0
 def on_mouse_press(self, x, y, buttons, modifiers):
     self.text.element.text = 'Mouse @ {}, {}, {}, {}'.format(
         x, y, buttons, modifiers)
     self.text.element.x, self.text.element.y = director.get_virtual_coordinates(
         x, y)
Пример #35
0
 def on_mouse_press(self,x,y,buttons,modifiers):
     self.posx, self.posy = director.get_virtual_coordinates(x,y)
     self.update_text(x,y)
     changeScene(game_scene)
Пример #36
0
 def on_mouse_release(self, x, y, buttons, modifiers):
     px, py = director.get_virtual_coordinates(x, y)
     if self.press_go:
         self.prize_cycle = 0
         self.can_stop = True
         self.press_go = False
Пример #37
0
 def on_mouse_motion(self, x, y, dx, dy):
     self.move(*director.get_virtual_coordinates(x, y))
 def on_mouse_press(self, x, y, buttons, modifiers):
     # 按下鼠标按键不仅更新鼠标位置,还改变标签的位置.这里使用director.get_virtual_coordinates(),用于保证即使窗口缩放过也能正确更新位置,如果直接用x,y会位置错乱,原因不明
     self.text.element.text = 'Mouse @ {}, {}, {}, {}'.format(x, y, buttons, modifiers)
     self.text.element.x, self.text.element.y = director.get_virtual_coordinates(x, y)
Пример #39
0
 def on_mouse_press(self, x, y, buttons, modifiers):
     px, py = director.get_virtual_coordinates(x, y)
     if self.does_contain_point((x, y)):
         self.on_processed_touch(x, y, buttons, modifiers)
Пример #40
0
 def on_mouse_press(self, x, y, buttons, modifiers):
     self.cat.position = director.get_virtual_coordinates(x, y)
Пример #41
0
 def on_mouse_press(self, x, y, buttons, modifiers):
     self.posx, self.posy = director.get_virtual_coordinates(x, y)
     if self.posx < 420 and self.posy > 620:
         director.pop()
Пример #42
0
    def on_mouse_press(self, x, y, buttons, modifiers):
        """event handler"""
        tw = self.map.tw
        cx, cy = director.get_virtual_coordinates(x, y)
        cell = self.map.cells
        tx = int((cx + self.map.view_x) / tw)
        ty = int((cy + self.map.view_y - self.viewport_height) / tw)
        if (tx < 0) or (ty < 0) or (tx >= len(cell)) or (ty >= len(cell[tx])):
            return  # click outside map
        else:
            if buttons == 1:  # 1: left, 2: middle etc.
                if self.marked_tile[0] < 0:
                    if ("trn_" + str(tx) + "_" + str(ty) in self.combatants
                        ) and (self.combatants["trn_" + str(tx) + "_" +
                                               str(ty)].side == "_tr"):
                        if self.combatants["trn_" + str(tx) + "_" +
                                           str(ty)].combatant == "Locomotive":
                            self.marked_tile = (tx, ty)
                            self.mark_valid_rails(
                                self.transarctica_combat_train,
                                self.marked_tile[1], 4)
                        elif self.combatants["trn_" + str(tx) + "_" +
                                             str(ty)].stat["spawn"] != "na":
                            self.marked_tile = (tx, ty)
                            self.mark_valid_move_squares(
                                self.marked_tile, 0, 1)
                            self.spawn_unit = self.combatants[
                                "trn_" + str(tx) + "_" + str(ty)].stat["spawn"]
                        elif self.combatants[
                                "trn_" + str(tx) + "_" +
                                str(ty)].combatant == "Machine gun":
                            self.marked_tile = (tx, ty)
                            self.mark_valid_move_squares(
                                self.marked_tile, 0, 0)
                            self.mark_valid_range_combat_squares(
                                self.combatants["trn_" + str(tx) + "_" +
                                                str(ty)].stat["max_range"], 8)
                        elif self.combatants["trn_" + str(tx) + "_" +
                                             str(ty)].combatant == "Cannon":
                            self.marked_tile = (tx, ty)
                            self.mark_valid_move_squares(
                                self.marked_tile, 0, 0)
                            max_range = self.combatants[
                                "trn_" + str(tx) + "_" +
                                str(ty)].stat["max_range"]
                            self.mark_valid_range_combat_squares(
                                abs(max_range), 16)
                            if max_range < 0:
                                self.mark_valid_indirect_combat_squares(
                                    abs(max_range))

                        else:
                            self.marked_tile = (tx, ty)
                            combat_unit = self.combatants["trn_" + str(tx) +
                                                          "_" + str(ty)]
                            self.bracket_sel.x = (self.marked_tile[0]) * tw
                            self.bracket_sel.y = (self.marked_tile[1]) * tw
                            self.mark_valid_move_squares(
                                self.marked_tile, 0,
                                combat_unit.stat["max_move"])
                            if combat_unit.stat["max_range"] > 1:
                                self.remove_combat_squares()
                                self.mark_valid_range_combat_squares(
                                    combat_unit.stat["max_range"], 4)
                else:
                    if (self.marked_tile != (tx, ty)):
                        if ("trn_" + str(tx) + "_" + str(ty)
                                in self.valid_squares):
                            if self.valid_squares["trn_" + str(tx) + "_" +
                                                  str(ty)]["type"] == "move":
                                if self.spawn_unit != "na":

                                    self.spawn_unit = "na"
                                if ("trn_" + str(self.marked_tile[0]) + "_" +
                                        str(self.marked_tile[1]) in
                                        self.combatants) and (self.combatants[
                                            "trn_" + str(self.marked_tile[0]) +
                                            "_" +
                                            str(self.marked_tile[1])].combatant
                                                              == "Locomotive"):
                                    self.move_path.clear()
                                    dist = int(cell[tx][ty].properties["dist"])
                                    self.move_combat_train(
                                        self.transarctica_combat_train, dist,
                                        ty)
                                    self.clear_valid_squares()
                                else:
                                    self.move_path.clear()
                                    self.create_move_path((tx, ty))
                                    self.move_combat_unit_blocked(
                                        self.move_path)
                                    self.clear_valid_squares()

                            else:
                                # self.valid_squares["trn_"+str(tx)+"_"+str(ty)]["type"]=="melee" or self.valid_squares["trn_"+str(tx)+"_"+str(ty)]["type"]=="ranged" or self.valid_squares["trn_"+str(tx)+"_"+str(ty)]["type"]=="indirect":
                                combat_unit = self.combatants[
                                    "trn_" + str(self.marked_tile[0]) + "_" +
                                    str(self.marked_tile[1])]
                                if self.valid_squares[
                                        "trn_" + str(tx) + "_" +
                                        str(ty)]["type"] == "melee":
                                    self.move_path.clear()
                                    self.create_move_path((tx, ty))
                                    if self.attack_combat_unit_close(tx, ty):
                                        self.move_combat_unit_blocked(
                                            self.move_path)
                                if self.valid_squares[
                                        "trn_" + str(tx) + "_" +
                                        str(ty)]["type"] == "ranged":
                                    self.attack_combat_unit_ranged(tx, ty)
                                if self.valid_squares[
                                        "trn_" + str(tx) + "_" +
                                        str(ty)]["type"] == "indirect":
                                    self.attack_combat_unit_ranged(tx, ty)
                                self.clear_valid_squares()
                    else:
                        self.clear_valid_squares()
            elif buttons == 4:  # 1: left, 2: middle etc.
                self.clear_valid_squares()
Пример #43
0
 def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
     self.move(*director.get_virtual_coordinates(x, y))
Пример #44
0
 def on_mouse_press(self, x, y, buttons, modifiers):
     x, y = director.get_virtual_coordinates(x, y)
     self.test.click(x, y)
Пример #45
0
    def check_LOS(self, target):
        self.LOS.end = target
        tw = self.map.tw
        cell = self.map.cells

        if abs(self.LOS.start[0] - self.LOS.end[0]) > abs(self.LOS.start[1] -
                                                          self.LOS.end[1]):
            axis = 0
        else:
            axis = 1

        if self.LOS.start[axis] > self.LOS.end[axis]:
            step = -4
        else:
            step = 4
        cc = (-1, -1)

        for pa in range(self.LOS.start[axis], self.LOS.end[axis], step):
            if axis == 0:
                px = pa
                py = (
                    ((self.LOS.end[1] - self.LOS.start[1]) *
                     (px - self.LOS.start[0])) //
                    (self.LOS.end[0] - self.LOS.start[0])) + self.LOS.start[1]
            else:
                py = pa
                px = (
                    ((self.LOS.end[0] - self.LOS.start[0]) *
                     (py - self.LOS.start[1])) //
                    (self.LOS.end[1] - self.LOS.start[1])) + self.LOS.start[0]

            cx, cy = director.get_virtual_coordinates(px, py)
            ctx = int((cx + self.map.view_x) / tw)
            cty = int((cy + self.map.view_y - self.viewport_height) / tw)

            if cc != (ctx, cty):
                cc = (ctx, cty)
                if (ctx < 0) or (ctx >= len(cell)) or (cty < 0) or (
                        cty >= len(cell[ctx])
                ) or cell[ctx][cty].properties["terrain"] == "h":
                    break
                else:
                    if ("trn_" + str(ctx) + "_" + str(cty)
                            not in self.valid_squares):
                        if ("trn_" + str(ctx) + "_" + str(cty)
                                in self.combatants) and (
                                    self.combatants["trn_" + str(ctx) + "_" +
                                                    str(cty)].side == "_vu"):
                            self.valid_squares["trn_" + str(ctx) + "_" +
                                               str(cty)] = {}
                            self.valid_squares["trn_" + str(ctx) + "_" +
                                               str(cty)]["dist"] = 99
                            cell[ctx][cty].properties["dist"] = 99
                            self.valid_squares["trn_" + str(ctx) + "_" +
                                               str(cty)]["type"] = "ranged"
                            square = Sprite(
                                self.gallery.content["trn"]
                                ["valid_square_" +
                                 self.valid_squares["trn_" + str(ctx) + "_" +
                                                    str(cty)]["type"]],
                                position=(((ctx + 0.5) * self.map.tw,
                                           (cty + 0.5) * self.map.tw)))
                            self.valid_squares["trn_" + str(ctx) + "_" +
                                               str(cty)]["sprite"] = square
                            self.valid_squares["trn_" + str(ctx) + "_" +
                                               str(cty)]["pos"] = (ctx, cty)
                            self.map.add(square)
Пример #46
0
 def on_mouse_press(self, x, y, buttons, modifiers):
     print(director.get_virtual_coordinates(x, y))
Пример #47
0
 def on_mouse_press(self, x, y, buttons, modifiers):
     self.posx, self.posy = director.get_virtual_coordinates(x, y)
     print(x, y)
Пример #48
0
 def on_mouse_release(self, x, y, buttons, modifiers):
     (x, y) = director.get_virtual_coordinates(x, y)
     if self.children[self.selected_index][1].is_inside_box(x, y):
         self._activate_item()
Пример #49
0
 def on_mouse_press(self, x, y, buttons, modifiers):
     self.mouse_target = director.get_virtual_coordinates(x, y)
     arrow = self.hero.attack(self.mouse_target)
     arrows.append(arrow)
Пример #50
0
 def on_mouse_press(self, x, y, button, mod):
     real_pos = director.get_virtual_coordinates(x, y)
     if self.contains(real_pos[0], real_pos[1]):
         self.cameraPress()