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.

WGDefault.cc 884B

1234567891011121314151617181920212223242526
  1. #include "WGDefault.h"
  2. void WGDefault::genChunk(Swan::WorldPlane &plane, Swan::Chunk &chunk) {
  3. int height = perlin_.octaveNoise0_1(chunk.pos_.x_ / (64.0 / 16), 8) * 10;
  4. int depth = perlin_.octaveNoise0_1(chunk.pos_.x_ / (64.0 / 9), 5) * 10 + 10;
  5. for (int cx = 0; cx < Swan::CHUNK_WIDTH; ++cx) {
  6. for (int cy = 0; cy < Swan::CHUNK_HEIGHT; ++cy) {
  7. Swan::TilePos tpos = Swan::TilePos(cx, cy) + Swan::TilePos(
  8. chunk.pos_.x_ * Swan::CHUNK_WIDTH, chunk.pos_.y_ * Swan::CHUNK_HEIGHT);
  9. if (tpos.y_ == height)
  10. chunk.tiles_[cx][cy] = tGrass_;
  11. else if (tpos.y_ > height && tpos.y_ <= depth)
  12. chunk.tiles_[cx][cy] = tDirt_;
  13. else if (tpos.y_ > depth)
  14. chunk.tiles_[cx][cy] = tStone_;
  15. else
  16. chunk.tiles_[cx][cy] = tAir_;
  17. }
  18. }
  19. }
  20. Swan::Entity &WGDefault::spawnPlayer(Swan::WorldPlane &plane) {
  21. return plane.spawnEntity("core::player", Swan::Vec2(0, 0));
  22. }