More worwk on korge-coffee

This commit is contained in:
Carlos Ballesteros Velasco
2017-05-08 20:38:37 +02:00
parent 0720695664
commit 1d04bc6e57
8 changed files with 577 additions and 43 deletions

1
.gitignore vendored
View File

@@ -3,3 +3,4 @@
/build
/classes
RECUP_*.fla
game.storage

View File

@@ -25,6 +25,7 @@ dependencies {
jtransc {
minimizeNames = true
//minimizeNames = false
treeshaking = true
assets("resources")

View File

@@ -0,0 +1,188 @@
<font>
<info face="font" size="72" bold="0" italic="0" charset="" unicode="" stretchH="100" smooth="1" aa="1" padding="2,2,2,2" spacing="0,0" outline="0"/>
<common lineHeight="80" base="57" scaleW="470" scaleH="512" pages="1" packed="0"/>
<pages>
<page id="0" file="font.png"/>
</pages>
<chars count="80">
<char id="97" x="2" y="2" width="43" height="47" xoffset="3" yoffset="18" xadvance="40" page="0" chnl="15"/>
<char id="98" x="2" y="51" width="41" height="61" xoffset="5" yoffset="5" xadvance="40" page="0" chnl="15"/>
<char id="99" x="2" y="114" width="41" height="47" xoffset="3" yoffset="18" xadvance="36" page="0" chnl="15"/>
<char id="100" x="2" y="163" width="41" height="61" xoffset="2" yoffset="5" xadvance="40" page="0" chnl="15"/>
<char id="101" x="2" y="226" width="43" height="47" xoffset="3" yoffset="18" xadvance="40" page="0" chnl="15"/>
<char id="102" x="45" y="51" width="30" height="61" xoffset="1" yoffset="4" xadvance="20" page="0" chnl="15"/>
<char id="103" x="45" y="114" width="41" height="62" xoffset="2" yoffset="18" xadvance="40" page="0" chnl="15"/>
<char id="104" x="77" y="2" width="39" height="60" xoffset="5" yoffset="5" xadvance="40" page="0" chnl="15"/>
<char id="105" x="2" y="275" width="15" height="60" xoffset="5" yoffset="5" xadvance="16" page="0" chnl="15"/>
<char id="106" x="2" y="337" width="24" height="75" xoffset="-4" yoffset="5" xadvance="16" page="0" chnl="15"/>
<char id="107" x="19" y="275" width="40" height="60" xoffset="5" yoffset="5" xadvance="36" page="0" chnl="15"/>
<char id="108" x="47" y="178" width="15" height="60" xoffset="5" yoffset="5" xadvance="16" page="0" chnl="15"/>
<char id="109" x="77" y="64" width="59" height="47" xoffset="5" yoffset="18" xadvance="60" page="0" chnl="15"/>
<char id="110" x="118" y="2" width="39" height="47" xoffset="5" yoffset="18" xadvance="40" page="0" chnl="15"/>
<char id="111" x="2" y="414" width="43" height="47" xoffset="2" yoffset="18" xadvance="40" page="0" chnl="15"/>
<char id="112" x="28" y="337" width="41" height="61" xoffset="5" yoffset="18" xadvance="40" page="0" chnl="15"/>
<char id="113" x="61" y="240" width="41" height="61" xoffset="3" yoffset="18" xadvance="40" page="0" chnl="15"/>
<char id="114" x="2" y="463" width="29" height="47" xoffset="5" yoffset="18" xadvance="24" page="0" chnl="15"/>
<char id="115" x="33" y="463" width="40" height="47" xoffset="2" yoffset="18" xadvance="36" page="0" chnl="15"/>
<char id="116" x="64" y="178" width="27" height="60" xoffset="1" yoffset="6" xadvance="20" page="0" chnl="15"/>
<char id="117" x="47" y="400" width="39" height="47" xoffset="5" yoffset="19" xadvance="40" page="0" chnl="15"/>
<char id="118" x="75" y="449" width="43" height="46" xoffset="1" yoffset="19" xadvance="36" page="0" chnl="15"/>
<char id="119" x="88" y="113" width="60" height="46" xoffset="0" yoffset="19" xadvance="52" page="0" chnl="15"/>
<char id="120" x="138" y="51" width="45" height="46" xoffset="0" yoffset="19" xadvance="36" page="0" chnl="15"/>
<char id="121" x="93" y="161" width="43" height="61" xoffset="1" yoffset="19" xadvance="36" page="0" chnl="15"/>
<char id="122" x="159" y="2" width="41" height="46" xoffset="1" yoffset="19" xadvance="36" page="0" chnl="15"/>
<char id="65" x="71" y="303" width="57" height="60" xoffset="0" yoffset="5" xadvance="48" page="0" chnl="15"/>
<char id="66" x="104" y="224" width="47" height="60" xoffset="5" yoffset="5" xadvance="48" page="0" chnl="15"/>
<char id="67" x="88" y="365" width="54" height="62" xoffset="4" yoffset="4" xadvance="52" page="0" chnl="15"/>
<char id="68" x="138" y="161" width="51" height="60" xoffset="6" yoffset="5" xadvance="52" page="0" chnl="15"/>
<char id="69" x="150" y="99" width="47" height="60" xoffset="6" yoffset="5" xadvance="48" page="0" chnl="15"/>
<char id="70" x="130" y="286" width="43" height="60" xoffset="6" yoffset="5" xadvance="44" page="0" chnl="15"/>
<char id="71" x="120" y="429" width="56" height="62" xoffset="4" yoffset="4" xadvance="56" page="0" chnl="15"/>
<char id="72" x="153" y="223" width="49" height="60" xoffset="6" yoffset="5" xadvance="52" page="0" chnl="15"/>
<char id="73" x="191" y="161" width="15" height="60" xoffset="7" yoffset="5" xadvance="20" page="0" chnl="15"/>
<char id="74" x="144" y="348" width="37" height="61" xoffset="2" yoffset="5" xadvance="36" page="0" chnl="15"/>
<char id="75" x="175" y="285" width="51" height="60" xoffset="5" yoffset="5" xadvance="48" page="0" chnl="15"/>
<char id="76" x="204" y="223" width="41" height="60" xoffset="5" yoffset="5" xadvance="40" page="0" chnl="15"/>
<char id="77" x="178" y="411" width="58" height="60" xoffset="5" yoffset="5" xadvance="60" page="0" chnl="15"/>
<char id="78" x="183" y="347" width="49" height="60" xoffset="5" yoffset="5" xadvance="52" page="0" chnl="15"/>
<char id="79" x="199" y="50" width="58" height="62" xoffset="3" yoffset="4" xadvance="56" page="0" chnl="15"/>
<char id="80" x="228" y="285" width="48" height="60" xoffset="6" yoffset="5" xadvance="48" page="0" chnl="15"/>
<char id="81" x="208" y="114" width="59" height="65" xoffset="3" yoffset="4" xadvance="56" page="0" chnl="15"/>
<char id="82" x="234" y="347" width="54" height="60" xoffset="6" yoffset="5" xadvance="52" page="0" chnl="15"/>
<char id="83" x="238" y="409" width="49" height="62" xoffset="3" yoffset="4" xadvance="48" page="0" chnl="15"/>
<char id="84" x="289" y="409" width="49" height="60" xoffset="2" yoffset="5" xadvance="44" page="0" chnl="15"/>
<char id="85" x="247" y="181" width="49" height="61" xoffset="6" yoffset="5" xadvance="52" page="0" chnl="15"/>
<char id="86" x="278" y="244" width="56" height="60" xoffset="0" yoffset="5" xadvance="48" page="0" chnl="15"/>
<char id="87" x="290" y="306" width="75" height="60" xoffset="1" yoffset="5" xadvance="68" page="0" chnl="15"/>
<char id="88" x="259" y="2" width="56" height="60" xoffset="0" yoffset="5" xadvance="48" page="0" chnl="15"/>
<char id="89" x="269" y="64" width="56" height="60" xoffset="0" yoffset="5" xadvance="48" page="0" chnl="15"/>
<char id="90" x="317" y="2" width="49" height="60" xoffset="1" yoffset="5" xadvance="44" page="0" chnl="15"/>
<char id="33" x="298" y="126" width="16" height="60" xoffset="6" yoffset="5" xadvance="20" page="0" chnl="15"/>
<char id="8470" x="316" y="126" width="77" height="60" xoffset="6" yoffset="5" xadvance="77" page="0" chnl="15"/>
<char id="59" x="327" y="64" width="16" height="56" xoffset="6" yoffset="19" xadvance="20" page="0" chnl="15"/>
<char id="37" x="336" y="188" width="64" height="63" xoffset="4" yoffset="4" xadvance="64" page="0" chnl="15"/>
<char id="58" x="202" y="2" width="16" height="46" xoffset="7" yoffset="19" xadvance="20" page="0" chnl="15"/>
<char id="63" x="368" y="2" width="42" height="61" xoffset="3" yoffset="4" xadvance="40" page="0" chnl="15"/>
<char id="42" x="298" y="188" width="32" height="30" xoffset="2" yoffset="4" xadvance="28" page="0" chnl="15"/>
<char id="40" x="395" y="65" width="25" height="76" xoffset="4" yoffset="4" xadvance="24" page="0" chnl="15"/>
<char id="41" x="340" y="368" width="26" height="76" xoffset="4" yoffset="4" xadvance="24" page="0" chnl="15"/>
<char id="95" x="75" y="497" width="50" height="13" xoffset="-1" yoffset="66" xadvance="40" page="0" chnl="15"/>
<char id="43" x="395" y="143" width="42" height="42" xoffset="4" yoffset="14" xadvance="42" page="0" chnl="15"/>
<char id="45" x="47" y="2" width="28" height="15" xoffset="2" yoffset="34" xadvance="24" page="0" chnl="15"/>
<char id="61" x="290" y="368" width="42" height="30" xoffset="4" yoffset="20" xadvance="42" page="0" chnl="15"/>
<char id="46" x="144" y="411" width="16" height="16" xoffset="7" yoffset="49" xadvance="20" page="0" chnl="15"/>
<char id="44" x="47" y="19" width="16" height="26" xoffset="6" yoffset="49" xadvance="20" page="0" chnl="15"/>
<char id="47" x="340" y="446" width="29" height="62" xoffset="0" yoffset="4" xadvance="20" page="0" chnl="15"/>
<char id="124" x="367" y="253" width="14" height="76" xoffset="7" yoffset="4" xadvance="19" page="0" chnl="15"/>
<char id="34" x="269" y="126" width="27" height="27" xoffset="3" yoffset="5" xadvance="26" page="0" chnl="15"/>
<char id="39" x="345" y="64" width="16" height="27" xoffset="3" yoffset="5" xadvance="14" page="0" chnl="15"/>
<char id="64" x="368" y="331" width="75" height="76" xoffset="4" yoffset="4" xadvance="73" page="0" chnl="15"/>
<char id="35" x="383" y="253" width="47" height="62" xoffset="1" yoffset="4" xadvance="40" page="0" chnl="15"/>
<char id="36" x="371" y="409" width="42" height="72" xoffset="3" yoffset="0" xadvance="40" page="0" chnl="15"/>
<char id="94" x="178" y="473" width="39" height="37" xoffset="2" yoffset="4" xadvance="34" page="0" chnl="15"/>
<char id="38" x="402" y="187" width="52" height="62" xoffset="3" yoffset="4" xadvance="48" page="0" chnl="15"/>
<char id="123" x="432" y="251" width="29" height="76" xoffset="2" yoffset="4" xadvance="24" page="0" chnl="15"/>
<char id="125" x="415" y="409" width="29" height="76" xoffset="2" yoffset="4" xadvance="24" page="0" chnl="15"/>
<char id="91" x="445" y="329" width="22" height="74" xoffset="5" yoffset="5" xadvance="20" page="0" chnl="15"/>
<char id="93" x="446" y="405" width="22" height="74" xoffset="1" yoffset="5" xadvance="20" page="0" chnl="15"/>
<char id="32" x="0" y="0" width="0" height="0" xoffset="1" yoffset="5" xadvance="20" page="0" chnl="15"/>
</chars>
<kernings count="96">
<kerning first="32" second="65" amount="-4"/>
<kerning first="32" second="84" amount="-1"/>
<kerning first="32" second="89" amount="-1"/>
<kerning first="65" second="32" amount="-4"/>
<kerning first="65" second="84" amount="-5"/>
<kerning first="65" second="86" amount="-5"/>
<kerning first="65" second="87" amount="-3"/>
<kerning first="65" second="89" amount="-5"/>
<kerning first="65" second="118" amount="-1"/>
<kerning first="65" second="119" amount="-1"/>
<kerning first="65" second="121" amount="-1"/>
<kerning first="70" second="44" amount="-8"/>
<kerning first="70" second="46" amount="-8"/>
<kerning first="70" second="65" amount="-4"/>
<kerning first="76" second="32" amount="-3"/>
<kerning first="76" second="84" amount="-5"/>
<kerning first="76" second="86" amount="-5"/>
<kerning first="76" second="87" amount="-5"/>
<kerning first="76" second="89" amount="-5"/>
<kerning first="76" second="121" amount="-3"/>
<kerning first="80" second="32" amount="-1"/>
<kerning first="80" second="44" amount="-9"/>
<kerning first="80" second="46" amount="-9"/>
<kerning first="80" second="65" amount="-5"/>
<kerning first="82" second="84" amount="-1"/>
<kerning first="82" second="86" amount="-1"/>
<kerning first="82" second="87" amount="-1"/>
<kerning first="82" second="89" amount="-1"/>
<kerning first="84" second="32" amount="-1"/>
<kerning first="84" second="44" amount="-8"/>
<kerning first="84" second="45" amount="-4"/>
<kerning first="84" second="46" amount="-8"/>
<kerning first="84" second="58" amount="-8"/>
<kerning first="84" second="59" amount="-8"/>
<kerning first="84" second="65" amount="-5"/>
<kerning first="84" second="79" amount="-1"/>
<kerning first="84" second="97" amount="-8"/>
<kerning first="84" second="99" amount="-8"/>
<kerning first="84" second="101" amount="-8"/>
<kerning first="84" second="105" amount="-3"/>
<kerning first="84" second="111" amount="-8"/>
<kerning first="84" second="114" amount="-3"/>
<kerning first="84" second="115" amount="-8"/>
<kerning first="84" second="117" amount="-3"/>
<kerning first="84" second="119" amount="-4"/>
<kerning first="84" second="121" amount="-4"/>
<kerning first="86" second="44" amount="-7"/>
<kerning first="86" second="45" amount="-4"/>
<kerning first="86" second="46" amount="-7"/>
<kerning first="86" second="58" amount="-3"/>
<kerning first="86" second="59" amount="-3"/>
<kerning first="86" second="65" amount="-5"/>
<kerning first="86" second="97" amount="-5"/>
<kerning first="86" second="101" amount="-4"/>
<kerning first="86" second="105" amount="-1"/>
<kerning first="86" second="111" amount="-4"/>
<kerning first="86" second="114" amount="-3"/>
<kerning first="86" second="117" amount="-3"/>
<kerning first="86" second="121" amount="-3"/>
<kerning first="87" second="44" amount="-4"/>
<kerning first="87" second="45" amount="-1"/>
<kerning first="87" second="46" amount="-4"/>
<kerning first="87" second="58" amount="-1"/>
<kerning first="87" second="59" amount="-1"/>
<kerning first="87" second="65" amount="-3"/>
<kerning first="87" second="97" amount="-3"/>
<kerning first="87" second="101" amount="-1"/>
<kerning first="87" second="105" amount="0"/>
<kerning first="87" second="111" amount="-1"/>
<kerning first="87" second="114" amount="-1"/>
<kerning first="87" second="117" amount="-1"/>
<kerning first="87" second="121" amount="-1"/>
<kerning first="89" second="32" amount="-1"/>
<kerning first="89" second="44" amount="-9"/>
<kerning first="89" second="45" amount="-7"/>
<kerning first="89" second="46" amount="-9"/>
<kerning first="89" second="58" amount="-4"/>
<kerning first="89" second="59" amount="-5"/>
<kerning first="89" second="65" amount="-5"/>
<kerning first="89" second="97" amount="-5"/>
<kerning first="89" second="101" amount="-7"/>
<kerning first="89" second="105" amount="-3"/>
<kerning first="89" second="111" amount="-7"/>
<kerning first="89" second="112" amount="-5"/>
<kerning first="89" second="113" amount="-7"/>
<kerning first="89" second="117" amount="-4"/>
<kerning first="89" second="118" amount="-4"/>
<kerning first="102" second="102" amount="-1"/>
<kerning first="114" second="44" amount="-4"/>
<kerning first="114" second="46" amount="-4"/>
<kerning first="118" second="44" amount="-5"/>
<kerning first="118" second="46" amount="-5"/>
<kerning first="119" second="44" amount="-4"/>
<kerning first="119" second="46" amount="-4"/>
<kerning first="121" second="44" amount="-5"/>
<kerning first="121" second="46" amount="-5"/>
</kernings>
</font>

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 KiB

View File

@@ -5,6 +5,12 @@
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name = "viewport" content = "width=device-width, initial-scale=1.0, user-scalable=no">
<style type="text/css">
*{
-webkit-tap-highlight-color: rgba(0,0,0,0);
-webkit-touch-callout: none;
}
</style>
</head>
<body>
<script src="program.js" type="text/javascript"></script>

Binary file not shown.

Binary file not shown.

View File

@@ -1,26 +1,52 @@
package com.soywiz.korge.games.coffee
import com.soywiz.korge.Korge
import com.soywiz.korge.animate.AnLibrary
import com.soywiz.korge.animate.playAndWaitEvent
import com.soywiz.korge.component.docking.jekllyButton
import com.soywiz.korge.animate.*
import com.soywiz.korge.bitmapfont.BitmapFont
import com.soywiz.korge.component.docking.jellyButton
import com.soywiz.korge.event.addEventListener
import com.soywiz.korge.input.mouse
import com.soywiz.korge.input.onDown
import com.soywiz.korge.input.onUp
import com.soywiz.korge.input.onUpAnywhere
import com.soywiz.korge.resources.Path
import com.soywiz.korge.scene.*
import com.soywiz.korge.service.Browser
import com.soywiz.korge.service.storage.Storage
import com.soywiz.korge.service.storage.item
import com.soywiz.korge.time.TimeSpan
import com.soywiz.korge.time.seconds
import com.soywiz.korge.time.sleep
import com.soywiz.korge.tween.Easing
import com.soywiz.korge.tween.get
import com.soywiz.korge.tween.tween
import com.soywiz.korge.tween.*
import com.soywiz.korge.view.*
import com.soywiz.korim.color.ColorTransform
import com.soywiz.korio.async.AsyncSignal
import com.soywiz.korio.async.Promise
import com.soywiz.korio.async.go
import com.soywiz.korio.async.waitOne
import com.soywiz.korio.inject.AsyncInjector
import com.soywiz.korio.inject.Optional
import com.soywiz.korio.inject.Singleton
import com.soywiz.korio.util.closeable
import com.soywiz.korma.geom.Anchor
import com.soywiz.korma.geom.Point2d
import com.soywiz.korma.random.get
import java.net.URL
import java.util.*
@Suppress("unused")
object KorgeCoffeeModule : Module() {
@JvmStatic fun main(args: Array<String>) = Korge(this@KorgeCoffeeModule)
@JvmStatic fun main(args: Array<String>) = Korge(KorgeCoffeeModule)
object MainDebug {
@JvmStatic fun main(args: Array<String>) = Korge(KorgeCoffeeModule, sceneClass = MainScene::class.java, sceneInjects = listOf(MainScene.State.MAIN_MENU), debug = true)
}
// Go directly to ingame to avoid testing main menu
object IngameDebug {
//@JvmStatic fun main(args: Array<String>) = Korge.invoke(KorgeCoffeeModule, sceneClass = MainScene::class.java, sceneInjects = listOf(MainScene.State.INGAME), debug = true)
@JvmStatic fun main(args: Array<String>) = Korge.invoke(KorgeCoffeeModule, sceneClass = MainScene::class.java, sceneInjects = listOf(MainScene.State.INGAME), debug = false)
}
override val title: String = "KorGE Coffee"
override val mainScene: Class<out Scene> = MainScene::class.java
@@ -30,24 +56,40 @@ object KorgeCoffeeModule : Module() {
override val virtualWidth: Int = 720
override val icon: String = "icon.png"
@Singleton
class GameStorage(
val storage: Storage
) {
var HiScore by storage.item("HiScore") { 0 }
}
suspend override fun init(injector: AsyncInjector) {
injector.get<Views>().registerPropertyTriggerSuspend("disabled") { view, key, value ->
view.mouseEnabled = false
}
}
@Singleton
class LibraryContainer(
@Path("font.fnt") val font: BitmapFont,
@Path("main.ani") val library: AnLibrary
)
class CreditsScene(
val lib: LibraryContainer,
val browser: Browser
val libraryContainer: LibraryContainer,
val browser: Browser,
val gameStorage: GameStorage
) : Scene() {
val lib = libraryContainer.library
suspend override fun sceneInit(sceneView: Container) {
sceneView += lib.library.createMovieClip("Credits")
sceneView["korge"].jekllyButton(1.2).onClick { browser.browse(URL("http://korge.soywiz.com/")) }
sceneView["kotlin"].jekllyButton(1.2).onClick { browser.browse(URL("https://kotlinlang.org/")) }
sceneView["animate"].jekllyButton(1.2).onClick { browser.browse(URL("http://www.adobe.com/products/animate.html")) }
sceneView["github"].jekllyButton(1.2).onClick { browser.browse(URL("https://github.com/soywiz/korge-samples/tree/master/korge-coffee")) }
sceneView["soywiz"].jekllyButton(1.2).onClick { browser.browse(URL("http://soywiz.com/")) }
sceneView["tamy"].jekllyButton(1.2).onClick { browser.browse(URL("http://comic.tamy.es/")) }
sceneView["close"].jekllyButton(1.2).onClick { this.sceneContainer.back(time = 0.3.seconds) }
sceneView += lib.createMovieClip("Credits")
sceneView["korge"].jellyButton(1.2).onClick { browser.browse(URL("http://korge.soywiz.com/")) }
sceneView["kotlin"].jellyButton(1.2).onClick { browser.browse(URL("https://kotlinlang.org/")) }
sceneView["animate"].jellyButton(1.2).onClick { browser.browse(URL("http://www.adobe.com/products/animate.html")) }
sceneView["github"].jellyButton(1.2).onClick { browser.browse(URL("https://github.com/soywiz/korge-samples/tree/master/korge-coffee")) }
sceneView["soywiz"].jellyButton(1.2).onClick { browser.browse(URL("http://soywiz.com/")) }
sceneView["tamy"].jellyButton(1.2).onClick { browser.browse(URL("http://comic.tamy.es/")) }
sceneView["close"].jellyButton(1.2).onClick { this.sceneContainer.back(time = 0.3.seconds) }
}
suspend override fun sceneBeforeLeaving() {
@@ -57,21 +99,24 @@ object KorgeCoffeeModule : Module() {
}
class MainMenuScene(
val lib: LibraryContainer
val libraryContainer: LibraryContainer,
val gameStorage: GameStorage
) : Scene() {
val lib = libraryContainer.library
lateinit var creditsSC: SceneContainer
val onStart = AsyncSignal<Unit>()
suspend override fun sceneInit(sceneView: Container) {
sceneView += lib.library.createMovieClip("MainMenu")
sceneView += lib.createMovieClip("MainMenu")
creditsSC = views.sceneContainer()
sceneView += creditsSC
sceneView["playButton"].jekllyButton(1.2).onClick {
sceneView["playButton"].jellyButton(1.2).onClick {
onStart(Unit)
}
sceneView["creditsButton"].jekllyButton(1.2).onClick {
sceneView["creditsButton"].jellyButton(1.2).onClick {
creditsSC.pushTo<CreditsScene>(time = 0.2.seconds)
}
sceneView["hiscore"].setText("${gameStorage.HiScore}")
}
suspend override fun sceneBeforeLeaving() {
@@ -81,53 +126,346 @@ object KorgeCoffeeModule : Module() {
}
class MainScene(
val lib: LibraryContainer
val lib: LibraryContainer,
@Optional val initialState: State?,
val gameStorage: GameStorage
) : Scene() {
enum class State { MAIN_MENU, INGAME }
lateinit var camera: Camera
lateinit var hud: View
lateinit var ingame: View
lateinit var mainMenuSC: SceneContainer
private suspend fun openMainMenu(transition: Boolean, callback: suspend () -> Unit) {
hud.alpha = 0.0
val mainMenu = mainMenuSC.pushTo<MainMenuScene>()
mainMenu.onStart {
callback()
}
if (transition) {
camera.tweenTo(
sceneView["menuCamera"]!!,
sceneView["action"]!!::colorTransform[ColorTransform.Add(-255, -255, -255, 0)],
time = 0.5.seconds, easing = Easing.EASE_OUT_QUAD
)
} else {
camera.setTo(sceneView["menuCamera"]!!)
sceneView["action"]?.colorTransform = ColorTransform.Add(-255, -255, -255, 0)
}
}
private suspend fun closeMainMenu() {
go {
mainMenuSC.back(time = 1.seconds, transition = AlphaTransition.withEasing(Easing.EASE_OUT_QUAD))
}
}
suspend override fun sceneInit(sceneView: Container) {
camera = views.camera()
sceneView += lib.library.createMovieClip("Cameras").apply { visible = false }
sceneView += camera.apply {
this += lib.library.createMovieClip("Ingame")
ingame = lib.library.createMovieClip("Ingame")
this += ingame
}
hud = lib.library.createMovieClip("Hud")
//(hud["scoreLabel"] as? AnTextField?)?.format = (hud["scoreLabel"] as? AnTextField?)?.format?.copy(face = Html.FontFace.Bitmap(lib.font))!!
//(hud["scoreText"] as? AnTextField?)?.format = (hud["scoreText"] as? AnTextField?)?.format?.copy(face = Html.FontFace.Bitmap(lib.font))!!
sceneView += hud
hud.alpha = 0.0
mainMenuSC = views.sceneContainer()
sceneView += mainMenuSC
val mainMenu = mainMenuSC.pushTo<MainMenuScene>()
mainMenu.onStart {
go {
mainMenuSC.back(time = 1.seconds, transition = AlphaTransition.withEasing(Easing.EASE_OUT_QUAD))
when (initialState) {
null, State.MAIN_MENU -> {
hud.alpha = 0.0
openMainMenu(transition = false) {
closeMainMenu()
startGame()
ingame()
}
}
State.INGAME -> {
camera.setTo(sceneView["ingameCamera"]!!)
sceneView["action"]?.colorTransform = ColorTransform.Add(0, 0, 0, 0)
sceneView["background"]?.alpha = 1.0
ingame()
}
startGame()
}
camera.setTo(sceneView["menuCamera"]!!)
sceneView["action"]?.colorTransform = ColorTransform.Add(-255, -255, -255, 0)
sceneView["pauseButton"]?.mouseEnabled = false
sceneView["pauseButton"].jellyButton(1.125).onClick {
//sceneView["ingame"]?.speed = 0.0
updateHiScore()
ingame.speed = 0.0
val oldCamera = camera.localMatrix.copy()
openMainMenu(transition = true) {
closeMainMenu()
camera.tween(
camera::localMatrix[oldCamera],
sceneView["action"]!!::colorTransform[ColorTransform.Add(0, 0, 0, 0)],
hud::alpha[1.0],
time = 0.5.seconds, easing = Easing.EASE_OUT_QUAD
)
ingame.speed = 1.0
}
//mainMenuSC.pushTo<MainMenuScene>()
}
}
suspend fun startGame() {
go {
val action = sceneView["action"]
action?.tween(action::colorTransform[ColorTransform.Add(0, 0, 0, 0)], time = 5.seconds, easing = Easing.LINEAR)
allowSpeedUp {
go {
val action = sceneView["action"]
action?.tween(action::colorTransform[ColorTransform.Add(0, 0, 0, 0)], time = 5.seconds, easing = Easing.LINEAR)
}
go {
hud.tween(hud::alpha[1.0], time = 2.seconds, easing = Easing.LINEAR)
}
camera.tweenTo(sceneView["showCamera"], time = 2.seconds, easing = Easing.EASE_IN_OUT_QUAD)
sceneView["messages"]?.speed = 0.7
sceneView["messages"].playAndWaitEvent("tap", "tap_continue")
camera.sleep(0.5.seconds)
go {
val background = sceneView["background"]
background?.tween(background::alpha[1.0], time = 1.seconds, easing = Easing.EASE_OUT_ELASTIC)
}
camera.tweenTo(sceneView["ingameCamera"], time = 1.seconds, easing = Easing.EASE_OUT_ELASTIC)
}
}
var score = 0
private fun updateScore() {
sceneView["scoreText"].setText("$score")
}
private fun incrementScore(delta: Int) {
score += delta
updateScore()
}
private suspend fun incrementScore(view: View, delta: Int) {
val scoreView = sceneView["score"] ?: views.container()
//val entityHigh = sceneView["entityHigh"] ?: views.container()
val entityHigh = sceneView["hudContainer"] ?: views.container()
val text = views.text("+$delta", textSize = 16.0).apply { entityHigh += this }
text.globalX = view.globalX
text.globalY = view.globalY
text.tween(
text::globalX[scoreView.globalX],
text::globalY[scoreView.globalY],
text::alpha[0.0],
time = 0.3.seconds
)
text.removeFromParent()
scoreView.tween(
scoreView::scale[0.7],
time = 0.2.seconds,
easing = Easing.EASE_OUT_ELASTIC
)
incrementScore(delta)
scoreView.tween(
scoreView::scale[1.0],
time = 0.2.seconds,
easing = Easing.EASE_OUT_ELASTIC
)
}
private val colorAddBlack = ColorTransform.Add(-255, -255, -255, 0).colorAdd
private val colorAddNormal = ColorTransform.Add(0, 0, 0, 0).colorAdd
class DismissKotlinMessage(val givePoints: Boolean)
fun destroyAllEntities() {
sceneView.dispatch(DismissKotlinMessage(givePoints = false))
}
var spawner = Promise.resolved(Unit)
var running = true
private fun updateHiScore() {
gameStorage.HiScore = Math.max(gameStorage.HiScore, score)
}
suspend fun allowSpeedUp(callback: suspend () -> Unit) {
val events = listOf(
views.stage.mouse.onDown { sceneView.speed = 5.0 },
views.stage.mouse.onUpAnywhere { sceneView.speed = 1.0 }
).closeable()
try {
callback()
} finally {
events.close()
sceneView.speed = 1.0
}
}
suspend fun gameOver() {
allowSpeedUp {
updateHiScore()
sceneView["pauseButton"]?.alpha = 0.0
destroyAllEntities()
spawner.cancel()
running = false
camera.tweenTo(sceneView["showCamera"], time = 0.5.seconds, easing = Easing.EASE_OUT_ELASTIC)
sceneView["action"].waitEvent("mainLoop")
sceneView["action"].playAndWaitEvent("drop", "dropZoom")
camera.tweenTo(sceneView["zoomCamera"], time = 0.5.seconds, easing = Easing.EASE_OUT_QUAD)
sceneView["action"].waitStop()
sceneView["messages"].playAndWaitStop("gameover")
sceneView.sleep(1.seconds)
sceneView.tween(sceneView::colorTransform[ColorTransform.Add(-255, -255, -255, 0)], time = 0.5.seconds)
this.sceneContainer.changeTo<MainScene>(initialState ?: State.MAIN_MENU)
//sceneView["action"].play("drop")
}
}
fun createEntity(globalPos: Point2d, scale: Double, reachTime: TimeSpan): View {
val kotlinHigh = lib.library.createMovieClip("KotlinHigh")
val kotlinLow = lib.library.createMovieClip("KotlinLow")
val entityHigh = sceneView["entityHigh"] ?: views.container()
val entityLow = sceneView["entityLow"] ?: views.container()
entityHigh += kotlinHigh
entityLow += kotlinLow
// Synchronize low part with high part
entityHigh.addUpdatable {
kotlinLow.globalMatrix = kotlinHigh.globalMatrix
kotlinLow.alpha = kotlinHigh.alpha
kotlinLow.colorAdd = kotlinHigh.colorAdd
}
val localDestination = kotlinHigh.globalToLocal(sceneView["rope"]!!.globalBounds.getAnchoredPosition(Anchor.MIDDLE_CENTER))
kotlinHigh.globalX = globalPos.x
kotlinHigh.globalY = globalPos.y
var cancelled = false
val movePromise = go {
kotlinHigh.tween(
kotlinHigh::scale[0.8, scale],
kotlinHigh::colorAdd[colorAddBlack, colorAddNormal].color(),
time = 0.3.seconds
)
//val distance = Math.hypot(globalDestination.x - kotlin.globalX, globalDestination.y - kotlin.globalY)
kotlinHigh.tween(
kotlinHigh::x[localDestination.x],
kotlinHigh::y[localDestination.y],
kotlinHigh::scale[kotlinHigh.scale * 0.75].easeOutQuad(),
//time = (distance * 5).milliseconds
time = reachTime
)
if (!cancelled) { // @TODO: Shouldn't be necessary since cancelling should cancell the whole process
go {
gameOver()
}
}
}
kotlinHigh.addEventListener<DismissKotlinMessage> {
kotlinHigh.mouseEnabled = false
cancelled = true
movePromise.cancel()
go {
if (it.givePoints) {
go {
incrementScore(kotlinHigh, delta = +1)
}
}
go {
kotlinHigh.tween(
kotlinHigh::colorAdd[colorAddBlack].color(),
kotlinHigh::scale[0.0],
time = 0.3.seconds
)
kotlinHigh.removeFromParent()
kotlinLow.removeFromParent()
//createEntity(x = random[0.0, 600.0 * 2], y = random[0.0, 1200.0 * 2], scale = 2.5)
}
}
}
kotlinHigh.mouse.apply { hitTestType = View.HitTestType.SHAPE }.onDown {
kotlinHigh.dispatch(DismissKotlinMessage(givePoints = true))
}
go {
hud?.tween(hud::alpha[1.0], time = 2.seconds, easing = Easing.LINEAR)
while (true) {
kotlinHigh.tween(kotlinHigh::rotationDegrees[0, 360], time = 2.seconds)
}
}
camera.tweenTo(sceneView["showCamera"], time = 2.seconds, easing = Easing.EASE_IN_OUT_QUAD)
sceneView["messages"]?.speed = 0.7
sceneView["messages"].playAndWaitEvent("destroy", "destroy_continue")
camera.sleep(0.5.seconds)
go {
val background = sceneView["background"]
background?.tween(background::alpha[1.0], time = 1.seconds, easing = Easing.EASE_OUT_ELASTIC)
return kotlinHigh
}
val random = Random()
data class DifficultyConfig(
val spawnCount: Int = 2,
val nextSpawnTime: ClosedRange<TimeSpan> = 1.seconds..1.seconds,
val scale: ClosedRange<Double> = 2.5..2.5,
val reachTime: ClosedRange<TimeSpan> = 2.seconds..2.seconds
)
private fun buildDifficultyConfig(step: Int): DifficultyConfig {
val spawnCount = when {
step < 5 -> 1
step < 20 -> random[listOf(1, 2)]
step < 30 -> random[listOf(1, 2, 2)]
step < 50 -> random[listOf(1, 2, 2, 2, 3)]
else -> random[listOf(1, 2, 2, 2, 3, 3, 3, 3, 3, 3)]
}
val reachTime = when {
step < 50 -> 2.seconds
else -> 1.5.seconds
} * spawnCount
return DifficultyConfig(
spawnCount = spawnCount,
nextSpawnTime = when {
step < 5 -> 1.8.seconds..2.2.seconds
step < 10 -> 1.5.seconds..2.0.seconds
step < 20 -> 1.seconds..1.5.seconds
else -> 0.8.seconds..1.seconds
},
scale = when {
step < 50 -> 2.5..2.5
step < 100 -> 2.0..2.5
step < 200 -> 1.5..2.0
else -> 1.0..1.5
},
reachTime = reachTime..reachTime * 1.1
)
}
suspend fun spawner() {
val spawnZones = sceneView.descendantsWithProp("spawnZone")
var step = 0
while (running) {
val config = buildDifficultyConfig(step)
for (n in 0 until config.spawnCount) {
val point = random[random[spawnZones].globalBounds]
createEntity(globalPos = point, scale = random[config.scale], reachTime = random[config.reachTime])
}
ingame.sleep(random[config.nextSpawnTime])
step++
}
}
suspend fun ingame() {
sceneView["pauseButton"]?.mouseEnabled = true
spawner = go {
spawner()
}
camera.tweenTo(sceneView["ingameCamera"], time = 1.seconds, easing = Easing.EASE_OUT_ELASTIC)
}
}
}