Ejemplo n.º 1
0
void CShowableAnim::show(SDL_Surface * to)
{
	if ( flags & BASE && frame != first)
		blitImage(first, group, to);
	blitImage(frame, group, to);

	if ((flags & PLAY_ONCE) && frame + 1 == last)
		return;

	if ( ++value == frameDelay )
	{
		value = 0;
		if ( ++frame >= last)
			reset();
	}
}
Ejemplo n.º 2
0
void OEMFGame :: die()
{
	musicPlayer->playSound(sounds[SND_OHNO]);
	m_player->m_vy = 0.0f;
	
	m_level->moveObject(m_player, m_level->startX() * 32, m_level->startY() * 32);
	
	if (m_lives > 0)
	{
		m_lives -= 1;
		darkenRect(160, 128, 320, 48);
		char msg[256];
		sprintf(msg, "You died! Lives left:    x%2d", m_lives);
		fonts[FNT_AMIGA]->blitText(this, msg, 0xFF7700, 176, 128 + 16, 320 - 32, false);
		blitImage(images[IMG_OEMFOEMINI], 160 + 112 + 80, 128 + 16);
		updateScreen();
		SDL_Delay(2000);
		fadeOut();
	}
	else
	{
		// GAME OVER!
		m_done = 1;
		darkenRect(160, 128, 320, 48);
		fonts[FNT_AMIGA]->blitCenterText(this, string("GAME OVER!"), 0xFF0000, 128 + 16, m_screenWidth, false);
		updateScreen();
		SDL_Delay(3000);
		fadeOut();
	}
}
Ejemplo n.º 3
0
void CShowableAnim::show(SDL_Surface * to)
{
	if ( flags & BASE )// && frame != first) // FIXME: results in graphical glytch in Fortress, upgraded hydra's dwelling
		blitImage(first, group, to);
	blitImage(frame, group, to);

	if ((flags & PLAY_ONCE) && frame + 1 == last)
		return;

	if ( ++value == frameDelay )
	{
		value = 0;
		if ( ++frame >= last)
			reset();
	}
}
Ejemplo n.º 4
0
void OEMFIntro :: run(void)
{
	// small hack to display "loading..." without the amiga rom being loaded
	
	OEMFImage * amigarom = new OEMFImage(PREPATH "font.png");
	OEMFFontFactory * tempfont = new OEMFFontFactory(amigarom, 32, 127, 8, 16, 96);
	delete amigarom;
	tempfont->blitCenterText(this, "Loading...", 0xFFFFFF00, 216, m_screenWidth);
	updateScreen();
	delete tempfont;
	
	// loading...
	setLoadProgressCB(progress, this);
	loadFilesIntoDataMemory("resources.def");
	clearRectWithColor(0, 216, 640, 16, 0xFF000000, false);
	updateScreen();
	
#ifndef __DEBUG__
	OEMFFontFactory * ff = fonts[FNT_AMIGA];
	OEMFFontFactory * menufont = fonts[FNT_MENU];
	OEMFImage * oemfoelogo = images[IMG_INTRO];
	
	// loading done
	//ripEffect(224, 16);
	SDL_Delay(1000);
	fadeOut();
	
	//clearWithColor(0xFFFFFF);
	//blitImage(images[IMG_SDL], (m_screenWidth - images[IMG_SDL]->width()) / 2, 120);
//	ff->blitCenterText(this, "http://www.libsdl.org", 0x330077, 400, m_screenWidth, false);
//	updateScreen();
//	SDL_Delay(3000);
//	fadeOut();

	ff->blitCenterText(this, "Royal Belgian Beer Squadron", 0xFFFFFFFF, 224, m_screenWidth);
	SDL_UpdateRect(m_screen, 0, 0, m_screenWidth, m_screenHeight);
	SDL_Delay(1500);
	//ripEffect(224, 16);
	fadeOut();
	
	ff->blitCenterText(this, "presents...", 0xFFFFFFFF, 224, m_screenWidth);
	SDL_UpdateRect(m_screen, 0, 0, m_screenWidth, m_screenHeight);
	SDL_Delay(1500);
	//ripEffect(224, 16);
	fadeOut();
	
	// draw welcome screen
	blitImage(oemfoelogo, 0, 0);
	ff->blitCenterText(this, "Idea:                      Oemfoe", 0xFFFFFFFF, 192+192, m_screenWidth, true);
	ff->blitCenterText(this, "Coding:                    Oemfoe", 0xFFFFFFFF, 208+192, m_screenWidth, true);
	ff->blitCenterText(this, "GFX:                       Kuroto", 0xFFFFFFFF, 224+192, m_screenWidth, true);
	ff->blitCenterText(this, "Music:            Belief Systems*", 0xFFFFFFFF, 240+192, m_screenWidth, true);
	SDL_UpdateRect(m_screen, 0, 0, m_screenWidth, m_screenHeight);
	SDL_Delay(3000);
#endif
	
	if (musicPlayer->isPlayingSong())
		musicPlayer->stopSong();
}
Ejemplo n.º 5
0
void VkPostprocess::BlitSceneToPostprocess()
{
	auto fb = GetVulkanFrameBuffer();

	fb->GetRenderState()->EndRenderPass();

	auto buffers = fb->GetBuffers();
	auto cmdbuffer = fb->GetDrawCommands();

	mCurrentPipelineImage = 0;

	VkImageTransition imageTransition;
	imageTransition.addImage(&buffers->SceneColor, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, false);
	imageTransition.addImage(&buffers->PipelineImage[mCurrentPipelineImage], VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, true);
	imageTransition.execute(fb->GetDrawCommands());

	if (buffers->GetSceneSamples() != VK_SAMPLE_COUNT_1_BIT)
	{
		auto sceneColor = buffers->SceneColor.Image.get();
		VkImageResolve resolve = {};
		resolve.srcOffset = { 0, 0, 0 };
		resolve.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
		resolve.srcSubresource.mipLevel = 0;
		resolve.srcSubresource.baseArrayLayer = 0;
		resolve.srcSubresource.layerCount = 1;
		resolve.dstOffset = { 0, 0, 0 };
		resolve.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
		resolve.dstSubresource.mipLevel = 0;
		resolve.dstSubresource.baseArrayLayer = 0;
		resolve.dstSubresource.layerCount = 1;
		resolve.extent = { (uint32_t)sceneColor->width, (uint32_t)sceneColor->height, 1 };
		cmdbuffer->resolveImage(
			sceneColor->image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
			buffers->PipelineImage[mCurrentPipelineImage].Image->image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
			1, &resolve);
	}
	else
	{
		auto sceneColor = buffers->SceneColor.Image.get();
		VkImageBlit blit = {};
		blit.srcOffsets[0] = { 0, 0, 0 };
		blit.srcOffsets[1] = { sceneColor->width, sceneColor->height, 1 };
		blit.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
		blit.srcSubresource.mipLevel = 0;
		blit.srcSubresource.baseArrayLayer = 0;
		blit.srcSubresource.layerCount = 1;
		blit.dstOffsets[0] = { 0, 0, 0 };
		blit.dstOffsets[1] = { sceneColor->width, sceneColor->height, 1 };
		blit.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
		blit.dstSubresource.mipLevel = 0;
		blit.dstSubresource.baseArrayLayer = 0;
		blit.dstSubresource.layerCount = 1;
		cmdbuffer->blitImage(
			sceneColor->image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
			buffers->PipelineImage[mCurrentPipelineImage].Image->image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
			1, &blit, VK_FILTER_NEAREST);
	}
}
Ejemplo n.º 6
0
void OEMFGame :: refreshScoreBoard()
{
	// scoreboard
	blitImage(images[IMG_SCOREB], 0, m_screenHeight - 32);
	char stats[1024];

	sprintf(stats, "Score: %6d", m_score);
	fonts[FNT_AMIGA]->blitText(this, stats, 0xFFFF00, 12, m_screenHeight-24, m_screenWidth-12, false);

	sprintf(stats, "              Lives:    x%2d", m_lives);
	fonts[FNT_AMIGA]->blitText(this, stats, 0xFF7700, 12, m_screenHeight-24, m_screenWidth-12, false);
	
#ifdef __DEBUG__
	sprintf(stats, "                            Level: %3d       (Scroll %d:%d)", m_levelNo, m_screenScrollX, m_screenScrollY);
#else
	sprintf(stats, "                            Level: %3d                          ", m_levelNo);
#endif
	fonts[FNT_AMIGA]->blitText(this, stats, 0x3399FF, 12, m_screenHeight-24, m_screenWidth-12, false);

	blitImage(images[IMG_OEMFOEMINI], 180, m_screenHeight - 24);
}
Ejemplo n.º 7
0
void View::update()
{
	// Draw the sky
	m_pImage->clear(0xff00ffff);

	// Draw the bird
	Bird& bird = model.bird;
	if(bird.time_since_flap < 4)
		m_pImage->blit(bird.x, bird.y, &image_bird2);
	else
		m_pImage->blit(bird.x, bird.y, &image_bird1);

	// Draw the tubes
	for(size_t i = 0; i < model.tubes.size(); i++) {
		Tube* t = model.tubes[i];
		if(t->up)
			m_pImage->blit(t->x, t->y, &image_tube_up);
		else
			m_pImage->blit(t->x, t->y - 400, &image_tube_down);
	}



	// Lock the screen for direct access to the pixels
	SDL_Surface *pScreen = m_pScreen;
	if ( SDL_MUSTLOCK(pScreen) )
	{
		if ( SDL_LockSurface(pScreen) < 0 )
			throw Ex("Failed to lock the SDL surface");
	}

	// Clear the screen
	SDL_FillRect(pScreen, NULL/*&r*/, 0x000000);

	// Draw the dialog
	blitImage(pScreen, m_screenRect.x, m_screenRect.y, m_pImage);

	// Unlock the screen
	if ( SDL_MUSTLOCK(pScreen) )
		SDL_UnlockSurface(pScreen);

	// Update the whole screen
	SDL_UpdateRect(pScreen, m_screenRect.x, m_screenRect.y, m_screenRect.w, m_screenRect.h);

}
Ejemplo n.º 8
0
void VkPostprocess::BlitCurrentToImage(VkTextureImage *dstimage, VkImageLayout finallayout)
{
	auto fb = GetVulkanFrameBuffer();

	fb->GetRenderState()->EndRenderPass();

	auto srcimage = &fb->GetBuffers()->PipelineImage[mCurrentPipelineImage];
	auto cmdbuffer = fb->GetDrawCommands();

	VkImageTransition imageTransition0;
	imageTransition0.addImage(srcimage, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, false);
	imageTransition0.addImage(dstimage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, true);
	imageTransition0.execute(cmdbuffer);

	VkImageBlit blit = {};
	blit.srcOffsets[0] = { 0, 0, 0 };
	blit.srcOffsets[1] = { srcimage->Image->width, srcimage->Image->height, 1 };
	blit.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
	blit.srcSubresource.mipLevel = 0;
	blit.srcSubresource.baseArrayLayer = 0;
	blit.srcSubresource.layerCount = 1;
	blit.dstOffsets[0] = { 0, 0, 0 };
	blit.dstOffsets[1] = { dstimage->Image->width, dstimage->Image->height, 1 };
	blit.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
	blit.dstSubresource.mipLevel = 0;
	blit.dstSubresource.baseArrayLayer = 0;
	blit.dstSubresource.layerCount = 1;
	cmdbuffer->blitImage(
		srcimage->Image->image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
		dstimage->Image->image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
		1, &blit, VK_FILTER_NEAREST);

	VkImageTransition imageTransition1;
	imageTransition1.addImage(dstimage, finallayout, false);
	imageTransition1.execute(cmdbuffer);
}
Ejemplo n.º 9
0
void OEMFGame :: initialize()
{
	float gravity = 0.5f;
	
	m_beginX = 0;
	m_beginY = 0;
	
	char levelfile[256];
	sprintf(levelfile, PREPATH "level%d.lvl", (int) m_levelNo);
	
	if (m_level != 0)
		delete m_level;
	FILE * fh = fopen(levelfile, "r");
	
	if (fh != 0)
	{
		// level found!
		fclose(fh);
		
		m_level = new OEMFLevel(levelfile);
	}
	else
	{
		m_level = new OEMFLevel(PREPATH "level1.lvl");
	}
	
	m_level->prepareForGame(); // very important!
	
	m_player = m_level->types[TYPE_START][0];
	
	m_physicsEnabled.clear();
	m_physicsEnabled.push_back(m_player); // apply physics to the player
	for (int i = 0; i < m_level->m_typeCounts[TYPE_MOVABLE]; ++i)
	{
		m_physicsEnabled.push_back(m_level->types[TYPE_MOVABLE][i]);
		m_level->types[TYPE_MOVABLE][i]->m_ay = gravity; // gravity
	}
	
	// reset the keys
	for (int i = 0; i < KEYCOUNT; ++i)
	{
		m_keyDown[i] = false;
	}
	
	// reset the physics components
	m_player->m_ay = gravity; // gravity
	
	if (fh != 0)
	{
		// initialisation done
		refreshCentered();
		refreshScoreBoard();
		updateScreen();
		
		darkenRect(160, 128, 320, 96);
		char levelbuffer[256];
		sprintf(levelbuffer, "Prepare for level %d:", m_levelNo);
		fonts[FNT_AMIGA]->blitCenterText(this, string(levelbuffer), 0xFF7700, 128 + 16, m_screenWidth);
		fonts[FNT_AMIGA]->blitCenterText(this, string("\"") + m_level->name() + "\"", 0xFFFF00, 128 + 32, m_screenWidth);
		fonts[FNT_AMIGA]->blitCenterText(this, string("Go Go Go!"), 0xFF0000, 128 + 64, m_screenWidth);
		updateScreen();
#ifndef __DEBUG__
		SDL_Delay(3000);
#endif
	}
	else
	{
		// game has ended!
		m_done = 1;
		blitImage(images[IMG_ENDSCREEN], 0, 0);
		blitImage(images[IMG_OEMFOE], 32, 320);
		fonts[FNT_AMIGA]->blitText(this,
//			"----/----|----/----|----/----|----/----|"
			"Congratulations! You reached the end of\n"
			"the game! You can now do something else\n"
			"with your life, but if you are too\n"
			"addicted, you can always use the Level\n"
			"Editor and create more worlds.\n"
			"Press any key to continue...",
			0xFFFF00, 80, 320, 320, false);
		updateScreen();
		waitForKey();
		fadeOut();
	}
}
Ejemplo n.º 10
0
void OEMFGame :: refresh()
{
	deque<OEMFGObject *> :: iterator it;
	int widthInBlocks = m_screenWidth / 32;
	int heightInBlocks = m_screenHeight / 32 - 1;
	// position calculations
	while (m_player->posX() < m_beginX * 32 - 16)
		m_beginX -= widthInBlocks;
	while (m_player->posX() > (m_beginX + widthInBlocks) * 32 - 16)
		m_beginX += widthInBlocks;
	while (m_player->posY() < m_beginY * 32 - 16)
		m_beginY -= heightInBlocks;
	while (m_player->posY() > (m_beginY + heightInBlocks) * 32 - 16)
		m_beginY += heightInBlocks;
	
	unsigned int x, y, ypos, width, height;
	width = m_level->width();
	height = m_level->height();
	
	tile_t * ltiles = m_level->tiles();
	
	// background
	// blitImageRect(images[m_level->background()], 0, 0, 0, 0, m_screenWidth, m_screenHeight - 32);
	blitImage(images[m_level->background()], 0, 0);
	for (y = m_beginY; y < height && (y-m_beginY) * 32 < m_screenHeight - 32; y++)
	{
		ypos = y * width;
		for (x = m_beginX; x < width && (x-m_beginX) * 32 < m_screenWidth; x++)
		{
			if (ltiles[x+ypos].bg != IMG_NULL)
				blitImage(images[ltiles[x+ypos].bg], (x-m_beginX) * 32, (y-m_beginY) * 32);
		}
	}
	
	// debug
//	for (y = m_beginY; y < height && (y-m_beginY) * 32 < m_screenHeight - 32; y++)
//	{
//		ypos = y * width;
//		for (x = m_beginX; x < width && (x-m_beginX) * 32 < m_screenWidth; x++)
//		{
//			int i = 0;
//			for (it = m_level->raster[x+ypos]->objects.begin(); it != m_level->raster[x+ypos]->objects.end(); it++)
//			{
//				blitImageRect(images[(*it)->image()],(x - m_beginX) * 32 + (i % 4) * 8,(y - m_beginY) * 32 + (i / 4) * 8,0,0, 8, 8);
//				i++;
//			}
//		}
//	}
	
	// foreground
	// draw exact tiles
	for (y = m_beginY; y < height && (y-m_beginY) * 32 < m_screenHeight - 32; y++)
	{
		ypos = y * width;
		for (x = m_beginX; x < width && (x-m_beginX) * 32 < m_screenWidth; x++)
		{
			for (it = m_level->raster[x+ypos]->objects.begin(); it != m_level->raster[x+ypos]->objects.end(); it++)
			{
				if ((*it)->image() != IMG_NULL && ((*it)->posX() % 32 == 0 && (*it)->posY() % 32 == 0 ))
					blitImage(images[(*it)->image()], (*it)->posX() - m_beginX * 32, (*it)->posY() - m_beginY * 32);
			}
		}
	}
	
	// draw odds
	for (y = m_beginY; y < height && (y-m_beginY) * 32 < m_screenHeight - 32; y++)
	{
		ypos = y * width;
		for (x = m_beginX; x < width && (x-m_beginX) * 32 < m_screenWidth; x++)
		{
			for (it = m_level->raster[x+ypos]->objects.begin(); it != m_level->raster[x+ypos]->objects.end(); it++)
			{
				if ((*it)->image() != IMG_NULL && ((*it)->posX() % 32 != 0 || (*it)->posY() % 32 != 0 ))
					blitImage(images[(*it)->image()], (*it)->posX() - m_beginX * 32, (*it)->posY() - m_beginY * 32);
			}

		}
	}
}
Ejemplo n.º 11
0
void OEMFGame :: refreshCentered()
{
	deque<OEMFGObject *> :: iterator it;
	int x, y, ypos;
	int width = m_level->width();
	int height = m_level->height();
	int posWidth = m_screenWidth / 32 + 2;
	int posHeight = m_screenHeight / 32 + 1;
	int centerX = (m_screenWidth - 32) / 2;
	int centerY = (m_screenHeight - 64) / 2;
	int beginX = m_player->posX() / 32 - centerX / 32 - 1;
	int beginY = m_player->posY() / 32 - centerY / 32 - 1;
	int beginPosX = -(m_player->posX() % 32);
	int beginPosY = -(m_player->posY() % 32);
	int totalBeginX = beginX * 32 - beginPosX - 16 + 32;
	int totalBeginY = beginY * 32 - beginPosY - 16 + 32;
	
	// Calculate bottom left boundary of level scrolling
	int maxScrollX = (m_level->width() - 1) * 32 - (m_screenWidth - 32);
	int maxScrollY = (m_level->height() - 1) * 32 - (m_screenHeight - 64);
	//m_screenScrollX = totalBeginX;
	//m_screenScrollY = totalBeginY;
	
	// Make sure the player is in the center rectangle of the screen...
	int playerScreenX = m_player->posX() - m_screenScrollX;
	int playerScreenY = m_player->posY() - m_screenScrollY;
	if (playerScreenX < 160) m_screenScrollX = m_player->posX() - 160;
	if (playerScreenY < 112) m_screenScrollY = m_player->posY() - 112;
	if (playerScreenX > 448) m_screenScrollX = m_player->posX() - 448;
	if (playerScreenY > 304) m_screenScrollY = m_player->posY() - 304;
	
	// ... but keep the boundaries of level within the screen.
	if (m_screenScrollX < 0) m_screenScrollX = 0;
	if (m_screenScrollY < 0) m_screenScrollY = 0;
	if (m_screenScrollX > maxScrollX) m_screenScrollX = maxScrollX;
	if (m_screenScrollY > maxScrollY) m_screenScrollY = maxScrollY;
	
	// Calculate object coordinates of top left block on the screen
	beginX = m_screenScrollX / 32 - 1;
	beginY = m_screenScrollY / 32 - 1;

	totalBeginX = m_screenScrollX;
	totalBeginY = m_screenScrollY;

	tile_t * ltiles = m_level->tiles();
	
	// swap all images of animations
	animateImages();
	
	// background
	blitImage(images[m_level->background()], 0, 0);
	for (y = beginY; y < height && (y-beginY) < posHeight; y++)
	{
		ypos = y * width;
		for (x = beginX; x < width && (x-beginX) < posWidth; x++)
		{
			if (x >= 0 && y >= 0)
			{
				if (ltiles[x+ypos].bg != IMG_NULL)
					blitImage(images[ltiles[x+ypos].bg], x * 32 - totalBeginX, y * 32 - totalBeginY);
			}
		}
	}
	
	// foreground
	// draw exact tiles
	for (y = beginY; y < height && (y-beginY) < posHeight; y++)
	{
		ypos = y * width;
		for (x = beginX; x < width && (x-beginX) < posWidth; x++)
		{
			if (x >= 0 && y >= 0)
			{
				for (it = m_level->raster[x+ypos]->objects.begin(); it != m_level->raster[x+ypos]->objects.end(); it++)
				{
					if ((*it)->image() != IMG_NULL && ((*it)->posX() % 32 == 0 && (*it)->posY() % 32 == 0))
						blitImage(images[(*it)->image()], (*it)->posX() - totalBeginX, (*it)->posY() - totalBeginY);
				}
			}
		}
	}
	// draw odd tiles
	for (y = beginY; y < height && (y-beginY) < posHeight; y++)
	{
		ypos = y * width;
		for (x = beginX; x < width && (x-beginX) < posWidth; x++)
		{
			if (x >= 0 && y >= 0)
			{
				for (it = m_level->raster[x+ypos]->objects.begin(); it != m_level->raster[x+ypos]->objects.end(); it++)
				{
					if ((*it)->image() != IMG_NULL && ((*it)->posX() % 32 != 0 || (*it)->posY() % 32 != 0))
						blitImage(images[(*it)->image()], (*it)->posX() - totalBeginX, (*it)->posY() - totalBeginY);
				}
			}
		}
	}
	
//	blitImage(images[IMG_SELECTION], beginPosX, beginPosY);
//	char buffer[1024];
//	sprintf(buffer, "beginX=%d beginY=%d beginPosX=%d beginPosY=%d", beginX, beginY, beginPosX, beginPosY);
//	fonts[FNT_AMIGA]->blitCenterText(this, buffer, 32 ,m_screenWidth, false);
}
Ejemplo n.º 12
0
void CShowableAnim::showAll(SDL_Surface * to)
{
	if ( flags & BASE )// && frame != first)
		blitImage(first, group, to);
	blitImage(frame, group, to);
}
Ejemplo n.º 13
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)
Ejemplo n.º 14
0
void OEMFMain :: run(void)
{
	unsigned int menuIndex = 0;
	unsigned int frames = 0;
	unsigned int timepassed;
	
	if (musicPlayer->isPlayingSong())
		musicPlayer->stopSong();
	string songfile = PREPATH "boiling.mp3";
	musicPlayer->playSongAtPath(songfile.c_str());
	
	drawIntro();
	
	SDL_Event event;
	int done = 0;
	while ( !done) {
		timepassed = SDL_GetTicks();
	
		OEMF_LOCKSCREEN;
		clearWithColor(0xFF000000, false);
		OEMF_UNLOCKSCREEN;
		blitImage(images[IMG_INTRO], 0, 0);
		for (unsigned int i = 0; i < m_menuCount; i++)
			fonts[FNT_MENU]->blitText(this, m_menuOptions[i].c_str(), 160, 240 + i * 32, 480, false);
		blitImage(images[IMG_OEMFOE], 128, (unsigned int) (240 + menuIndex * 32 + sin(frames / 2.0) * 8));
		SDL_UpdateRect(m_screen, 128, 232, 512, 248);
		
		/* Check for events */
		while (SDL_PollEvent(&event))
		{
			switch (event.type)
			{
				case SDL_MOUSEMOTION:
					break;
				case SDL_MOUSEBUTTONDOWN:
					break;
				case SDL_KEYDOWN:
					if (event.key.keysym.sym == SDLK_ESCAPE)
					{	
						done = 1;
					} 
					else if (event.key.keysym.sym == SDLK_UP)
					{
						menuIndex = (menuIndex - 1 + m_menuCount) % m_menuCount;
						musicPlayer->playSound(sounds[SND_TOK]);
					}
					else if (event.key.keysym.sym == SDLK_DOWN)
					{
						menuIndex = (menuIndex + 1) % m_menuCount;
						musicPlayer->playSound(sounds[SND_TOK]);
					}
					else if (event.key.keysym.sym == SDLK_p)
					{
						SDL_SaveBMP(m_screen, "screenshot.bmp");
					}
					else if (event.key.keysym.sym == SDLK_RETURN)
					{
						musicPlayer->playSound(sounds[SND_TIK]);
						if (menuIndex == 4)
						{
							fadeOut();
							done = 1;
						}
						else if (menuIndex == 0) // new game
						{
							fadeOut();
							OEMFGame * game = new OEMFGame(m_screen, m_execPath, m_screenWidth, m_screenHeight, m_screenBpp);
							game->run();
							delete game;
							drawIntro();
						}
						else if (menuIndex == 3) // level editor
						{
							fadeOut();
							OEMFLevelEdit * leveledit = new OEMFLevelEdit(m_screen, m_execPath, m_screenWidth, m_screenHeight, m_screenBpp);
							leveledit->run();
							delete leveledit;
							drawIntro();
						}
						else if (menuIndex == 2) // options
						{
							unsigned int choice = 0;
							string * options = new string[2];
							while (choice != 2) // not exit
							{
								if (musicEnabled)
									options[0] = "Turn Music Off";
								else
									options[0] = "Turn Music On";
								options[1] = "Toggle Fullscreen";
								drawIntro();
								choice = chooseList(2 /* exit */, "Options", options, 2);
								if (choice == 0)
								{
									musicEnabled = !musicEnabled;
									if (!musicEnabled)
									{
										if (musicPlayer->isPlayingSong())
											musicPlayer->stopSong();
									}
									else
									{
										musicPlayer->playSongAtPath(songfile.c_str());
									}
								}
								else if (choice == 1)
								{
									if (fullscreenMode)
									{
										m_screen = SDL_SetVideoMode(m_screenWidth, m_screenHeight, m_screenBpp, SDL_SWSURFACE);
										m_fb = (Uint32 *) m_screen->pixels;
										m_pitch = (Uint32) m_screen->pitch / 4;
										fullscreenMode = false;
									}
									else
									{
										m_screen = SDL_SetVideoMode(m_screenWidth, m_screenHeight, m_screenBpp, SDL_SWSURFACE | SDL_FULLSCREEN);
										m_fb = (Uint32 *) m_screen->pixels;
										m_pitch = (Uint32) m_screen->pitch / 4;
										fullscreenMode = true;
									}
									choice = 2;
								}
							}
							drawIntro();
						}
						else
						{
							fadeOut();
							fonts[FNT_MENU]->blitCenterText(this, "NOT AVAILABLE YET", 240, m_screenWidth);
							SDL_UpdateRect(m_screen, 0, 0, m_screenWidth, m_screenHeight);
							SDL_Delay(2000);
							string test = fonts[FNT_MENU]->inputText(this, "default", 32, 32, 10);
							drawIntro();
						}
					}
					break;
				case SDL_QUIT:
					done = 1;
					break;
				default:
					break;
			}
		}
		frames++;
		
		// 30 FPS
		timepassed = SDL_GetTicks() - timepassed;
		if (timepassed <= 33)
			SDL_Delay(33 - timepassed);
	}
}
Ejemplo n.º 15
0
void OEMFMain :: drawIntro(void)
{
	clearWithColor(0xFF000000, false);
	blitImage(images[IMG_INTRO], 0, 0);
	SDL_UpdateRect(m_screen, 0, 0, m_screenWidth, m_screenHeight);
}