예제 #1
0
void Viewport::draw()
{
	if(worm) // Should not be necessary further on
	{
		if(worm->visible)
		{
			int lifebarWidth = worm->health * 100 / worm->settings->health;
			drawBar(inGameX, 161, lifebarWidth, lifebarWidth/10 + 234);
		}
		else
		{
			int lifebarWidth = 100 - (worm->killedTimer * 25) / 37;
			if(lifebarWidth > 0)
			{
				if(lifebarWidth > 100)
					lifebarWidth = 100;
				drawBar(inGameX, 161, lifebarWidth, lifebarWidth/10 + 234);
			}
		}
	}
	
	// Draw kills status
	
	WormWeapon& ww = worm->weapons[worm->currentWeapon];
	
	if(ww.available)
	{
		if(ww.ammo > 0)
		{
			int ammoBarWidth = ww.ammo * 100 / game.weapons[ww.id].ammo;
			
			if(ammoBarWidth > 0)
				drawBar(inGameX, 166, ammoBarWidth, ammoBarWidth/10 + 245);
		}
	}
	else
	{
		int ammoBarWidth = 0;
		
		if(game.weapons[ww.id].loadingTime != 0)
		{
			ammoBarWidth = 100 - ww.loadingLeft * 100 / game.weapons[ww.id].computedLoadingTime;
		}
		else
		{
			ammoBarWidth = 100 - ww.loadingLeft * 100;
		}
		
		if(ammoBarWidth > 0)
			drawBar(inGameX, 166, ammoBarWidth, ammoBarWidth/10 + 245);
		
		if((game.cycles % 20) > 10
		&& worm->visible)
		{
			gfx.font.drawText(game.texts.reloading, inGameX, 164, 50);
		}
	}
	
	gfx.font.drawText((game.texts.kills + toString(worm->kills)), inGameX, 171, 10);
	
	switch(game.settings.gameMode)
	{
	case Settings::GMKillEmAll:
	{
		gfx.font.drawText((game.texts.lives + toString(worm->lives)), inGameX, 178, 6);
	}
	break;
	
	case Settings::GMGameOfTag:
	{
		int const stateColours[] = {6, 10, 79, 4};
		
		int state = 0;
		
		for(std::size_t i = 0; i < game.worms.size(); ++i)
		{
			Worm& w = *game.worms[i];
			
			if(&w != worm
			&& w.timer >= worm->timer)
				state = 1; // We're better or equal off
		}
		
		int colour;
		if(game.lastKilled == worm)
			colour = stateColours[state];
		else
			colour = stateColours[state + 2];
		
		gfx.font.drawText(timeToString(worm->timer), 5, 106 + 84*worm->index, 161, colour);
	}
	break;
	}	

	PreserveClipRect pcr(gfx.screen);
	
	SDL_Rect viewportClip;
	viewportClip.x = rect.x1;
	viewportClip.y = rect.y1;
	viewportClip.w = rect.width();
	viewportClip.h = rect.height();
	
	SDL_SetClipRect(gfx.screen, &viewportClip);
	
	int offsX = rect.x1 - x;
	int offsY = rect.y1 - y;
	
	blitImageNoKeyColour(gfx.screen, &game.level.data[0], offsX, offsY, game.level.width, game.level.height); // TODO: Unhardcode
	
	if(!worm->visible
	&& worm->killedTimer <= 0
	&& !worm->ready)
	{
		gfx.font.drawText(game.texts.pressFire, rect.center_x() - 30, 76, 0);
		gfx.font.drawText(game.texts.pressFire, rect.center_x() - 31, 75, 50);
	}

	if(bannerY > -8
	&& worm->health <= 0)
	{	
		if(game.settings.gameMode == Settings::GMGameOfTag
		&& game.gotChanged)
		{
			gfx.font.drawText(S[YoureIt], rect.x1 + 3, bannerY + 1, 0);
			gfx.font.drawText(S[YoureIt], rect.x1 + 2, bannerY, 50);
		}
	}
	
	for(std::size_t i = 0; i < game.viewports.size(); ++i)
	{
		Viewport* v = game.viewports[i];
		if(v != this
		&& v->worm->health <= 0
		&& v->bannerY > -8)
		{
			if(v->worm->lastKilledBy == worm)
			{
				std::string msg(S[KilledMsg] + v->worm->settings->name);
				gfx.font.drawText(msg, rect.x1 + 3, v->bannerY + 1, 0);
				gfx.font.drawText(msg, rect.x1 + 2, v->bannerY, 50);
			}
			else
			{
				std::string msg(v->worm->settings->name + S[CommittedSuicideMsg]);
				gfx.font.drawText(msg, rect.x1 + 3, v->bannerY + 1, 0);
				gfx.font.drawText(msg, rect.x1 + 2, v->bannerY, 50);
			}
		}
	}

	for(Game::BonusList::iterator i = game.bonuses.begin(); i != game.bonuses.end(); ++i)
	{
		if(i->timer > C[BonusFlickerTime] || (game.cycles & 3) == 0)
		{
			int f = gfx.bonusFrames[i->frame];
			
			blitImage(
				gfx.screen,
				gfx.smallSprites.spritePtr(f),
				ftoi(i->x) - x - 3 + rect.x1,
				ftoi(i->y) - y - 3 + rect.y1,
				7, 7);
				
			if(game.settings.shadow)
			{
				blitShadowImage(
					gfx.screen,
					gfx.smallSprites.spritePtr(f),
					ftoi(i->x) - x - 5 + rect.x1,
					ftoi(i->y) - y - 1 + rect.y1, // This was - 3 in the original, but that seems wrong
					7, 7);
			}
			
			if(game.settings.namesOnBonuses
			&& i->frame == 0)
			{
				std::string const& name = game.weapons[i->weapon].name;
				int len = int(name.size()) * 4;
				
				gfx.drawTextSmall(
					name.c_str(),
					ftoi(i->x) - x - len/2 + rect.x1,
					ftoi(i->y) - y - 10 + rect.y1);
			}
		}
	}
		
	for(Game::SObjectList::iterator i = game.sobjects.begin(); i != game.sobjects.end(); ++i)
	{
		SObjectType& t = game.sobjectTypes[i->id];
		int frame = i->curFrame + t.startFrame;
		
		// TODO: Check that blitImageR is the correct one to use (probably)
		blitImageR(
			gfx.screen,
			gfx.largeSprites.spritePtr(frame),
			i->x + offsX,
			i->y + offsY,
			16, 16);
			
		if(game.settings.shadow)
		{
			blitShadowImage(
				gfx.screen,
				gfx.largeSprites.spritePtr(frame),
				i->x + offsX - 3,
				i->y + offsY + 3, // TODO: Original doesn't offset the shadow, which is clearly wrong. Check that this offset is correct.
				16, 16);
		}
	}
		
	// TODO: Check order of drawing between bonuses, wobjects, etc.
	
	for(Game::WObjectList::iterator i = game.wobjects.begin(); i != game.wobjects.end(); ++i)
	{
		Weapon& w = game.weapons[i->id];
		
		if(w.startFrame > -1)
		{
			int curFrame = i->curFrame;
			int shotType = w.shotType;
			
			if(shotType == 2)
			{
				curFrame += 4;
				curFrame >>= 3;
				if(curFrame < 0)
					curFrame = 16;
				else if(curFrame > 15)
					curFrame -= 16;
			}
			else if(shotType == 3)
예제 #2
0
파일: blit.hpp 프로젝트: JOogway/liero
inline void blitImageNoKeyColour(Bitmap& scr, PalIdx* mem, int x, int y, int width, int height)
{
	blitImageNoKeyColour(scr, mem, x, y, width, height, width);
}
예제 #3
0
inline void blitImageNoKeyColour(SDL_Surface* scr, PalIdx* mem, int x, int y, int width, int height)
{
	blitImageNoKeyColour(scr, mem, x, y, width, height, width);
}