Exemple #1
0
// Draw the train line at the time
//  line1: 150 frames (=> Belgrade)
//  line2: 61 frames (=> Constantinople)
void TrainLine::draw(uint32 time) {
	assert(time >= kTimeCityParis && time <= kTimeCityConstantinople);

	// Check that sequences have been loaded
	if (!_frameLine1 || !_frameLine2)
		error("TrainLine::process: Line sequences have not been loaded correctly!");

	// Clear existing frames
	clear();

	// Get the index of the last city the train has visited
	uint index = 0;
	for (uint i = 0; i < ARRAYSIZE(_trainCities); i++)
		if ((uint32)_trainCities[i].time <= time)
			index = i;

	uint16 frame;
	if (time > (uint32)_trainCities[index].time) {
		// Interpolate linearly to use a frame between the cities
		uint8 diffFrames = _trainCities[index + 1].frame - _trainCities[index].frame;
		uint diffTimeCities = (uint)(_trainCities[index + 1].time - _trainCities[index].time);
		uint traveledTime = (time - (uint)_trainCities[index].time);
		frame = (uint16)(_trainCities[index].frame + (traveledTime * diffFrames) / diffTimeCities);
	} else {
		// Exactly on the city
		frame = _trainCities[index].frame;
	}

	// Set frame, z-order and queue
	if (frame < 150) {
		_frameLine1->setFrame(frame);

		_frameLine1->getInfo()->location = 1;
		getScenes()->addToQueue(_frameLine1);
	} else {
		// We passed Belgrade
		_frameLine1->setFrame(149);
		_frameLine2->setFrame(frame - 150);

		_frameLine1->getInfo()->location = 1;
		_frameLine2->getInfo()->location = 1;

		getScenes()->addToQueue(_frameLine1);
		getScenes()->addToQueue(_frameLine2);
	}
}
Exemple #2
0
//////////////////////////////////////////////////////////////////////////
// Processing
//////////////////////////////////////////////////////////////////////////
void Fighter::process() {
	if (!_fight)
		error("[Fighter::handleAction] Fighter not initialized properly");

	if (!_sequence) {
		if (_frame) {
			getScenes()->removeFromQueue(_frame);
			getScenes()->setCoordinates(_frame);
		}
		SAFE_DELETE(_frame);
		return;
	}

	if (_sequence->count() <= _frameIndex) {
		switch(_action) {
		default:
			break;

		case kFightAction101:
			setSequenceAndDraw(_sequenceIndex2, kFightSequenceType1);
			_sequenceIndex2 = 0;
			break;

		case kFightActionResetFrame:
			_frameIndex = 0;
			break;

		case kFightAction103:
			setSequenceAndDraw(0, kFightSequenceType1);
			handleAction(kFightAction101);
			_opponent->setSequenceAndDraw(0, kFightSequenceType1);
			_opponent->handleAction(kFightAction101);
			_opponent->update();
			break;

		case kFightActionWin:
			_fight->bailout(Fight::kFightEndWin);
			break;

		case kFightActionLost:
			_fight->bailout(Fight::kFightEndLost);
			break;
		}
	}

	if (_fight->isRunning()) {

		// Get the current sequence frame
		SequenceFrame *frame = new SequenceFrame(_sequence, (uint16)_frameIndex);
		frame->getInfo()->location = 1;

		if (_frame == frame) {
			delete frame;
			return;
		}

		getSound()->playFightSound(frame->getInfo()->soundAction, frame->getInfo()->field_31);

		// Add current frame to queue and advance
		getScenes()->addToQueue(frame);
		_frameIndex++;

		if (_frame) {
			getScenes()->removeFromQueue(_frame);

			if (!frame->getInfo()->field_2E)
				getScenes()->setCoordinates(_frame);
		}

		// Replace by new frame
		delete _frame;
		_frame = frame;
	}
}