mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-08 12:51:51 +09:00
can see camera working but not the actor gravity
This commit is contained in:
17
src/net/torvald/gdx/backends/lwjgl/audio/Opus.kt
Normal file
17
src/net/torvald/gdx/backends/lwjgl/audio/Opus.kt
Normal file
@@ -0,0 +1,17 @@
|
||||
package net.torvald.gdx.backends.lwjgl.audio
|
||||
|
||||
import com.badlogic.gdx.backends.lwjgl.audio.OggInputStream
|
||||
import com.badlogic.gdx.backends.lwjgl.audio.OpenALAudio
|
||||
import com.badlogic.gdx.backends.lwjgl.audio.OpenALMusic
|
||||
import com.badlogic.gdx.backends.lwjgl.audio.OpenALSound
|
||||
import com.badlogic.gdx.files.FileHandle
|
||||
import com.badlogic.gdx.utils.StreamUtils
|
||||
import java.io.ByteArrayOutputStream
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2017-06-26.
|
||||
*/
|
||||
|
||||
class Opus {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package net.torvald.gdx.backends.lwjgl.audio;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2017-06-26.
|
||||
*/
|
||||
public class OpusInputStream extends InputStream {
|
||||
public OpusInputStream() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(@NotNull byte[] b) throws IOException {
|
||||
return super.read(b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(@NotNull byte[] b, int off, int len) throws IOException {
|
||||
return super.read(b, off, len);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long skip(long n) throws IOException {
|
||||
return super.skip(n);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int available() throws IOException {
|
||||
return super.available();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
super.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void mark(int readlimit) {
|
||||
super.mark(readlimit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void reset() throws IOException {
|
||||
super.reset();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean markSupported() {
|
||||
return super.markSupported();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -93,7 +93,6 @@ class SpriteAnimation(val parentActor: ActorWithPhysics) {
|
||||
|
||||
if (visible) {
|
||||
val region = textureRegion.get(currentRow, currentFrame)
|
||||
region.flip(flipHorizontal, !flipVertical)
|
||||
batch.color = colorFilter
|
||||
|
||||
batch.draw(region,
|
||||
|
||||
@@ -158,10 +158,10 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
|
||||
}
|
||||
|
||||
// Create camera with the desired resolution
|
||||
camera = OrthographicCamera(width, height)
|
||||
//camera = OrthographicCamera(width, height)
|
||||
|
||||
// Move camera center to push 0,0 into the corner
|
||||
camera.translate(width / 2, height / 2)
|
||||
//camera.translate(width / 2, height / 2)
|
||||
|
||||
// Set Y to point downwards
|
||||
camera.setToOrtho(true, width, height)
|
||||
@@ -181,6 +181,9 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
|
||||
|
||||
|
||||
fun enter() {
|
||||
initViewPort(Gdx.graphics.width, Gdx.graphics.height, Gdx.graphics.width.toFloat() / Gdx.graphics.height.toFloat())
|
||||
|
||||
|
||||
// load things when the game entered this "state"
|
||||
// load necessary shaders
|
||||
//shader12BitCol = Shader.makeShader("./assets/4096.vert", "./assets/4096.frag")
|
||||
@@ -414,27 +417,47 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
|
||||
|
||||
|
||||
blendNormal()
|
||||
camera.position.set(0f, 0f, 0f) // make camara work
|
||||
batch.projectionMatrix = camera.combined
|
||||
batch.inUse {
|
||||
camera.position.set(WorldCamera.gdxCamX, WorldCamera.gdxCamY, 0f) // make camara work
|
||||
camera.update()
|
||||
batch.projectionMatrix = camera.combined
|
||||
|
||||
WeatherMixer.render(batch) // drawing to gwin so that any lights from lamp wont "leak" to the skybox
|
||||
// e.g. Bright blue light on sunset
|
||||
|
||||
|
||||
LightmapRenderer.renderLightMap()
|
||||
|
||||
BlocksDrawer.renderWall(batch)
|
||||
BlocksDrawer.renderTerrain(batch)
|
||||
|
||||
|
||||
batch.color = Color.WHITE
|
||||
player?.drawBody(batch)
|
||||
}
|
||||
|
||||
|
||||
println("Player: (${player?.hitbox?.centeredX}, ${player?.hitbox?.centeredY})")
|
||||
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// draw map related stuffs //
|
||||
/////////////////////////////
|
||||
worldDrawFrameBuffer.inAction {
|
||||
/*worldDrawFrameBuffer.inAction {
|
||||
// FIXME wrong and flipped coord; one camera code does not concern other
|
||||
|
||||
camera.position.set(-WorldCamera.x.toFloat(), -WorldCamera.y.toFloat(), 0f) // make camara work
|
||||
batch.projectionMatrix = camera.combined
|
||||
|
||||
batch.inUse {
|
||||
camera.position.set(WorldCamera.x.toFloat(), WorldCamera.y.toFloat(), 0f) // make camara work
|
||||
camera.update()
|
||||
batch.projectionMatrix = camera.combined
|
||||
|
||||
|
||||
batch.color = Color.WHITE
|
||||
batch.fillRect(WorldCamera.x.toFloat(), WorldCamera.y.toFloat(), 16f, 16f)
|
||||
|
||||
|
||||
|
||||
BlocksDrawer.renderWall(batch)
|
||||
actorsRenderBehind.forEach { it.drawBody(batch) }
|
||||
actorsRenderBehind.forEach { it.drawGlow(batch) }
|
||||
@@ -540,7 +563,7 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
|
||||
batch.inUse {
|
||||
val tex = backDrawFrameBuffer.colorBufferTexture // TODO zoom!
|
||||
batch.draw(tex, 0f, 0f)
|
||||
}
|
||||
}*/
|
||||
//backG.drawImage(worldDrawFrameBuffer.getScaledCopy(screenZoom), 0f, 0f)
|
||||
//backG.flush()
|
||||
|
||||
|
||||
@@ -599,12 +599,6 @@ infix fun Color.minus(other: Color) = Color( // don't turn into an operator!
|
||||
)
|
||||
|
||||
fun Int.toHex() = this.toLong().and(0xFFFFFFFF).toString(16).padStart(8, '0').toUpperCase()
|
||||
fun Long.toHex() = {
|
||||
val sb = StringBuilder()
|
||||
(0..16).forEach {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -323,6 +323,10 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
|
||||
override fun update(delta: Float) {
|
||||
if (isUpdate && !flagDespawn) {
|
||||
|
||||
hitbox.translate(0.0, 2.0)
|
||||
|
||||
|
||||
|
||||
if (!assertPrinted) assertInit()
|
||||
|
||||
if (sprite != null) sprite!!.update(delta)
|
||||
@@ -1317,7 +1321,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
|
||||
|
||||
|
||||
|
||||
private inline fun forEachOccupyingTileNum(consumer: (Int?) -> Unit) {
|
||||
private fun forEachOccupyingTileNum(consumer: (Int?) -> Unit) {
|
||||
val tiles = ArrayList<Int?>()
|
||||
for (y in tilewiseHitbox.startY.toInt()..tilewiseHitbox.endY.toInt()) {
|
||||
for (x in tilewiseHitbox.startX.toInt()..tilewiseHitbox.endX.toInt()) {
|
||||
@@ -1328,7 +1332,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
|
||||
return tiles.forEach(consumer)
|
||||
}
|
||||
|
||||
private inline fun forEachOccupyingTile(consumer: (BlockProp?) -> Unit) {
|
||||
private fun forEachOccupyingTile(consumer: (BlockProp?) -> Unit) {
|
||||
val tileProps = ArrayList<BlockProp?>()
|
||||
for (y in tilewiseHitbox.startY.toInt()..tilewiseHitbox.endY.toInt()) {
|
||||
for (x in tilewiseHitbox.startX.toInt()..tilewiseHitbox.endX.toInt()) {
|
||||
@@ -1339,7 +1343,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
|
||||
return tileProps.forEach(consumer)
|
||||
}
|
||||
|
||||
private inline fun forEachOccupyingTilePos(hitbox: Hitbox, consumer: (BlockAddress) -> Unit) {
|
||||
private fun forEachOccupyingTilePos(hitbox: Hitbox, consumer: (BlockAddress) -> Unit) {
|
||||
val newTilewiseHitbox = Hitbox.fromTwoPoints(
|
||||
hitbox.startX.div(TILE_SIZE).floor(),
|
||||
hitbox.startY.div(TILE_SIZE).floor(),
|
||||
@@ -1357,7 +1361,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
|
||||
return tilePosList.forEach(consumer)
|
||||
}
|
||||
|
||||
private inline fun forEachFeetTileNum(consumer: (Int?) -> Unit) {
|
||||
private fun forEachFeetTileNum(consumer: (Int?) -> Unit) {
|
||||
val tiles = ArrayList<Int?>()
|
||||
|
||||
// offset 1 pixel to the down so that friction would work
|
||||
@@ -1370,7 +1374,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
|
||||
return tiles.forEach(consumer)
|
||||
}
|
||||
|
||||
private inline fun forEachFeetTile(consumer: (BlockProp?) -> Unit) {
|
||||
private fun forEachFeetTile(consumer: (BlockProp?) -> Unit) {
|
||||
val tileProps = ArrayList<BlockProp?>()
|
||||
|
||||
// offset 1 pixel to the down so that friction would work
|
||||
|
||||
@@ -125,7 +125,7 @@ object DecodeTapestry {
|
||||
if (colourModel != FORMAT_16 && colourModel != FORMAT_64)
|
||||
throw RuntimeException("Invalid colour model: $colourModel")
|
||||
|
||||
val width = file[6].toUint().shl(8) + file[7].toUint()
|
||||
val width = file[7].toUint().shl(8) + file[6].toUint()
|
||||
|
||||
val artNameBytes = ArrayList<Byte>()
|
||||
val authorNameBytes = ArrayList<Byte>()
|
||||
|
||||
@@ -32,7 +32,6 @@ object ItemCodex {
|
||||
val ITEM_DYNAMIC = 32768..0x0FFF_FFFF
|
||||
val ACTORID_MIN = ITEM_DYNAMIC.endInclusive + 1
|
||||
|
||||
|
||||
private val itemImagePlaceholder = TextureRegion(Texture("./assets/item_kari_24.tga"))
|
||||
|
||||
|
||||
|
||||
@@ -289,11 +289,11 @@ import java.util.*
|
||||
}
|
||||
|
||||
fun drawRectBack(x: Int, y: Int, w: Int, h: Int, c: Int = color) {
|
||||
(0..w - 1).forEach {
|
||||
for (it in 0..w - 1) {
|
||||
vram.setBackgroundPixel(x + it, y, c)
|
||||
vram.setBackgroundPixel(x + it, y + h - 1, c)
|
||||
}
|
||||
(1..h - 2).forEach {
|
||||
for (it in 1..h - 2) {
|
||||
vram.setBackgroundPixel(x, y + it, c)
|
||||
vram.setBackgroundPixel(x + w - 1, y + it, c)
|
||||
}
|
||||
@@ -306,11 +306,11 @@ import java.util.*
|
||||
}
|
||||
|
||||
fun drawRectFore(x: Int, y: Int, w: Int, h: Int, c: Int = color) {
|
||||
(0..w - 1).forEach {
|
||||
for (it in 0..w - 1) {
|
||||
vram.setForegroundPixel(x + it, y, c)
|
||||
vram.setForegroundPixel(x + it, y + h - 1, c)
|
||||
}
|
||||
(1..h - 2).forEach {
|
||||
for (it in 1..h - 2) {
|
||||
vram.setForegroundPixel(x, y + it, c)
|
||||
vram.setForegroundPixel(x + w - 1, y + it, c)
|
||||
}
|
||||
|
||||
@@ -203,7 +203,7 @@ import java.util.*
|
||||
rgba, 0,
|
||||
rgba.size - displacement
|
||||
)
|
||||
(rgba.size - 1 downTo rgba.size - displacement + 1).forEach { rgba[it] = 0.toByte() }
|
||||
for (it in rgba.size - 1 downTo rgba.size - displacement + 1) { rgba[it] = 0.toByte() }
|
||||
}
|
||||
else {
|
||||
System.arraycopy(
|
||||
@@ -211,7 +211,7 @@ import java.util.*
|
||||
rgba, displacement,
|
||||
rgba.size - displacement
|
||||
)
|
||||
(0..displacement - 1).forEach { rgba[it] = 0.toByte() }
|
||||
for (it in 0..displacement - 1) { rgba[it] = 0.toByte() }
|
||||
}
|
||||
|
||||
cursorY += -amount
|
||||
|
||||
@@ -101,7 +101,7 @@ object BlocksDrawer {
|
||||
val tileItemImgPixMap = Pixmap(TILE_SIZE * 16, TILE_SIZE * GameWorld.TILES_SUPPORTED / 16, Pixmap.Format.RGBA8888)
|
||||
tileItemImgPixMap.pixels.rewind()
|
||||
|
||||
(ITEM_TILES).forEach { tileID ->
|
||||
for (tileID in ITEM_TILES) {
|
||||
|
||||
val tile = tilesTerrain.get((tileID % 16) * 16, (tileID / 16))
|
||||
|
||||
|
||||
@@ -16,6 +16,10 @@ object WorldCamera {
|
||||
private set
|
||||
var y: Int = 0
|
||||
private set
|
||||
var gdxCamX: Float = 0f
|
||||
private set
|
||||
var gdxCamY: Float = 0f
|
||||
private set
|
||||
var width: Int = 0
|
||||
private set
|
||||
var height: Int = 0
|
||||
@@ -42,6 +46,14 @@ object WorldCamera {
|
||||
world!!.height * TILE_SIZE - height - TILE_SIZE.toFloat()
|
||||
))
|
||||
|
||||
|
||||
gdxCamX = Math.round(// X only: ROUNDWORLD implementation
|
||||
(player?.hitbox?.centeredX?.toFloat() ?: 0f)).toFloat()
|
||||
gdxCamY = Math.round(FastMath.clamp(
|
||||
(player?.hitbox?.centeredY?.toFloat() ?: 0f),
|
||||
TILE_SIZE.toFloat(),
|
||||
world!!.height * TILE_SIZE - height - TILE_SIZE.toFloat()
|
||||
)).toFloat()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user