From 52a261de58458a03ce4fff92a9ceee3eb65d8ed6 Mon Sep 17 00:00:00 2001 From: trotFunky Date: Mon, 27 May 2019 13:50:49 +0200 Subject: [PATCH] First commit, world map creation --- .gitignore | 2 ++ CMakeLists.txt | 18 ++++++++++++ Player.cpp | 10 +++++++ Player.h | 21 ++++++++++++++ World.cpp | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++ World.h | 36 ++++++++++++++++++++++++ main.cpp | 14 ++++++++++ 7 files changed, 176 insertions(+) create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 Player.cpp create mode 100644 Player.h create mode 100644 World.cpp create mode 100644 World.h create mode 100644 main.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..696c0c1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +**/cmake-build-* +**/.idea/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..caf14ed --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,18 @@ +cmake_minimum_required(VERSION 3.14) +project(raycasting) + +set(CMAKE_CXX_STANDARD 14) + +# Detect and add SFML +set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules" ${CMAKE_MODULE_PATH}) +find_package(SFML COMPONENTS system window graphics network audio REQUIRED) + +if(NOT SFML_FOUND) + message(FATAL_ERROR "SFML could not be found") +endif() + +add_executable(raycasting main.cpp Player.cpp Player.h World.cpp World.h) + +target_link_libraries(raycasting + sfml-window + sfml-graphics) \ No newline at end of file diff --git a/Player.cpp b/Player.cpp new file mode 100644 index 0000000..7a8196d --- /dev/null +++ b/Player.cpp @@ -0,0 +1,10 @@ +// +// Created by trotfunky on 27/05/19. +// + +#include "Player.h" + + +Player::Player(float x, float y, float alpha) : x(x), y(y), orientation(alpha) +{} + diff --git a/Player.h b/Player.h new file mode 100644 index 0000000..8063e66 --- /dev/null +++ b/Player.h @@ -0,0 +1,21 @@ +// +// Created by trotfunky on 27/05/19. +// + +#ifndef RAYCASTING_PLAYER_H +#define RAYCASTING_PLAYER_H + + +class Player { +public: + Player(float x, float y, float alpha); + + float x; + float y; + float orientation; + + static constexpr float fov = 70; +}; + + +#endif //RAYCASTING_PLAYER_H diff --git a/World.cpp b/World.cpp new file mode 100644 index 0000000..30738b5 --- /dev/null +++ b/World.cpp @@ -0,0 +1,75 @@ +// +// Created by trotfunky on 27/05/19. +// + +#include "World.h" + + +World::World(int w, int h, std::vector 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(x)+w* static_cast(y))); +} + +void World::setBlock(BlockType block, int x, int y, int width, int height) +{ + for(int i = 0;i +#include + +enum class BlockType { + AIR, + WALL, + DOOR, + WINDOW, +}; + +class World { +public: + World(int w, int h, std::vector worldMap = {}); + + int getW() const; + int getH() const; + + BlockType getBlock(float x, float y) const; + void setBlock(BlockType block, int x, int y, int width = 1, int height = 1); + + friend std::ostream& operator<<(std::ostream& ostream, World const & world); +private: + int w; + int h; + std::vector map; +}; + + +#endif //RAYCASTING_WORLD_H diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..3689d6d --- /dev/null +++ b/main.cpp @@ -0,0 +1,14 @@ +#include +#include "SFML/Graphics.hpp" + +#include "World.h" + +int main() +{ + std::cout << "Hello, World!" << std::endl; + World world(10,10); + world.setBlock(BlockType::AIR,1,1,8,8); + world.setBlock(BlockType::WALL,4,4,2,2); + std::cout << world << std::endl; + return 0; +} \ No newline at end of file