123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- #include "common/world/World.h"
- #include "common/world/HighMap.h"
- #include "utils/Random.h"
- World::World(const BlockRegistry& blockRegistry)
- : blockRegistry(blockRegistry), blocks(7, 7), dirty(true) {
- }
- void World::setBlock(int x, int y, int z, const Block& block) {
- blocks.set(x, y, z, block.getId());
- }
- const Block& World::getBlock(int x, int y, int z) const {
- return blockRegistry.getBlock(blocks.get(x, y, z));
- }
- int World::getSize() const {
- return blocks.getSize();
- }
- int World::getHeight() const {
- return blocks.getHeight();
- }
- void World::addPlayer(Player* p) {
- players.add(p);
- }
- void World::preTick() {
- for(Player* p : players) {
- p->lastPosition = p->position;
- p->lastLengthAngle = p->lengthAngle;
- p->lastWidthAngle = p->widthAngle;
- p->acceleration = Vector3(0.0f, -0.5f, 0.0f);
- }
- }
- void World::tick() {
- for(Player* p : players) {
- p->acceleration +=
- Vector3(-p->velocity[0] * 0.7f, 0.0f, -p->velocity[2] * 0.7f);
- p->velocity += p->acceleration;
- p->position += p->velocity;
- int x = p->position[0];
- int y = p->position[1];
- int z = p->position[2];
- while(getBlock(x, y, z).getId() != 0 ||
- getBlock(x - 1, y, z).getId() != 0 ||
- getBlock(x + 1, y, z).getId() != 0 ||
- getBlock(x, y, z - 1).getId() != 0 ||
- getBlock(x, y, z + 1).getId() != 0) {
- y++;
- }
- p->position[1] = y + 1.0f;
- }
- }
|