Implemented border for splitscreen view
This commit is contained in:
parent
4ecc53abb3
commit
77dc2f0ceb
8 changed files with 135 additions and 16 deletions
|
@ -98,7 +98,7 @@ set(SOURCES
|
|||
src/levels.hpp
|
||||
src/sprites/tiling/tilemap.cpp
|
||||
src/sprites/tiling/tilemap.hpp
|
||||
src/sprites/tiling/tilemap_config.hpp src/sprites/tiling/tileset_config.hpp src/sprites/tiling/tileset.cpp src/sprites/tiling/tileset.hpp src/game/frame_counter.cpp src/game/frame_counter.hpp src/game/level/level_renderer.cpp src/game/level/level_renderer.hpp src/sprites/skymap/skymap.cpp src/sprites/skymap/skymap.hpp src/game/camera/multiplayer_view.cpp src/game/camera/multiplayer_view.hpp)
|
||||
src/sprites/tiling/tilemap_config.hpp src/sprites/tiling/tileset_config.hpp src/sprites/tiling/tileset.cpp src/sprites/tiling/tileset.hpp src/game/frame_counter.cpp src/game/frame_counter.hpp src/game/level/level_renderer.cpp src/game/level/level_renderer.hpp src/sprites/skymap/skymap.cpp src/sprites/skymap/skymap.hpp src/game/camera/multiplayer_view.cpp src/game/camera/multiplayer_view.hpp src/game/camera/multiplayer_borders.cpp src/game/camera/multiplayer_borders.hpp)
|
||||
|
||||
set(PHYSICS_00_SOURCES
|
||||
src/prototypes/physics_00.cpp)
|
||||
|
|
27
TODO.md
27
TODO.md
|
@ -2,26 +2,25 @@
|
|||
|
||||
## Next
|
||||
|
||||
- [ ] Split screen
|
||||
- Mutliplayer viewports wrong aspect ratio
|
||||
|
||||
## Bugs
|
||||
|
||||
- [ ] Player spawns initially at (0,0) and almost fails to jump to target spawn
|
||||
- [ ] Mutliplayer viewports wrong aspect ratio
|
||||
- [ ] Player disconnect in multiplayer sometimes targetting disconnected player or something like that
|
||||
- Player spawns initially at (0,0) and almost fails to jump to target spawn
|
||||
- Player disconnect in multiplayer sometimes targeting disconnected player or something like that
|
||||
|
||||
## High priority
|
||||
|
||||
- [ ] Procedural level generation
|
||||
- [ ] Physics
|
||||
- [ ] Damage other players on contact
|
||||
- [ ] Menu (At least before the game starts a player-join-screen)
|
||||
- [ ] Game over screen
|
||||
- [ ] Score
|
||||
- [ ] Proper player graphics
|
||||
- [ ] Collectables with graphics
|
||||
- Procedural level generation
|
||||
- Physics
|
||||
- Damage other players on contact
|
||||
- Menu (At least before the game starts a player-join-screen)
|
||||
- Game over screen
|
||||
- Score
|
||||
- Proper player graphics
|
||||
- Collectables with graphics
|
||||
|
||||
## Low priority
|
||||
|
||||
- [ ] Player actions like shrinking hole or throwing bomb
|
||||
- [ ] Sound
|
||||
- Player actions like shrinking hole or throwing bomb
|
||||
- Sound
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#define DEF_TV_VIEW_SIZE_PADDING sf::Vector2f(0.5f, 0.5f)
|
||||
#define MP_VIEW_ADD_NEW_PLAYERS true
|
||||
#define MP_VIEW_REMOVE_DISCONNECTED_PLAYERS true
|
||||
#define MP_VIEW_BORDER_COLOR sf::Color::Black
|
||||
|
||||
// Simulations
|
||||
#define MAPSIM_WALL_THICKNESS 3.f
|
||||
|
|
65
src/game/camera/multiplayer_borders.cpp
Normal file
65
src/game/camera/multiplayer_borders.cpp
Normal file
|
@ -0,0 +1,65 @@
|
|||
#include <SFML/Graphics/VertexArray.hpp>
|
||||
#include "multiplayer_borders.hpp"
|
||||
#include "../../config.h"
|
||||
|
||||
MultiplayerBorders::MultiplayerBorders(int firstRowViewCount, int secondRowViewCount)
|
||||
: view(new sf::View(sf::Vector2f(0.5f, 0.5f), sf::Vector2f(1, 1)))
|
||||
{
|
||||
createBorders(firstRowViewCount, secondRowViewCount);
|
||||
}
|
||||
|
||||
void MultiplayerBorders::createBorders(int firstRowViewCount, int secondRowViewCount)
|
||||
{
|
||||
int lineCount = firstRowViewCount + secondRowViewCount - 1;
|
||||
if (lineCount <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
lines = sf::VertexArray(sf::Lines, lineCount * 2);
|
||||
float lineHeight = secondRowViewCount > 0 ? 0.5f : 1.f;
|
||||
|
||||
// First row
|
||||
int firstRowLineCount = firstRowViewCount - 1;
|
||||
createRowOfLines(0, firstRowLineCount, 0, lineHeight);
|
||||
|
||||
if (secondRowViewCount <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Horizontal separator
|
||||
createLine(firstRowLineCount,
|
||||
{0, lineHeight},
|
||||
{1, lineHeight});
|
||||
|
||||
// Second row
|
||||
int secondRowLineCount = secondRowViewCount - 1;
|
||||
createRowOfLines(firstRowLineCount + 1, secondRowLineCount, lineHeight, lineHeight);
|
||||
}
|
||||
|
||||
void MultiplayerBorders::draw(sf::RenderWindow *window)
|
||||
{
|
||||
window->setView(*view);
|
||||
window->draw(lines);
|
||||
}
|
||||
|
||||
void MultiplayerBorders::createRowOfLines(int startIndex, int count, float topOffset, float height)
|
||||
{
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
float horizontalProgress = (float) (i + 1) / (float) (count + 1);
|
||||
createLine(startIndex + i,
|
||||
{horizontalProgress, topOffset},
|
||||
{horizontalProgress, topOffset + height});
|
||||
}
|
||||
}
|
||||
|
||||
void MultiplayerBorders::createLine(int lineIndex, sf::Vector2f firstPoint, sf::Vector2f secondPoint)
|
||||
{
|
||||
lines[lineIndex * 2].position = firstPoint;
|
||||
lines[lineIndex * 2 + 1].position = secondPoint;
|
||||
|
||||
lines[lineIndex * 2].color = MP_VIEW_BORDER_COLOR;
|
||||
lines[lineIndex * 2 + 1].color = MP_VIEW_BORDER_COLOR;
|
||||
}
|
26
src/game/camera/multiplayer_borders.hpp
Normal file
26
src/game/camera/multiplayer_borders.hpp
Normal file
|
@ -0,0 +1,26 @@
|
|||
#ifndef HOLESOME_MULTIPLAYER_BORDERS_HPP
|
||||
#define HOLESOME_MULTIPLAYER_BORDERS_HPP
|
||||
|
||||
|
||||
#include "../game_object.h"
|
||||
|
||||
class MultiplayerBorders : public GameObject
|
||||
{
|
||||
public:
|
||||
explicit MultiplayerBorders(int firstRowViewCount = 0, int secondRowViewCount = 0);
|
||||
|
||||
void draw(sf::RenderWindow *window) override;
|
||||
|
||||
void createBorders(int firstRowViewCount, int secondRowViewCount = 0);
|
||||
|
||||
private:
|
||||
sf::VertexArray lines{};
|
||||
sf::View* view = nullptr;
|
||||
|
||||
void createRowOfLines(int startIndex, int count, float topOffset, float height);
|
||||
|
||||
void createLine(int lineIndex, sf::Vector2f firstPoint, sf::Vector2f secondPoint);
|
||||
};
|
||||
|
||||
|
||||
#endif //HOLESOME_MULTIPLAYER_BORDERS_HPP
|
|
@ -97,12 +97,18 @@ void MultiplayerView::updateLayout() const
|
|||
it->second->setViewport({0, 0}, {0.5, 1});
|
||||
it++;
|
||||
it->second->setViewport({0.5, 0}, {0.5, 1});
|
||||
|
||||
borders->createBorders(2);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Calculate layout
|
||||
int firstRowViewCount = ceil(viewCount / 2.f);
|
||||
int secondRowViewCount = viewCount - firstRowViewCount;
|
||||
|
||||
borders->createBorders(firstRowViewCount, secondRowViewCount);
|
||||
|
||||
int index = 0;
|
||||
for (auto &view: getViews())
|
||||
{
|
||||
|
@ -132,3 +138,17 @@ std::vector<std::shared_ptr<TrackingView>> MultiplayerView::getViews() const
|
|||
}
|
||||
return views;
|
||||
}
|
||||
|
||||
void MultiplayerView::draw(sf::RenderWindow *window)
|
||||
{
|
||||
if (borders != nullptr)
|
||||
{
|
||||
borders->draw(window);
|
||||
}
|
||||
}
|
||||
|
||||
MultiplayerView::MultiplayerView()
|
||||
: borders(std::make_shared<MultiplayerBorders>()), viewsForPlayers({})
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -6,13 +6,16 @@
|
|||
#include "../game_object.h"
|
||||
#include "tracking_view.h"
|
||||
#include "../player/player.hpp"
|
||||
#include "multiplayer_borders.hpp"
|
||||
|
||||
class MultiplayerView : public GameObject
|
||||
{
|
||||
public:
|
||||
static std::shared_ptr<MultiplayerView> getInstance();
|
||||
|
||||
MultiplayerView() = default;
|
||||
MultiplayerView();
|
||||
|
||||
void draw(sf::RenderWindow *window) override;
|
||||
|
||||
void update() override;
|
||||
|
||||
|
@ -27,6 +30,8 @@ private:
|
|||
|
||||
std::map<int, std::shared_ptr<TrackingView>> viewsForPlayers; // Player ID => View
|
||||
void updateLayout() const;
|
||||
|
||||
std::shared_ptr<MultiplayerBorders> borders;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -9,4 +9,7 @@ void LevelRenderer::draw(sf::RenderWindow *window)
|
|||
view->setViewForWindow();
|
||||
GameObject::draw(window);
|
||||
}
|
||||
|
||||
// Render borders between views
|
||||
MultiplayerView::getInstance()->draw(window);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue