void Unit::draw(TerrainObject *loc, graphic_set *grpc) { // there should always be a location assert(loc != nullptr); auto top_action = this->top(); auto &draw_pos = loc->pos.draw; auto draw_graphic = top_action->type(); if (!grpc || grpc->count(draw_graphic) == 0) { this->log(MSG(warn) << "Graphic not available"); return; } // the texture to draw with auto draw_texture = grpc->at(draw_graphic); if (!draw_texture) { this->log(MSG(warn) << "Graphic null"); return; } // frame specified by the current action auto draw_frame = top_action->current_frame(); // players color if available unsigned color = 0; if (this->has_attribute(attr_type::owner)) { auto &own_attr = this->get_attribute<attr_type::owner>(); color = own_attr.player.color; } // check if object has a direction if (this->has_attribute(attr_type::direction)) { // directional textures auto &d_attr = this->get_attribute<attr_type::direction>(); coord::phys3_delta draw_dir = d_attr.unit_dir; draw_texture->draw(draw_pos.to_camgame(), draw_dir, draw_frame, color); if (grpc->count(graphic_type::shadow) > 0) { auto unit_shadow = grpc->at(graphic_type::shadow); if (unit_shadow) { // position without height component coord::phys3 shadow_pos = draw_pos; shadow_pos.up = 0; unit_shadow->draw(shadow_pos.to_camgame(), draw_dir, draw_frame, color); } } } else { draw_texture->draw(draw_pos.to_camgame(), draw_frame, color); } top_action->draw_debug(); }
void draw_screen() { SDL_BlitSurface(map_surface, NULL, screen, &mapRect); //SDL_FillRect(info_surface, 0, 0xffff0000); //SDL_FillRect(score_surface, 0, 0xff00ff00); //SDL_BlitSurface(score_surface, NULL, info_surface, &scoreRect); SDL_BlitSurface(info_surface, NULL, screen, &infoRect); //SDL_BlitSurface(map_overlay, NULL, screen, 0); draw_debug(); SDL_Flip(screen); }
void render() { glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0f, 0.0f, 0.0f); calculate_field_size(); draw_food(); draw_ants(); if (grid) draw_grid(); calculate_fps(); if (debug) { draw_debug(); } glutSwapBuffers(); }