aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/Minimap.kt
diff options
context:
space:
mode:
authorJames Barnett <noreply@jamesbarnett.xyz>2020-12-28 15:49:23 +0000
committerJames Barnett <noreply@jamesbarnett.xyz>2020-12-28 15:49:23 +0000
commitf28500d963d6546feda522d7748a0462a568ba28 (patch)
tree0240d3528277930b28790c336ed10d77ea8928e1 /src/main/kotlin/Minimap.kt
parent01727649bb1fbe3e0c721a850bd21973d7e760f2 (diff)
downloadkotlin-raycaster-f28500d963d6546feda522d7748a0462a568ba28.tar.xz
kotlin-raycaster-f28500d963d6546feda522d7748a0462a568ba28.zip
Refactor components
Diffstat (limited to 'src/main/kotlin/Minimap.kt')
-rw-r--r--src/main/kotlin/Minimap.kt17
1 files changed, 7 insertions, 10 deletions
diff --git a/src/main/kotlin/Minimap.kt b/src/main/kotlin/Minimap.kt
index dc7cc91..eb762ab 100644
--- a/src/main/kotlin/Minimap.kt
+++ b/src/main/kotlin/Minimap.kt
@@ -2,16 +2,13 @@ import kotlinx.browser.document
import org.w3c.dom.CanvasRenderingContext2D
import org.w3c.dom.HTMLCanvasElement
-class Minimap(private val map: List<List<Int>>) {
-
+class Minimap(private val map: Map) {
private val scale = 30
- private val mapWidth = map[0].size
- private val mapHeight = map.size
private val canvas = (document.createElement("canvas") as HTMLCanvasElement)
.apply {
- width = mapWidth * scale
- height = mapHeight * scale
+ width = map.width * scale
+ height = map.height * scale
id = "minimap"
style.width = "${width}px"
style.height = "${height}px"
@@ -23,9 +20,9 @@ class Minimap(private val map: List<List<Int>>) {
}
private fun drawMap() {
- for (y in 0 until mapHeight) {
- for (x in 0 until mapWidth) {
- val wall = map[y][x]
+ for (y in 0 until map.height) {
+ for (x in 0 until map.height) {
+ val wall = map.data[y][x]
if (wall > 0) {
context.fillStyle = "#000000"
context.fillRect((x * scale).toDouble(), (y * scale).toDouble(), scale.toDouble(), scale.toDouble())
@@ -35,7 +32,7 @@ class Minimap(private val map: List<List<Int>>) {
}
fun update(camera: Camera) {
- context.clearRect(0.0, 0.0, (mapWidth * scale).toDouble(), (mapHeight * scale).toDouble())
+ context.clearRect(0.0, 0.0, (map.width * scale).toDouble(), (map.height * scale).toDouble())
drawMap()
context.fillStyle = "#FF0000"
context.fillRect(camera.xPos * scale, camera.yPos * scale, scale.toDouble(), scale.toDouble())