2023-08-16 13:10:48 +10:00
|
|
|
package gay.pizza.CavesOfJolk
|
|
|
|
|
|
|
|
import com.badlogic.gdx.ApplicationAdapter
|
|
|
|
import com.badlogic.gdx.Gdx
|
|
|
|
import com.badlogic.gdx.graphics.*
|
|
|
|
import com.badlogic.gdx.graphics.g2d.BitmapFont
|
|
|
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
|
|
|
import com.badlogic.gdx.graphics.g3d.*
|
|
|
|
import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute
|
2023-08-16 16:26:05 +10:00
|
|
|
import com.badlogic.gdx.graphics.g3d.attributes.FloatAttribute
|
2023-08-16 13:10:48 +10:00
|
|
|
import com.badlogic.gdx.graphics.g3d.attributes.IntAttribute
|
|
|
|
import com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute
|
|
|
|
import com.badlogic.gdx.graphics.g3d.environment.DirectionalLight
|
|
|
|
import com.badlogic.gdx.graphics.g3d.shaders.DefaultShader
|
|
|
|
import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder
|
|
|
|
import com.badlogic.gdx.graphics.g3d.utils.TextureDescriptor
|
|
|
|
import com.badlogic.gdx.math.*
|
|
|
|
import com.badlogic.gdx.utils.ScreenUtils
|
|
|
|
import gay.pizza.CavesOfJolk.Resources.Companion.assetManager
|
|
|
|
|
|
|
|
class Game: ApplicationAdapter()
|
|
|
|
{
|
|
|
|
private lateinit var texJolk: Texture
|
|
|
|
private lateinit var fntComic: BitmapFont
|
|
|
|
private lateinit var cube: Model
|
|
|
|
private lateinit var floor: Model
|
|
|
|
|
|
|
|
private lateinit var spriteBatch: SpriteBatch
|
|
|
|
private lateinit var modelBatch: ModelBatch
|
|
|
|
private lateinit var env: Environment
|
|
|
|
|
|
|
|
private lateinit var colin: Colin
|
|
|
|
private var jolkRot = 0.0f
|
|
|
|
|
|
|
|
private lateinit var cubeInstance: ModelInstance
|
|
|
|
private lateinit var floorInstance: ModelInstance
|
|
|
|
private lateinit var suzanneInstance: ModelInstance
|
|
|
|
|
|
|
|
private fun makeCube(texture: Texture): Model
|
|
|
|
{
|
|
|
|
val modelBuilder = ModelBuilder()
|
|
|
|
val size = 2.0f
|
2023-08-16 16:26:05 +10:00
|
|
|
val material = Material(
|
|
|
|
ColorAttribute.createDiffuse(XnaColor.White),
|
|
|
|
TextureAttribute(TextureAttribute.Diffuse,
|
|
|
|
TextureDescriptor(texture,
|
|
|
|
Texture.TextureFilter.Linear,
|
|
|
|
Texture.TextureFilter.Linear,
|
|
|
|
Texture.TextureWrap.ClampToEdge,
|
|
|
|
Texture.TextureWrap.ClampToEdge)),
|
|
|
|
ColorAttribute.createSpecular(XnaColor.Gray),
|
|
|
|
FloatAttribute.createShininess(20.0f))
|
2023-08-16 13:10:48 +10:00
|
|
|
val attribs = VertexAttributes.Usage.Position or VertexAttributes.Usage.TextureCoordinates or VertexAttributes.Usage.Normal
|
|
|
|
return modelBuilder.createBox(size, size, size, material, attribs.toLong())
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun makeFloor(texture: Texture): Model
|
|
|
|
{
|
|
|
|
val modelBuilder = ModelBuilder()
|
2023-08-16 16:26:05 +10:00
|
|
|
val material = Material(
|
|
|
|
ColorAttribute.createDiffuse(XnaColor.BlanchedAlmond.lighten(0.01)),
|
|
|
|
ColorAttribute.createSpecular(XnaColor.BlanchedAlmond.mix(XnaColor.Black, 0.4f)),
|
|
|
|
FloatAttribute.createShininess(65.0f),
|
|
|
|
TextureAttribute.createDiffuse(texture))
|
2023-08-16 13:10:48 +10:00
|
|
|
val attribs = VertexAttributes.Usage.Position or VertexAttributes.Usage.TextureCoordinates or VertexAttributes.Usage.Normal
|
|
|
|
val size = 10.0f
|
|
|
|
return modelBuilder.createRect(
|
|
|
|
0.0f, 0.0f, 0.0f,
|
|
|
|
size, 0.0f, 0.0f,
|
|
|
|
size, 0.0f, -size,
|
|
|
|
0.0f, 0.0f, -size,
|
|
|
|
0.0f, 1.0f, 0.0f,
|
|
|
|
material, attribs.toLong())
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun create()
|
|
|
|
{
|
|
|
|
Resources.instance.loadAssets()
|
|
|
|
assetManager.finishLoading()
|
|
|
|
|
|
|
|
texJolk = assetManager.get("jolkmeup.jpg")
|
|
|
|
fntComic = assetManager.get("Comic Sans MS.ttf")
|
2023-08-16 16:26:05 +10:00
|
|
|
val suzanne = assetManager.get("suzanne.g3db", Model::class.java)
|
2023-08-16 13:10:48 +10:00
|
|
|
|
2023-08-16 16:26:05 +10:00
|
|
|
// Override ridiculous shininess because i cbf to fix the model
|
|
|
|
for (i in suzanne.materials)
|
|
|
|
i.set(FloatAttribute.createShininess(30.0f))
|
2023-08-16 13:10:48 +10:00
|
|
|
|
|
|
|
cube = makeCube(texJolk)
|
|
|
|
floor = makeFloor(assetManager.get("cobblestone.png"))
|
|
|
|
|
|
|
|
spriteBatch = SpriteBatch()
|
|
|
|
|
|
|
|
env = Environment()
|
2023-08-17 21:17:28 +10:00
|
|
|
env.set(
|
|
|
|
IntAttribute.createCullFace(GL20.GL_BACK),
|
|
|
|
ColorAttribute.createAmbientLight(XnaColor.DarkSlateGray.lighten(-0.6)),
|
|
|
|
ColorAttribute.createFog(XnaColor.CornflowerBlue))
|
|
|
|
env.set(
|
|
|
|
CustomIntAttribute.createFogMode(CustomIntAttribute.FogModes.Depth),
|
|
|
|
CustomIntAttribute.createFogType(CustomIntAttribute.FogTypes.Smooth),
|
|
|
|
CustomFloatAttribute.createFogNear(0.75f),
|
|
|
|
CustomFloatAttribute.createFogFar(20.5f))
|
|
|
|
/*
|
|
|
|
env.set(
|
|
|
|
CustomIntAttribute.createFogMode(CustomIntAttribute.FogModes.Distance),
|
|
|
|
CustomIntAttribute.createFogType(CustomIntAttribute.FogTypes.Exp2),
|
|
|
|
CustomFloatAttribute.createFogDensity(0.1f))
|
|
|
|
*/
|
2023-08-16 13:10:48 +10:00
|
|
|
env.add(DirectionalLight().set(XnaColor.White, Vector3(1.0f, -1.0f, -1.0f).nor()))
|
|
|
|
|
2023-08-17 21:17:28 +10:00
|
|
|
val shaderConfig = DefaultShader.Config()
|
2023-08-16 13:10:48 +10:00
|
|
|
shaderConfig.numDirectionalLights = 1
|
|
|
|
shaderConfig.numPointLights = 0
|
|
|
|
shaderConfig.numBones = 0
|
2023-08-17 21:17:28 +10:00
|
|
|
modelBatch = ModelBatch(CustomDefaultShaderProvider(shaderConfig))
|
2023-08-16 13:10:48 +10:00
|
|
|
|
|
|
|
colin = Colin()
|
|
|
|
|
|
|
|
cubeInstance = ModelInstance(cube)
|
|
|
|
floorInstance = ModelInstance(floor)
|
2023-08-16 16:26:05 +10:00
|
|
|
suzanneInstance = ModelInstance(suzanne)
|
2023-08-16 13:10:48 +10:00
|
|
|
suzanneInstance.transform = Matrix4().translate(3.0f, 1.0f, -3.5f)
|
|
|
|
}
|
|
|
|
|
2023-08-16 16:54:45 +10:00
|
|
|
override fun resize(width: Int, height: Int)
|
|
|
|
{
|
|
|
|
colin.resize(width, height)
|
|
|
|
spriteBatch.projectionMatrix.setToOrtho2D(0.0f, 0.0f,
|
|
|
|
Gdx.graphics.getWidth().toFloat(),
|
|
|
|
Gdx.graphics.getHeight().toFloat());
|
|
|
|
}
|
|
|
|
|
2023-08-16 13:10:48 +10:00
|
|
|
private fun update(deltaTime: Float)
|
|
|
|
{
|
|
|
|
colin.update(deltaTime)
|
|
|
|
|
|
|
|
jolkRot += 15.0f * deltaTime
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun render()
|
|
|
|
{
|
|
|
|
val deltaTime = Gdx.graphics.deltaTime
|
|
|
|
update(deltaTime)
|
|
|
|
|
2023-08-17 21:17:28 +10:00
|
|
|
ScreenUtils.clear(XnaColor.CornflowerBlue, true)
|
2023-08-16 13:10:48 +10:00
|
|
|
|
|
|
|
val jolkPos = Vector3(0.0f, 1.0f + MathUtils.sin(jolkRot * 0.25f) * 0.25f, -4.0f)
|
|
|
|
val world = Matrix4()
|
|
|
|
.setTranslation(jolkPos)
|
|
|
|
.rotateRad(1.0f, 0.0f, 0.0f, jolkRot * 0.25f)
|
|
|
|
.rotate(0.0f, 1.0f, 0.0f, jolkRot)
|
|
|
|
.scale(0.25f, 0.25f, 0.25f)
|
|
|
|
cubeInstance.transform = world
|
|
|
|
|
|
|
|
modelBatch.begin(colin.camera)
|
|
|
|
modelBatch.render(floorInstance, env)
|
|
|
|
modelBatch.render(cubeInstance, env)
|
|
|
|
modelBatch.render(suzanneInstance, env)
|
|
|
|
modelBatch.end()
|
|
|
|
|
|
|
|
spriteBatch.begin()
|
|
|
|
colin.draw(spriteBatch)
|
|
|
|
val textPos = colin.camera.project(jolkPos)
|
|
|
|
if (textPos.z < 1.0)
|
|
|
|
fntComic.draw(spriteBatch, "I am filled with jolk", textPos.x, textPos.y)
|
|
|
|
fntComic.draw(spriteBatch, "${colin.position.x}\n${colin.position.y}", 10.0f, Gdx.graphics.height - 10.0f)
|
|
|
|
spriteBatch.end()
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun dispose()
|
|
|
|
{
|
|
|
|
floor.dispose()
|
|
|
|
cube.dispose()
|
|
|
|
modelBatch.dispose()
|
|
|
|
spriteBatch.dispose()
|
|
|
|
assetManager.dispose()
|
|
|
|
}
|
|
|
|
}
|