diff options
| author | James Barnett <noreply@jamesbarnett.xyz> | 2020-12-28 16:25:19 +0000 |
|---|---|---|
| committer | James Barnett <noreply@jamesbarnett.xyz> | 2020-12-28 16:25:19 +0000 |
| commit | 9e886b392fbc6f8dfac1ce8f6943a7a1679bce74 (patch) | |
| tree | 81ff992d818b5aa92090b6c02f5685e08bb6fdab /src/main/kotlin/main.kt | |
| parent | f28500d963d6546feda522d7748a0462a568ba28 (diff) | |
| download | kotlin-raycaster-9e886b392fbc6f8dfac1ce8f6943a7a1679bce74.tar.xz kotlin-raycaster-9e886b392fbc6f8dfac1ce8f6943a7a1679bce74.zip | |
Refactor input handling. General cleanup
Diffstat (limited to 'src/main/kotlin/main.kt')
| -rw-r--r-- | src/main/kotlin/main.kt | 47 |
1 files changed, 5 insertions, 42 deletions
diff --git a/src/main/kotlin/main.kt b/src/main/kotlin/main.kt index c07a661..65995e1 100644 --- a/src/main/kotlin/main.kt +++ b/src/main/kotlin/main.kt @@ -1,19 +1,8 @@ -import kotlinx.browser.document - -private const val MOVE_SPEED = 0.5 -private const val ROTATE_SPEED = 5 - -data class RaycastContext( - val renderer: Renderer, - val camera: Camera, - val map: Map, - val minimap: Minimap -) - fun main() { - val renderer = Renderer(640, 480) + val raycaster = Raycaster() + val renderer = Renderer(viewportWidth = 640, viewportHeight = 480) val camera = Camera( - fov = 60, + fov = 90, xPos = 2.0, yPos = 2.0, rotation = 90.0 @@ -23,37 +12,11 @@ fun main() { val context = RaycastContext(renderer, camera, map, minimap) - val raycaster = Raycaster() - - document.onkeydown = { - when (it.code) { - "KeyW" -> { - console.log("key w") - val cameraCos = kotlin.math.cos(toRadians(camera.rotation)) * MOVE_SPEED - val cameraSin = kotlin.math.sin(toRadians(camera.rotation)) * MOVE_SPEED - camera.xPos += cameraCos - camera.yPos += cameraSin - } - "KeyS" -> { - console.log("key s") - val cameraCos = kotlin.math.cos(toRadians(camera.rotation)) * MOVE_SPEED - val cameraSin = kotlin.math.sin(toRadians(camera.rotation)) * MOVE_SPEED - camera.xPos -= cameraCos - camera.yPos -= cameraSin - } - "KeyA" -> { - console.log("key a") - camera.rotation -= ROTATE_SPEED - } - "KeyD" -> { - console.log("key d") - camera.rotation += ROTATE_SPEED - } - } + CameraController(camera, moveSpeed = 0.5, rotateSpeed = 5) { paint(raycaster, context) - console.log("camera x:${camera.xPos} y:${camera.yPos} r: ${camera.rotation}") } + // Do an initial paint and wait for input paint(raycaster, context) } |