diff --git a/lib/kotludens/com/persesgames/game/Game.kt b/lib/kotludens/com/persesgames/game/Game.kt index 2388888..3abdd56 100644 --- a/lib/kotludens/com/persesgames/game/Game.kt +++ b/lib/kotludens/com/persesgames/game/Game.kt @@ -64,8 +64,10 @@ val windowWidth = window.innerWidth.toInt() val windowHeight = window.innerHeight.toInt() - if (view.windowWidth != windowWidth || - view.windowHeight != windowHeight) { + if (view.lastWindowWidth != windowWidth || + view.lastWindowHeight != windowHeight) { + view.lastWindowWidth = windowWidth + view.lastWindowHeight = windowHeight view.windowWidth = windowWidth view.windowHeight = windowHeight @@ -82,8 +84,8 @@ gl().viewport(0, 0, view.width.toInt(), view.height.toInt()) - val left = 0 //(windowWidth - view.windowWidth) / 2 - val top = 0 //(windowHeight - view.windowHeight) / 2 + val left = (windowWidth - view.windowWidth) / 2 + val top = (windowHeight - view.windowHeight) / 2 canvas.setAttribute("style", "position: absolute; left: ${left}px; top: ${top}px; z-index: 5; width: ${view.windowWidth}px; height: ${view.windowHeight}px;" ) textCanvas.setAttribute("style", "position: absolute; left: ${left}px; top: ${top}px; z-index: 10; width: ${view.windowWidth}px; height: ${view.windowHeight}px;" ) diff --git a/lib/kotludens/com/persesgames/game/Game.kt b/lib/kotludens/com/persesgames/game/Game.kt index 2388888..3abdd56 100644 --- a/lib/kotludens/com/persesgames/game/Game.kt +++ b/lib/kotludens/com/persesgames/game/Game.kt @@ -64,8 +64,10 @@ val windowWidth = window.innerWidth.toInt() val windowHeight = window.innerHeight.toInt() - if (view.windowWidth != windowWidth || - view.windowHeight != windowHeight) { + if (view.lastWindowWidth != windowWidth || + view.lastWindowHeight != windowHeight) { + view.lastWindowWidth = windowWidth + view.lastWindowHeight = windowHeight view.windowWidth = windowWidth view.windowHeight = windowHeight @@ -82,8 +84,8 @@ gl().viewport(0, 0, view.width.toInt(), view.height.toInt()) - val left = 0 //(windowWidth - view.windowWidth) / 2 - val top = 0 //(windowHeight - view.windowHeight) / 2 + val left = (windowWidth - view.windowWidth) / 2 + val top = (windowHeight - view.windowHeight) / 2 canvas.setAttribute("style", "position: absolute; left: ${left}px; top: ${top}px; z-index: 5; width: ${view.windowWidth}px; height: ${view.windowHeight}px;" ) textCanvas.setAttribute("style", "position: absolute; left: ${left}px; top: ${top}px; z-index: 10; width: ${view.windowWidth}px; height: ${view.windowHeight}px;" ) diff --git a/lib/kotludens/com/persesgames/game/View.kt b/lib/kotludens/com/persesgames/game/View.kt index 772113b..e5590e0 100644 --- a/lib/kotludens/com/persesgames/game/View.kt +++ b/lib/kotludens/com/persesgames/game/View.kt @@ -10,6 +10,8 @@ } class View( + var lastWindowWidth: Int = 2000, + var lastWindowHeight: Int = 1000, var windowWidth: Int = 2000, var windowHeight: Int = 1000, var width: Float = 1024f, @@ -52,13 +54,13 @@ if (aspectRatio < minAspectRatio) { aspectRatio = minAspectRatio - windowWidth = (windowHeight * aspectRatio).toInt() + windowHeight = (windowWidth / aspectRatio).toInt() } if (aspectRatio > maxAspectRatio) { aspectRatio = maxAspectRatio - windowHeight = (windowWidth / aspectRatio).toInt() + windowWidth = (windowHeight * aspectRatio).toInt() } when (viewType) { diff --git a/lib/kotludens/com/persesgames/game/Game.kt b/lib/kotludens/com/persesgames/game/Game.kt index 2388888..3abdd56 100644 --- a/lib/kotludens/com/persesgames/game/Game.kt +++ b/lib/kotludens/com/persesgames/game/Game.kt @@ -64,8 +64,10 @@ val windowWidth = window.innerWidth.toInt() val windowHeight = window.innerHeight.toInt() - if (view.windowWidth != windowWidth || - view.windowHeight != windowHeight) { + if (view.lastWindowWidth != windowWidth || + view.lastWindowHeight != windowHeight) { + view.lastWindowWidth = windowWidth + view.lastWindowHeight = windowHeight view.windowWidth = windowWidth view.windowHeight = windowHeight @@ -82,8 +84,8 @@ gl().viewport(0, 0, view.width.toInt(), view.height.toInt()) - val left = 0 //(windowWidth - view.windowWidth) / 2 - val top = 0 //(windowHeight - view.windowHeight) / 2 + val left = (windowWidth - view.windowWidth) / 2 + val top = (windowHeight - view.windowHeight) / 2 canvas.setAttribute("style", "position: absolute; left: ${left}px; top: ${top}px; z-index: 5; width: ${view.windowWidth}px; height: ${view.windowHeight}px;" ) textCanvas.setAttribute("style", "position: absolute; left: ${left}px; top: ${top}px; z-index: 10; width: ${view.windowWidth}px; height: ${view.windowHeight}px;" ) diff --git a/lib/kotludens/com/persesgames/game/View.kt b/lib/kotludens/com/persesgames/game/View.kt index 772113b..e5590e0 100644 --- a/lib/kotludens/com/persesgames/game/View.kt +++ b/lib/kotludens/com/persesgames/game/View.kt @@ -10,6 +10,8 @@ } class View( + var lastWindowWidth: Int = 2000, + var lastWindowHeight: Int = 1000, var windowWidth: Int = 2000, var windowHeight: Int = 1000, var width: Float = 1024f, @@ -52,13 +54,13 @@ if (aspectRatio < minAspectRatio) { aspectRatio = minAspectRatio - windowWidth = (windowHeight * aspectRatio).toInt() + windowHeight = (windowWidth / aspectRatio).toInt() } if (aspectRatio > maxAspectRatio) { aspectRatio = maxAspectRatio - windowHeight = (windowWidth / aspectRatio).toInt() + windowWidth = (windowHeight * aspectRatio).toInt() } when (viewType) { diff --git a/lib/kotludens/com/persesgames/map/tiled/TiledMap.kt b/lib/kotludens/com/persesgames/map/tiled/TiledMap.kt index fba2034..770ba8d 100644 --- a/lib/kotludens/com/persesgames/map/tiled/TiledMap.kt +++ b/lib/kotludens/com/persesgames/map/tiled/TiledMap.kt @@ -64,11 +64,7 @@ val tcTop: Float, val tcRight: Float, val tcBottom: Float - ) { - fun render(x: Float, y: Float) { - texture.queueTileDraw(x, y, tcLeft, tcTop, tcRight, tcBottom) - } -} + ) class TiledMap(dir: String = "", url: String) { val properties: Map = HashMap() @@ -108,6 +104,7 @@ var tcTop = 0f var tcRight = 0f var tcBottom = 0f + var scale = 1f if (tilesets != null) { for (tileset in tilesets) { @@ -139,6 +136,8 @@ tcBottom += pixelH tcTop -= pixelH + + scale = (tileset.tilewidth / tileset.imagewidth.toFloat()) } } } @@ -146,7 +145,7 @@ if (name != null) { val texture = Textures.get(name) - texture.queueTileDraw(x, y, tcLeft, tcTop, tcRight, tcBottom) + texture.queueTileDraw(x, y, tcLeft, tcTop, tcRight, tcBottom, scale) } } diff --git a/lib/kotludens/com/persesgames/game/Game.kt b/lib/kotludens/com/persesgames/game/Game.kt index 2388888..3abdd56 100644 --- a/lib/kotludens/com/persesgames/game/Game.kt +++ b/lib/kotludens/com/persesgames/game/Game.kt @@ -64,8 +64,10 @@ val windowWidth = window.innerWidth.toInt() val windowHeight = window.innerHeight.toInt() - if (view.windowWidth != windowWidth || - view.windowHeight != windowHeight) { + if (view.lastWindowWidth != windowWidth || + view.lastWindowHeight != windowHeight) { + view.lastWindowWidth = windowWidth + view.lastWindowHeight = windowHeight view.windowWidth = windowWidth view.windowHeight = windowHeight @@ -82,8 +84,8 @@ gl().viewport(0, 0, view.width.toInt(), view.height.toInt()) - val left = 0 //(windowWidth - view.windowWidth) / 2 - val top = 0 //(windowHeight - view.windowHeight) / 2 + val left = (windowWidth - view.windowWidth) / 2 + val top = (windowHeight - view.windowHeight) / 2 canvas.setAttribute("style", "position: absolute; left: ${left}px; top: ${top}px; z-index: 5; width: ${view.windowWidth}px; height: ${view.windowHeight}px;" ) textCanvas.setAttribute("style", "position: absolute; left: ${left}px; top: ${top}px; z-index: 10; width: ${view.windowWidth}px; height: ${view.windowHeight}px;" ) diff --git a/lib/kotludens/com/persesgames/game/View.kt b/lib/kotludens/com/persesgames/game/View.kt index 772113b..e5590e0 100644 --- a/lib/kotludens/com/persesgames/game/View.kt +++ b/lib/kotludens/com/persesgames/game/View.kt @@ -10,6 +10,8 @@ } class View( + var lastWindowWidth: Int = 2000, + var lastWindowHeight: Int = 1000, var windowWidth: Int = 2000, var windowHeight: Int = 1000, var width: Float = 1024f, @@ -52,13 +54,13 @@ if (aspectRatio < minAspectRatio) { aspectRatio = minAspectRatio - windowWidth = (windowHeight * aspectRatio).toInt() + windowHeight = (windowWidth / aspectRatio).toInt() } if (aspectRatio > maxAspectRatio) { aspectRatio = maxAspectRatio - windowHeight = (windowWidth / aspectRatio).toInt() + windowWidth = (windowHeight * aspectRatio).toInt() } when (viewType) { diff --git a/lib/kotludens/com/persesgames/map/tiled/TiledMap.kt b/lib/kotludens/com/persesgames/map/tiled/TiledMap.kt index fba2034..770ba8d 100644 --- a/lib/kotludens/com/persesgames/map/tiled/TiledMap.kt +++ b/lib/kotludens/com/persesgames/map/tiled/TiledMap.kt @@ -64,11 +64,7 @@ val tcTop: Float, val tcRight: Float, val tcBottom: Float - ) { - fun render(x: Float, y: Float) { - texture.queueTileDraw(x, y, tcLeft, tcTop, tcRight, tcBottom) - } -} + ) class TiledMap(dir: String = "", url: String) { val properties: Map = HashMap() @@ -108,6 +104,7 @@ var tcTop = 0f var tcRight = 0f var tcBottom = 0f + var scale = 1f if (tilesets != null) { for (tileset in tilesets) { @@ -139,6 +136,8 @@ tcBottom += pixelH tcTop -= pixelH + + scale = (tileset.tilewidth / tileset.imagewidth.toFloat()) } } } @@ -146,7 +145,7 @@ if (name != null) { val texture = Textures.get(name) - texture.queueTileDraw(x, y, tcLeft, tcTop, tcRight, tcBottom) + texture.queueTileDraw(x, y, tcLeft, tcTop, tcRight, tcBottom, scale) } } diff --git a/lib/kotludens/com/persesgames/texture/Textures.kt b/lib/kotludens/com/persesgames/texture/Textures.kt index e0ea7fc..111f08a 100644 --- a/lib/kotludens/com/persesgames/texture/Textures.kt +++ b/lib/kotludens/com/persesgames/texture/Textures.kt @@ -104,13 +104,13 @@ } } - fun queueTileDraw(x: Float, y: Float, tcLeft: Float, tcTop: Float, tcRight: Float, tcBottom: Float) { - shaderProgramMesh.queue( x, y, left, bottom, tcLeft, tcBottom, 1f/8f, 0f) - shaderProgramMesh.queue( x, y, left, top, tcLeft, tcTop, 1f/8f, 0f) - shaderProgramMesh.queue( x, y, right, top, tcRight, tcTop, 1f/8f, 0f) - shaderProgramMesh.queue( x, y, right, top, tcRight, tcTop, 1f/8f, 0f) - shaderProgramMesh.queue( x, y, right, bottom, tcRight, tcBottom, 1f/8f, 0f) - shaderProgramMesh.queue( x, y, left, bottom, tcLeft, tcBottom, 1f/8f, 0f) + 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) if (shaderProgramMesh.remaining() < 36) { render() diff --git a/lib/kotludens/com/persesgames/game/Game.kt b/lib/kotludens/com/persesgames/game/Game.kt index 2388888..3abdd56 100644 --- a/lib/kotludens/com/persesgames/game/Game.kt +++ b/lib/kotludens/com/persesgames/game/Game.kt @@ -64,8 +64,10 @@ val windowWidth = window.innerWidth.toInt() val windowHeight = window.innerHeight.toInt() - if (view.windowWidth != windowWidth || - view.windowHeight != windowHeight) { + if (view.lastWindowWidth != windowWidth || + view.lastWindowHeight != windowHeight) { + view.lastWindowWidth = windowWidth + view.lastWindowHeight = windowHeight view.windowWidth = windowWidth view.windowHeight = windowHeight @@ -82,8 +84,8 @@ gl().viewport(0, 0, view.width.toInt(), view.height.toInt()) - val left = 0 //(windowWidth - view.windowWidth) / 2 - val top = 0 //(windowHeight - view.windowHeight) / 2 + val left = (windowWidth - view.windowWidth) / 2 + val top = (windowHeight - view.windowHeight) / 2 canvas.setAttribute("style", "position: absolute; left: ${left}px; top: ${top}px; z-index: 5; width: ${view.windowWidth}px; height: ${view.windowHeight}px;" ) textCanvas.setAttribute("style", "position: absolute; left: ${left}px; top: ${top}px; z-index: 10; width: ${view.windowWidth}px; height: ${view.windowHeight}px;" ) diff --git a/lib/kotludens/com/persesgames/game/View.kt b/lib/kotludens/com/persesgames/game/View.kt index 772113b..e5590e0 100644 --- a/lib/kotludens/com/persesgames/game/View.kt +++ b/lib/kotludens/com/persesgames/game/View.kt @@ -10,6 +10,8 @@ } class View( + var lastWindowWidth: Int = 2000, + var lastWindowHeight: Int = 1000, var windowWidth: Int = 2000, var windowHeight: Int = 1000, var width: Float = 1024f, @@ -52,13 +54,13 @@ if (aspectRatio < minAspectRatio) { aspectRatio = minAspectRatio - windowWidth = (windowHeight * aspectRatio).toInt() + windowHeight = (windowWidth / aspectRatio).toInt() } if (aspectRatio > maxAspectRatio) { aspectRatio = maxAspectRatio - windowHeight = (windowWidth / aspectRatio).toInt() + windowWidth = (windowHeight * aspectRatio).toInt() } when (viewType) { diff --git a/lib/kotludens/com/persesgames/map/tiled/TiledMap.kt b/lib/kotludens/com/persesgames/map/tiled/TiledMap.kt index fba2034..770ba8d 100644 --- a/lib/kotludens/com/persesgames/map/tiled/TiledMap.kt +++ b/lib/kotludens/com/persesgames/map/tiled/TiledMap.kt @@ -64,11 +64,7 @@ val tcTop: Float, val tcRight: Float, val tcBottom: Float - ) { - fun render(x: Float, y: Float) { - texture.queueTileDraw(x, y, tcLeft, tcTop, tcRight, tcBottom) - } -} + ) class TiledMap(dir: String = "", url: String) { val properties: Map = HashMap() @@ -108,6 +104,7 @@ var tcTop = 0f var tcRight = 0f var tcBottom = 0f + var scale = 1f if (tilesets != null) { for (tileset in tilesets) { @@ -139,6 +136,8 @@ tcBottom += pixelH tcTop -= pixelH + + scale = (tileset.tilewidth / tileset.imagewidth.toFloat()) } } } @@ -146,7 +145,7 @@ if (name != null) { val texture = Textures.get(name) - texture.queueTileDraw(x, y, tcLeft, tcTop, tcRight, tcBottom) + texture.queueTileDraw(x, y, tcLeft, tcTop, tcRight, tcBottom, scale) } } diff --git a/lib/kotludens/com/persesgames/texture/Textures.kt b/lib/kotludens/com/persesgames/texture/Textures.kt index e0ea7fc..111f08a 100644 --- a/lib/kotludens/com/persesgames/texture/Textures.kt +++ b/lib/kotludens/com/persesgames/texture/Textures.kt @@ -104,13 +104,13 @@ } } - fun queueTileDraw(x: Float, y: Float, tcLeft: Float, tcTop: Float, tcRight: Float, tcBottom: Float) { - shaderProgramMesh.queue( x, y, left, bottom, tcLeft, tcBottom, 1f/8f, 0f) - shaderProgramMesh.queue( x, y, left, top, tcLeft, tcTop, 1f/8f, 0f) - shaderProgramMesh.queue( x, y, right, top, tcRight, tcTop, 1f/8f, 0f) - shaderProgramMesh.queue( x, y, right, top, tcRight, tcTop, 1f/8f, 0f) - shaderProgramMesh.queue( x, y, right, bottom, tcRight, tcBottom, 1f/8f, 0f) - shaderProgramMesh.queue( x, y, left, bottom, tcLeft, tcBottom, 1f/8f, 0f) + 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) if (shaderProgramMesh.remaining() < 36) { render() diff --git a/src/com/persesgames/shooter/Shooter.kt b/src/com/persesgames/shooter/Shooter.kt index 8cf7a18..9bb8376 100644 --- a/src/com/persesgames/shooter/Shooter.kt +++ b/src/com/persesgames/shooter/Shooter.kt @@ -66,7 +66,7 @@ val map = TiledMap("maps", "level_1_01.json") var sprites = SpriteBatch() - var x = -640f + 64f + var x = -2000f var y = 15500f var sprite = Sprite("SHIP") var numberOfSprites: Int = 5000 @@ -99,7 +99,7 @@ override fun update(time: Float, delta: Float) { this.time = time - val speed = 500f // units per second + val speed = 1500f // units per second if (Keys.isDown(KeyCode.LEFT)) { x -= delta * speed @@ -151,6 +151,8 @@ sprites.draw(sprite, x.toFloat(), y.toFloat(), scale = 0.4f + Math.sin(time.toDouble() + r).toFloat(), rotation = r * 10f) } + sprites.draw(sprite, -350f, -350f, scale = 4f, rotation = -time) + sprites.render() Texts.drawText(20f, 150f, "Drawing $numberOfSprites sprites per frame.") @@ -167,6 +169,9 @@ Game.view.setToWidth(2000f) Game.view.drawMode = DrawMode.LINEAR + Game.view.minAspectRatio = 0.9f + Game.view.maxAspectRatio = 1.5f + Game.start(WelcomeScreen()) } diff --git a/lib/kotludens/com/persesgames/game/Game.kt b/lib/kotludens/com/persesgames/game/Game.kt index 2388888..3abdd56 100644 --- a/lib/kotludens/com/persesgames/game/Game.kt +++ b/lib/kotludens/com/persesgames/game/Game.kt @@ -64,8 +64,10 @@ val windowWidth = window.innerWidth.toInt() val windowHeight = window.innerHeight.toInt() - if (view.windowWidth != windowWidth || - view.windowHeight != windowHeight) { + if (view.lastWindowWidth != windowWidth || + view.lastWindowHeight != windowHeight) { + view.lastWindowWidth = windowWidth + view.lastWindowHeight = windowHeight view.windowWidth = windowWidth view.windowHeight = windowHeight @@ -82,8 +84,8 @@ gl().viewport(0, 0, view.width.toInt(), view.height.toInt()) - val left = 0 //(windowWidth - view.windowWidth) / 2 - val top = 0 //(windowHeight - view.windowHeight) / 2 + val left = (windowWidth - view.windowWidth) / 2 + val top = (windowHeight - view.windowHeight) / 2 canvas.setAttribute("style", "position: absolute; left: ${left}px; top: ${top}px; z-index: 5; width: ${view.windowWidth}px; height: ${view.windowHeight}px;" ) textCanvas.setAttribute("style", "position: absolute; left: ${left}px; top: ${top}px; z-index: 10; width: ${view.windowWidth}px; height: ${view.windowHeight}px;" ) diff --git a/lib/kotludens/com/persesgames/game/View.kt b/lib/kotludens/com/persesgames/game/View.kt index 772113b..e5590e0 100644 --- a/lib/kotludens/com/persesgames/game/View.kt +++ b/lib/kotludens/com/persesgames/game/View.kt @@ -10,6 +10,8 @@ } class View( + var lastWindowWidth: Int = 2000, + var lastWindowHeight: Int = 1000, var windowWidth: Int = 2000, var windowHeight: Int = 1000, var width: Float = 1024f, @@ -52,13 +54,13 @@ if (aspectRatio < minAspectRatio) { aspectRatio = minAspectRatio - windowWidth = (windowHeight * aspectRatio).toInt() + windowHeight = (windowWidth / aspectRatio).toInt() } if (aspectRatio > maxAspectRatio) { aspectRatio = maxAspectRatio - windowHeight = (windowWidth / aspectRatio).toInt() + windowWidth = (windowHeight * aspectRatio).toInt() } when (viewType) { diff --git a/lib/kotludens/com/persesgames/map/tiled/TiledMap.kt b/lib/kotludens/com/persesgames/map/tiled/TiledMap.kt index fba2034..770ba8d 100644 --- a/lib/kotludens/com/persesgames/map/tiled/TiledMap.kt +++ b/lib/kotludens/com/persesgames/map/tiled/TiledMap.kt @@ -64,11 +64,7 @@ val tcTop: Float, val tcRight: Float, val tcBottom: Float - ) { - fun render(x: Float, y: Float) { - texture.queueTileDraw(x, y, tcLeft, tcTop, tcRight, tcBottom) - } -} + ) class TiledMap(dir: String = "", url: String) { val properties: Map = HashMap() @@ -108,6 +104,7 @@ var tcTop = 0f var tcRight = 0f var tcBottom = 0f + var scale = 1f if (tilesets != null) { for (tileset in tilesets) { @@ -139,6 +136,8 @@ tcBottom += pixelH tcTop -= pixelH + + scale = (tileset.tilewidth / tileset.imagewidth.toFloat()) } } } @@ -146,7 +145,7 @@ if (name != null) { val texture = Textures.get(name) - texture.queueTileDraw(x, y, tcLeft, tcTop, tcRight, tcBottom) + texture.queueTileDraw(x, y, tcLeft, tcTop, tcRight, tcBottom, scale) } } diff --git a/lib/kotludens/com/persesgames/texture/Textures.kt b/lib/kotludens/com/persesgames/texture/Textures.kt index e0ea7fc..111f08a 100644 --- a/lib/kotludens/com/persesgames/texture/Textures.kt +++ b/lib/kotludens/com/persesgames/texture/Textures.kt @@ -104,13 +104,13 @@ } } - fun queueTileDraw(x: Float, y: Float, tcLeft: Float, tcTop: Float, tcRight: Float, tcBottom: Float) { - shaderProgramMesh.queue( x, y, left, bottom, tcLeft, tcBottom, 1f/8f, 0f) - shaderProgramMesh.queue( x, y, left, top, tcLeft, tcTop, 1f/8f, 0f) - shaderProgramMesh.queue( x, y, right, top, tcRight, tcTop, 1f/8f, 0f) - shaderProgramMesh.queue( x, y, right, top, tcRight, tcTop, 1f/8f, 0f) - shaderProgramMesh.queue( x, y, right, bottom, tcRight, tcBottom, 1f/8f, 0f) - shaderProgramMesh.queue( x, y, left, bottom, tcLeft, tcBottom, 1f/8f, 0f) + 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) if (shaderProgramMesh.remaining() < 36) { render() diff --git a/src/com/persesgames/shooter/Shooter.kt b/src/com/persesgames/shooter/Shooter.kt index 8cf7a18..9bb8376 100644 --- a/src/com/persesgames/shooter/Shooter.kt +++ b/src/com/persesgames/shooter/Shooter.kt @@ -66,7 +66,7 @@ val map = TiledMap("maps", "level_1_01.json") var sprites = SpriteBatch() - var x = -640f + 64f + var x = -2000f var y = 15500f var sprite = Sprite("SHIP") var numberOfSprites: Int = 5000 @@ -99,7 +99,7 @@ override fun update(time: Float, delta: Float) { this.time = time - val speed = 500f // units per second + val speed = 1500f // units per second if (Keys.isDown(KeyCode.LEFT)) { x -= delta * speed @@ -151,6 +151,8 @@ sprites.draw(sprite, x.toFloat(), y.toFloat(), scale = 0.4f + Math.sin(time.toDouble() + r).toFloat(), rotation = r * 10f) } + sprites.draw(sprite, -350f, -350f, scale = 4f, rotation = -time) + sprites.render() Texts.drawText(20f, 150f, "Drawing $numberOfSprites sprites per frame.") @@ -167,6 +169,9 @@ Game.view.setToWidth(2000f) Game.view.drawMode = DrawMode.LINEAR + Game.view.minAspectRatio = 0.9f + Game.view.maxAspectRatio = 1.5f + Game.start(WelcomeScreen()) } diff --git a/web/index.html b/web/index.html index 548feb9..c6d2a42 100644 --- a/web/index.html +++ b/web/index.html @@ -5,6 +5,7 @@ Title