aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/Minimap.kt
diff options
context:
space:
mode:
authorJames Barnett <noreply@jamesbarnett.xyz>2020-12-30 14:38:34 +0000
committerJames Barnett <noreply@jamesbarnett.xyz>2020-12-30 14:38:34 +0000
commit83b0b4cb19d7f0137cde962ee81a900baf2bd953 (patch)
tree838204167415de676190a1534767497f084e7a7b /src/main/kotlin/Minimap.kt
parentad192fe7068081ed88f8616581bf450d601e99b1 (diff)
downloadkotlin-raycaster-83b0b4cb19d7f0137cde962ee81a900baf2bd953.tar.xz
kotlin-raycaster-83b0b4cb19d7f0137cde962ee81a900baf2bd953.zip
Add switchable texture sets. Fix minimap
Diffstat (limited to 'src/main/kotlin/Minimap.kt')
-rw-r--r--src/main/kotlin/Minimap.kt12
1 files changed, 5 insertions, 7 deletions
diff --git a/src/main/kotlin/Minimap.kt b/src/main/kotlin/Minimap.kt
index eb762ab..34862e0 100644
--- a/src/main/kotlin/Minimap.kt
+++ b/src/main/kotlin/Minimap.kt
@@ -3,15 +3,13 @@ import org.w3c.dom.CanvasRenderingContext2D
import org.w3c.dom.HTMLCanvasElement
class Minimap(private val map: Map) {
- private val scale = 30
+ private val scale = 20
private val canvas = (document.createElement("canvas") as HTMLCanvasElement)
.apply {
width = map.width * scale
height = map.height * scale
id = "minimap"
- style.width = "${width}px"
- style.height = "${height}px"
}
private val context = canvas.getContext("2d") as CanvasRenderingContext2D
@@ -21,7 +19,7 @@ class Minimap(private val map: Map) {
private fun drawMap() {
for (y in 0 until map.height) {
- for (x in 0 until map.height) {
+ for (x in 0 until map.width) {
val wall = map.data[y][x]
if (wall > 0) {
context.fillStyle = "#000000"
@@ -35,15 +33,15 @@ class Minimap(private val map: Map) {
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())
+ context.fillRect((camera.xPos * scale)-5, (camera.yPos * scale)-5, 10.0, 10.0)
context.strokeStyle = "#00FF00"
context.lineWidth = 2.0
context.beginPath()
context.moveTo(camera.xPos * scale, camera.yPos * scale)
- val cameraCos = kotlin.math.cos(toRadians(camera.rotation)) * 4
- val cameraSin = kotlin.math.sin(toRadians(camera.rotation)) * 4
+ val cameraCos = kotlin.math.cos(toRadians(camera.rotation))
+ val cameraSin = kotlin.math.sin(toRadians(camera.rotation))
val dirX = camera.xPos + cameraCos
val dirY = camera.yPos + cameraSin