Changeset 791


Ignore:
Timestamp:
Aug 1, 2011, 12:23:24 AM (8 years ago)
Author:
sam
Message:

monsterz: eagles and clouds now span across the whole width of the screen
instead of the initial 384×384 square.

Location:
trunk/monsterz
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/monsterz/monsterz.h

    r786 r791  
    5555static int const MAX_PIECES = 12;
    5656
    57 /* Duration of an eagle flight */
    58 static int const DURATION_EAGLE = 3000;
     57/* Time step of the eagle, in milliseconds per pixel */
     58static int const STEP_EAGLE = 10;
     59/* Number of clouds on screen */
     60static int const MAX_CLOUDS = 10;
    5961
    6062/* Minimal duration of the idle loop */
  • trunk/monsterz/title.cpp

    r790 r791  
    4040
    4141private:
    42     TileSet *title, *stars, *clouds, *eagle, *logo, *ground;
     42    TileSet *title, *stars, *clouds, *logo, *ground;
    4343    TileSet *anim[6];
    4444    TileSet *event[7];
     
    6161    period, nextperiod;
    6262
    63     vec2 cloudpos[5];
    64     vec2 cloudspeed[5];
     63    vec2 cloudpos[MAX_CLOUDS];
     64    vec2 cloudspeed[MAX_CLOUDS];
    6565
    6666    vec2i ground_pos;
    6767
    68     int eagley;
    69 
    70     float timer, length, eagletimer;
     68    struct
     69    {
     70        TileSet *tiles;
     71        int y;
     72        float duration, timer;
     73    }
     74    eagle;
     75
     76    float timer, length;
    7177    int nframes, animid;
    7278};
     
    121127  : data(new TitleData())
    122128{
     129    /* FIXME: this should not be hardcoded */
     130    position = vec3i(0, 0, 1);
     131    bbox[0] = position;
     132    bbox[1] = bbox[0] + vec3i(640, 480, 0);
     133
    123134    srand(rand() ^ time(NULL));
    124135
    125136    data->logo = Tiler::Register(PNG_TITLE_LOGO, vec2i(380, 181), 0, 1.0f);
    126137    data->ground = Tiler::Register(PNG_TITLE_GROUND, vec2i(384, 80), 0, 1.0f);
    127     data->ground_pos = vec2i(640 / 2 - 384 / 2, 480 / 4 - 80);
     138    data->ground_pos = vec2i((vec2)(bbox[1] - bbox[0]) / vec2i(2, 4))
     139                     - vec2i(384, 80);
    128140
    129141    data->title = Tiler::Register(PNG_TITLE, 384, 0, 1.0f);
    130142    data->stars = Tiler::Register(PNG_STARS, vec2i(384, 144), 0, 1.0f);
    131143    data->clouds = Tiler::Register(PNG_CLOUDS, vec2i(160, 32), 0, 1.0f);
    132     data->eagle = Tiler::Register(PNG_EAGLE, 16, 0, 1.0f);
     144    data->eagle.tiles = Tiler::Register(PNG_EAGLE, 16, 0, 1.0f);
    133145    for (int n = 0; n < 6; n++)
    134146        data->anim[n] = Tiler::Register(PNG_TITLEANIM[n],
     
    141153    data->nextperiod = TitleData::DAY;
    142154    data->timer = RandF(2000.0f, 3000.0f);
    143     data->eagletimer = RandF(DURATION_EAGLE, 4 * DURATION_EAGLE);
    144 
    145     for (int n = 0; n < 5; n++)
    146     {
    147         data->cloudpos[n] = vec2(RandF(384), RandF(130, 190));
     155    /* Time needed for the eagle to cross the screen */
     156    data->eagle.duration = (bbox[1].x - bbox[0].x + 16) * STEP_EAGLE;
     157    data->eagle.timer = RandF(data->eagle.duration, 4 * data->eagle.duration);
     158
     159    for (int n = 0; n < MAX_CLOUDS; n++)
     160    {
     161        data->cloudpos[n] = vec2(RandF((bbox[1] - bbox[0]).x),
     162                                 RandF(80) + (bbox[1] - bbox[0]).y - 300);
    148163        data->cloudspeed[n] = RandF(-0.01f, 0.01f);
    149164    }
    150165
    151     data->eagley = 140 + rand() % 40;
    152 
    153     position = vec3i(24, 72, 1);
    154     bbox[0] = position;
    155     bbox[1] = bbox[0] + vec3i(384, 384, 0);
     166    data->eagle.y = 140 + rand() % 40;
    156167
    157168    Input::TrackMouse(this);
     
    163174
    164175    data->timer -= deltams;
    165     data->eagletimer -= deltams;
     176    data->eagle.timer -= deltams;
    166177
    167178    /* Probability of playing an animation given the current period */
     
    173184    static int const t2[] = { 2, 4, 11, 4, 6, 2 };
    174185
    175     for (int n = 0; n < 5; n++)
    176     {
     186    for (int n = 0; n < MAX_CLOUDS; n++)
     187    {
     188        float wrap = bbox[1].x - bbox[0].x;
    177189        data->cloudpos[n].x += deltams * data->cloudspeed[n].x;
    178         if (data->cloudpos[n].x > 384.0f)
    179             data->cloudpos[n].x -= 384.0f;
     190        if (data->cloudpos[n].x > wrap)
     191            data->cloudpos[n].x -= wrap;
    180192        else if (data->cloudpos[n].x < 0.0f)
    181             data->cloudpos[n].x += 384.0f;
     193            data->cloudpos[n].x += wrap;
    182194    }
    183195
     
    185197    {
    186198    case TitleData::IDLE:
    187         if (data->eagletimer < 0.0f)
    188         {
    189             data->eagletimer = RandF(DURATION_EAGLE, 4 * DURATION_EAGLE);
    190             data->eagley = 140 + rand() % 40;
     199        if (data->eagle.timer < 0.0f)
     200        {
     201            data->eagle.timer = RandF(data->eagle.duration, 4 * data->eagle.duration);
     202            data->eagle.y = 140 + rand() % 40;
    191203        }
    192204        if (data->timer > 0.0f)
     
    292304    int cloudoff = data->period == TitleData::DAY ? 0 : 3;
    293305
    294     for (int n = 0; n < 5; n++)
    295     {
    296         int cloudid = n * 4 + cloudoff;
     306    for (int n = 0; n < MAX_CLOUDS; n++)
     307    {
     308        /* There are only 5 cloud sprites */
     309        int cloudid = (n % 5) * 4 + cloudoff;
    297310        Scene::GetDefault()->AddTile(data->clouds, cloudid,
    298                                      24 + data->cloudpos[n].x,
    299                                      72 + data->cloudpos[n].y, 2, 0);
     311                                     data->cloudpos[n].x,
     312                                     data->cloudpos[n].y, 2, 0);
    300313        Scene::GetDefault()->AddTile(data->clouds, cloudid,
    301                                      24 + data->cloudpos[n].x - 384.0f,
    302                                      72 + data->cloudpos[n].y, 2, 0);
     314                                     data->cloudpos[n].x - bbox[1].x + bbox[0].x,
     315                                     data->cloudpos[n].y, 2, 0);
    303316    }
    304317
    305318    /* Maybe an eagle? */
    306     if (data->eagletimer >= 0.0f)
    307     {
    308         int eagleid = (int)(data->eagletimer / 100) % 6;
     319    if (data->eagle.timer >= 0.0f)
     320    {
     321        int eagleid = (int)(data->eagle.timer / 100) % 6;
    309322        if (data->period != TitleData::DAY)
    310323            eagleid += 6;
    311         float phase = sinf(data->eagletimer * (2.0f * M_PI / 100 / 6));
    312         int x = (DURATION_EAGLE - data->eagletimer) * 384 / DURATION_EAGLE;
    313         int y = data->eagley + 5.0f * sinf(phase);
    314         Scene::GetDefault()->AddTile(data->eagle, eagleid,
     324        float phase = sinf(data->eagle.timer * (2.0f * M_PI / 100 / 6));
     325        int x = (data->eagle.duration - data->eagle.timer) / STEP_EAGLE;
     326        int y = data->eagle.y + 5.0f * sinf(phase);
     327        Scene::GetDefault()->AddTile(data->eagle.tiles, eagleid,
    315328                                     24 + x, 72 + y, 3, 0);
    316329    }
     
    372385    Tiler::Deregister(data->stars);
    373386    Tiler::Deregister(data->clouds);
    374     Tiler::Deregister(data->eagle);
     387    Tiler::Deregister(data->eagle.tiles);
    375388    for (int n = 0; n < 6; n++)
    376389        Tiler::Deregister(data->anim[n]);
Note: See TracChangeset for help on using the changeset viewer.