diff options
| author | Freya Murphy <freya@freyacat.org> | 2026-03-26 23:15:33 -0400 |
|---|---|---|
| committer | Freya Murphy <freya@freyacat.org> | 2026-03-27 23:09:23 -0400 |
| commit | f8322cd21cde68a72b05efbad3a05b8e67c0bdd0 (patch) | |
| tree | d7e60bc8fedadc8fa7ae725571cad1f398eaf6dc /core/src/world/Position.kt | |
| download | kenshinshideandseek2-f8322cd21cde68a72b05efbad3a05b8e67c0bdd0.tar.gz kenshinshideandseek2-f8322cd21cde68a72b05efbad3a05b8e67c0bdd0.tar.bz2 kenshinshideandseek2-f8322cd21cde68a72b05efbad3a05b8e67c0bdd0.zip | |
initial
Diffstat (limited to 'core/src/world/Position.kt')
| -rw-r--r-- | core/src/world/Position.kt | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/core/src/world/Position.kt b/core/src/world/Position.kt new file mode 100644 index 0000000..daea3ab --- /dev/null +++ b/core/src/world/Position.kt @@ -0,0 +1,54 @@ +package cat.freya.khs.world + +import cat.freya.khs.config.LegacyPosition +import cat.freya.khs.player.Player +import kotlin.math.pow +import kotlin.math.sqrt + +data class Position(var x: Double = 0.0, var y: Double = 0.0, var z: Double = 0.0) { + + /// Create a new position of self + offset + fun move(offset: Position): Position { + return Position(this.x + offset.x, this.y + offset.y, this.z + offset.z) + } + + /// Translate self by offset + fun moveSelf(offset: Position) { + this.x += offset.x + this.y += offset.y + this.z += offset.z + } + + /// Create a new position of self.x + offset + fun moveX(offset: Double): Position { + return this.move(Position(offset, 0.0, 0.0)) + } + + /// Create a new position of self.y + offset + fun moveY(offset: Double): Position { + return this.move(Position(0.0, offset, 0.0)) + } + + /// Create a new position of self.z + offset + fun moveZ(offset: Double): Position { + return this.move(Position(0.0, 0.0, offset)) + } + + fun distance(other: Position): Double { + val dx = this.x - other.x + val dy = this.y - other.y + val dz = this.z - other.z + val distanceSquared = dx.pow(2) + dy.pow(2) + dz.pow(2) + return sqrt(distanceSquared) + } + + fun teleport(player: Player) { + player.teleport(this) + } + + fun withWorld(worldName: String): Location { + return Location(this.x, this.y, this.z, worldName) + } + + fun toLegacy(): LegacyPosition = LegacyPosition(x, y, z, null) +} |