hax::Level* hax::initNewGame(){ //create objects Level* test = new Level(); Area* borg = new Castle("Hogwarts"); Area* kth = new School("KTH"); Area* skog = new Forest("FoReSt Of DoOm"); Area* tysk = new Shop("IKEA"); Character* albus = new Wizard("Albus"); Character* voldy = new Wizard("Voldy"); Character* conan = new Barbarian("Conan"); Character* snape = new Wizard("Snape"); Character* necro = new Necromancer("Sauron"); Key* nyckel = new Key(); Container* sack = new Backpack(); //build level test->add(borg); test->add(kth); test->add(skog); test->add(tysk); test->add(albus); test->add(voldy); test->add(conan); test->add(necro); borg->addRoute(new Road("north", borg, kth)); borg->addRoute(new Road("west", borg, skog)); kth->addRoute(new Road("south", kth, borg)); kth->addRoute(new Door("southwest", kth, skog, nyckel)); kth->addRoute(new Door("in", kth, tysk)); skog->addRoute(new Road("east", skog, borg, new Tree())); skog->addRoute(new Road("northeast", skog, kth, snape)); tysk->addRoute(new Door("out", tysk, kth)); //add Character to Area borg->enter(albus); borg->enter(necro); kth->enter(conan); kth->enter(voldy); //add Object to Area kth->pick_up(nyckel); borg->pick_up(sack); //add Object to Character return test; };
int main(int argc, char ** argv) { try { // game engine subsystems Graphics graphics; Level level; Time time; // load level level.setLevel(graphics.load("levels/mountains.bmp")); level.setBackground(graphics.load("levels/summer_sky.bmp")); auto player1 = Ship(); auto player2 = Ship(Player::Two); player1.setSpawn(Point(50, 250)); player1.respawn(); player2.setSpawn(Point(100, 250)); player2.respawn(); player1.setImage(graphics.load("ships/ship2.bmp")); player2.setImage(graphics.load("ships/ship3.bmp")); level.add(player1); level.add(player2); // rendering loop bool quit{ false }; while(!quit) { // calculate framerate int frameTime = time.frame(); int fps = (int)round(1000.f / frameTime); Input::Event e; do { // handle input e = Input::nextInput(); if(e == Input::QUIT) quit = true; level.notify(e); } while(e != Input::NO_EVENT); graphics.clear(); level.update(frameTime); level.draw(graphics); graphics.draw(std::to_string(fps) + " fps", Point(25, graphics.getHeight() - 20.f)); graphics.present(); } } catch(std::exception e) { return EXIT_FAILURE; // error return code } return EXIT_SUCCESS; // normal program exit }