Browse Source

a bit more lighting

fix/style
Martin Dørum 3 years ago
parent
commit
86952836a5

+ 13
- 12
core.mod/src/entities/PlayerEntity.cc View File

@@ -39,18 +39,6 @@ void PlayerEntity::update(const Swan::Context &ctx, float dt) {
}
}

Swan::Vec2 headPos = body_.topMid() + Swan::Vec2(0, 0.5);
Swan::TilePos tilePos = Swan::Vec2i(floor(headPos.x), floor(headPos.y));
if (!placed_light_) {
ctx.plane.addLight(tilePos, LIGHT_LEVEL);
placed_light_ = true;
light_tile_ = tilePos;
} else if (tilePos != light_tile_) {
ctx.plane.removeLight(light_tile_, LIGHT_LEVEL);
ctx.plane.addLight(tilePos, LIGHT_LEVEL);
light_tile_ = tilePos;
}

// Move left
if (ctx.game.isKeyPressed(SDL_SCANCODE_A) || ctx.game.isKeyPressed(SDL_SCANCODE_LEFT)) {
physics_.force += Swan::Vec2(-MOVE_FORCE, 0);
@@ -82,6 +70,19 @@ void PlayerEntity::update(const Swan::Context &ctx, float dt) {
anims_[(int)state_].tick(dt);

physics(ctx, dt, { .mass = MASS });

// Do this after moving so that it's not behind
Swan::Vec2 headPos = body_.topMid() + Swan::Vec2(0, 0.5);
Swan::TilePos tilePos = Swan::Vec2i(floor(headPos.x), floor(headPos.y));
if (!placed_light_) {
ctx.plane.addLight(tilePos, LIGHT_LEVEL);
placed_light_ = true;
light_tile_ = tilePos;
} else if (tilePos != light_tile_) {
ctx.plane.removeLight(light_tile_, LIGHT_LEVEL);
ctx.plane.addLight(tilePos, LIGHT_LEVEL);
light_tile_ = tilePos;
}
}

void PlayerEntity::tick(const Swan::Context &ctx, float dt) {

+ 1
- 1
core.mod/src/entities/PlayerEntity.h View File

@@ -24,7 +24,7 @@ private:
static constexpr float JUMP_VEL = 11;
static constexpr float DOWN_FORCE = 20 * MASS;
static constexpr Swan::Vec2 SIZE = Swan::Vec2(0.6, 1.9);
static constexpr int LIGHT_LEVEL = 8;
static constexpr int LIGHT_LEVEL = 30;

enum class State {
IDLE,

+ 1
- 1
libswan/src/LightServer.cc View File

@@ -309,7 +309,7 @@ void LightServer::processChunkLights(LightChunk &chunk, ChunkPos cpos) {
std::min((int)round(light), 255);

if (light > 0 && chunk.blocks[y * CHUNK_WIDTH + x]) {
chunk.bounces.emplace_back(base + Vec2i(x, y), light);
chunk.bounces.emplace_back(base + Vec2i(x, y), light * 0.1);
}
}
}

Loading…
Cancel
Save