Skip to content
Snippets Groups Projects
Select Git revision
  • 624e114bd3b626925bf5bcdbaf50722dfda8af39
  • main default protected
  • leveleditor
  • david-author
  • clang-tidy-cleanup
  • architecture-refactoring
  • cleanUpMenus
  • doxygen-cleanup
  • project-structure-refactoring
  • interpolation
  • buildingFeatures
  • win_end_screen
  • helpMenu
  • leveleditor-placement
  • text-rendering
  • updated_unit_contextmenu
  • level-from-commandline
  • unit_contextmenu
  • player
  • engine-scaling
  • clang-tidy
21 results

main.cpp

Blame
  • main.cpp 2.95 KiB
    #include "building.hpp"
    #include "effect.hpp"
    #include "engine.hpp"
    #include "level.hpp"
    #include "spritesheet.hpp"
    #include "tile.hpp"
    #include "unit.hpp"
    #include "window.hpp"
    #include <cstddef>
    #include <vector>
    #include <SDL2/SDL.h>
    #include <SDL_image.h>
    #include <stdexcept>
    
    using namespace advanced_wars;
    
    int main() {
    
      if (SDL_Init(SDL_INIT_VIDEO) < 0) {
        throw std::runtime_error("SDL could not initialize: " +
                                 std::string(SDL_GetError()));
      }
    
      int imgFlags = IMG_INIT_PNG;
      if (!(IMG_Init(imgFlags) & imgFlags)) {
        throw std::runtime_error(
            "SDL_image could not initialize! SDL_image Error: " +
            std::string(IMG_GetError()));
      }
    
      Window window("Advanced Wars", 960, 960);
    
      Engine engine(window);
    
      // Construct a level
      std::vector<Tile> tiles;
      for (int y = 0; y < 20; y++) {
        for (int x = 0; x < 20; x++) {
          tiles.push_back(Tile(TileId::PLAIN, x, y));
        }
      }
    
      // Fill the edges with water
      for (size_t n = 0; n < 20; n++) {
        // Vertical
        tiles.at(n * 20) = Tile(TileId::WATER, 0, n);
        tiles.at(n * 20 + 19) = Tile(TileId::WATER, 19, n);
        // Horizontal
        tiles.at(n) = Tile(TileId::WATER, n, 0);
        tiles.at(19 * 20 + n) = Tile(TileId::WATER, n, 19);
      }
    
      // Make the edges cliffs
      for (size_t n = 1; n < 19; n++) {
        // Vertical
        tiles.at(n * 20 + 1) = Tile(TileId::CLIFF_RIGHT, 1, n);
        tiles.at(n * 20 + 18) = Tile(TileId::CLIFF_LEFT, 18, n);
    
        // Horizontal
        tiles.at(20 + n) = Tile(TileId::CLIFF_BOTTOM, n, 1);
        tiles.at(18 * 20 + n) = Tile(TileId::CLIFF_TOP, n, 18);
      }
    
      // Fix the corners
      tiles.at(20 + 1) = Tile(TileId::CLIFF_CORNER_TOP_LEFT, 1, 1);
      tiles.at(20 + 18) = Tile(TileId::CLIFF_CORNER_TOP_RIGHT, 18, 1);
      tiles.at(18 * 20 + 1) = Tile(TileId::CLIFF_CORNER_BOTTOM_LEFT, 1, 18);
      tiles.at(18 * 20 + 18) = Tile(TileId::CLIFF_CORNER_BOTTOM_RIGHT, 18, 18);
    
      // Buildings