void GraphicsMap::Draw() { ScreenGame->clear(); // First draw the map objects onto the graphical map for (int x = 0; x < MapWidth; x++) for (int y = 0; y < MapHeight; y++) { if (FOVMap.map[x][y]) DrawDisplayTile(x, y, ToDraw->GetMapCell(x,y)->GetTile(), ScreenGame); else DrawDisplayTile(x, y, DisplayTile(' ', TCODColor::black, TCODColor::black), ScreenGame); } // Draw the items to the graphical map for (unsigned int i = 0; i < (ToDraw->Items.size()); i++) { // Get the item from the map Item* itm = ToDraw->Items[i]; // If it's in the FOV, draw it if (FOVMap.map[itm->GetX()][itm->GetY()]) DrawDisplayTile(itm->GetX(), itm->GetY(), itm->GetTile(), ScreenGame); else DrawDisplayTile(itm->GetX(), itm->GetY(), DisplayTile(' ', TCODColor::black, TCODColor::black), ScreenGame); } // Draw the beings to the graphical map for (unsigned int i = 0; i < (ToDraw->Beings.size()); i++) { // Get the being from the map Being* b = ToDraw->Beings[i]; if (FOVMap.map[b->GetX()][b->GetY()]) DrawDisplayTile(b->GetX(), b->GetY(), b->GetTile(), ScreenGame); else DrawDisplayTile(b->GetX(), b->GetY(), DisplayTile(' ', TCODColor::black, TCODColor::black), ScreenGame); } }
void GraphicsManager::Draw(EntityManager* entity_manager) { // Check for new renderable entities TODO // Get all renderable components vector<IComponent*> renderable_components = entity_manager->GetAllComponentsOfType(COMP_RENDER); int i = 0; // Iterate through the object components for (vector<IComponent*>::iterator it = renderable_components.begin(); it != renderable_components.end(); ++it) { RenderComponent* renderableComponent = (RenderComponent*)(*it); SpriteDefinition spriteDef = GetSpriteDefinition(renderableComponent->_id); int x = renderableComponent->_position.x; int y = renderableComponent->_position.y; if (x < 0) x = 511 + x; if (y < 0) y = 255 + y; SetObject(i, (spriteDef.shape << 14) | ATTR0_Y(y) | ATTR0_8BPP | ATTR0_AFF, ATTR1_SIZE(spriteDef.size) | ATTR1_X(x) | ATTR1_AFF(0), ATTR2_PALBANK(0) | ATTR2_ID4(spriteDef.char_bb_identifier)); ObjAffine* renderAffine = &( (ObjAffine*) ObjBuffer)[0]; //float theta = (float)(++player.angleDegrees % 360) * (M_PI/180); float angle = (float)(renderableComponent->_angleDegrees % 360) * (M_PI / 180); renderAffine->pa = float2fx( cos(angle) ); renderAffine->pb = float2fx( -sin(angle) ); renderAffine->pc = float2fx( sin(angle) ); renderAffine->pd = float2fx( cos(angle) ); ++i; } UpdateObjects(); // Get all background components vector<IComponent*> background_components = entity_manager->GetAllComponentsOfType(COMP_BACKGROUND); // Iterate through the background components for (vector<IComponent*>::iterator it = background_components.begin(); it != background_components.end(); ++it) { BackgroundComponent* backgroundComponent = (BackgroundComponent*)(*it); // Scroll background if (backgroundComponent->_background_id == BG_PIPES) { REG_BG1HOFS = backgroundComponent->_integer_position.x; } // Update tiles if (backgroundComponent->_background_id == BG_PIPES || backgroundComponent->_background_id == BG_SCORE) { for (int x = 0; x < 32; x++) { for (int y = 0; y < 32; y++) { DisplayTile(x, y, backgroundComponent->_tiles[x][y], backgroundComponent->_screen_bb); } } } if (backgroundComponent->_update_screen) { for (int x = 0; x < 32; x++) { for (int y = 0; y < 32; y++) { DisplayTile(x, y, backgroundComponent->_tiles[x][y], backgroundComponent->_screen_bb); } } backgroundComponent->_update_screen = false; } } }