Advertisement
Guest User

Constructor problem

a guest
Sep 5th, 2015
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.57 KB | None | 0 0
  1. //main.cpp
  2. #include "Core.h"
  3.  
  4. Core core;
  5.  
  6. int main()
  7. {
  8.     core.run();
  9. }
  10.  
  11.  
  12.  
  13. //Core.h
  14. #ifndef CORE_H
  15. #define CORE_H
  16.  
  17. #include <SFML/Graphics.hpp>
  18. #include <iostream>
  19.  
  20. #include "World.h"
  21. #include "WindowManager.h"
  22.  
  23. class Core
  24. {
  25.     public:
  26.         Core();
  27.         void run();
  28.         void getInput();
  29.         void render();
  30.     private:
  31.         WindowManager windowManager;
  32.         World firstMap;
  33. };
  34.  
  35. #endif // CORE_H
  36.  
  37.  
  38.  
  39.  
  40. //Core.cpp
  41. #include "Core.h"
  42.  
  43. Core::Core()
  44. {
  45.     std::cout << "Core constructor" << std::endl;
  46.     firstMap.createWorld();
  47.     windowManager.createWindow();
  48. }
  49.  
  50. void Core::run()
  51. {
  52.     while (windowManager.window.isOpen())
  53.     {
  54.     //This stuff here I cutted out because game loop things are working just perfectly.
  55.     }
  56. }
  57.  
  58.  
  59.  
  60. //World.h
  61. #ifndef WORLD_H
  62. #define WORLD_H
  63.  
  64. #include <SFML/Graphics.hpp>
  65. #include <vector>
  66.  
  67. #include "WindowManager.h"
  68.  
  69. class World
  70. {
  71.     public:
  72.         World();
  73.         void createWorld();
  74.         std::vector<sf::RectangleShape> vecGrassTile;
  75.         std::vector<sf::RectangleShape> vecDirtTile;
  76.     private:
  77.         WindowManager windowManager;
  78.         int tileFullSize;
  79.         sf::Vector2f tileSize;
  80.         sf::RectangleShape grassTile;
  81.         sf::RectangleShape dirtTile;
  82. };
  83.  
  84. #endif // WORLD_H
  85.  
  86.  
  87.  
  88. //World.cpp
  89. #include "World.h"
  90.  
  91. World::World()
  92. {
  93.     std::cout << "World constructor" << std::endl;
  94.     //here i initialize tile stuff, no problem, i cutted it out.
  95. }
  96.  
  97. void World::createWorld()
  98. {
  99.   //here i create world, no problem with it, i cutted it out.
  100. }
  101.  
  102. //WindowManager.h
  103. #ifndef WINDOWMANAGER_H
  104. #define WINDOWMANAGER_H
  105.  
  106. #include <iostream>
  107. #include <SFML/Graphics.hpp>
  108.  
  109. #include "WindowProperties.h"
  110.  
  111. class WindowManager
  112. {
  113.     public:
  114.         WindowManager();
  115.         void createWindow();
  116.         sf::RenderWindow window;
  117.         sf::Vector2i screenDimensions;
  118.         std::string gameTitle;
  119. };
  120.  
  121. #endif // WINDOWMANAGER_H
  122.  
  123.  
  124.  
  125. //WindowManager.cpp
  126. #include "WindowManager.h"
  127.  
  128. WindowManager::WindowManager()
  129. {
  130.     std::cout << "WindowManager constructor" << std::endl;
  131.     screenDimensions.x = 1286; screenDimensions.y = 720;
  132.     gameTitle = "Platformer Game - Alpha v0.1 - Programmed by Hengad";
  133.     std::cout << "Window options(WindowProperties class) initialized successfully" << std::endl;
  134. }
  135.  
  136. void WindowManager::createWindow()
  137. {
  138.     window.create(sf::VideoMode(screenDimensions.x, screenDimensions.y), gameTitle, sf::Style::Close | sf::Style::Titlebar | !sf::Style::Resize);
  139.     std::cout << "Window created successfully" << std::endl;
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement