mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-11 19:34:03 +01:00
feat: Reworking folder structures, adding world.hpp and world.cpp and world constructor
This commit is contained in:
parent
5d2ec62f08
commit
0bbdbbb221
27
SFMLEngine/makingAGameTick/Classes/Other/world.cpp
Normal file
27
SFMLEngine/makingAGameTick/Classes/Other/world.cpp
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#ifndef WORLD_CPP // ZA WARUDO
|
||||||
|
#define WORLD_CPP
|
||||||
|
|
||||||
|
World::World(sf::RenderWindow& window)
|
||||||
|
: mWindow(window)
|
||||||
|
, mWorldView(window.getDefaultView())
|
||||||
|
, mWorldBounds
|
||||||
|
(
|
||||||
|
WORLD_LEFT_X_POSITION,
|
||||||
|
WORLD_TOP_Y_POSITION,
|
||||||
|
mWorldView.getSize().x,
|
||||||
|
WORLD_HEIGHT
|
||||||
|
)
|
||||||
|
, mSpawnPosition
|
||||||
|
(
|
||||||
|
mWorldView.getSize().x / 2.f,
|
||||||
|
mWorldBounds.height - mWorldView.getSize().y
|
||||||
|
)
|
||||||
|
, mScrollSpeed ( WORLD_SCROLL_SPEED )
|
||||||
|
, mPlayerAircraft(nullptr)
|
||||||
|
{
|
||||||
|
// loadTextures();
|
||||||
|
// buildScene();
|
||||||
|
// mWorldView.setCenter(mSpawnPosition);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // WORLD_CPP
|
||||||
42
SFMLEngine/makingAGameTick/Classes/Other/world.hpp
Normal file
42
SFMLEngine/makingAGameTick/Classes/Other/world.hpp
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
#ifndef WORLD_HPP // ZA WARUDO
|
||||||
|
#define WORLD_HPP
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include "../SceneNodeDerrivatives/SceneNode.hpp"
|
||||||
|
#include "../SceneNodeDerrivatives/aircraft.hpp"
|
||||||
|
|
||||||
|
class World : private sf::NonCopyable // We only have one world and we do not want to copy it #StopClimateChange amiright
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit World(sf::RenderWindow& window);
|
||||||
|
void update(sf::Time deltaTime);
|
||||||
|
void draw();
|
||||||
|
private:
|
||||||
|
void loadTextures();
|
||||||
|
void buildScene();
|
||||||
|
|
||||||
|
private:
|
||||||
|
enum Layer
|
||||||
|
{
|
||||||
|
Background,
|
||||||
|
Air,
|
||||||
|
LayerCount
|
||||||
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
|
sf::RenderWindow& mWindow; // reference to the render window
|
||||||
|
sf::View mWorldView; // current world's view
|
||||||
|
TextureHolder mTextures; // All the textures needed inside the world
|
||||||
|
SceneNode mSceneGraph;
|
||||||
|
std::array<SceneNode*, LayerCount> mSceneLayers; // Pointers to access the scene graph's layerr nodes
|
||||||
|
|
||||||
|
sf::FloatRect mWorldBounds; // Bounding rectangle of the world
|
||||||
|
sf::Vector2f mSpawnPosition; // Where player plane appears in the beginning
|
||||||
|
float mScrollSpeed; // Speed with which the world is scrolled
|
||||||
|
Aircraft* mPlayerAircraft; // Pointer to player aircraft
|
||||||
|
};
|
||||||
|
|
||||||
|
// std::array is a class template for fixed size static arrays, same functionality, performance as C arrays but allows copies, assignment, passing or returning objects from the function, additional safety and usefull methods like size(), begin() or end()
|
||||||
|
|
||||||
|
#include "world.cpp"
|
||||||
|
#endif // WORLD_HPP
|
||||||
Binary file not shown.
@ -25,4 +25,11 @@ const sf::Time TIME_PER_FRAME = sf::seconds(1.f / 60.f); // 1 frame is 1 / 60 of
|
|||||||
// Error strings
|
// Error strings
|
||||||
const std::string TEXTURE_LOAD_ERROR = "TextureHolder::load - Failed to load ";
|
const std::string TEXTURE_LOAD_ERROR = "TextureHolder::load - Failed to load ";
|
||||||
|
|
||||||
|
// World constants
|
||||||
|
const float WORLD_LEFT_X_POSITION = 0;
|
||||||
|
const float WORLD_TOP_Y_POSITION = 0;
|
||||||
|
// const float WORLD_WIDTH = 0; by default mWorldView.getSize().x
|
||||||
|
const float WORLD_HEIGHT = 2000;
|
||||||
|
const float WORLD_SCROLL_SPEED = -1;
|
||||||
|
|
||||||
#endif // CONSTANTS_HPP
|
#endif // CONSTANTS_HPP
|
||||||
|
|||||||
@ -4,16 +4,18 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <SFML/Graphics.hpp>
|
#include <SFML/Graphics.hpp>
|
||||||
#include "constants.hpp"
|
#include "constants.hpp"
|
||||||
#include "resources.hpp"
|
#include "./Classes/Other/resources.hpp"
|
||||||
#include "SceneNode.hpp"
|
#include "./Classes/Other/world.hpp"
|
||||||
#include "SpriteNode.hpp"
|
#include "./Classes/SceneNodeDerrivatives/SceneNode.hpp"
|
||||||
#include "entity.hpp"
|
#include "./Classes/SceneNodeDerrivatives/SpriteNode.hpp"
|
||||||
#include "aircraft.hpp"
|
#include "./Classes/SceneNodeDerrivatives/entity.hpp"
|
||||||
|
#include "./Classes/SceneNodeDerrivatives/aircraft.hpp"
|
||||||
#include "basic.cpp"
|
#include "basic.cpp"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Game
|
class Game
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|||||||
Binary file not shown.
@ -1,5 +0,0 @@
|
|||||||
#ifndef WORLD_CPP // ZA WARUDO
|
|
||||||
#define WORLD_CPP
|
|
||||||
|
|
||||||
|
|
||||||
#endif WORLD_CPP
|
|
||||||
@ -1,7 +0,0 @@
|
|||||||
#ifndef WORLD_HPP // ZA WARUDO
|
|
||||||
#define WORLD_HPP
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "world.cpp"
|
|
||||||
#endif WORLD_HPP
|
|
||||||
Loading…
Reference in New Issue
Block a user