1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
|
/*
* $Id: stagemanager.d,v 1.2 2004/05/14 14:35:38 kenta Exp $
*
* Copyright 2004 Kenta Cho. All rights reserved.
*/
module abagames.tf.stagemanager;
private import std.string;
private import std.conv;
private import std.math;
private import bulletml;
private import abagames.util.logger;
private import abagames.util.rand;
private import abagames.util.vector;
private import abagames.util.csv;
private import abagames.util.iterator;
private import abagames.util.actorpool;
private import abagames.util.logger;
private import abagames.util.bulletml.bullet;
private import abagames.util.sdl.sound;
private import abagames.tf.enemyspec;
private import abagames.tf.barragemanager;
private import abagames.tf.field;
private import abagames.tf.gamemanager;
private import abagames.tf.enemy;
private import abagames.tf.soundmanager;
/**
* Handle the appearance of enemies.
*/
public class StageManager {
public:
static const int STAGE_NUM = 5;
float rank, speedRank;
private:
static const int APPEARANCE_MAX = 8;
GameManager manager;
EnemyPool enemies;
Field field;
StagePattern[STAGE_NUM] stage;
alias ArrayIterator!(EnemyAppearancePattern) EAPIterator;
EAPIterator pattern;
EnemyAppearancePattern nextApp;
int cnt;
EnemyAppearance[APPEARANCE_MAX] appearance;
int eaIdx;
Rand rand;
int warningCnt;
bool bossComing;
public this(GameManager manager, EnemyPool enemies, Field field) {
this.manager = manager;
this.enemies = enemies;
this.field = field;
rand = new Rand;
foreach (ref EnemyAppearance ea; appearance)
ea = new EnemyAppearance;
eaIdx = appearance.length;
uint sn = 1;
foreach (ref StagePattern sp; stage) {
Logger.info("Load stage: " ~ to!string(sn));
sp = new StagePattern("stg" ~ to!string(sn) ~ ".stg");
sn++;
}
Logger.info("Load stages completed.");
}
public void start(int sn) {
pattern = new EAPIterator(stage[sn].pattern);
nextApp = pattern.next;
rand.setSeed(stage[sn].randSeed);
warningCnt = stage[sn].warningCnt;
Bullet.setRandSeed(stage[sn].randSeed);
cnt = 0;
bossComing = false;
rank = 0;
speedRank = 1;
foreach (EnemyAppearance ea; appearance)
ea.cnt = -1;
}
private void setAppearance(EnemyAppearancePattern eap, bool isBoss) {
eaIdx--;
if (eaIdx < 0)
eaIdx = appearance.length - 1;
EnemyAppearance ea = appearance[eaIdx];
ea.pattern = eap;
ea.cnt = 0;
ea.wait = eap.waitTillEnemiesDestroyed;
ea.isBoss = isBoss;
}
public void move() {
if (nextApp) {
while (nextApp.startTime <= cnt) {
setAppearance(nextApp, bossComing);
if (bossComing)
bossComing = false;
if (!pattern.hasNext) {
nextApp = null;
break;
}
nextApp = pattern.next;
}
}
cnt++;
if (cnt == warningCnt) {
manager.drawWarning();
bossComing = true;
Music.fadeMusic();
}
if (cnt >= warningCnt && cnt <= warningCnt + 200 && (cnt - warningCnt) % 100 == 0)
SoundManager.playSe(SoundManager.Se.WARNING);
if (cnt == warningCnt + 240) {
if (manager.stage == STAGE_NUM - 1)
SoundManager.playBgm(SoundManager.Bgm.LAST_BOSS);
else
SoundManager.playBgm(SoundManager.Bgm.BOSS);
}
foreach (EnemyAppearance ea; appearance) {
if (ea.cnt < 0)
continue;
if (ea.wait && Enemy.totalNum <= 0)
ea.wait = false;
if ((ea.cnt % ea.pattern.interval) == 0) {
EnemyAppearancePattern p = ea.pattern;
float x, y;
switch (p.posType) { default: break;
case EnemyAppearancePattern.AppearancePos.FRONT:
x = field.size.x - p.spec.sizeXm * 1.1f;
y = field.size.y * (p.pos + rand.nextSignedFloat(p.width));
break;
case EnemyAppearancePattern.AppearancePos.TOP:
x = field.size.x * (p.pos + rand.nextSignedFloat(p.width));
y = field.size.y - p.spec.sizeYm * 1.1f;
break;
}
if (!ea.wait)
addEnemy(x, y, p.spec, p.move, ea.isBoss);
}
ea.cnt++;
if (ea.cnt >= ea.pattern.duration) {
ea.cnt = -1;
continue;
}
}
}
private void addEnemy(float x, float y, EnemySpec spec, EnemyMovePattern move, bool isBoss) {
Enemy en = cast(Enemy) enemies.getInstance();
if (!en)
return;
en.set(x, y, spec, move, isBoss);
}
public void setRank(float r) {
rank = r * 0.24;
}
}
public class EnemyAppearance {
public:
EnemyAppearancePattern pattern;
int cnt;
bool wait;
bool isBoss;
}
public class StagePattern {
public:
EnemyAppearancePattern[] pattern;
long randSeed;
int warningCnt;
private:
static const string STAGE_DIR_NAME = "/usr/share/games/tumiki-fighters/stage";
static int[string] posTypeStr;
public static this() {
posTypeStr["f"] = 0;
posTypeStr["u"] = 1;
}
// Initialize StagePattern with the array.
// randSeed, warningCnt
// [startTime, duration, interval, posType(f(front), u(up)), pos, width,
// waitTillAllEnemiesDestoryed,
// EnemySpec file name,
// move BulletML file name, {speedRank}/{withdrawCnt, speed, [x, y], [idx, speed, [x, y]]}],
// (use PointsMovePattern when moveBulletML == "p", end when x == "e", idx == "e")
public this(string[] data) {
StringIterator si = new StringIterator(data);
randSeed = to!int(si.next);
warningCnt = to!int(si.next);
for (;;) {
if (!si.hasNext)
break;
int startTime = to!int(si.next);
int duration = to!int(si.next);
int interval = to!int(si.next);
string v = si.next;
int posType = posTypeStr[v];
float pos = to!float(si.next);
float width = to!float(si.next);
v = si.next;
bool wted;
if (v == "y")
wted = true;
else
wted = false;
v = si.next;
EnemySpec es = EnemySpec.getInstance(v);
EnemyAppearancePattern eap = new EnemyAppearancePattern
(startTime, duration, interval, posType, pos, width, wted, es);
float d;
v = si.next;
if (v == "p") {
eap.startSetPointsMove();
eap.setWithdrawCnt(to!int(si.next));
int atIdx = PointsMovePattern.BASIC_PATTERN_IDX;
for (;;) {
float speed = to!float(si.next);
eap.setMoveSpeed(atIdx, speed);
for (;;) {
v = si.next;
if (v == "e")
break;
float x = to!float(v);
float y = to!float(si.next);
eap.addMovePoint(atIdx, x, y);
}
v = si.next;
if (v == "e")
break;
atIdx = to!int(v);
}
} else {
eap.setMoveBulletML(v);
eap.setSpeedRank(to!float(si.next));
}
switch (posType) { default: break;
case EnemyAppearancePattern.AppearancePos.FRONT:
d = PI / 2 * 3;
break;
case EnemyAppearancePattern.AppearancePos.TOP:
d = PI;
break;
}
eap.setInitialDeg(d);
pattern ~= eap;
}
}
public this(string fileName) {
string[] data = CSVTokenizer.readFile(STAGE_DIR_NAME ~ "/" ~ fileName);
this(data);
}
}
public class EnemyAppearancePattern {
public:
static enum AppearancePos {
FRONT, TOP,
}
int startTime, duration, interval;
int posType;
float pos, width;
bool waitTillEnemiesDestroyed;
EnemySpec spec;
EnemyMovePattern move;
public this(int st, int dr, int it, int pt, float p, float wt, bool wted, EnemySpec es) {
startTime = st;
duration = dr;
interval = it;
posType = pt;
pos = p;
width = wt;
waitTillEnemiesDestroyed = wted;
spec = es;
}
public void setInitialDeg(float d) {
move.deg = d;
}
public void startSetPointsMove() {
move = new PointsMovePattern;
}
public void setWithdrawCnt(int c) {
(cast(PointsMovePattern) move).withdrawCnt = c;
}
public void setMoveSpeed(int idx, float s) {
(cast(PointsMovePattern) move).speed[idx] = s;
}
public void addMovePoint(int idx, float x, float y) {
(cast(PointsMovePattern) move).point[idx] ~= new Vector(x, y);
}
public void setMoveBulletML(string fn) {
move = new BulletMLMovePattern;
(cast(BulletMLMovePattern) move).parser = BarrageManager.getInstance(fn);
if (!(cast(BulletMLMovePattern) move).parser)
throw new Error("File not found: " ~ fn);
}
public void setSpeedRank(float s) {
(cast(BulletMLMovePattern) move).speed = s;
}
}
public abstract class EnemyMovePattern {
public:
float deg;
}
public class BulletMLMovePattern: EnemyMovePattern {
public:
BulletMLParser *parser;
float speed;
}
public class PointsMovePattern: EnemyMovePattern {
public:
static const int BASIC_PATTERN_IDX = -1;
Vector[][int] point;
float[int] speed;
int withdrawCnt;
}
|