Browse Source

fix build, change namespace, reorder init

master
noerw 2 years ago
parent
commit
59423478d8
8 changed files with 30 additions and 69 deletions
  1. 2
    0
      .gitignore
  2. 1
    1
      Makefile
  3. 1
    1
      game.cpp
  4. 1
    46
      game.hpp
  5. 19
    18
      main.cpp
  6. 1
    1
      main.hpp
  7. 4
    1
      mainmenu.cpp
  8. 1
    1
      mainmenu.hpp

+ 2
- 0
.gitignore View File

@@ -1,3 +1,5 @@
game

*.dll
*.exe
*.o

+ 1
- 1
Makefile View File

@@ -8,7 +8,7 @@ LDFLAGS = -L "SFML21/lib" -lsfml-system -lsfml-window -lsfml-graphics
# for Windows using MinGW
#LDFLAGS = -L "SFML21/lib" -lmingw32 -lsfml-main -lsfml-system -lsfml-window -lsfml-graphics

OBJ = mainmenu.o main.o
OBJ = game.o mainmenu.o main.o

game: $(OBJ)
$(CC) $(CFLAGS) -o game $(OBJ) $(LDFLAGS)

+ 1
- 1
game.cpp View File

@@ -4,7 +4,7 @@

#include "game.hpp"

namespace Game {
namespace Proto4 {

bool Game::init() {
return true;

+ 1
- 46
game.hpp View File

@@ -7,7 +7,7 @@

#pragma once

namespace Game {
namespace Proto4 {
enum class GameState { Uninitialized, Running, Paused, Finished };

class Game : public sf::Drawable, public sf::Transformable {
@@ -29,49 +29,4 @@ namespace Game {
uint32_t score = 0;

};

bool Game::init() {
return true;
}

AppState Game::update(sf::RenderWindow &window, sf::Time timestep) {
sf::Event event;

while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed) {
window.close();
} else if (event.type == sf::Event::Resized) {
// resize the views, so everything is still displayed
// proportionally
//view.setSize(event.size.width, event.size.height);
//view.setCenter(event.size.width / 2, event.size.height / 2);
} else if (event.type == sf::Event::KeyPressed) {
if (event.key.code == sf::Keyboard::Q)
return AppState::MainMenu;
}
}

return AppState::Game;
}

void Game::draw(sf::RenderTarget &window, sf::RenderStates states) const {
}

bool Game::start() {
return true;
}

bool Game::pause() {
return true;
}

bool Game::resume() {
return true;
}

bool Game::reset() {
return true;
}


}

+ 19
- 18
main.cpp View File

@@ -9,7 +9,7 @@
#include "mainmenu.hpp"
#include "game.hpp"

namespace Game {
namespace Proto4 {

// because we want to create the objects in init(), we use the default
// constructor, so nothing can go wrong here
@@ -21,18 +21,29 @@ namespace Game {

bool init() {

sf::ContextSettings settings;
if (!font.loadFromFile("Audiowide-Regular.ttf")) {
std::cout << "Unable to load font. Aborting execution.";
return false;
}

if (
!menu.init(font) ||
!game.init()
) {
return false;
}

// set antialising for shapes
// this doesnt affect textures
// (requires sf::Texture::setSmooth() )
sf::ContextSettings settings;
settings.antialiasingLevel = 4;

// open window after everything has loaded to avoid
// 'window not responding' warning
window.create(sf::VideoMode(xResolution, yResolution, colorDepth),
gameTitle, sf::Style::Default, settings);
window.setPosition(sf::Vector2i(0, 0));

// hide mouse cursor
window.setMouseCursorVisible(false);

if (!window.isOpen()) {
@@ -40,18 +51,6 @@ namespace Game {
return false;
}

if (!font.loadFromFile("Audiowide-Regular.ttf")) {
std::cout << "Unable to load font. Aborting execution.";
return false;
}

if (
!menu.init(font) ||
!game.init()
) {
return false;
}

return true;
}

@@ -100,6 +99,8 @@ namespace Game {

void mainloop() {

// draw as often as possible and
// update multiple times with a fixed timestep as needed
sf::Clock clock;
sf::Time previousTime = sf::milliseconds(0);
sf::Time lagTime = sf::milliseconds(0);
@@ -120,7 +121,7 @@ namespace Game {
}

int main() {
if (!Game::init()) return 1;
Game::mainloop();
if (!Proto4::init()) return 1;
Proto4::mainloop();
return 0;
}

+ 1
- 1
main.hpp View File

@@ -5,7 +5,7 @@

#pragma once

namespace Game {
namespace Proto4 {

enum class AppState { Game, MainMenu, Exit };


+ 4
- 1
mainmenu.cpp View File

@@ -5,7 +5,10 @@
#include "main.hpp"
#include "mainmenu.hpp"

namespace Game {
namespace Proto4 {

// IDEA: implement Menu superclass, which has a sf::Text title, vector<MenuAction> actions, and implements updating and drawing?
// eg. struct MenuAction { sf::Keyboard key, String text, AppState transition }

bool MainMenu::init(sf::Font &font) {
font = font;

+ 1
- 1
mainmenu.hpp View File

@@ -6,7 +6,7 @@

#include "main.hpp"

namespace Game {
namespace Proto4 {

class MainMenu : public sf::Drawable, public sf::Transformable {
public:

Loading…
Cancel
Save