Ejemplo n.º 1
0
    def on_screen(self, window_scale, game_grid):

        rect = self.get_rect(window_scale)
        scaled_grid = (0, 0) + gfunc.tuple_mult(game_grid, window_scale)

        if gfunc.touching(rect, scaled_grid):
            return True
        return False
Ejemplo n.º 2
0
    def do_damage(self, enemies, dt, *args):

        # Do damage here
        for enemy in enemies:

            pos = enemy.get_pos()
            if pos:

                rect1 = pos[0] + 0.5, pos[1] + 0.5, 0, 0
                rect2 = self.pos[0], self.pos[1], 1, 1

                if gfunc.touching(rect1, rect2):
                    enemy.health -= self.damage * dt

                    return enemies
        return enemies
Ejemplo n.º 3
0
    def do_damage(self, enemies, window_scale):
        self.aim(enemies)

        for enemy in enemies:
            enemy_rect = enemy.get_rect(window_scale)

            if enemy_rect:

                for bullet in self.projectiles:
                    bullet_rect = bullet.get_rect(window_scale)

                    if gfunc.touching(bullet_rect, enemy_rect):

                        enemy.health -= bullet.damage
                        bullet_index = self.projectiles.index(bullet)
                        self.projectiles.pop(bullet_index)

        return enemies
Ejemplo n.º 4
0
    def do_damage(self, enemies, *args):

        # Aim
        self.aim(enemies)

        eindex = 1

        for enemy in enemies:
            enemy_pos = enemy.get_rect(1)
            if enemy_pos:

                for x, y in self.points:
                    rect1 = x, y, 0, 0

                    if gfunc.touching(rect1, enemy_pos):
                        enemy.health -= self.damage / eindex
                        eindex += 1
                        break

        self.points = [self.pos]

        # Do damage here
        return enemies
Ejemplo n.º 5
0
    def tower_selection(self, window, window_scale, playing_grid,
                        tower_select_rows, money, dt):
        k = key.get_pressed()

        def draw_rect(colour):
            pos = mouse_extras.get_pos()
            pos[0] *= window_scale
            pos[1] *= window_scale

            rect = Surface((window_scale, window_scale))
            rect.set_alpha(128)
            rect.fill(colour)
            window.blit(rect, pos)

        selection_rect = self.draw_selection_block(window, window_scale,
                                                   playing_grid,
                                                   tower_select_rows)

        # Show towers in selection part
        for tower_i in range(len(self.usable_towers)):
            tower = self.usable_towers[tower_i]

            # Change index to pos
            y = int(tower_i / playing_grid[0])
            x = tower_i - y * playing_grid[0]
            y += playing_grid[1]

            # Scale pos
            x *= window_scale
            y *= window_scale

            # Scale img
            img = transform.scale(tower.img,
                                  (int(window_scale), int(window_scale)))

            # Show
            window.blit(img, (x, y))

        # Delete tower
        if not self.held_tower or k[K_LSHIFT]:

            if mouse_extras.get_states()[2] == -1 or (
                    mouse_extras.get_pressed()[2] and k[K_LSHIFT]):
                mouse_pos = mouse_extras.get_pos()

                # What tower(s) are the mouse over?
                highest = 0
                del_tower_index = None

                for tower_index in range(len(self.towers)):
                    tower = self.towers[tower_index]

                    # Is it in the right pos?
                    if tower.pos == mouse_pos:

                        # Is it above the others?
                        if tower.layer >= highest:

                            highest = tower.layer
                            del_tower_index = tower_index

                # Is there one to delete?
                if del_tower_index != None:
                    tower = self.towers[del_tower_index]

                    # Is it a block?
                    if self.towers[del_tower_index].id == 'block':
                        index = self.blocks.index(self.towers[del_tower_index])
                        self.blocks.pop(index)

                    self.towers.pop(del_tower_index)
                    money += tower.cost

        # Show placed towers
        for tower in self.towers:
            tower.show(window, window_scale, dt)

        # Show held tower
        if self.held_tower:
            scaled_pos = mouse_extras.get_pos()
            img = transform.scale(self.held_tower.img,
                                  (int(window_scale), int(window_scale)))

            scaled_pos[0] *= window_scale
            scaled_pos[1] *= window_scale

            def show_tower():
                window.blit(img, scaled_pos)

            # Can the tower be placed?
            # Is it in the playing area

            # Does the held tower need to be let go?
            if mouse_extras.get_states()[2] == -1 and not k[K_LSHIFT]:
                self.held_tower = None
                return money

            # Does it need to be placed?
            pos = mouse_extras.get_pos()
            if pos[1] < playing_grid[1]:

                # Check that the necessary base(s) are there
                towers_in_slot = []
                for tower in self.towers:
                    if tower.pos == pos:
                        towers_in_slot.append(tower)

                held_layer = self.held_tower.layer
                okay = True

                # Check that there are no towers in the same slot and layer
                for tower in towers_in_slot:
                    if tower.layer == held_layer:
                        okay = False

                # Is it on the lowest layer? (Is it a base)
                if held_layer == 0:
                    if len(towers_in_slot) != 0:
                        okay = False

                # Is it on 2nd layer (needs base)
                if held_layer == 1:
                    if len(towers_in_slot) != 1:
                        okay = False

                    # Is there something under it?
                    if len(towers_in_slot) >= 1:

                        # Is it not a block?
                        if towers_in_slot[0].id != 'block':
                            okay = False

                if okay:

                    if money >= self.held_tower.Tower(()).cost:
                        draw_rect((100, 255, 100))
                        show_tower()
                    else:
                        draw_rect((255, 100, 100))
                        show_tower()
                    # Does the held tower need to be placed?
                    if mouse_extras.get_states()[0] == -1 or (
                            mouse_extras.get_pressed()[0] and k[K_LSHIFT]):

                        # Does the player have enough money
                        tower = self.held_tower.Tower(pos)
                        if money >= tower.cost:

                            # Place the tower
                            self.towers.append(tower)
                            money -= tower.cost

                            # Is it a block
                            if tower.id == 'block':
                                self.blocks.append(tower)

                        # Should the tower still be held on to?
                        if not key.get_pressed()[K_LSHIFT]:
                            self.held_tower = None

                else:
                    draw_rect((255, 100, 100))
                    show_tower()

            else:
                draw_rect((255, 100, 100))
                show_tower()

        # Does a tower need to be picked up?
        else:

            mouse_states = mouse_extras.get_states()
            if mouse_states[0] == -1:

                # Pick up tower
                pos = mouse_extras.get_pos()
                mouse_rect = [
                    pos[0] * window_scale, pos[1] * window_scale, 0, 0
                ]

                if gfunc.touching(mouse_rect, selection_rect):

                    pos = mouse_extras.get_pos()
                    pos[1] -= playing_grid[1]

                    index = pos[1] * playing_grid[0]
                    index += pos[0]

                    if index < len(self.usable_towers):
                        tower = self.usable_towers[index]
                        self.held_tower = tower

        return money