diff --git a/.idea/modules/kudens.iml b/.idea/modules/kudens.iml index 59b1a92..1a18df3 100644 --- a/.idea/modules/kudens.iml +++ b/.idea/modules/kudens.iml @@ -2,31 +2,12 @@ - - - + + + + diff --git a/.idea/modules/kudens.iml b/.idea/modules/kudens.iml index 59b1a92..1a18df3 100644 --- a/.idea/modules/kudens.iml +++ b/.idea/modules/kudens.iml @@ -2,31 +2,12 @@ - - - + + + + diff --git a/.idea/modules/kudens_main.iml b/.idea/modules/kudens_main.iml index 1ee6f69..0c9cf9b 100644 --- a/.idea/modules/kudens_main.iml +++ b/.idea/modules/kudens_main.iml @@ -2,70 +2,29 @@ - - - + + + + + + + diff --git a/.idea/modules/kudens.iml b/.idea/modules/kudens.iml index 59b1a92..1a18df3 100644 --- a/.idea/modules/kudens.iml +++ b/.idea/modules/kudens.iml @@ -2,31 +2,12 @@ - - - + + + + diff --git a/.idea/modules/kudens_main.iml b/.idea/modules/kudens_main.iml index 1ee6f69..0c9cf9b 100644 --- a/.idea/modules/kudens_main.iml +++ b/.idea/modules/kudens_main.iml @@ -2,70 +2,29 @@ - - - + + + + + + + diff --git a/.idea/modules/kudens_test.iml b/.idea/modules/kudens_test.iml index f6b4473..8282556 100644 --- a/.idea/modules/kudens_test.iml +++ b/.idea/modules/kudens_test.iml @@ -2,70 +2,29 @@ - - - + + + + + + + diff --git a/.idea/modules/kudens.iml b/.idea/modules/kudens.iml index 59b1a92..1a18df3 100644 --- a/.idea/modules/kudens.iml +++ b/.idea/modules/kudens.iml @@ -2,31 +2,12 @@ - - - + + + + diff --git a/.idea/modules/kudens_main.iml b/.idea/modules/kudens_main.iml index 1ee6f69..0c9cf9b 100644 --- a/.idea/modules/kudens_main.iml +++ b/.idea/modules/kudens_main.iml @@ -2,70 +2,29 @@ - - - + + + + + + + diff --git a/.idea/modules/kudens_test.iml b/.idea/modules/kudens_test.iml index f6b4473..8282556 100644 --- a/.idea/modules/kudens_test.iml +++ b/.idea/modules/kudens_test.iml @@ -2,70 +2,29 @@ - - - + + + + + + + diff --git a/src/main/kotlin/games/perses/game/Game.kt b/src/main/kotlin/games/perses/game/Game.kt index 544b6e9..d563e44 100644 --- a/src/main/kotlin/games/perses/game/Game.kt +++ b/src/main/kotlin/games/perses/game/Game.kt @@ -45,8 +45,8 @@ webglcanvas = webGlCanvas.getContext("experimental-webgl") } - if (webglcanvas is WebGLRenderingContext) { - webgl = webglcanvas + if (webglcanvas != null) { + webgl = webglcanvas as WebGLRenderingContext } else { console.log("webgl?", webglcanvas) window.alert("Your browser doesn't seem to support webgl!") @@ -54,8 +54,8 @@ throw IllegalStateException("Your browser doesn't seem to support webgl!") } - if (canvas2dcanvas is CanvasRenderingContext2D) { - canvas2d = canvas2dcanvas + if (canvas2dcanvas != null) { + canvas2d = canvas2dcanvas as CanvasRenderingContext2D } else { console.log("canvas2d?", canvas2dcanvas) window.alert("Your browser doesn't seem to support 2d canvas!") diff --git a/.idea/modules/kudens.iml b/.idea/modules/kudens.iml index 59b1a92..1a18df3 100644 --- a/.idea/modules/kudens.iml +++ b/.idea/modules/kudens.iml @@ -2,31 +2,12 @@ - - - + + + + diff --git a/.idea/modules/kudens_main.iml b/.idea/modules/kudens_main.iml index 1ee6f69..0c9cf9b 100644 --- a/.idea/modules/kudens_main.iml +++ b/.idea/modules/kudens_main.iml @@ -2,70 +2,29 @@ - - - + + + + + + + diff --git a/.idea/modules/kudens_test.iml b/.idea/modules/kudens_test.iml index f6b4473..8282556 100644 --- a/.idea/modules/kudens_test.iml +++ b/.idea/modules/kudens_test.iml @@ -2,70 +2,29 @@ - - - + + + + + + + diff --git a/src/main/kotlin/games/perses/game/Game.kt b/src/main/kotlin/games/perses/game/Game.kt index 544b6e9..d563e44 100644 --- a/src/main/kotlin/games/perses/game/Game.kt +++ b/src/main/kotlin/games/perses/game/Game.kt @@ -45,8 +45,8 @@ webglcanvas = webGlCanvas.getContext("experimental-webgl") } - if (webglcanvas is WebGLRenderingContext) { - webgl = webglcanvas + if (webglcanvas != null) { + webgl = webglcanvas as WebGLRenderingContext } else { console.log("webgl?", webglcanvas) window.alert("Your browser doesn't seem to support webgl!") @@ -54,8 +54,8 @@ throw IllegalStateException("Your browser doesn't seem to support webgl!") } - if (canvas2dcanvas is CanvasRenderingContext2D) { - canvas2d = canvas2dcanvas + if (canvas2dcanvas != null) { + canvas2d = canvas2dcanvas as CanvasRenderingContext2D } else { console.log("canvas2d?", canvas2dcanvas) window.alert("Your browser doesn't seem to support 2d canvas!") diff --git a/src/main/kotlin/games/perses/input/Keys.kt b/src/main/kotlin/games/perses/input/Keys.kt index 1860155..d293d43 100644 --- a/src/main/kotlin/games/perses/input/Keys.kt +++ b/src/main/kotlin/games/perses/input/Keys.kt @@ -15,6 +15,7 @@ */ enum class KeyCode(val keyCode: Int) { + ESC(27), LEFT(37), UP(38), DOWN(40), diff --git a/.idea/modules/kudens.iml b/.idea/modules/kudens.iml index 59b1a92..1a18df3 100644 --- a/.idea/modules/kudens.iml +++ b/.idea/modules/kudens.iml @@ -2,31 +2,12 @@ - - - + + + + diff --git a/.idea/modules/kudens_main.iml b/.idea/modules/kudens_main.iml index 1ee6f69..0c9cf9b 100644 --- a/.idea/modules/kudens_main.iml +++ b/.idea/modules/kudens_main.iml @@ -2,70 +2,29 @@ - - - + + + + + + + diff --git a/.idea/modules/kudens_test.iml b/.idea/modules/kudens_test.iml index f6b4473..8282556 100644 --- a/.idea/modules/kudens_test.iml +++ b/.idea/modules/kudens_test.iml @@ -2,70 +2,29 @@ - - - + + + + + + + diff --git a/src/main/kotlin/games/perses/game/Game.kt b/src/main/kotlin/games/perses/game/Game.kt index 544b6e9..d563e44 100644 --- a/src/main/kotlin/games/perses/game/Game.kt +++ b/src/main/kotlin/games/perses/game/Game.kt @@ -45,8 +45,8 @@ webglcanvas = webGlCanvas.getContext("experimental-webgl") } - if (webglcanvas is WebGLRenderingContext) { - webgl = webglcanvas + if (webglcanvas != null) { + webgl = webglcanvas as WebGLRenderingContext } else { console.log("webgl?", webglcanvas) window.alert("Your browser doesn't seem to support webgl!") @@ -54,8 +54,8 @@ throw IllegalStateException("Your browser doesn't seem to support webgl!") } - if (canvas2dcanvas is CanvasRenderingContext2D) { - canvas2d = canvas2dcanvas + if (canvas2dcanvas != null) { + canvas2d = canvas2dcanvas as CanvasRenderingContext2D } else { console.log("canvas2d?", canvas2dcanvas) window.alert("Your browser doesn't seem to support 2d canvas!") diff --git a/src/main/kotlin/games/perses/input/Keys.kt b/src/main/kotlin/games/perses/input/Keys.kt index 1860155..d293d43 100644 --- a/src/main/kotlin/games/perses/input/Keys.kt +++ b/src/main/kotlin/games/perses/input/Keys.kt @@ -15,6 +15,7 @@ */ enum class KeyCode(val keyCode: Int) { + ESC(27), LEFT(37), UP(38), DOWN(40), diff --git a/src/main/kotlin/games/perses/shader/ShaderProgramMesh.kt b/src/main/kotlin/games/perses/shader/ShaderProgramMesh.kt index 36356bd..eb4203f 100644 --- a/src/main/kotlin/games/perses/shader/ShaderProgramMesh.kt +++ b/src/main/kotlin/games/perses/shader/ShaderProgramMesh.kt @@ -27,7 +27,7 @@ init { attribBuffer = webgl.createBuffer() ?: throw IllegalStateException("Unable to create webgl buffer!") - webgl.bindBuffer(WebGLRenderingContext.ARRAY_BUFFER, attribBuffer); + webgl.bindBuffer(WebGLRenderingContext.ARRAY_BUFFER, attribBuffer) } fun queue(vararg vertices: Float) { diff --git a/.idea/modules/kudens.iml b/.idea/modules/kudens.iml index 59b1a92..1a18df3 100644 --- a/.idea/modules/kudens.iml +++ b/.idea/modules/kudens.iml @@ -2,31 +2,12 @@ - - - + + + + diff --git a/.idea/modules/kudens_main.iml b/.idea/modules/kudens_main.iml index 1ee6f69..0c9cf9b 100644 --- a/.idea/modules/kudens_main.iml +++ b/.idea/modules/kudens_main.iml @@ -2,70 +2,29 @@ - - - + + + + + + + diff --git a/.idea/modules/kudens_test.iml b/.idea/modules/kudens_test.iml index f6b4473..8282556 100644 --- a/.idea/modules/kudens_test.iml +++ b/.idea/modules/kudens_test.iml @@ -2,70 +2,29 @@ - - - + + + + + + + diff --git a/src/main/kotlin/games/perses/game/Game.kt b/src/main/kotlin/games/perses/game/Game.kt index 544b6e9..d563e44 100644 --- a/src/main/kotlin/games/perses/game/Game.kt +++ b/src/main/kotlin/games/perses/game/Game.kt @@ -45,8 +45,8 @@ webglcanvas = webGlCanvas.getContext("experimental-webgl") } - if (webglcanvas is WebGLRenderingContext) { - webgl = webglcanvas + if (webglcanvas != null) { + webgl = webglcanvas as WebGLRenderingContext } else { console.log("webgl?", webglcanvas) window.alert("Your browser doesn't seem to support webgl!") @@ -54,8 +54,8 @@ throw IllegalStateException("Your browser doesn't seem to support webgl!") } - if (canvas2dcanvas is CanvasRenderingContext2D) { - canvas2d = canvas2dcanvas + if (canvas2dcanvas != null) { + canvas2d = canvas2dcanvas as CanvasRenderingContext2D } else { console.log("canvas2d?", canvas2dcanvas) window.alert("Your browser doesn't seem to support 2d canvas!") diff --git a/src/main/kotlin/games/perses/input/Keys.kt b/src/main/kotlin/games/perses/input/Keys.kt index 1860155..d293d43 100644 --- a/src/main/kotlin/games/perses/input/Keys.kt +++ b/src/main/kotlin/games/perses/input/Keys.kt @@ -15,6 +15,7 @@ */ enum class KeyCode(val keyCode: Int) { + ESC(27), LEFT(37), UP(38), DOWN(40), diff --git a/src/main/kotlin/games/perses/shader/ShaderProgramMesh.kt b/src/main/kotlin/games/perses/shader/ShaderProgramMesh.kt index 36356bd..eb4203f 100644 --- a/src/main/kotlin/games/perses/shader/ShaderProgramMesh.kt +++ b/src/main/kotlin/games/perses/shader/ShaderProgramMesh.kt @@ -27,7 +27,7 @@ init { attribBuffer = webgl.createBuffer() ?: throw IllegalStateException("Unable to create webgl buffer!") - webgl.bindBuffer(WebGLRenderingContext.ARRAY_BUFFER, attribBuffer); + webgl.bindBuffer(WebGLRenderingContext.ARRAY_BUFFER, attribBuffer) } fun queue(vararg vertices: Float) { diff --git a/src/main/kotlin/games/perses/texture/Textures.kt b/src/main/kotlin/games/perses/texture/Textures.kt index 7be77ef..79c43b1 100644 --- a/src/main/kotlin/games/perses/texture/Textures.kt +++ b/src/main/kotlin/games/perses/texture/Textures.kt @@ -18,6 +18,7 @@ * Date: 17-4-16 * Time: 14:52 */ + //language=GLSL private val vertexShaderSource = """ attribute vec2 a_position; @@ -57,6 +58,7 @@ } """ +//language=GLSL private val fragmentShaderSource = """ precision mediump float; @@ -86,7 +88,7 @@ val bottom = -height / 2f val top = height / 2f - fun queueDraw(x: Float, y: Float, scale: Float, rotation: Float) { + fun queueDraw(x: Float, y: Float, scale: Float = 1f, rotation: Float = 0f) { shaderProgramMesh.queue( x, y, left, bottom, 0f, 0f, scale, rotation) shaderProgramMesh.queue( x, y, left, top, 0f, 1f, scale, rotation) shaderProgramMesh.queue( x, y, right, top, 1f, 1f, scale, rotation) @@ -99,13 +101,37 @@ } } - fun queueTileDraw(x: Float, y: Float, tcLeft: Float, tcTop: Float, tcRight: Float, tcBottom: Float, scale: Float) { - shaderProgramMesh.queue( x, y, left, bottom, tcLeft, tcBottom, scale, 0f) - shaderProgramMesh.queue( x, y, left, top, tcLeft, tcTop, scale, 0f) - shaderProgramMesh.queue( x, y, right, top, tcRight, tcTop, scale, 0f) - shaderProgramMesh.queue( x, y, right, top, tcRight, tcTop, scale, 0f) - shaderProgramMesh.queue( x, y, right, bottom, tcRight, tcBottom, scale, 0f) - shaderProgramMesh.queue( x, y, left, bottom, tcLeft, tcBottom, scale, 0f) + fun queueTileDraw(x: Float, y: Float, tcLeft: Float, tcTop: Float, tcRight: Float, tcBottom: Float, scale: Float = 1f, rotation: Float = 0f) { + shaderProgramMesh.queue( x, y, left, bottom, tcLeft, tcBottom, scale, rotation) + shaderProgramMesh.queue( x, y, left, top, tcLeft, tcTop, scale, rotation) + shaderProgramMesh.queue( x, y, right, top, tcRight, tcTop, scale, rotation) + shaderProgramMesh.queue( x, y, right, top, tcRight, tcTop, scale, rotation) + shaderProgramMesh.queue( x, y, right, bottom, tcRight, tcBottom, scale, rotation) + shaderProgramMesh.queue( x, y, left, bottom, tcLeft, tcBottom, scale, rotation) + + if (shaderProgramMesh.remaining() < 36) { + render() + } + } + + fun queueTileDraw(x: Float, y: Float, horCount: Int, verCount: Int, frame: Int, scale: Float = 1f, rotation: Float = 0f) { + val tcw = 1f / horCount + val tch = 1f / verCount + + val tcx = frame % (horCount * verCount) * tcw + val tcy = frame / (horCount * verCount) * tch + + val left = -(width / horCount) / 2f + val right = (width / horCount) / 2f + val bottom = -(height / verCount) / 2f + val top = (height / verCount) / 2f + + shaderProgramMesh.queue( x, y, left, bottom, tcx, tcy + tch, scale, rotation) + shaderProgramMesh.queue( x, y, left, top, tcx, tcy, scale, rotation) + shaderProgramMesh.queue( x, y, right, top, tcx + tcw, tcy, scale, rotation) + shaderProgramMesh.queue( x, y, right, top, tcx + tcw, tcy, scale, rotation) + shaderProgramMesh.queue( x, y, right, bottom, tcx + tcw, tcy + tch, scale, rotation) + shaderProgramMesh.queue( x, y, left, bottom, tcx, tcy + tch, scale, rotation) if (shaderProgramMesh.remaining() < 36) { render()