A 2D tile-based sandbox game.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Game.cc 733B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include "Game.h"
  2. #include <dlfcn.h>
  3. #include <math.h>
  4. #include <time.h>
  5. #include <memory>
  6. #include "Tile.h"
  7. #include "Win.h"
  8. namespace Swan {
  9. void Game::createWorld(const std::string &worldgen) {
  10. world_.reset(new World(this, time(NULL)));
  11. world_->setWorldGen(worldgen);
  12. world_->setCurrentPlane(world_->addPlane());
  13. world_->spawnPlayer();
  14. }
  15. TilePos Game::getMouseTile() {
  16. auto mousePos = getMousePos();
  17. return TilePos(
  18. (int)floor(win_.cam_.x + mousePos.x / (Swan::TILE_SIZE * win_.scale_)),
  19. (int)floor(win_.cam_.y + mousePos.y / (Swan::TILE_SIZE * win_.scale_)));
  20. }
  21. void Game::draw() {
  22. world_->draw(win_);
  23. }
  24. void Game::update(float dt) {
  25. world_->update(dt);
  26. }
  27. void Game::tick(float dt) {
  28. world_->tick(dt);
  29. }
  30. }