Skip to content

Commit

Permalink
apply lightLevel to entities
Browse files Browse the repository at this point in the history
  • Loading branch information
j0code committed Feb 5, 2024
1 parent 5c512c4 commit be68c01
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/entity/Entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,15 @@ export default class Entity {
if (this.position.y < world.minY - 50) this.die(world)
}

draw(g: Graphics) {
draw(g: Graphics, world: World) {
const block = world.getBlock(this.position.x, this.position.y, this.position.z)
const light = block?.lightLevel ?? 15

g.save()
g.translate(this.x, this.y)
g.translate(-this.size.x/2, 0) // to center (x)

g.brightness(light / 15)
this.texture?.draw(g, this.size.x, this.size.y)

g.restore()
Expand Down
2 changes: 1 addition & 1 deletion src/world/World.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export default class World {
for (let z = this.minZ; z <= this.maxZ; z++) {
if (z == 0) { // draw entities behind blocks (e.g. water)
for (let entity of this.getAllEntities()) {
entity.draw(g)
entity.draw(g, this)
}
}
for (let y = this.minY; y <= this.maxY; y++) {
Expand Down

0 comments on commit be68c01

Please sign in to comment.