Skip to content

Commit

Permalink
Merge pull request #27 from Blaarkies/#17-add-weapons
Browse files Browse the repository at this point in the history
#17 add weapons
  • Loading branch information
Blaarkies authored Apr 19, 2020
2 parents c4e47f1 + b78d973 commit f91b25e
Show file tree
Hide file tree
Showing 47 changed files with 1,930 additions and 579 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# <h1>Volynov</h1>
<h3>A space artillery game designed for players that want to destroy each other and the planets around them. Fire missiles, bomb, high tech payloads, and sabotage equipment at the enemy and odge their attempts to do the same. All spaceships, planets and warheads are influenced by realistic physics to produce n-body orbits and collisions.</h3>
<h3>A space artillery game designed for players that want to destroy each other and the planets around them. Fire missiles, bombs, high tech payloads, and sabotage equipment at the enemy and dodge their attempts to do the same. All spaceships, planets and warheads are influenced by realistic physics to produce n-body orbits and collisions.</h3>

<br>
<h6>2020 03 01, First contact, again
Expand Down
150 changes: 101 additions & 49 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,8 @@ plugins {
kotlin("jvm") version "1.3.41"
}

kotlin {
experimental {
coroutines = org.jetbrains.kotlin.gradle.dsl.Coroutines.ENABLE
}
}

group = "blaarkies"
version = "0.0-SNAPSHOT"
version = "0.0.0"

repositories {
mavenCentral()
Expand All @@ -21,13 +15,6 @@ val kotlinVersion = "1.3.10"
val lwjglVersion = "3.2.3"
val lwjglNatives = "natives-windows"

tasks.test {
useJUnitPlatform()
testLogging {
events("PASSED", "SKIPPED", "FAILED")
}
}

dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3")
Expand All @@ -39,49 +26,114 @@ dependencies {
implementation(platform("org.lwjgl:lwjgl-bom:$lwjglVersion"))
val lwjglList = listOf(
arrayOf("lwjgl", true),
// arrayOf("lwjgl-assimp", true),
// arrayOf("lwjgl-bgfx", true),
// arrayOf("lwjgl-cuda", false),
// arrayOf("lwjgl-egl", false),
// arrayOf("lwjgl-assimp", true),
// arrayOf("lwjgl-bgfx", true),
// arrayOf("lwjgl-cuda", false),
// arrayOf("lwjgl-egl", false),
arrayOf("lwjgl-glfw", true),
arrayOf("lwjgl-jawt", false),
// arrayOf("lwjgl-jemalloc", true),
// arrayOf("lwjgl-libdivide", true),
// arrayOf("lwjgl-llvm", true),
// arrayOf("lwjgl-lmdb", true),
// arrayOf("lwjgl-lz4", true),
// arrayOf("lwjgl-meow", true),
// arrayOf("lwjgl-nanovg", true),
// arrayOf("lwjgl-nfd", true),
// arrayOf("lwjgl-nuklear", true),
// arrayOf("lwjgl-odbc", false),
// arrayOf("lwjgl-openal", true),
// arrayOf("lwjgl-opencl", false),
// arrayOf("lwjgl-jemalloc", true),
// arrayOf("lwjgl-libdivide", true),
// arrayOf("lwjgl-llvm", true),
// arrayOf("lwjgl-lmdb", true),
// arrayOf("lwjgl-lz4", true),
// arrayOf("lwjgl-meow", true),
// arrayOf("lwjgl-nanovg", true),
// arrayOf("lwjgl-nfd", true),
// arrayOf("lwjgl-nuklear", true),
// arrayOf("lwjgl-odbc", false),
// arrayOf("lwjgl-openal", true),
// arrayOf("lwjgl-opencl", false),
arrayOf("lwjgl-opengl", true),
// arrayOf("lwjgl-opengles", true),
// arrayOf("lwjgl-openvr", true),
// arrayOf("lwjgl-opus", true),
// arrayOf("lwjgl-ovr", true),
// arrayOf("lwjgl-par", true),
// arrayOf("lwjgl-remotery", true),
// arrayOf("lwjgl-rpmalloc", true),
// arrayOf("lwjgl-shaderc", true),
// arrayOf("lwjgl-sse", true),
// arrayOf("lwjgl-opengles", true),
// arrayOf("lwjgl-openvr", true),
// arrayOf("lwjgl-opus", true),
// arrayOf("lwjgl-ovr", true),
// arrayOf("lwjgl-par", true),
// arrayOf("lwjgl-remotery", true),
// arrayOf("lwjgl-rpmalloc", true),
// arrayOf("lwjgl-shaderc", true),
// arrayOf("lwjgl-sse", true),
arrayOf("lwjgl-stb", true)
// arrayOf("lwjgl-tinyexr", true),
// arrayOf("lwjgl-tinyfd", true),
// arrayOf("lwjgl-tootle", true),
// arrayOf("lwjgl-vma", true),
// arrayOf("lwjgl-vulkan", false),
// arrayOf("lwjgl-xxhash", true),
// arrayOf("lwjgl-yoga", true),
// arrayOf("lwjgl-zstd", true)
// arrayOf("lwjgl-tinyexr", true),
// arrayOf("lwjgl-tinyfd", true),
// arrayOf("lwjgl-tootle", true),
// arrayOf("lwjgl-vma", true),
// arrayOf("lwjgl-vulkan", false),
// arrayOf("lwjgl-xxhash", true),
// arrayOf("lwjgl-yoga", true),
// arrayOf("lwjgl-zstd", true)
)
lwjglList.forEach { implementation("org.lwjgl", it[0].toString()) }
lwjglList.filter { it[1] == true }
.forEach { runtimeOnly("org.lwjgl", it[0].toString(), classifier = lwjglNatives) }
}

tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "11"
sourceSets {
main {
resources {
exclude("textures", "fonts")
}
}
}

tasks {

withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}

register<Zip>("zipFolder") {
from("$buildDir/Volynov-$version")
destinationDirectory.set(File("$buildDir/"))
}

task("renameFolder") {
mustRunAfter("createBat")
doLast {
file("$buildDir/libs").renameTo(file("$buildDir/Volynov-$version"))
}
}

task("createBat") {
mustRunAfter("uberJar")
doLast {
File("$buildDir/libs/run.bat")
.writeText("""|chcp 65001
|java -Dfile.encoding=UTF-8 -Dorg.lwjgl.util.Debug=true -jar ./volynov-$version-uber.jar
|pause
""".trimMargin())
}
}

register<Copy>("copyTextures") {
from("$projectDir/src/main/resources")
exclude("shaders")
into("$buildDir/libs")
}

register<Jar>("uberJar") {
dependsOn(configurations.runtimeClasspath)

archiveClassifier.set("uber")
manifest { attributes["Main-Class"] = "MainKt" }

from(sourceSets.main.get().output)
from({
configurations.runtimeClasspath.get()
.filter { it.name.endsWith("jar") }
.map { zipTree(it) }
})
}

task("package") {
group = "build"
dependsOn("clean", "uberJar", "copyTextures", "createBat", "renameFolder", "zipFolder")
}
}

tasks.test {
group = "build"
useJUnitPlatform()
testLogging { events("PASSED", "SKIPPED", "FAILED") }
}
2 changes: 1 addition & 1 deletion src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import kotlin.system.exitProcess
fun main() = runBlocking {
try {
val gameLogic: IGameLogic = AppLogic()
val gameEngine = AppRunner("Volynov", 700, 700, true, gameLogic)
val gameEngine = AppRunner("Volynov", 1920, 1080, true, gameLogic)
gameEngine.run()
} catch (exception: Exception) {
exception.printStackTrace()
Expand Down
7 changes: 3 additions & 4 deletions src/main/kotlin/app/AppLogic.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@ class AppLogic : IGameLogic {
private val renderer = Renderer()

private val gameState = GameState()
private val textures = TextureHolder()
private val drawer = Drawer(renderer, textures)
private val gamePhaseHandler = GamePhaseHandler(gameState, drawer, textures)
private val drawer = Drawer(renderer)
private val gamePhaseHandler = GamePhaseHandler(gameState, drawer)
private val inputHandler = InputHandler(gamePhaseHandler)

@Throws(Exception::class)
override fun init(window: Window) {
gameState.init(window)
renderer.init(gameState.camera)
textures.init()
drawer.init()
gamePhaseHandler.init(window)
inputHandler.init(window)
}
Expand Down
42 changes: 26 additions & 16 deletions src/main/kotlin/display/Window.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
package display

import display.events.MouseButtonEvent
import display.events.MouseScrollEvent
import io.reactivex.subjects.PublishSubject
import org.jbox2d.common.Vec2
import org.lwjgl.BufferUtils
import org.lwjgl.glfw.GLFW
import org.lwjgl.glfw.GLFW.glfwGetKey
import org.lwjgl.glfw.GLFW.glfwGetKeyName
import org.lwjgl.glfw.GLFWErrorCallback
import org.lwjgl.opengl.GL
import org.lwjgl.opengl.GL11
import org.lwjgl.opengl.GL11.*
import org.lwjgl.system.Callback
import org.lwjgl.system.MemoryUtil
import utility.Common.makeVec2
import java.nio.DoubleBuffer

class Window(private val title: String, var width: Int, var height: Int, private var vSync: Boolean) {

Expand All @@ -21,7 +26,8 @@ class Window(private val title: String, var width: Int, var height: Int, private
val keyboardEvent = PublishSubject.create<KeyboardEvent>()
val mouseButtonEvent = PublishSubject.create<MouseButtonEvent>()
val cursorPositionEvent = PublishSubject.create<Vec2>()
val mouseScrollEvent = PublishSubject.create<Vec2>()
val mouseScrollEvent = PublishSubject.create<MouseScrollEvent>()
val textInputEvent = PublishSubject.create<String>()

fun init() {
// Setup an error callback. The default implementation
Expand All @@ -41,20 +47,22 @@ class Window(private val title: String, var width: Int, var height: Int, private
GLFW.glfwWindowHint(GLFW.GLFW_SAMPLES, 4) // anti-aliasing

// Create the window
windowHandle = GLFW.glfwCreateWindow(width, height, title, MemoryUtil.NULL, MemoryUtil.NULL)
if (windowHandle == MemoryUtil.NULL) {
throw RuntimeException("Failed to create the GLFW window")
}
windowHandle = GLFW.glfwCreateWindow(width, height, title, GLFW.glfwGetPrimaryMonitor(), MemoryUtil.NULL)
// windowHandle = GLFW.glfwCreateWindow(width, height, title, MemoryUtil.NULL, MemoryUtil.NULL)
// if (windowHandle == MemoryUtil.NULL) {
// throw RuntimeException("Failed to create the GLFW window")
// }
// Setup resize callback
GLFW.glfwSetFramebufferSizeCallback(windowHandle) { _, width, height ->
this.width = width
this.height = height
}

// Get the resolution of the primary monitor
val videoMode = GLFW.glfwGetVideoMode(GLFW.glfwGetPrimaryMonitor())!!
// val videoMode = GLFW.glfwGetVideoMode(GLFW.glfwGetPrimaryMonitor())!!
// Center our window
GLFW.glfwSetWindowPos(windowHandle, (videoMode.width() - width) / 2, (videoMode.height() - height) / 2)
// GLFW.glfwSetWindowPos(windowHandle, (videoMode.width() - width) / 2, (videoMode.height() - height) / 2)

GLFW.glfwMakeContextCurrent(windowHandle) // Make the OpenGL context current
if (isVSync()) { // Enable v-sync
GLFW.glfwSwapInterval(1)
Expand All @@ -67,7 +75,7 @@ class Window(private val title: String, var width: Int, var height: Int, private
}

private fun setupInputCallbacks() {
GLFW.glfwSetKeyCallback(windowHandle) { window, key, scancode, action, mods ->
GLFW.glfwSetKeyCallback(windowHandle) { _, key, scancode, action, mods ->
if (action == GLFW.GLFW_PRESS) {
when {
key == GLFW.GLFW_KEY_F12 -> {
Expand All @@ -82,20 +90,22 @@ class Window(private val title: String, var width: Int, var height: Int, private
}
}?.let { callbacks.add(it) }

GLFW.glfwSetMouseButtonCallback(windowHandle) { window, button, action, mods ->
GLFW.glfwSetMouseButtonCallback(windowHandle) { _, button, action, mods ->
mouseButtonEvent.onNext(MouseButtonEvent(button, action, mods, getCursorPosition()))
}?.let { callbacks.add(it) }

GLFW.glfwSetCursorPosCallback(windowHandle) { window, xPos, yPos ->
cursorPositionEvent.onNext(Vec2(xPos.toFloat(), yPos.toFloat()))
GLFW.glfwSetCursorPosCallback(windowHandle) { _, xPos, yPos ->
cursorPositionEvent.onNext(makeVec2(xPos, yPos))
}?.let { callbacks.add(it) }

GLFW.glfwSetScrollCallback(windowHandle) { window, xOffset, yOffset ->
mouseScrollEvent.onNext(Vec2(xOffset.toFloat(), yOffset.toFloat()))
GLFW.glfwSetScrollCallback(windowHandle) { _, xOffset, yOffset ->
mouseScrollEvent.onNext(MouseScrollEvent(makeVec2(xOffset, yOffset), getCursorPosition()))
}?.let { callbacks.add(it) }

// glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
// glfwSetCharCallback(window, character_callback);
GLFW.glfwSetCharCallback(windowHandle) { _, codepoint ->
textInputEvent.onNext(Character.toChars(codepoint)[0].toString())
}?.let { callbacks.add(it) }
// glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
}

fun setClearColor(r: Float, g: Float, b: Float, alpha: Float) {
Expand All @@ -120,7 +130,7 @@ class Window(private val title: String, var width: Int, var height: Int, private
val y = BufferUtils.createDoubleBuffer(1)
GLFW.glfwGetCursorPos(windowHandle, x, y)

return Vec2(x.get().toFloat(), y.get().toFloat())
return makeVec2(x, y)
}

fun exit() {
Expand Down
Loading

0 comments on commit f91b25e

Please sign in to comment.