Changeset 791
- Timestamp:
- Aug 1, 2011, 12:23:24 AM (9 years ago)
- Location:
- trunk/monsterz
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/monsterz/monsterz.h
r786 r791 55 55 static int const MAX_PIECES = 12; 56 56 57 /* Duration of an eagle flight */ 58 static int const DURATION_EAGLE = 3000; 57 /* Time step of the eagle, in milliseconds per pixel */ 58 static int const STEP_EAGLE = 10; 59 /* Number of clouds on screen */ 60 static int const MAX_CLOUDS = 10; 59 61 60 62 /* Minimal duration of the idle loop */ -
trunk/monsterz/title.cpp
r790 r791 40 40 41 41 private: 42 TileSet *title, *stars, *clouds, * eagle, *logo, *ground;42 TileSet *title, *stars, *clouds, *logo, *ground; 43 43 TileSet *anim[6]; 44 44 TileSet *event[7]; … … 61 61 period, nextperiod; 62 62 63 vec2 cloudpos[ 5];64 vec2 cloudspeed[ 5];63 vec2 cloudpos[MAX_CLOUDS]; 64 vec2 cloudspeed[MAX_CLOUDS]; 65 65 66 66 vec2i ground_pos; 67 67 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; 71 77 int nframes, animid; 72 78 }; … … 121 127 : data(new TitleData()) 122 128 { 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 123 134 srand(rand() ^ time(NULL)); 124 135 125 136 data->logo = Tiler::Register(PNG_TITLE_LOGO, vec2i(380, 181), 0, 1.0f); 126 137 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); 128 140 129 141 data->title = Tiler::Register(PNG_TITLE, 384, 0, 1.0f); 130 142 data->stars = Tiler::Register(PNG_STARS, vec2i(384, 144), 0, 1.0f); 131 143 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); 133 145 for (int n = 0; n < 6; n++) 134 146 data->anim[n] = Tiler::Register(PNG_TITLEANIM[n], … … 141 153 data->nextperiod = TitleData::DAY; 142 154 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); 148 163 data->cloudspeed[n] = RandF(-0.01f, 0.01f); 149 164 } 150 165 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; 156 167 157 168 Input::TrackMouse(this); … … 163 174 164 175 data->timer -= deltams; 165 data->eagle timer -= deltams;176 data->eagle.timer -= deltams; 166 177 167 178 /* Probability of playing an animation given the current period */ … … 173 184 static int const t2[] = { 2, 4, 11, 4, 6, 2 }; 174 185 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; 177 189 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; 180 192 else if (data->cloudpos[n].x < 0.0f) 181 data->cloudpos[n].x += 384.0f;193 data->cloudpos[n].x += wrap; 182 194 } 183 195 … … 185 197 { 186 198 case TitleData::IDLE: 187 if (data->eagle timer < 0.0f)188 { 189 data->eagle timer = RandF(DURATION_EAGLE, 4 * DURATION_EAGLE);190 data->eagle y = 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; 191 203 } 192 204 if (data->timer > 0.0f) … … 292 304 int cloudoff = data->period == TitleData::DAY ? 0 : 3; 293 305 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; 297 310 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); 300 313 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); 303 316 } 304 317 305 318 /* Maybe an eagle? */ 306 if (data->eagle timer >= 0.0f)307 { 308 int eagleid = (int)(data->eagle timer / 100) % 6;319 if (data->eagle.timer >= 0.0f) 320 { 321 int eagleid = (int)(data->eagle.timer / 100) % 6; 309 322 if (data->period != TitleData::DAY) 310 323 eagleid += 6; 311 float phase = sinf(data->eagle timer * (2.0f * M_PI / 100 / 6));312 int x = ( DURATION_EAGLE - data->eagletimer) * 384 / DURATION_EAGLE;313 int y = data->eagle y + 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, 315 328 24 + x, 72 + y, 3, 0); 316 329 } … … 372 385 Tiler::Deregister(data->stars); 373 386 Tiler::Deregister(data->clouds); 374 Tiler::Deregister(data->eagle );387 Tiler::Deregister(data->eagle.tiles); 375 388 for (int n = 0; n < 6; n++) 376 389 Tiler::Deregister(data->anim[n]);
Note: See TracChangeset
for help on using the changeset viewer.