Ajout de la fonction render au monde
Joueur déplaçable début du cast de rayon Trop fatigué pour faire de la trigo
This commit is contained in:
parent
76306196c0
commit
59939d182b
5 changed files with 117 additions and 4 deletions
66
World.cpp
66
World.cpp
|
@ -5,7 +5,8 @@
|
|||
#include "World.h"
|
||||
|
||||
|
||||
World::World(int w, int h, std::vector<BlockType> worldMap) : w(w), h(h), map(std::move(worldMap))
|
||||
World::World(int w, int h, sf::Color groundColor, sf::Color ceilingColor, std::vector<BlockType> worldMap) : w(w), h(h),
|
||||
groundColor(groundColor), ceilingColor(ceilingColor), map(std::move(worldMap)), player(0,0,0)
|
||||
{
|
||||
map.resize(w*h,BlockType::WALL);
|
||||
}
|
||||
|
@ -51,7 +52,14 @@ std::ostream& operator<<(std::ostream& ostream, World const& world)
|
|||
{
|
||||
case BlockType::AIR:
|
||||
{
|
||||
ostream << " ";
|
||||
if(static_cast<int>(world.player.x) == i%world.w && static_cast<int>(world.player.y) == i/world.h)
|
||||
{
|
||||
ostream << "P";
|
||||
}
|
||||
else
|
||||
{
|
||||
ostream << " ";
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BlockType::WALL:
|
||||
|
@ -73,3 +81,57 @@ std::ostream& operator<<(std::ostream& ostream, World const& world)
|
|||
}
|
||||
return(ostream);
|
||||
}
|
||||
|
||||
void World::fillColumn(sf::RenderWindow& window, int column, float scale, sf::Color wallColor) const
|
||||
{
|
||||
float columnHeight = window.getSize().y*scale;
|
||||
sf::RectangleShape pixelColumn(sf::Vector2f(1,columnHeight));
|
||||
pixelColumn.setPosition(column,(window.getSize().y-columnHeight)/2.0);
|
||||
pixelColumn.setFillColor(wallColor);
|
||||
|
||||
window.draw(pixelColumn);
|
||||
}
|
||||
|
||||
float World::castRay(float originX, float originY, float orientation)
|
||||
{
|
||||
float deltaX;
|
||||
float deltaY;
|
||||
if(orientation < 45 || orientation > 315)
|
||||
{
|
||||
deltaX = ;
|
||||
}
|
||||
else if(orientation < 135)
|
||||
{
|
||||
|
||||
}
|
||||
else if(orientation < 225)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return();
|
||||
}
|
||||
|
||||
void World::render(sf::RenderWindow& window) const
|
||||
{
|
||||
sf::RectangleShape ground = sf::RectangleShape(sf::Vector2f(window.getSize().x,window.getSize().y/2.0));
|
||||
ground.setFillColor(groundColor);
|
||||
ground.setPosition(0,window.getSize().y/2.0);
|
||||
|
||||
sf::RectangleShape ceiling = sf::RectangleShape(sf::Vector2f(window.getSize().x,window.getSize().y/2.0));
|
||||
ceiling.setFillColor(ceilingColor);
|
||||
|
||||
window.draw(ground);
|
||||
window.draw(ceiling);
|
||||
|
||||
for(int i = 0;i<window.getSize().x;i++)
|
||||
{
|
||||
fillColumn(window, i, 0.5);
|
||||
std::cout << i << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue