├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── src
├── commonMain
│ ├── assetsSource
│ │ ├── cube.blend
│ │ ├── cube.blend1
│ │ └── cube.gltf
│ ├── resources
│ │ └── cube.protobuf
│ └── kotlin
│ │ └── your
│ │ └── game
│ │ ├── components
│ │ └── Cube.kt
│ │ ├── MyGame.kt
│ │ └── systems
│ │ └── RotatingCubeSystem.kt
├── jsMain
│ ├── resources
│ │ └── index.html
│ └── kotlin
│ │ └── your
│ │ └── game
│ │ └── Main.kt
└── jvmMain
│ └── kotlin
│ └── your
│ └── game
│ └── Main.kt
├── .gitattributes
├── .gitignore
├── README.md
├── settings.gradle.kts
├── LICENSE
├── .github
└── workflows
│ └── build_bundles.yml
├── gradlew.bat
└── gradlew
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/minigdx/minigdx-game-template/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/src/commonMain/assetsSource/cube.blend:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/minigdx/minigdx-game-template/HEAD/src/commonMain/assetsSource/cube.blend
--------------------------------------------------------------------------------
/src/commonMain/assetsSource/cube.blend1:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/minigdx/minigdx-game-template/HEAD/src/commonMain/assetsSource/cube.blend1
--------------------------------------------------------------------------------
/src/commonMain/resources/cube.protobuf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/minigdx/minigdx-game-template/HEAD/src/commonMain/resources/cube.protobuf
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | #
2 | # https://help.github.com/articles/dealing-with-line-endings/
3 | #
4 | # These are explicitly windows files and should use crlf
5 | *.bat text eol=crlf
6 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.2-bin.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /build/
3 |
4 | # Ignore Gradle GUI config
5 | gradle-app.setting
6 |
7 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
8 | !gradle-wrapper.jar
9 |
10 | # Cache of project
11 | .gradletasknamecache
12 |
13 | # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
14 | # gradle/wrapper/gradle-wrapper.properties
15 |
16 | .idea
17 |
--------------------------------------------------------------------------------
/src/jsMain/resources/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | MiniGDX - Your Game
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/your/game/components/Cube.kt:
--------------------------------------------------------------------------------
1 | package your.game.components
2 |
3 | import com.github.dwursteisen.minigdx.Seconds
4 | import com.github.dwursteisen.minigdx.ecs.components.Component
5 |
6 | /**
7 | * Cube component: tag to mark entities that are cube.
8 | */
9 | class Cube(
10 | // Remaining time of the cube movement
11 | var duration: Seconds = 0f
12 | ) : Component
13 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # MiniGDX Game Template
2 |
3 | Create your first game using miniGDX by clicking the "Use this Template" button above.
4 |
5 | The game will be configured for:
6 |
7 | - the JVM platform (try it by running `./gradlew runJvm` command!)
8 | - the Web platform (try it by running `./gradlew runJs` command!)
9 |
10 |
11 | Get [more informations](https://github.com/minigdx) on miniGDX.
12 |
13 | ## Github Actions
14 |
15 | This template contains [github actions](https://docs.github.com/en/actions) that generate
16 | the bundles of your game for you.
17 |
--------------------------------------------------------------------------------
/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | /*
2 | * This file was generated by the Gradle 'init' task.
3 | *
4 | * The settings file is used to specify which projects to include in your build.
5 | *
6 | * Detailed information about configuring a multi-project build in Gradle can be found
7 | * in the user manual at https://docs.gradle.org/6.8.2/userguide/multi_project_builds.html
8 | */
9 |
10 | rootProject.name = "minigdx-game-template"
11 |
12 | pluginManagement {
13 | repositories {
14 | gradlePluginPortal()
15 | google()
16 | maven {
17 | url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
18 | }.mavenContent {
19 | includeVersionByRegex("com.github.minigdx.(.*)", "(.*)", "LATEST-SNAPSHOT")
20 | includeVersionByRegex("com.github.minigdx", "(.*)", "LATEST-SNAPSHOT")
21 | }
22 | mavenLocal()
23 | jcenter()
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 dwursteisen
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/.github/workflows/build_bundles.yml:
--------------------------------------------------------------------------------
1 | name: Build bundles for all platforms
2 | # This workflow is triggered on pushes to the repository or can be trigger manually.
3 | on: [push, workflow_dispatch]
4 |
5 | jobs:
6 | build:
7 | runs-on: ubuntu-latest
8 |
9 | steps:
10 | - name: Checkout the repo
11 | uses: actions/checkout@v2
12 | - name: Validate Gradle Wrapper
13 | uses: gradle/wrapper-validation-action@v1
14 | - name: Cache gradle
15 | uses: actions/cache@v1
16 | with:
17 | path: ~/.gradle/caches
18 | key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle.kts') }}
19 | restore-keys: |
20 | ${{ runner.os }}-gradle
21 | - name: Set up JDK 11
22 | uses: actions/setup-java@v1
23 | with:
24 | java-version: 11
25 | - name: Bundle Game
26 | run: ./gradlew bundle-js bundle-jar
27 | - name: Archive production artifacts
28 | uses: actions/upload-artifact@v2
29 | with:
30 | name: bundles
31 | path: build/minigdx/*
32 | retention-days: 3
33 |
34 | env:
35 | GRADLE_OPTS: -Dorg.gradle.configureondemand=true -Dorg.gradle.parallel=true -Dkotlin.incremental=false -Dorg.gradle.jvmargs="-Xmx3g -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8"
36 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/your/game/MyGame.kt:
--------------------------------------------------------------------------------
1 | package your.game
2 |
3 | import com.dwursteisen.minigdx.scene.api.Scene
4 | import com.dwursteisen.minigdx.scene.api.relation.ObjectType
5 | import com.github.dwursteisen.minigdx.GameContext
6 | import com.github.dwursteisen.minigdx.ecs.Engine
7 | import com.github.dwursteisen.minigdx.ecs.entities.EntityFactory
8 | import com.github.dwursteisen.minigdx.ecs.systems.System
9 | import com.github.dwursteisen.minigdx.file.get
10 | import com.github.dwursteisen.minigdx.game.Game
11 | import your.game.components.Cube
12 | import your.game.systems.RotatingCubeSystem
13 |
14 | class MyGame(override val gameContext: GameContext) : Game {
15 |
16 | private val scene by gameContext.fileHandler.get("cube.protobuf")
17 |
18 | override fun createEntities(entityFactory: EntityFactory) {
19 | // Create all entities needed at startup
20 | // The scene is the node graph that can be updated in Blender
21 | scene.children.forEach { node ->
22 | // Create an entity using all information from this node (model, position, camera, ...)
23 | val entity = entityFactory.createFromNode(node, scene)
24 |
25 | // The node is the cube from the Blender file
26 | if(node.type == ObjectType.MODEL) {
27 | // Mark this entity as being a cube
28 | entity.add(Cube())
29 | }
30 | }
31 | }
32 |
33 | override fun createSystems(engine: Engine): List {
34 | // Create all systems used by the game
35 | return listOf(RotatingCubeSystem())
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/your/game/Main.kt:
--------------------------------------------------------------------------------
1 | package your.game
2 |
3 | import com.github.dwursteisen.minigdx.GameApplicationBuilder
4 | import com.github.dwursteisen.minigdx.GameConfiguration
5 | import com.github.dwursteisen.minigdx.GameScreenConfiguration
6 | import com.github.dwursteisen.minigdx.Window
7 |
8 | object Main {
9 |
10 | @JvmStatic
11 | fun main(vararg args: String) {
12 | // This class can be run unsing the command `./gradlew runJvm`
13 | GameApplicationBuilder(
14 | gameConfigurationFactory = {
15 | GameConfiguration(
16 | // Name of the game
17 | gameName = "My Game",
18 | // Screen configuration used for your game (ie: how should render your game)
19 | gameScreenConfiguration = GameScreenConfiguration.WithRatio(16f / 9f),
20 | // Is your game should use show debug information? (hitbox, ...)
21 | debug = false,
22 | // (JVM Specific configuration)
23 | // Configuration of the window use to render your game
24 | window = Window(
25 | // Width of the window
26 | 1024,
27 | // Height of the window
28 | (1024 * 9f / 16f).toInt(),
29 | // Name of the window
30 | "My Game - running on the JVM"
31 | )
32 | )
33 | },
34 | // Creation of your game
35 | gameFactory = { MyGame(it) }
36 | ).start() // Don't forget to call the start method to run your game!
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/your/game/systems/RotatingCubeSystem.kt:
--------------------------------------------------------------------------------
1 | package your.game.systems
2 |
3 | import com.github.dwursteisen.minigdx.Seconds
4 | import com.github.dwursteisen.minigdx.ecs.entities.Entity
5 | import com.github.dwursteisen.minigdx.ecs.entities.position
6 | import com.github.dwursteisen.minigdx.ecs.systems.EntityQuery
7 | import com.github.dwursteisen.minigdx.ecs.systems.System
8 | import com.github.dwursteisen.minigdx.input.Key
9 | import your.game.components.Cube
10 | import kotlin.math.abs
11 | import kotlin.math.cos
12 |
13 | /**
14 | * Rotate entities with [Cube] component by 90 degrees per second.
15 | */
16 | class RotatingCubeSystem : System(EntityQuery.of(Cube::class)) {
17 |
18 | override fun update(delta: Seconds, entity: Entity) {
19 | val component = entity.get(Cube::class)
20 | // If the key SPACE is pressed one time,
21 | // then set the duration of the component to 2 seconds.
22 | if(input.isKeyJustPressed(Key.SPACE)) {
23 | component.duration = 2f
24 | }
25 |
26 | // If there is a duration, the cube can be scaled
27 | if(component.duration > 0f) {
28 | component.duration -= delta
29 | // Compute the scale regarding the remaining duration using a cosine function
30 | // and keep the absolute value so the scale is always positive.
31 | val scale = abs(cos(component.duration))
32 |
33 | // Set the scale of the cube.
34 | entity.position.setLocalScale(
35 | x = scale,
36 | y = scale,
37 | z = scale
38 | )
39 | }
40 |
41 | // Rotate the cube of 90 degrees per second.
42 | entity.position.addLocalRotation(y = 90f, delta = delta)
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/jsMain/kotlin/your/game/Main.kt:
--------------------------------------------------------------------------------
1 | package your.game
2 |
3 | import com.github.dwursteisen.minigdx.GameApplicationBuilder
4 | import com.github.dwursteisen.minigdx.GameConfiguration
5 | import com.github.dwursteisen.minigdx.GameScreenConfiguration
6 | import org.w3c.dom.HTMLCanvasElement
7 | import org.w3c.dom.get
8 | import kotlinx.browser.document
9 | import kotlinx.browser.window
10 |
11 | fun main() {
12 | // Look for the first canvas in current page.
13 | val canvas = document.getElementsByTagName("canvas")[0] ?: throw IllegalArgumentException(
14 | "No