Пример #1
0
    def endstep(self, game, state, frametime):
        super(Shot, self).endstep(game, state, frametime)

        self.flight_time += frametime

        angle = int(round(self.direction)) % 360
        if angle in self.shot_hitmasks:
            mask = self.shot_hitmasks[angle]
        else:
            mask = function.load_mask(constants.SPRITE_FOLDER + "projectiles/shots/0.png").rotate(angle)
            self.shot_hitmasks[angle] = mask

        # FIXME: "and self.flight_time > constants.PHYSICS_TIMESTEP" is an extremely hacky way to prevent negative time collisions. Is there a better method?
        if ((state.map.collision_mask.overlap(mask, (int(round(self.x)), int(round(self.y))))) and self.flight_time >= constants.PHYSICS_TIMESTEP) or self.flight_time >= self.max_flight_time:
            # calculate unit speeds (speeds normalized into the range 0-1)
            h_unit_speed = math.cos(math.radians(self.direction))
            v_unit_speed = -math.sin(math.radians(self.direction))
        
            x, y = self.x, self.y
        
            # move back until we're not colliding anymore - this is the colliding point
            while state.map.collision_mask.overlap(mask, (int(round(x)), int(round(y)))):
                x -= h_unit_speed
                y -= v_unit_speed
        
            self.destroy(state)
Пример #2
0
    def endstep(self, game, state, frametime):
        super(Shot, self).endstep(game, state, frametime)

        self.flight_time += frametime

        angle = int(self.direction) % 360
        if angle in self.shot_hitmasks:
            mask = self.shot_hitmasks[angle]
        else:
            mask = function.load_mask("projectiles/shots/0").rotate(angle)
            self.shot_hitmasks[angle] = mask

        if game.map.collision_mask.overlap(mask, (int(self.x), int(self.y))) or self.flight_time > self.max_flight_time:
            # calculate unit speeds (speeds normalized into the range 0-1)
            h_unit_speed = math.cos(math.radians(self.direction))
            v_unit_speed = -math.sin(math.radians(self.direction))

            x, y = self.x, self.y

            # move back until we're not colliding anymore - this is the colliding point
            while game.map.collision_mask.overlap(mask, (int(x), int(y))):
                x -= h_unit_speed
                y -= v_unit_speed

            self.destroy(state)
Пример #3
0
    def endstep(self, game, state, frametime):
        super(Shot, self).endstep(game, state, frametime)

        self.flight_time += frametime

        angle = int(round(self.direction)) % 360
        if angle in self.shot_hitmasks:
            mask = self.shot_hitmasks[angle]
        else:
            mask = function.load_mask(constants.SPRITE_FOLDER +
                                      "projectiles/shots/0.png").rotate(angle)
            self.shot_hitmasks[angle] = mask

        # FIXME: "and self.flight_time > constants.PHYSICS_TIMESTEP" is an extremely hacky way to prevent negative time collisions. Is there a better method?
        if ((game.map.collision_mask.overlap(
                mask, (int(round(self.x)), int(round(self.y)))))
                and self.flight_time >= constants.PHYSICS_TIMESTEP
            ) or self.flight_time >= self.max_flight_time:
            # calculate unit speeds (speeds normalized into the range 0-1)
            h_unit_speed = math.cos(math.radians(self.direction))
            v_unit_speed = -math.sin(math.radians(self.direction))

            x, y = self.x, self.y

            # move back until we're not colliding anymore - this is the colliding point
            while game.map.collision_mask.overlap(
                    mask, (int(round(x)), int(round(y)))):
                x -= h_unit_speed
                y -= v_unit_speed

            self.destroy(state)
Пример #4
0
 def set_map(self, mapname):
     self.mapname = mapname
     
     self.collision_mask = function.load_mask("maps/"+mapname+"/wallmask.png")
     x, y = self.collision_mask.get_size()
     self.collision_mask = self.collision_mask.scale(x*6, y*6)
     
     self.width, self.height = self.collision_mask.get_size()
Пример #5
0
    def set_map(self, mapname):
        self.mapname = mapname

        self.collision_mask = function.load_mask("maps/" + mapname +
                                                 "/wallmask.png")
        x, y = self.collision_mask.get_size()
        self.collision_mask = self.collision_mask.scale(x * 6, y * 6)

        self.width, self.height = self.collision_mask.get_size()
Пример #6
0
    def endstep(self, game, state, frametime):
        super(Rocket, self).endstep(game, state, frametime)

        self.flight_time += frametime

        angle = int(self.direction) % 360
        if angle in self.rocket_hitmasks:
            mask = self.rocket_hitmasks[angle]
        else:
            mask = function.load_mask("projectiles/rockets/0").rotate(angle)
            self.rocket_hitmasks[angle] = mask

        if game.map.collision_mask.overlap(mask, (int(self.x), int(self.y))) or self.flight_time > self.max_flight_time:
            self.destroy(game, state, frametime)
Пример #7
0
    def endstep(self, game, state, frametime):
        super(Rocket, self).endstep(game, state, frametime)

        self.flight_time += frametime

        angle = int(round(self.direction)) % 360
        if angle in self.rocket_hitmasks:
            mask = self.rocket_hitmasks[angle]
        else:
            mask = function.load_mask(constants.SPRITE_FOLDER + "projectiles/rockets/0.png").rotate(angle)
            self.rocket_hitmasks[angle] = mask

        # FIXME: "and self.flight_time > constants.PHYSICS_TIMESTEP" is an extremely hacky way to prevent negative time collisions. Is there a better method?
        if ((state.map.collision_mask.overlap(mask, (int(round(self.x)), int(round(self.y))))) and self.flight_time >= constants.PHYSICS_TIMESTEP) or self.flight_time >= self.max_flight_time:
            self.destroy(game, state, frametime)
Пример #8
0
    def endstep(self, game, state, frametime):
        super(Flame, self).endstep(game, state, frametime)

        self.flight_time += frametime

        angle = int(round(self.direction))

        if angle in self.flame_hitmasks:
            mask = self.flame_hitmasks[angle]
        else:
            mask = function.load_mask(constants.SPRITE_FOLDER +
                                      "projectiles/flames/0.png").rotate(angle)
            self.flame_hitmasks[angle] = mask

        # FIXME: "and self.flight_time > constants.PHYSICS_TIMESTEP" is an extremely hacky way to prevent negative time collisions. Is there a better method?
        if ((game.map.collision_mask.overlap(
                mask, (int(round(self.x)), int(round(self.y)))))
                and self.flight_time >= constants.PHYSICS_TIMESTEP
            ) or self.flight_time > self.max_flight_time:
            self.destroy(state)