Пример #1
0
void Starfield::draw() const {
    const RgbColor slowColor   = GetRGBTranslateColorShade(kStarColor, MEDIUM);
    const RgbColor mediumColor = GetRGBTranslateColorShade(kStarColor, LIGHT);
    const RgbColor fastColor   = GetRGBTranslateColorShade(kStarColor, LIGHTER);

    switch (g.ship.get() ? g.ship->presenceState : kNormalPresence) {
        default:
            if (!_warp_stars) {
                Points points;
                // we're not warping in any way
                for (const scrollStarType* star : range(_stars, _stars + kScrollStarNum)) {
                    if (star->speed != kNoStar) {
                        const RgbColor* color = &slowColor;
                        if (star->speed == kMediumStarSpeed) {
                            color = &mediumColor;
                        } else if (star->speed == kFastStarSpeed) {
                            color = &fastColor;
                        }

                        points.draw(star->location, *color);
                    }
                }
                break;
            }

        case kWarpInPresence:
        case kWarpOutPresence:
        case kWarpingPresence: {
            Lines lines;
            for (const scrollStarType* star : range(_stars, _stars + kScrollStarNum)) {
                if (star->speed != kNoStar) {
                    const RgbColor* color = &slowColor;
                    if (star->speed == kMediumStarSpeed) {
                        color = &mediumColor;
                    } else if (star->speed == kFastStarSpeed) {
                        color = &fastColor;
                    }

                    if (star->age > 1) {
                        lines.draw(star->location, star->oldLocation, *color);
                    }
                }
            }
            break;
        }
    }

    Points points;
    for (const scrollStarType* star : range(_stars + kSparkStarOffset, _stars + kAllStarNum)) {
        if ((star->speed != kNoStar) && (star->age > 0)) {
            const RgbColor color =
                    GetRGBTranslateColorShade(star->hue, (star->age >> kSparkAgeToShadeShift) + 1);
            points.draw(star->location, color);
        }
    }
}
Пример #2
0
static void alter_condition_true_yet(Handle<Action> action) {
    const auto alter = action->argument.alterConditionTrueYet;
    int32_t begin = alter.first;
    int32_t end = begin + std::max(0, alter.count_minus_1) + 1;
    for (auto l: range(begin, end)) {
        g.level->condition(l)->set_true_yet(alter.true_yet);
    }
}
Пример #3
0
static void alter_hidden(Handle<Action> action) {
    const auto alter = action->argument.alterHidden;
    int32_t begin = alter.first;
    int32_t end = begin + std::max(0, alter.count_minus_1) + 1;
    for (auto i: range(begin, end)) {
        UnhideInitialObject(i);
    }
}
Пример #4
0
void Starfield::show() {
    if (g.ship.get() && g.ship->active && (g.ship->presenceState != kWarpInPresence) &&
        (g.ship->presenceState != kWarpOutPresence) &&
        (g.ship->presenceState != kWarpingPresence)) {
        if (_warp_stars) {
            // we were warping but now are not; erase warped stars
            _warp_stars = false;
            for (scrollStarType* star : range(_stars, _stars + kScrollStarNum)) {
                if (star->speed != kNoStar) {
                    if (star->age < 2) {
                        ++star->age;
                    }
                }
            }
        }
    } else {
        // we're warping now
        _warp_stars = true;

        for (scrollStarType* star : range(_stars, _stars + kScrollStarNum)) {
            if (star->speed != kNoStar) {
                if (star->age < 2) {
                    ++star->age;
                }
            }
        }
    }

    for (scrollStarType* star : range(_stars + kScrollStarNum, _stars + kAllStarNum)) {
        if (star->speed != kNoStar) {
            if (star->age <= 0) {
                star->speed = kNoStar;
            }
        }
    }

    _last_clip_bottom = viewport().bottom;
}
Пример #5
0
void Starfield::move(ticks by_units) {
    if (!g.ship.get() || !g.ship->active) {
        return;
    }

    const Rect viewport    = antares::viewport();
    const Rect play_screen = antares::play_screen();

    const fixedPointType slowVelocity = {
            scale_by(g.ship->velocity.h * kSlowStarFraction * by_units.count(), gAbsoluteScale),
            scale_by(g.ship->velocity.v * kSlowStarFraction * by_units.count(), gAbsoluteScale),
    };

    const fixedPointType mediumVelocity = {
            scale_by(g.ship->velocity.h * kMediumStarFraction * by_units.count(), gAbsoluteScale),
            scale_by(g.ship->velocity.v * kMediumStarFraction * by_units.count(), gAbsoluteScale),
    };

    const fixedPointType fastVelocity = {
            scale_by(g.ship->velocity.h * kFastStarFraction * by_units.count(), gAbsoluteScale),
            scale_by(g.ship->velocity.v * kFastStarFraction * by_units.count(), gAbsoluteScale),
    };

    for (scrollStarType* star : range(_stars, _stars + kScrollStarNum)) {
        const fixedPointType* velocity;
        switch (star->speed) {
            case kSlowStarSpeed: velocity = &slowVelocity; break;
            case kMediumStarSpeed: velocity = &mediumVelocity; break;
            case kFastStarSpeed: velocity = &fastVelocity; break;
            default:
            case kNoStar: continue;
        }

        star->motionFraction.h += velocity->h;
        star->motionFraction.v += velocity->v;

        int32_t h;
        if (star->motionFraction.h >= Fixed::zero()) {
            h = more_evil_fixed_to_long(star->motionFraction.h + Fixed::from_float(0.5));
        } else {
            h = more_evil_fixed_to_long(star->motionFraction.h - Fixed::from_float(0.5)) + 1;
        }
        star->location.h += h;
        star->motionFraction.h -= Fixed::from_long(h);

        int32_t v;
        if (star->motionFraction.v >= Fixed::zero()) {
            v = more_evil_fixed_to_long(star->motionFraction.v + Fixed::from_float(0.5));
        } else {
            v = more_evil_fixed_to_long(star->motionFraction.v - Fixed::from_float(0.5)) + 1;
        }
        star->location.v += v;
        star->motionFraction.v -= Fixed::from_long(v);

        if ((star->location.h < viewport.left) && (star->oldLocation.h < viewport.left)) {
            star->location.h += play_screen.width() - 1;
            star->location.v       = Randomize(play_screen.height()) + viewport.top;
            star->motionFraction.h = star->motionFraction.v = Fixed::zero();
            star->speed                                     = RandomStarSpeed();
            star->age                                       = 0;
        } else if (
                (star->location.h >= viewport.right) && (star->oldLocation.h >= viewport.right)) {
            star->location.h -= play_screen.width();
            star->location.v       = Randomize(play_screen.height()) + viewport.top;
            star->motionFraction.h = star->motionFraction.v = Fixed::zero();
            star->speed                                     = RandomStarSpeed();
            star->age                                       = 0;
        } else if ((star->location.v < viewport.top) && (star->oldLocation.v < viewport.top)) {
            star->location.h = Randomize(play_screen.width()) + viewport.left;
            star->location.v += play_screen.height() - 1;
            star->motionFraction.h = star->motionFraction.v = Fixed::zero();
            star->speed                                     = RandomStarSpeed();
            star->age                                       = 0;
        } else if (
                (star->location.v >= play_screen.bottom) &&
                (star->oldLocation.v >= play_screen.bottom)) {
            star->location.h = Randomize(play_screen.width()) + viewport.left;
            star->location.v -= play_screen.height();
            star->motionFraction.h = star->motionFraction.v = Fixed::zero();
            star->speed                                     = RandomStarSpeed();
            star->age                                       = 0;
        }

        if (_warp_stars && (star->age == 0)) {
            switch (star->speed) {
                case kSlowStarSpeed: velocity = &slowVelocity; break;
                case kMediumStarSpeed: velocity = &mediumVelocity; break;
                case kFastStarSpeed: velocity = &fastVelocity; break;
                case kNoStar: throw std::runtime_error("invalid value of star->speed.");
            }
            star->location.h -= mFixedToLong(velocity->h);
            star->location.v -= mFixedToLong(velocity->v);
        }
    }

    for (scrollStarType* star : range(_stars + kSparkStarOffset, _stars + kAllStarNum)) {
        if (star->speed == kNoStar) {
            continue;
        }
        star->age -= star->speed * by_units.count();

        star->motionFraction.h += star->velocity.h * by_units.count() + slowVelocity.h;
        star->motionFraction.v += star->velocity.v * by_units.count() + slowVelocity.v;

        int32_t h;
        if (star->motionFraction.h >= Fixed::zero()) {
            h = more_evil_fixed_to_long(star->motionFraction.h + Fixed::from_float(0.5));
        } else {
            h = more_evil_fixed_to_long(star->motionFraction.h - Fixed::from_float(0.5)) + 1;
        }
        star->location.h += h;
        star->motionFraction.h -= Fixed::from_long(h);

        int32_t v;
        if (star->motionFraction.v >= Fixed::zero()) {
            v = more_evil_fixed_to_long(star->motionFraction.v + Fixed::from_float(0.5));
        } else {
            v = more_evil_fixed_to_long(star->motionFraction.v - Fixed::from_float(0.5)) + 1;
        }
        star->location.v += v;
        star->motionFraction.v -= Fixed::from_long(v);
    }
}
Пример #6
0
void Starfield::prepare_to_move() {
    for (scrollStarType* star : range(_stars, _stars + kAllStarNum)) {
        star->oldLocation = star->location;
    }
}