Exemple #1
0
/**
 * Draw the layer.
 *
 * @param tileSet The tile set to use for non-flipped tiles
 * @param flippedTileSet The tile set to use for flipped tiles
 */
void JJ2Layer::draw (SDL_Surface* tileSet, SDL_Surface* flippedTileSet) {

	SDL_Rect src, dst;
	int vX, vY;
	int x, y;

	// Set tile drawing dimensions
	src.w = TTOI(1);
	src.h = TTOI(1);
	src.x = 0;


	// Calculate the layer view
	vX = FTOI(FTOI(viewX) * xSpeed);
	vY = FTOI(FTOI(viewY) * ySpeed);

	if (limit) {

		if (!tileX) {

			if (vX + canvasW > TTOI(width)) vX = TTOI(width) - canvasW;

		}

		if (!tileY) {

			vY -= canvasH - SH;
			if (vY + canvasH > TTOI(height)) vY = TTOI(height) - canvasH;

		}

	}

	for (y = 0; y <= ITOT(canvasH - 1) + 1; y++) {

		for (x = 0; x <= ITOT(canvasW - 1) + 1; x++) {

			dst.x = TTOI(x) - (vX & 31);
			dst.y = TTOI(y) - (vY & 31);
			src.y = TTOI(getTile(x + ITOT(vX), y + ITOT(vY)));
			if (src.y) SDL_BlitSurface(getFlipped(x + ITOT(vX), y + ITOT(vY))? flippedTileSet: tileSet, &src, canvas, &dst);

		}

	}

	return;

}
Exemple #2
0
/**
 * Draw the JJ2 level.
 */
void JJ2Level::draw () {

	int width, height;
	int x, y;
	unsigned int change;


	width = layer->getWidth();
	height = layer->getHeight();


	// Calculate change since last step
	change = getTimeChange();


	// Calculate viewport
	if (game && (stage == LS_END)) game->view(paused? 0: ((ticks - prevTicks) * 160));
	else localPlayer->getJJ2LevelPlayer()->view(ticks, paused? 0: (ticks - prevTicks), change);

	// Ensure the new viewport is within the level
	if (FTOI(viewX) + canvasW >= TTOI(width)) viewX = ITOF(TTOI(width) - canvasW);
	if (viewX < 0) viewX = 0;
	if (FTOI(viewY) + canvasH >= TTOI(height)) viewY = ITOF(TTOI(height) - canvasH);
	if (viewY < 0) viewY = 0;


	// Show background layers
	for (x = 7; x >= 3; x--) layers[x]->draw(tileSet, flippedTileSet);


	// Show the events
	if (events) events->draw(ticks, change);


	// Show the players
	for (x = 0; x < nPlayers; x++) players[x].getJJ2LevelPlayer()->draw(ticks, change);


	// Show foreground layers
	for (x = 2; x >= 0; x--) layers[x]->draw(tileSet, flippedTileSet);


	// Temporary lines showing the water level
	drawRect(0, FTOI(waterLevel - viewY), canvasW, 2, 72);
	drawRect(0, FTOI(waterLevel - viewY) + 3, canvasW, 1, 72);
	drawRect(0, FTOI(waterLevel - viewY) + 6, canvasW, 1, 72);
	drawRect(0, FTOI(waterLevel - viewY) + 10, canvasW, 1, 72);


	// Black-out areas outside the level (for high resolutions)

	if (TTOI(layers[3]->getWidth()) - FTOI(viewX) < canvasW)
		drawRect(TTOI(layers[3]->getWidth()) - FTOI(viewX), 0,
			canvasW, canvasH, JJ2_BLACK);

	if (TTOI(layers[3]->getHeight()) - FTOI(viewY) < canvasH)
		drawRect(0, TTOI(layers[3]->getHeight()) - FTOI(viewY),
			TTOI(layers[3]->getWidth()) - FTOI(viewX), canvasH, JJ2_BLACK);


	// Show "panel" data

	// Show score
	if (multiplayer) game->getMode()->drawScore(font);
	else panelSmallFont->showNumber(localPlayer->getScore(), 64, 8);


	// Draw hearts

	x = localPlayer->getJJ2LevelPlayer()->getEnergy();

	for (y = 1; y <= x; y++) {

		drawRect(canvasW - (y * 12), 4, 8, 8, 48);

	}


	// Show lives
	panelSmallFont->showNumber(localPlayer->getLives(), 16, canvasH - 16);


	// Show ammo
	if (localPlayer->getAmmoType() == -1) {

		panelSmallFont->showString(":", canvasW - 24, canvasH - 16);
		panelSmallFont->showString(";", canvasW - 16, canvasH - 16);

	} else panelSmallFont->showNumber(localPlayer->getAmmo(), canvasW - 8, canvasH - 16);


	return;

}