Пример #1
0
void shutdown_sprites()
{
    for (SpriteMap::iterator iter = sprite_map.begin(); iter != sprite_map.end(); ++iter)
    {
        al_destroy_bitmap(iter->second);
    }
}
Пример #2
0
void DatDebugViewListBox::OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const
{
    SpriteMap::const_iterator spr_iter = sprites.find(int(n));
    if(spr_iter != sprites.end())
        spr_iter->second->DrawTo(&dc, SPRITE_SIZE_32x32, rect.GetX(), rect.GetY(), rect.GetWidth(), rect.GetHeight());

    if(int(n) == GetSelection()) {
        dc.SetTextForeground(wxColor(0xFF, 0xFF, 0xFF));
    } else {
        dc.SetTextForeground(wxColor(0x00, 0x00, 0x00));
    }

    dc.DrawText(wxString() << n, rect.GetX() + 40, rect.GetY() + 6);
}
Пример #3
0
Sprite::Sprite(const char *filepath,
               units::Pixel source_x, units::Pixel source_y,
               units::Pixel source_width, units::Pixel source_height,
               bool flip_horizontal,
               bool flip_vertical) :
    source_x(source_x),
    source_y(source_y),
    source_width(source_width),
    source_height(source_height),
    flip_horizontal(flip_horizontal),
    flip_vertical(flip_vertical)
{
    assert(filepath);

    if (sprite_map.count(filepath) == 0)
    {
        sprite_map[filepath] = al_load_bitmap(filepath);
        if (sprite_map[filepath] == NULL)
        {
            fprintf(stderr, "Could not find image: %s\n", filepath);
            exit(EXIT_FAILURE);
        }
    }
    image = sprite_map[filepath];
}
Пример #4
0
bool ComponentAnim::loadAnimation(StandardEnemyAnimation anim, Direction direction, std::string name, FILE* from)
{
	// Cargar animación indicada de from
	if (from == NULL || name == "")
		return false;

	int numFrames, speed;
	int* frameList;
	EnemyFrameData frameData;
	EnemyAnimData animData;

	// Leemos datos de la animación

	// 0.Speed
	if (fscanf(from, "%d", &speed) < 1)
		return false;

	// 1.Nº frames
	if (fscanf(from, "%d", &numFrames) < 1)
		return false;

	animData.animSpeed = speed;
	animData.numFrames = numFrames;

	// Se instancia el contenedor de frames
	frameList = new int[numFrames];

	// Se carga cada frame
	for (int i = 0; i < numFrames; i++)
	{
		frameData = loadAnimationFrame(from);
		frameList[i] = frameData.frameId;
		animData.frameData.push_back(frameData);
	}

	// Se añade la animación al graphic con el nombre indicado
	SpriteMap* gfx = ((SpriteMap*) e->graphic);
	gfx->addAnim(name, frameList, numFrames, speed, true);

	// Se mappea la anim
	animList.insert(make_pair(make_pair(anim, direction), name));
	// Y se agrega su info
	animDataList.insert(make_pair(make_pair(anim, direction), animData));
	delete frameList;

	return true;
};
Пример #5
0
		Texture GetTextureMap()
		{
			if(bUpdated)
			{
				textureMap = spriteMap->GenerateTexture(m_gl);
				bUpdated = false;
			}
			return textureMap;
		}
Пример #6
0
		const CharInfo& AddCharInfo(wchar_t t)
		{
			bUpdated = true;
			infoByChar.Add(t, (uint32)infos.size());
			infos.emplace_back();
			CharInfo& ci = infos.back();

			FT_Face* pFace = &face;

			ci.glyphID = FT_Get_Char_Index(*pFace, t);
			if(ci.glyphID == 0)
			{
				pFace = &fallbackFont;
				ci.glyphID = FT_Get_Char_Index(*pFace, t);
			}
			FT_Load_Glyph(*pFace, ci.glyphID, FT_LOAD_DEFAULT);

			if((*pFace)->glyph->format != FT_GLYPH_FORMAT_BITMAP)
			{
				FT_Render_Glyph((*pFace)->glyph, FT_RENDER_MODE_NORMAL);
			}

			ci.topOffset = (*pFace)->glyph->bitmap_top;
			ci.leftOffset = (*pFace)->glyph->bitmap_left;
			ci.advance = (float)(*pFace)->glyph->advance.x / 64.0f;

			Image img = ImageRes::Create(Vector2i((*pFace)->glyph->bitmap.width, (*pFace)->glyph->bitmap.rows));
			Colori* pDst = img->GetBits();
			uint8* pSrc = (*pFace)->glyph->bitmap.buffer;
			uint32 nLen = (*pFace)->glyph->bitmap.width * (*pFace)->glyph->bitmap.rows;
			for(uint32 i = 0; i < nLen; i++)
			{
				pDst[0].w = pSrc[0];
				Reinterpret<VectorBase<uint8, 3>>(pDst[0]) = VectorBase<uint8, 3>(255, 255, 255);
				pSrc++;
				pDst++;
			}
			uint32 nIndex = spriteMap->AddSegment(img);
			ci.coords = spriteMap->GetCoords(nIndex);

			return ci;
		}
Пример #7
0
int main()
{
	// Init GLFW
	glfwInit();
	
	// Create a GLFWwindow object that we can use for GLFW's functions
	Window window = Window(WIDTH, HEIGHT, TITLE);
	window.DefineViewport();

	//glfwSetInputMode(window.getWindowPtr(), GLFW_CURSOR, GLFW_CURSOR_DISABLED);			
	/// ^(Maybe use this later)

	// Callback functions
	glfwSetKeyCallback(window.getWindowPtr() , key_callback);

	// Init GLEW
	glewExperimental = GL_TRUE;
	glewInit();

	// Enable alpha channel transparency
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	// Load and compile shaders to a program
	Shader ShaderProgram = Shader("../deps/shaders/shadervert.vs", "../deps/shaders/shaderfrag.fs");

	// Load explosion graphics
	extern_Explosion.Init(ShaderProgram.GetProgramID());

	// Load texture/Game objects
	Texture2D texture_background1 = Texture2D("../deps/textures/backgroundSpace_01.1.png", PNG_RGB);
	SpriteMap Background = SpriteMap(texture_background1, 1.0f, 1.0f, glm::vec3(0.0f, 0.0f, 0.0f), 1.0f, BACKGROUND);

	Player PlayerShip;
	PlayerShip.Init(moveSpeed);

	Enemy Enemies;
	Enemies.Init();

	// Projection matrix: ortho for 2D
	glm::mat4 proj = glm::ortho(0, window.getWidth(), 0, window.getHeight());


	// Game loop
	while (!window.ShouldClose())
	{
		double startFrame = glfwGetTime();  ///< for FPS limiting

		// Check if any events have been activiated and call callback function (via GLFW)
		glfwPollEvents();

		// Clear the colorbuffer
		glClearColor(0.6f, 0.8f, 0.8f, 1.0f);
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		/*	   Drawing	    */

		ShaderProgram.Use();

		// Background position and drawing calculations - just identity matrix
		glm::mat4 model;
		GLint modelLoc = glGetUniformLocation(ShaderProgram.GetProgramID(), "model");
		glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model));

		Background.BackgroundScroll(scrollSpeed);
		Background.Draw();

		Collision::EnemyHit(&PlayerShip, &Enemies);
		Collision::PlayerHit(&PlayerShip, &Enemies);
		Collision::ShipsCollide(&PlayerShip, &Enemies);

		PlayerShip.Move(keys);
		PlayerShip.AddShots(keys);
		PlayerShip.Draw(ShaderProgram.GetProgramID());
		
		Enemies.Move();
		Enemies.Shoot(PlayerShip.GetPosition());
		Enemies.Draw(ShaderProgram.GetProgramID());

		extern_Explosion.Draw();

		// FPS Calculation/Limiting
		float fps = CalculateFPS();
		static int printFPS = 0;
		if (printFPS == 100) {
			Enemies.Add(EN_0, PlayerShip.GetPosition());
			Enemies.Add(EN_1, PlayerShip.GetPosition());
			std::cout << fps << std::endl;
			printFPS = 0;
		} else {
			printFPS++;
		}
		
		
		LimitFPS(FPS, startFrame);
		
		if (PlayerShip.GetLives() <= 0)
		{
			window.Close();
		}

		// Swap the screen buffers
		window.SwapBuffers();
	}

	Background.Delete();
	PlayerShip.Delete();
	Enemies.DeleteAll();
	extern_Explosion.DeleteAll();

	// Close GLFW
	glfwTerminate();
	return 0;
}