First commit, world map creation
This commit is contained in:
commit
76306196c0
7 changed files with 176 additions and 0 deletions
75
World.cpp
Normal file
75
World.cpp
Normal file
|
@ -0,0 +1,75 @@
|
|||
//
|
||||
// Created by trotfunky on 27/05/19.
|
||||
//
|
||||
|
||||
#include "World.h"
|
||||
|
||||
|
||||
World::World(int w, int h, std::vector<BlockType> worldMap) : w(w), h(h), map(std::move(worldMap))
|
||||
{
|
||||
map.resize(w*h,BlockType::WALL);
|
||||
}
|
||||
|
||||
int World::getW() const
|
||||
{
|
||||
return w;
|
||||
}
|
||||
|
||||
int World::getH() const
|
||||
{
|
||||
return h;
|
||||
}
|
||||
|
||||
BlockType World::getBlock(float x, float y) const
|
||||
{
|
||||
return(map.at(static_cast<int>(x)+w* static_cast<int>(y)));
|
||||
}
|
||||
|
||||
void World::setBlock(BlockType block, int x, int y, int width, int height)
|
||||
{
|
||||
for(int i = 0;i<height;i++)
|
||||
{
|
||||
for(int j = 0;j<width;j++)
|
||||
{
|
||||
if(x+j<w && y+i < h)
|
||||
{
|
||||
map.at((y+i)*w+x+j) = block;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& ostream, World const& world)
|
||||
{
|
||||
for(int i = 0;i<world.w*world.h;i++)
|
||||
{
|
||||
if(i%world.w == 0)
|
||||
{
|
||||
ostream << std::endl;
|
||||
}
|
||||
switch(world.getBlock(i%world.w,i/world.w))
|
||||
{
|
||||
case BlockType::AIR:
|
||||
{
|
||||
ostream << " ";
|
||||
break;
|
||||
}
|
||||
case BlockType::WALL:
|
||||
{
|
||||
ostream << "W";
|
||||
break;
|
||||
}
|
||||
case BlockType::DOOR:
|
||||
{
|
||||
ostream << "D";
|
||||
break;
|
||||
}
|
||||
case BlockType::WINDOW:
|
||||
{
|
||||
ostream << "W";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return(ostream);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue