Skip to content
Snippets Groups Projects
Select Git revision
  • e7884cb24a165915ea84fd44d6e0cbbb587349b5
  • main default protected
  • NIS-Workshop
  • dev_yhe_citymodel
  • dev_jbr_mkr_gui
  • dev_jli_grid_test
  • dev_jgn_gridmodel
  • dev_jgn_buscharging
  • dev_jli_gridmodel
  • dev_jfu_community
  • sce_mobility_district
  • dev_jbr_mkr_updating_pandas
  • dev_market_comp
  • dev_V2X_jfu
  • dev_network_yni
  • dev_nni_prosumer_rh
  • dev_haoyu
  • Landlord-to-Tenant_Study
  • dev_lcoe
  • dev_transfer_V2X
  • dev_jfu_V2X
  • v1.1
22 results

runme.py

Blame
  • main.cpp 1.62 KiB
    #include "core/Engine.hpp"
    #include "core/Spritesheet.hpp"
    #include "core/Window.hpp"
    #include "ui/context/ContextMenu.hpp"
    #include "ui/menu/Menu.hpp"
    
    #include <SDL2/SDL.h>
    #include <SDL_image.h>
    #include <iostream>
    #include <memory>
    #include <stdexcept>
    #include <vector>
    
    using namespace advanced_wars;
    
    int main(int argc, char* argv[])
    {
        if (argc <= 1)
        {
            std::cerr << "Please provide the path to the level that you want to play as a command line "
                         "argument."
                      << std::endl;
            return 1;
        }
    
        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);
    
        Spritesheet spritesheet("res/spritesheet.h5", engine);
    
        engine.setSpritesheet(spritesheet);
    
        std::shared_ptr<Menu>        menu = std::make_shared<Menu>(0, argv[1]);
        std::shared_ptr<ContextMenu> context_menu = std::make_shared<ContextMenu>();
        context_menu->setOptions({"Move", "Info", "Wait"});
    
        std::string basePath = SDL_GetBasePath();
        std::string relativePath = "res/main_background.png";
        std::string fullPath = basePath + relativePath;
        menu->loadBackground(engine, fullPath.c_str());
    
        engine.pushScene(menu);
    
        while (!engine.exited())
        {
            engine.pump();
            engine.render();
        }
    
        return 0;
    }