void Boid::Trace(Texture* entityTexture, SDL_Renderer* renderer, int step) { // Keep current alpha and change it to step by step Uint8 alphaOld = Texture_GetAlpha(entityTexture); Uint8 alphaInit = 80; Uint8 alphaDelta = alphaInit / step; Uint8 alphaToUse = alphaInit - alphaDelta; // In/Out params to modify Vector2D stepPosition = position; Vector2D stepSpeed = speed; int stepAngle = 0; for (int i = 0; i < step; ++i) { // Simulate Step SimulateUpdate(1 / 60.0f, stepPosition, stepSpeed, stepAngle, target->position); // Update Alpha Texture_SetAlpha(entityTexture, alphaToUse); alphaToUse -= alphaDelta; // Render Simulation Texture_Render(entityTexture, renderer, (int)stepPosition.x - (width * scaleX) / 2, (int)stepPosition.y - (height * scaleY) / 2, nullptr, scaleX, scaleY, stepAngle); } // Restore Alpha Texture_SetAlpha(entityTexture, alphaOld); }
Action MainMenu_Show(MainMenu *m, Container *container) { Action ret; while (1) { Container_Refresh(container); /* Check if mouse clicked and if over a menu texture */ if (Container_MouseClickedButton(container, m->buttons.start)) { /* Mouse clicked start button */ ret = START; break; } if (Container_MouseClickedButton(container, m->buttons.quit)) { /* Mouse clicked quit button */ ret = QUIT; break; } Texture_Render(m->background, container->renderer, 0, 0, NULL); Texture_Render(m->buttons.start.texture, container->renderer, m->buttons.start.renderRect.x, m->buttons.start.renderRect.y, NULL); Texture_Render(m->buttons.quit.texture, container->renderer, m->buttons.quit.renderRect.x, m->buttons.quit.renderRect.y, NULL); } return ret; }
void BitmapFont_RenderText(BitmapFont* bitmapFont, SDL_Renderer* renderer, int x, int y, std::string text) { //If the font has been built if( bitmapFont->bitmap != NULL ) { //Temp offsets int curX = x, curY = y; //Go through the text for( int i = 0; i < (int)text.length(); ++i ) { //If the current character is a space if( text[ i ] == ' ' ) { //Move over curX += bitmapFont->space; } //If the current character is a newline else if( text[ i ] == '\n' ) { //Move down curY += bitmapFont->newLine; //Move back curX = x; } else { //Get the ASCII value of the character int ascii = (unsigned char)text[ i ]; //Show the character Texture_Render(bitmapFont->bitmap, renderer, curX, curY, &bitmapFont->chars[ ascii ] ); //Move over the width of the character with one pixel of padding curX += bitmapFont->chars[ ascii ].w + 1; } } } }
//Render every object in the world void World_Render(World *w, unsigned int dt, Container *container) { /* Render the background first */ Texture_Render(w->background.still, container->renderer, 0, 0, NULL); /* Render all of the objects */ for (int i = 0; i < w->ObjectTypeCount; i++) { for (int o = 0; o < w->ObjectTypes[i]->instance_count; o++) { /* Render the object */ ObjectType_RenderObject(w->ObjectTypes[i], o, dt, container); } } for (int i = 0; i < w->goalpost->instance_count; i++) { ObjectType_RenderObject(w->goalpost, i, dt, container); } /* Render all of the characters/enemies */ for (int i = 0; i < 3; i++) { for (int e = 0; e < w->EnemyTypes[i]->object_type->instance_count; e++) { /* Render the enemy */ CharacterType_RenderCharacter(w->EnemyTypes[i], e, dt, container); } } Player_Render(w->player, dt, container); }
void PathWorldState::Render() { FC_DrawAlign(fontSmall, display->renderer, 0, 0, FC_ALIGN_LEFT, (char*)" > Press 'R' to start or restart"); Grid_Render(&labyrinth, display->renderer, origin, Colors::CARROT); StaticTexture_Render(&graphTexture, display->renderer, 0, 0); for (int i = 0; i < labyrinth.width; ++i) { for (int j = 0; j < labyrinth.height; ++j) { int currentWeight = labyrinth.array[i][j].weight; Uint32 colorToUse; switch (currentWeight) { case 0: colorToUse = Colors::SUNFLOWER; break; case 1: colorToUse = Colors::NEPHRITIS; break; case 2: colorToUse = Colors::GREEN_SEA; break; case 3: colorToUse = Colors::ASBESTOS; break; case 4: colorToUse = Colors::ORANGE; break; case 5: colorToUse = Colors::ALIZARIN; break; } if (algorithm == AlgorithmEnum::BFS_FLOOD) { if (visited[i][j] == true) { colorToUse = Colors::POMEGRANATE; } } boxColor(display->renderer, origin.x + i * labyrinth.cellSize, origin.y + j * labyrinth.cellSize, origin.x + i * labyrinth.cellSize + labyrinth.cellSize, origin.y + j * labyrinth.cellSize + labyrinth.cellSize, colorToUse); if (labyrinth.array[i][j].cameFrom != nullptr) { int fromDirection = Node_GetDirection(&labyrinth.array[i][j], labyrinth.array[i][j].cameFrom); float angleToRender = 0.0f; switch (fromDirection) { case 0: angleToRender = 0.0f; break; case 1: angleToRender = 90.0f; break; case 2: angleToRender = 180.0f; break; case 3: angleToRender = 270.0f; break; case 4: angleToRender = 45.0f; break; case 5: angleToRender = 135.0f; break; case 6: angleToRender = 225.0f; break; case 7: angleToRender = 315.0f; break; } Texture_Render(&arrowTexture, display->renderer, origin.x + i * labyrinth.cellSize + labyrinth.cellSize / 4, origin.y + j * labyrinth.cellSize + labyrinth.cellSize / 4, nullptr, 1.0f, 1.0f, angleToRender); } if (labyrinth.array[i][j].isWall == true) { boxColor(display->renderer, origin.x + i * labyrinth.cellSize, origin.y + j * labyrinth.cellSize, origin.x + i * labyrinth.cellSize + labyrinth.cellSize, origin.y + j * labyrinth.cellSize + labyrinth.cellSize, Colors::WHITE); } if (i == currentX && j == currentY && doStart == true) { boxColor(display->renderer, origin.x + i * labyrinth.cellSize, origin.y + j * labyrinth.cellSize, origin.x + i * labyrinth.cellSize + labyrinth.cellSize, origin.y + j * labyrinth.cellSize + labyrinth.cellSize, Colors::MIDNIGHT_BLUE); } if (i == startX && j == startY) { boxColor(display->renderer, origin.x + i * labyrinth.cellSize, origin.y + j * labyrinth.cellSize, origin.x + i * labyrinth.cellSize + labyrinth.cellSize, origin.y + j * labyrinth.cellSize + labyrinth.cellSize, Colors::POMEGRANATE); } if (algorithm != AlgorithmEnum::BFS_FLOOD && algorithm != AlgorithmEnum::BFS_PATH && algorithm != AlgorithmEnum::A_STAR_MULTIPLE) { if (i == endX && j == endY) { boxColor(display->renderer, origin.x + i * labyrinth.cellSize, origin.y + j * labyrinth.cellSize, origin.x + i * labyrinth.cellSize + labyrinth.cellSize, origin.y + j * labyrinth.cellSize + labyrinth.cellSize, Colors::WISTERIA); } } } } hero.Render(&heroTexture, display->renderer); minotaur.Render(&boidTexture, display->renderer); }