Downloads containing EnemyWaves.j2as

Downloads
Name Author Game Mode Rating
JJ2 1.23 vanilla: Miscellaneous stuff Violet CLM Multiple N/A Download file

File preview

void onLevelLoad() {
	jjObjectPresets[OBJECT::SANDWICH].behavior = EnemyWaves;
}

///@Event 178=Enemy Waves                     |-|Enemy      |Enemy|Waves
void EnemyWaves(jjOBJ@ obj) {
	switch (obj.state) {
		case STATE::START:
			obj.playerHandling = HANDLING::PARTICLE;
			obj.age = 0;
			obj.state = STATE::WAIT;
		case STATE::WAIT:
			for (int i = 0; i < jjLocalPlayerCount; ++i) {
				const jjPLAYER@ play = jjLocalPlayers[i];
				if (int(play.xPos) >> 5 == int(obj.xPos) >> 5 && abs(play.yPos - obj.yPos) < 300) { //test for proximity
					obj.state = STATE::ATTACK;
					//begin fight: find some way to enclose the player in the designated arena, maybe make a noise or something, idk
					jjTriggers[0] = true;
					break;
				}
			}
			break;
		case STATE::DEACTIVATE:
			obj.deactivate();
			break;
		case STATE::ATTACK: {
			const auto@ currentWave = Waves[obj.age];
			const uint numberOfEnemies = currentWave.length;
			for (uint i = 0; i < numberOfEnemies; ++i) {
				const auto@ currentEnemyToAdd = currentWave[i];
				obj.var[i] = jjAddObject(uint8(currentEnemyToAdd[0]), obj.xOrg + currentEnemyToAdd[1] * 32, obj.yOrg + currentEnemyToAdd[2] * 32, currentEnemyToAdd.length == 3 ? 0 : uint16(currentEnemyToAdd[3] * 70), CREATOR::OBJECT, FadeInWrapper);
			}
			obj.state = STATE::ROTATE;
			break; }
		case STATE::ROTATE: {
			const auto@ currentWave = Waves[obj.age];
			const uint numberOfEnemies = currentWave.length;
			for (uint i = 0; i < numberOfEnemies; ++i) {
				const jjOBJ@ enemy = jjObjects[obj.var[i]];
				if (enemy.isActive && enemy.eventID == uint8(currentWave[i][0]) && enemy.creatorType == CREATOR::OBJECT)
					return;
			}
			if (uint(obj.age += 1) >= Waves.length) {
				//finished! let the player out and so on.
				jjTriggers[0] = false;
				jjTriggers[1] = true;
			} else {
				obj.state = STATE::ATTACK;
				//maybe make a noise here or something to indicate a new wave's started?
			}
			break; }
	}
}
void FadeInWrapper(jjOBJ@ obj) {
	if (obj.state == STATE::START) {
		obj.behave(jjObjectPresets[obj.eventID].behavior, false);
		obj.oldState = obj.state;
		obj.playerHandling = HANDLING::PARTICLE;
		obj.state = STATE::FADEIN;
	} else {
		if (obj.creatorID != 0)
			obj.creatorID = obj.creatorID - 1;
		else if (++obj.age < 64)
			jjDrawSpriteFromCurFrame(obj.xPos, obj.yPos, obj.curFrame, obj.direction, SPRITE::BLEND_NORMAL, obj.age << 2);
		else {
			obj.playerHandling = jjObjectPresets[obj.eventID].playerHandling;
			obj.state = obj.oldState;
			obj.behavior = jjObjectPresets[obj.eventID].behavior;
			obj.behave();
		}
	}
}

//first array item: enemy object type
//second: horizontal distance from EnemyWaves object, e.g. -2.5 is two and a half tiles to its left
//third: vertical distance from EnemyWaves object
//fourth (optional): number of seconds to wait before enemy appears as part of this wave

//use no more than eleven enemies per wave

const array<array<array<float>>> Waves = {
	{ //first wave
		{OBJECT::BAT, 0, -0.25},
		{OBJECT::BAT, 3.33, -0.25},
		{OBJECT::BAT, 6.67, -0.25},
		{OBJECT::BAT, 10, -0.25}
	},{ //second wave
		{OBJECT::DOGGYDOGG, 0, 6},
		{OBJECT::DOGGYDOGG, 10, 6},
		{OBJECT::RAVEN, 4, 2, 1.33},
		{OBJECT::RAVEN, 8, 1, 2.67},
		{OBJECT::RAVEN, 1, 4, 4.00},
		{OBJECT::RAVEN, 7, 5, 5.33}
	},{ //third wave
		{OBJECT::MONKEY, 5, 6},
		{OBJECT::MONKEY, 1, 6, 2},
		{OBJECT::MONKEY, 9, 6, 2},
		{OBJECT::BAT, 2.5, -0.25, 4.5},
		{OBJECT::BAT, 7.5, -0.25, 4.5}
	}
};