Ejemplo n.º 1
0
    def show(self, window, window_scale, dt, *args):

        # Scale images
        base = transform.scale(self.base_img,
                               (int(window_scale), int(window_scale)))
        barrel = transform.scale(self.barrel_img,
                                 (int(window_scale), int(window_scale)))

        # Rotate barrel
        if self.rot: barrel = transform.rotate(barrel, self.rot)

        # Get correct position after rotation
        rect = barrel.get_rect()
        offset = (window_scale - rect.width) / 2, (window_scale -
                                                   rect.height) / 2

        pos = list(self.pos)

        # Add recoil
        scale = 0.2 * self.recoil
        slope = gfunc.slope(self.rot)
        xc = slope[0] * scale * window_scale
        yc = slope[1] * scale * window_scale

        # Work out scaled pos
        pos[0] *= window_scale
        pos[1] *= window_scale

        # Show
        window.blit(base, pos)
        window.blit(barrel, (pos[0] + offset[0] + xc, pos[1] + offset[1] + yc))
Ejemplo n.º 2
0
    def shoot(self, dt, game_size, game_scale):

        self.last_time += dt
        if self.last_time >= self.max_time:

            if self.aiming:

                self.last_time -= self.max_time

                # Shoot
                self.recoil = game_scale * 0.1
                slope = gfunc.slope(self.rot)

                # Make a list of points that will receive damage
                pos = self.pos[0] + 0.5, self.pos[1] + 0.5
                points = [pos]
                accuracy = 0.1 # Lower is better

                while True:
                    last_pos = points[len(points) - 1]
                    next_pos = (round(last_pos[0] - slope[0], 5), round(last_pos[1] - slope[1], 5))
                    points.append(next_pos)

                    # Have we made it to the edge of the map?
                    if next_pos[0] < -1 or next_pos[0] > game_size[0] + 1 or next_pos[1] < -1 or next_pos[1] > game_size[1] + 1:
                        break

                self.shots.append([points[len(points) - 1], 0.2])
                for value in points: self.points.append(value)
Ejemplo n.º 3
0
    def show(self, window, window_scale, dt):

        # Show base
        base_img = transform.scale(self.base_img, (int(window_scale), int(window_scale)))

        # Work out scaled pos
        pos = list(self.pos)
        pos[0] *= window_scale
        pos[1] *= window_scale

        # Show
        window.blit(base_img, pos)

        # Show gun
        center_pos = pos[0] + window_scale / 2, pos[1] + window_scale / 2

        gun_img = transform.scale(self.gun_img, (int(window_scale), int(window_scale)))
        gun_img = transform.rotate(gun_img, self.rot)

        rect = gun_img.get_rect()
        pos = [center_pos[0] - rect.width / 2, center_pos[1] - rect.height / 2]

        # Add recoil
        slope = gfunc.slope(self.rot)
        change = slope[0] * self.recoil, slope[1] * self.recoil

        pos[0] += change[0]
        pos[1] += change[1]

        window.blit(gun_img, pos)
Ejemplo n.º 4
0
    def __init__(self, pos, rot, destination, speed=12):
        self.pos = list(pos)
        self.speed = speed
        self.dest = destination

        self.dist = math.sqrt((pos[0] - destination[0])**2 +
                              (pos[1] - destination[1])**2)
        self.dist2 = 0  # Distance travelled

        self.slope = gfunc.slope(rot)

        self.angle = self.get_angle()
        self.id = 'bomb'

        self.height = 0.3  # Multiplied by the window scale
Ejemplo n.º 5
0
    def shoot(self, dt):

        self.last_shot += dt * 10

        if self.last_shot >= self.time:
            self.last_shot -= self.time

            if self.rot and self.aiming:

                pos = list(self.pos)
                pos[0] += 0.5
                pos[1] += 0.5

                self.projectiles.append(Bullet(pos, gfunc.slope(self.rot - 180)))
                self.recoil = 0.5