summaryrefslogtreecommitdiff
path: root/src/main/kotlin/de/romjaki/pluggabledino/main.kt
blob: ca9acc016d7237ca518eedb492fa94ed23c8eca0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package de.romjaki.pluggabledino

import de.romjaki.pluggabledino.api.Events
import de.romjaki.pluggabledino.api.PluginLoader
import de.romjaki.pluggabledino.events.InitEvent
import de.romjaki.pluggabledino.events.PostInitEvent
import de.romjaki.pluggabledino.events.PreInitEvent
import de.romjaki.pluggabledino.states.*
import org.newdawn.slick.AppGameContainer
import org.newdawn.slick.GameContainer
import org.newdawn.slick.Input
import org.newdawn.slick.state.StateBasedGame


const val WIDTH = 640
const val HEIGHT = 480
const val REAL_WIDTH = 800
const val REAL_HEIGHT = 600
const val WIDTH_RATIO = REAL_WIDTH.toFloat() / WIDTH
const val HEIGHT_RATIO = REAL_HEIGHT.toFloat() / HEIGHT
const val FPS = 60
const val VERSION = 1.0

const val SPLASHSCREEN = 0
const val MAINMENU = 1
const val SETTINGS = 3
const val GAME = 2
const val LOST = 4
var lastscore = 0
var highscore = 0
var score = 0
val settings = SettingsState()

fun main(args: Array<String>) {
    if (args.size > 1 && args[0] == "dev") {
        PluginLoader.loadDevPlugin(args[1])
    }
    PluginLoader.loadPlugins()
    Input.disableControllers()
    val app = AppGameContainer(Application())
    app.setDisplayMode(REAL_WIDTH, REAL_HEIGHT, false)
    app.setTargetFrameRate(FPS)
    app.setShowFPS(true)
    Events.broadcastEvent(PreInitEvent(app))
    Events.broadcastEvent(InitEvent(app, settings))
    Events.broadcastEvent(PostInitEvent(app))
    app.start()

}

class Application : StateBasedGame("Dino Game v$VERSION") {
    override fun initStatesList(container: GameContainer?) {
        addState(SplashScreen())
        addState(MainMenu())
        addState(settings)
        addState(GameState())
        addState(LostState())
    }
}