├── .gitignore ├── LICENSE ├── README.md ├── android ├── AndroidManifest.xml ├── assets │ ├── background.png │ ├── fun_in_a_bottle.mp3 │ ├── ground.png │ ├── hit.wav │ ├── jump.wav │ ├── roboto_bold.ttf │ ├── sprites.png │ └── sprites.txt ├── build.gradle ├── proguard-project.txt ├── project.properties ├── res │ ├── drawable-hdpi │ │ └── ic_launcher.png │ ├── drawable-mdpi │ │ └── ic_launcher.png │ ├── drawable-xhdpi │ │ └── ic_launcher.png │ ├── drawable-xxhdpi │ │ └── ic_launcher.png │ ├── values │ │ ├── .gitignore │ │ ├── strings.xml │ │ └── styles.xml │ └── xml │ │ └── app_tracker_config.xml └── src │ └── com │ ├── gamestudio24 │ └── martianrun │ │ ├── MainApplication.java │ │ └── android │ │ └── AndroidLauncher.java │ └── google │ └── games │ └── basegameutils │ ├── GameHelper.java │ └── GameHelperUtils.java ├── build.gradle ├── core ├── build.gradle └── src │ ├── MartianRun.gwt.xml │ └── com │ └── gamestudio24 │ └── martianrun │ ├── MartianRun.java │ ├── actors │ ├── Background.java │ ├── Enemy.java │ ├── GameActor.java │ ├── Ground.java │ ├── Runner.java │ ├── Score.java │ └── menu │ │ ├── AboutButton.java │ │ ├── AboutLabel.java │ │ ├── AchievementsButton.java │ │ ├── GameButton.java │ │ ├── GameLabel.java │ │ ├── LeaderboardButton.java │ │ ├── MusicButton.java │ │ ├── PauseButton.java │ │ ├── PausedLabel.java │ │ ├── ShareButton.java │ │ ├── SoundButton.java │ │ ├── StartButton.java │ │ └── Tutorial.java │ ├── box2d │ ├── EnemyUserData.java │ ├── GroundUserData.java │ ├── RunnerUserData.java │ └── UserData.java │ ├── enums │ ├── Difficulty.java │ ├── EnemyType.java │ ├── GameState.java │ └── UserDataType.java │ ├── screens │ └── GameScreen.java │ ├── stages │ └── GameStage.java │ └── utils │ ├── AssetsManager.java │ ├── AudioUtils.java │ ├── BodyUtils.java │ ├── Constants.java │ ├── GameEventListener.java │ ├── GameManager.java │ ├── RandomUtils.java │ └── WorldUtils.java ├── desktop ├── build.gradle └── src │ └── com │ └── gamestudio24 │ └── martianrun │ └── desktop │ └── DesktopLauncher.java ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | ## Java 2 | 3 | *.class 4 | *.war 5 | *.ear 6 | hs_err_pid* 7 | 8 | ## GWT 9 | war/ 10 | html/war/gwt_bree/ 11 | html/gwt-unitCache/ 12 | .apt_generated/ 13 | html/war/WEB-INF/deploy/ 14 | html/war/WEB-INF/classes/ 15 | .gwt/ 16 | gwt-unitCache/ 17 | www-test/ 18 | .gwt-tmp/ 19 | 20 | ## Android Studio and Intellij and Android in general 21 | android/libs/armeabi/ 22 | android/libs/armeabi-v7a/ 23 | android/libs/x86/ 24 | android/gen/ 25 | .idea/ 26 | *.ipr 27 | *.iws 28 | *.iml 29 | out/ 30 | com_crashlytics_export_strings.xml 31 | *.keystore 32 | 33 | ## Eclipse 34 | .classpath 35 | .project 36 | .metadata 37 | **/bin/ 38 | tmp/ 39 | *.tmp 40 | *.bak 41 | *.swp 42 | *~.nib 43 | local.properties 44 | .settings/ 45 | .loadpath 46 | .externalToolBuilders/ 47 | *.launch 48 | 49 | ## NetBeans 50 | **/nbproject/private/ 51 | build/ 52 | nbbuild/ 53 | dist/ 54 | nbdist/ 55 | nbactions.xml 56 | nb-configuration.xml 57 | 58 | ## Gradle 59 | 60 | .gradle 61 | build/ 62 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Martian Run! 2 | 3 | A 2D running game built with [libGDX](http://libgdx.badlogicgames.com). 4 | 5 | Get it on Google Play 6 | 7 | You can find a tutorial on how this project started here: 8 | 9 | * [Part 1: Project and World Setup](http://williammora.com/a-running-game-with-libgdx-part-1) 10 | * [Part 2: Main Character and Controls](http://williammora.com/a-running-game-with-libgdx-part-2) 11 | * [Part 3: Enemies](http://williammora.com/a-running-game-with-libgdx-part-3) 12 | * [Part 4: Background Animation](http://williammora.com/a-running-game-with-libgdx-part-4) 13 | * [Part 5: Character Animations](http://williammora.com/a-running-game-with-libgdx-part-5) 14 | 15 | **Please, DO NOT publish this same game to Google Play. Use it as a blueprint for your game development** 16 | 17 | ## Features 18 | * Runs on Android and desktop 19 | * On Android, uses [Google Play Game Services](https://developers.google.com/games/services/) and 20 | [AdMob](https://www.google.com/admob/) 21 | 22 | ## Setup 23 | You need to add the following string resources to your Android project in order for the module to 24 | compile: 25 | 26 | ```xml 27 | 28 | 29 | UA-XXXXXXXX-X 30 | 31 | 34 | XXXXXXXXXXX 35 | 36 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | ``` 57 | 58 | ## Credits 59 | Developed by [William Mora](http://williammora.com) 60 | 61 | Powered by [libGDX](http://libgdx.badlogicgames.com) 62 | 63 | Graphics by [Kenney](http://www.kenney.nl/) 64 | 65 | Music by [Kevin MacLeod](http://incompetech.com) 66 | 67 | ## License 68 | Copyright 2015 William Mora 69 | 70 | Licensed under the Apache License, Version 2.0 (the "License"); 71 | you may not use this file except in compliance with the License. 72 | You may obtain a copy of the License at 73 | 74 | http://www.apache.org/licenses/LICENSE-2.0 75 | 76 | Unless required by applicable law or agreed to in writing, software 77 | distributed under the License is distributed on an "AS IS" BASIS, 78 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 79 | See the License for the specific language governing permissions and 80 | limitations under the License. 81 | -------------------------------------------------------------------------------- /android/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 17 | 18 | 21 | 22 | 25 | 26 | 29 | 30 | 33 | 34 | 37 | 38 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /android/assets/background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wmora/martianrun/1ed66436cd49c60101d557bcfa2454c5185785a5/android/assets/background.png -------------------------------------------------------------------------------- /android/assets/fun_in_a_bottle.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wmora/martianrun/1ed66436cd49c60101d557bcfa2454c5185785a5/android/assets/fun_in_a_bottle.mp3 -------------------------------------------------------------------------------- /android/assets/ground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wmora/martianrun/1ed66436cd49c60101d557bcfa2454c5185785a5/android/assets/ground.png -------------------------------------------------------------------------------- /android/assets/hit.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wmora/martianrun/1ed66436cd49c60101d557bcfa2454c5185785a5/android/assets/hit.wav -------------------------------------------------------------------------------- /android/assets/jump.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wmora/martianrun/1ed66436cd49c60101d557bcfa2454c5185785a5/android/assets/jump.wav -------------------------------------------------------------------------------- /android/assets/roboto_bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wmora/martianrun/1ed66436cd49c60101d557bcfa2454c5185785a5/android/assets/roboto_bold.ttf -------------------------------------------------------------------------------- /android/assets/sprites.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wmora/martianrun/1ed66436cd49c60101d557bcfa2454c5185785a5/android/assets/sprites.png -------------------------------------------------------------------------------- /android/assets/sprites.txt: -------------------------------------------------------------------------------- 1 | sprites.png 2 | format: RGBA8888 3 | filter: Linear,Linear 4 | repeat: none 5 | about 6 | rotate: false 7 | xy: 52, 52 8 | size: 48, 48 9 | orig: 48, 48 10 | offset: 0, 0 11 | index: -1 12 | alienBeige_dodge 13 | rotate: false 14 | xy: 71, 301 15 | size: 67, 72 16 | orig: 67, 72 17 | offset: 0, 0 18 | index: -1 19 | alienBeige_hit 20 | rotate: false 21 | xy: 2, 301 22 | size: 67, 92 23 | orig: 67, 92 24 | offset: 0, 0 25 | index: -1 26 | alienBeige_jump 27 | rotate: false 28 | xy: 134, 206 29 | size: 66, 93 30 | orig: 66, 93 31 | offset: 0, 0 32 | index: -1 33 | alienBeige_run1 34 | rotate: false 35 | xy: 140, 301 36 | size: 68, 93 37 | orig: 68, 93 38 | offset: 0, 0 39 | index: -1 40 | alienBeige_run2 41 | rotate: false 42 | xy: 2, 396 43 | size: 70, 96 44 | orig: 70, 96 45 | offset: 0, 0 46 | index: -1 47 | barnacle_bite1 48 | rotate: false 49 | xy: 55, 102 50 | size: 51, 57 51 | orig: 51, 57 52 | offset: 0, 0 53 | index: -1 54 | barnacle_bite2 55 | rotate: false 56 | xy: 2, 102 57 | size: 51, 58 58 | orig: 51, 58 59 | offset: 0, 0 60 | index: -1 61 | bee_fly1 62 | rotate: false 63 | xy: 108, 102 64 | size: 56, 48 65 | orig: 56, 48 66 | offset: 0, 0 67 | index: -1 68 | bee_fly2 69 | rotate: false 70 | xy: 126, 162 71 | size: 61, 42 72 | orig: 61, 42 73 | offset: 0, 0 74 | index: -1 75 | close 76 | rotate: false 77 | xy: 2, 2 78 | size: 48, 48 79 | orig: 48, 48 80 | offset: 0, 0 81 | index: -1 82 | fly_fly1 83 | rotate: false 84 | xy: 166, 102 85 | size: 57, 45 86 | orig: 57, 45 87 | offset: 0, 0 88 | index: -1 89 | fly_fly2 90 | rotate: false 91 | xy: 67, 206 92 | size: 65, 39 93 | orig: 65, 39 94 | offset: 0, 0 95 | index: -1 96 | ladyBug_walk1 97 | rotate: false 98 | xy: 63, 162 99 | size: 61, 34 100 | orig: 61, 34 101 | offset: 0, 0 102 | index: -1 103 | ladyBug_walk2 104 | rotate: false 105 | xy: 2, 162 106 | size: 59, 42 107 | orig: 59, 42 108 | offset: 0, 0 109 | index: -1 110 | leaderboard 111 | rotate: false 112 | xy: 2, 818 113 | size: 201, 201 114 | orig: 201, 201 115 | offset: 0, 0 116 | index: -1 117 | music_off 118 | rotate: false 119 | xy: 152, 2 120 | size: 48, 48 121 | orig: 48, 48 122 | offset: 0, 0 123 | index: -1 124 | music_on 125 | rotate: false 126 | xy: 2, 52 127 | size: 48, 48 128 | orig: 48, 48 129 | offset: 0, 0 130 | index: -1 131 | pause 132 | rotate: false 133 | xy: 202, 2 134 | size: 48, 48 135 | orig: 48, 48 136 | offset: 0, 0 137 | index: -1 138 | play 139 | rotate: false 140 | xy: 102, 2 141 | size: 48, 48 142 | orig: 48, 48 143 | offset: 0, 0 144 | index: -1 145 | play_big 146 | rotate: false 147 | xy: 2, 616 148 | size: 200, 200 149 | orig: 200, 200 150 | offset: 0, 0 151 | index: -1 152 | share 153 | rotate: false 154 | xy: 52, 2 155 | size: 48, 48 156 | orig: 48, 48 157 | offset: 0, 0 158 | index: -1 159 | sound_off 160 | rotate: false 161 | xy: 202, 52 162 | size: 48, 48 163 | orig: 48, 48 164 | offset: 0, 0 165 | index: -1 166 | sound_on 167 | rotate: false 168 | xy: 102, 52 169 | size: 48, 48 170 | orig: 48, 48 171 | offset: 0, 0 172 | index: -1 173 | spider_walk1 174 | rotate: false 175 | xy: 74, 396 176 | size: 72, 51 177 | orig: 72, 51 178 | offset: 0, 0 179 | index: -1 180 | spider_walk2 181 | rotate: false 182 | xy: 148, 396 183 | size: 77, 53 184 | orig: 77, 53 185 | offset: 0, 0 186 | index: -1 187 | star 188 | rotate: false 189 | xy: 152, 52 190 | size: 48, 48 191 | orig: 48, 48 192 | offset: 0, 0 193 | index: -1 194 | tutorial_left 195 | rotate: false 196 | xy: 2, 494 197 | size: 120, 120 198 | orig: 120, 120 199 | offset: 0, 0 200 | index: -1 201 | tutorial_right 202 | rotate: false 203 | xy: 124, 494 204 | size: 120, 120 205 | orig: 120, 120 206 | offset: 0, 0 207 | index: -1 208 | worm_walk1 209 | rotate: false 210 | xy: 189, 162 211 | size: 63, 23 212 | orig: 63, 23 213 | offset: 0, 0 214 | index: -1 215 | worm_walk2 216 | rotate: false 217 | xy: 2, 206 218 | size: 63, 23 219 | orig: 63, 23 220 | offset: 0, 0 221 | index: -1 222 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | def loadProperty(name) { 2 | hasProperty(name) ? "${getProperty(name)}" : "" 3 | } 4 | 5 | android { 6 | buildToolsVersion "21.1.2" 7 | compileSdkVersion 21 8 | 9 | defaultConfig { 10 | applicationId "com.gamestudio24.cityescape.android" 11 | targetSdkVersion 21 12 | minSdkVersion 9 13 | versionCode 21 14 | versionName "1.5.1" 15 | } 16 | 17 | sourceSets { 18 | main { 19 | manifest.srcFile 'AndroidManifest.xml' 20 | java.srcDirs = ['src'] 21 | resources.srcDirs = ['src'] 22 | aidl.srcDirs = ['src'] 23 | renderscript.srcDirs = ['src'] 24 | res.srcDirs = ['res'] 25 | assets.srcDirs = ['assets'] 26 | } 27 | 28 | instrumentTest.setRoot('tests') 29 | } 30 | 31 | signingConfigs { 32 | release { 33 | storeFile file(loadProperty("GAMESTUDIO24_RELEASE_KEYSTORE_PATH") ?: signingConfigs.debug.storeFile) 34 | storePassword loadProperty("GAMESTUDIO24_RELEASE_PASSWORD") ?: signingConfigs.debug.storePassword 35 | keyAlias loadProperty("GAMESTUDIO24_RELEASE_KEY_ALIAS") ?: signingConfigs.debug.keyAlias 36 | keyPassword loadProperty("GAMESTUDIO24_RELEASE_KEY_PASSWORD") ?: signingConfigs.debug.keyPassword 37 | } 38 | } 39 | 40 | buildTypes { 41 | release { 42 | signingConfig signingConfigs.release 43 | } 44 | } 45 | } 46 | 47 | // needed to add JNI shared libraries to APK when compiling on CLI 48 | tasks.withType(com.android.build.gradle.tasks.PackageApplication) { pkgTask -> 49 | pkgTask.jniFolders = new HashSet() 50 | pkgTask.jniFolders.add(new File(projectDir, 'libs')) 51 | } 52 | 53 | // called every time gradle gets executed, takes the native dependencies of 54 | // the natives configuration, and extracts them to the proper libs/ folders 55 | // so they get packed with the APK. 56 | task copyAndroidNatives() { 57 | file("libs/armeabi/").mkdirs(); 58 | file("libs/armeabi-v7a/").mkdirs(); 59 | file("libs/x86/").mkdirs(); 60 | 61 | configurations.natives.files.each { jar -> 62 | def outputDir = null 63 | if (jar.name.endsWith("natives-armeabi-v7a.jar")) outputDir = file("libs/armeabi-v7a") 64 | if (jar.name.endsWith("natives-armeabi.jar")) outputDir = file("libs/armeabi") 65 | if (jar.name.endsWith("natives-x86.jar")) outputDir = file("libs/x86") 66 | if (outputDir != null) { 67 | copy { 68 | from zipTree(jar) 69 | into outputDir 70 | include "*.so" 71 | } 72 | } 73 | } 74 | } 75 | 76 | task run(type: Exec) { 77 | def path 78 | def localProperties = project.file("../local.properties") 79 | if (localProperties.exists()) { 80 | Properties properties = new Properties() 81 | localProperties.withInputStream { instr -> 82 | properties.load(instr) 83 | } 84 | def sdkDir = properties.getProperty('sdk.dir') 85 | if (sdkDir) { 86 | path = sdkDir 87 | } else { 88 | path = "$System.env.ANDROID_HOME" 89 | } 90 | } else { 91 | path = "$System.env.ANDROID_HOME" 92 | } 93 | 94 | def adb = path + "/platform-tools/adb" 95 | commandLine "$adb", 'shell', 'am', 'start', '-n', 'com.gamestudio24.cityescape.android/com.gamestudio24.martianrun.android.AndroidLauncher' 96 | } 97 | 98 | // sets up the Android Eclipse project, using the old Ant based build. 99 | eclipse { 100 | // need to specify Java source sets explicitely, SpringSource Gradle Eclipse plugin 101 | // ignores any nodes added in classpath.file.withXml 102 | sourceSets { 103 | main { 104 | java.srcDirs "src", 'gen' 105 | } 106 | } 107 | 108 | jdt { 109 | sourceCompatibility = 1.6 110 | targetCompatibility = 1.6 111 | } 112 | 113 | classpath { 114 | plusConfigurations += [project.configurations.compile] 115 | containers 'com.android.ide.eclipse.adt.ANDROID_FRAMEWORK', 'com.android.ide.eclipse.adt.LIBRARIES' 116 | } 117 | 118 | project { 119 | name = appName + "-android" 120 | natures 'com.android.ide.eclipse.adt.AndroidNature' 121 | buildCommands.clear(); 122 | buildCommand "com.android.ide.eclipse.adt.ResourceManagerBuilder" 123 | buildCommand "com.android.ide.eclipse.adt.PreCompilerBuilder" 124 | buildCommand "org.eclipse.jdt.core.javabuilder" 125 | buildCommand "com.android.ide.eclipse.adt.ApkBuilder" 126 | } 127 | } 128 | 129 | // sets up the Android Idea project, using the old Ant based build. 130 | idea { 131 | module { 132 | sourceDirs += file("src"); 133 | scopes = [COMPILE: [plus: [project.configurations.compile]]] 134 | 135 | iml { 136 | withXml { 137 | def node = it.asNode() 138 | def builder = NodeBuilder.newInstance(); 139 | builder.current = node; 140 | builder.component(name: "FacetManager") { 141 | facet(type: "android", name: "Android") { 142 | configuration { 143 | option(name: "UPDATE_PROPERTY_FILES", value: "true") 144 | } 145 | } 146 | } 147 | } 148 | } 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /android/proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /android/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-19 15 | -------------------------------------------------------------------------------- /android/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wmora/martianrun/1ed66436cd49c60101d557bcfa2454c5185785a5/android/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wmora/martianrun/1ed66436cd49c60101d557bcfa2454c5185785a5/android/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wmora/martianrun/1ed66436cd49c60101d557bcfa2454c5185785a5/android/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wmora/martianrun/1ed66436cd49c60101d557bcfa2454c5185785a5/android/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/res/values/.gitignore: -------------------------------------------------------------------------------- 1 | # This is the file where I place the values used for the game's packaging process 2 | # You may safely ignore this. Refer to the Setup section in the README file for all missing strings 3 | # from version control 4 | services-ids.xml -------------------------------------------------------------------------------- /android/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | 20 | 21 | Martian Run! 22 | 23 | 24 | Failed to sign in. Please check your network connection and try again. 25 | The application is incorrectly configured. Check that the package name and signing certificate match the client ID created in Developer Console. Also, if the application is not yet published, check that the account you are trying to sign in with is listed as a tester account. See logs for more information. 26 | License check failed. 27 | Unknown error. 28 | 29 | 30 | -------------------------------------------------------------------------------- /android/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /android/res/xml/app_tracker_config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | 20 | 21 | 22 | true 23 | 24 | 25 | true 26 | 27 | 28 | Game Screen 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /android/src/com/gamestudio24/martianrun/MainApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014. William Mora 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.gamestudio24.martianrun; 18 | 19 | import android.app.Application; 20 | import com.gamestudio24.martianrun.android.R; 21 | import com.google.android.gms.analytics.GoogleAnalytics; 22 | 23 | public class MainApplication extends Application { 24 | 25 | @Override 26 | public void onCreate() { 27 | super.onCreate(); 28 | GoogleAnalytics.getInstance(this).newTracker(R.xml.app_tracker_config); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /android/src/com/gamestudio24/martianrun/android/AndroidLauncher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014. William Mora 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.gamestudio24.martianrun.android; 18 | 19 | import android.content.Intent; 20 | import android.os.Bundle; 21 | import android.view.View; 22 | import android.view.Window; 23 | import android.view.WindowManager; 24 | import android.widget.RelativeLayout; 25 | 26 | import com.badlogic.gdx.backends.android.AndroidApplication; 27 | import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration; 28 | import com.gamestudio24.martianrun.MartianRun; 29 | import com.gamestudio24.martianrun.utils.Constants; 30 | import com.gamestudio24.martianrun.utils.GameEventListener; 31 | import com.gamestudio24.martianrun.utils.GameManager; 32 | import com.google.android.gms.ads.AdRequest; 33 | import com.google.android.gms.ads.AdSize; 34 | import com.google.android.gms.ads.AdView; 35 | import com.google.android.gms.analytics.GoogleAnalytics; 36 | import com.google.android.gms.games.Games; 37 | import com.google.games.basegameutils.GameHelper; 38 | 39 | public class AndroidLauncher extends AndroidApplication implements GameHelper.GameHelperListener, 40 | GameEventListener { 41 | 42 | private static String SAVED_LEADERBOARD_REQUESTED = "SAVED_LEADERBOARD_REQUESTED"; 43 | private static String SAVED_ACHIEVEMENTS_REQUESTED = "SAVED_ACHIEVEMENTS_REQUESTED"; 44 | 45 | private GameHelper gameHelper; 46 | 47 | private AdView mAdView; 48 | private boolean mLeaderboardRequested; 49 | private boolean mAchievementsRequested; 50 | 51 | @Override 52 | protected void onCreate(Bundle savedInstanceState) { 53 | super.onCreate(savedInstanceState); 54 | 55 | // Create the layout 56 | RelativeLayout layout = new RelativeLayout(this); 57 | 58 | requestWindowFeature(Window.FEATURE_NO_TITLE); 59 | getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 60 | WindowManager.LayoutParams.FLAG_FULLSCREEN); 61 | getWindow().clearFlags( 62 | WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); 63 | 64 | AndroidApplicationConfiguration config = new AndroidApplicationConfiguration(); 65 | 66 | // Game view 67 | View gameView = initializeForView(new MartianRun(this), config); 68 | layout.addView(gameView); 69 | 70 | 71 | mAdView = createAdView(); 72 | mAdView.loadAd(createAdRequest()); 73 | 74 | layout.addView(mAdView, getAdParams()); 75 | 76 | setContentView(layout); 77 | 78 | gameHelper = new GameHelper(this, GameHelper.CLIENT_GAMES); 79 | gameHelper.setup(this); 80 | gameHelper.setMaxAutoSignInAttempts(0); 81 | } 82 | 83 | @Override 84 | protected void onStart() { 85 | super.onStart(); 86 | gameHelper.onStart(this); 87 | GoogleAnalytics.getInstance(this).reportActivityStart(this); 88 | } 89 | 90 | @Override 91 | protected void onStop() { 92 | super.onStop(); 93 | gameHelper.onStop(); 94 | GoogleAnalytics.getInstance(this).reportActivityStop(this); 95 | } 96 | 97 | @Override 98 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 99 | super.onActivityResult(requestCode, resultCode, data); 100 | gameHelper.onActivityResult(requestCode, resultCode, data); 101 | } 102 | 103 | @Override 104 | protected void onSaveInstanceState(Bundle outState) { 105 | super.onSaveInstanceState(outState); 106 | outState.putBoolean(SAVED_LEADERBOARD_REQUESTED, mLeaderboardRequested); 107 | outState.putBoolean(SAVED_ACHIEVEMENTS_REQUESTED, mAchievementsRequested); 108 | } 109 | 110 | @Override 111 | protected void onRestoreInstanceState(Bundle savedInstanceState) { 112 | super.onRestoreInstanceState(savedInstanceState); 113 | mLeaderboardRequested = savedInstanceState.getBoolean(SAVED_LEADERBOARD_REQUESTED, false); 114 | mAchievementsRequested = savedInstanceState.getBoolean(SAVED_ACHIEVEMENTS_REQUESTED, false); 115 | } 116 | 117 | private AdRequest createAdRequest() { 118 | return new AdRequest.Builder() 119 | .addTestDevice(AdRequest.DEVICE_ID_EMULATOR) 120 | .build(); 121 | } 122 | 123 | private AdView createAdView() { 124 | AdView adView = new AdView(this); 125 | 126 | adView.setAdSize(AdSize.SMART_BANNER); 127 | adView.setAdUnitId(getAdMobUnitId()); 128 | 129 | return adView; 130 | } 131 | 132 | private RelativeLayout.LayoutParams getAdParams() { 133 | RelativeLayout.LayoutParams adParams = new RelativeLayout.LayoutParams( 134 | RelativeLayout.LayoutParams.MATCH_PARENT, 135 | RelativeLayout.LayoutParams.WRAP_CONTENT); 136 | 137 | adParams.addRule(RelativeLayout.ALIGN_PARENT_TOP); 138 | 139 | return adParams; 140 | } 141 | 142 | @Override 143 | public void onSignInFailed() { 144 | // handle sign-in failure (e.g. show Sign In button) 145 | mLeaderboardRequested = false; 146 | mAchievementsRequested = false; 147 | } 148 | 149 | @Override 150 | public void onSignInSucceeded() { 151 | // handle sign-in success 152 | if (GameManager.getInstance().hasSavedMaxScore()) { 153 | GameManager.getInstance().submitSavedMaxScore(); 154 | } 155 | 156 | if (mLeaderboardRequested) { 157 | displayLeaderboard(); 158 | mLeaderboardRequested = false; 159 | } 160 | 161 | if (mAchievementsRequested) { 162 | displayAchievements(); 163 | mAchievementsRequested = false; 164 | } 165 | } 166 | 167 | @Override 168 | public void displayAd() { 169 | mAdView.setVisibility(View.VISIBLE); 170 | } 171 | 172 | @Override 173 | public void hideAd() { 174 | mAdView.setVisibility(View.GONE); 175 | } 176 | 177 | @Override 178 | public void submitScore(int score) { 179 | if (gameHelper.isSignedIn()) { 180 | Games.Leaderboards.submitScore(gameHelper.getApiClient(), 181 | getString(R.string.leaderboard_high_scores), score); 182 | } else { 183 | GameManager.getInstance().saveScore(score); 184 | } 185 | } 186 | 187 | @Override 188 | public void displayLeaderboard() { 189 | if (gameHelper.isSignedIn()) { 190 | startActivityForResult(Games.Leaderboards.getLeaderboardIntent(gameHelper.getApiClient(), 191 | getString(R.string.leaderboard_high_scores)), 24); 192 | } else { 193 | gameHelper.beginUserInitiatedSignIn(); 194 | mLeaderboardRequested = true; 195 | } 196 | } 197 | 198 | @Override 199 | public void displayAchievements() { 200 | if (gameHelper.isSignedIn()) { 201 | startActivityForResult( 202 | Games.Achievements.getAchievementsIntent(gameHelper.getApiClient()), 25); 203 | } else { 204 | gameHelper.beginUserInitiatedSignIn(); 205 | mAchievementsRequested = true; 206 | } 207 | } 208 | 209 | @Override 210 | public void share() { 211 | String url = String.format("http://play.google.com/store/apps/details?id=%s", 212 | BuildConfig.APPLICATION_ID); 213 | String message = String.format(Constants.SHARE_MESSAGE_PREFIX, url); 214 | Intent share = new Intent(Intent.ACTION_SEND); 215 | share.setType("text/plain"); 216 | share.putExtra(Intent.EXTRA_TEXT, message); 217 | startActivity(Intent.createChooser(share, Constants.SHARE_TITLE)); 218 | } 219 | 220 | @Override 221 | public void unlockAchievement(String id) { 222 | if (gameHelper.isSignedIn()) { 223 | Games.Achievements.unlock(gameHelper.getApiClient(), id); 224 | GameManager.getInstance().setAchievementUnlocked(id); 225 | } 226 | } 227 | 228 | @Override 229 | public void incrementAchievement(String id, int steps) { 230 | if (gameHelper.isSignedIn()) { 231 | Games.Achievements.increment(gameHelper.getApiClient(), id, steps); 232 | GameManager.getInstance().incrementAchievementCount(id, steps); 233 | } 234 | } 235 | 236 | @Override 237 | public String getGettingStartedAchievementId() { 238 | return getString(R.string.achievement_getting_started); 239 | } 240 | 241 | @Override 242 | public String getLikeARoverAchievementId() { 243 | return getString(R.string.achievement_like_a_rover); 244 | } 245 | 246 | @Override 247 | public String getSpiritAchievementId() { 248 | return getString(R.string.achievement_spirit); 249 | } 250 | 251 | @Override 252 | public String getCuriosityAchievementId() { 253 | return getString(R.string.achievement_curiosity); 254 | } 255 | 256 | @Override 257 | public String get5kClubAchievementId() { 258 | return getString(R.string.achievement_5k_club); 259 | } 260 | 261 | @Override 262 | public String get10kClubAchievementId() { 263 | return getString(R.string.achievement_10k_club); 264 | } 265 | 266 | @Override 267 | public String get25kClubAchievementId() { 268 | return getString(R.string.achievement_25k_club); 269 | } 270 | 271 | @Override 272 | public String get50kClubAchievementId() { 273 | return getString(R.string.achievement_50k_club); 274 | } 275 | 276 | @Override 277 | public String get10JumpStreetAchievementId() { 278 | return getString(R.string.achievement_10_jump_street); 279 | } 280 | 281 | @Override 282 | public String get100JumpStreetAchievementId() { 283 | return getString(R.string.achievement_100_jump_street); 284 | } 285 | 286 | @Override 287 | public String get500JumpStreetAchievementId() { 288 | return getString(R.string.achievement_500_jump_street); 289 | } 290 | 291 | private String getAdMobUnitId() { 292 | return getString(R.string.ad_unit_id); 293 | } 294 | 295 | } 296 | -------------------------------------------------------------------------------- /android/src/com/google/games/basegameutils/GameHelperUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.games.basegameutils; 18 | 19 | import android.app.Activity; 20 | import android.content.Context; 21 | import android.content.pm.PackageManager; 22 | import android.content.pm.Signature; 23 | import android.content.res.Resources; 24 | import android.util.Log; 25 | 26 | import com.gamestudio24.martianrun.android.R; 27 | import com.google.android.gms.common.ConnectionResult; 28 | import com.google.android.gms.games.GamesActivityResultCodes; 29 | 30 | import java.security.MessageDigest; 31 | import java.security.NoSuchAlgorithmException; 32 | 33 | /** 34 | * Created by btco on 2/10/14. 35 | */ 36 | class GameHelperUtils { 37 | public static final int R_UNKNOWN_ERROR = 0; 38 | public static final int R_SIGN_IN_FAILED = 1; 39 | public static final int R_APP_MISCONFIGURED = 2; 40 | public static final int R_LICENSE_FAILED = 3; 41 | 42 | private final static String[] FALLBACK_STRINGS = { 43 | "*Unknown error.", 44 | "*Failed to sign in. Please check your network connection and try again.", 45 | "*The application is incorrectly configured. Check that the package name and signing " + 46 | "certificate match the client ID created in Developer Console. Also, if the " + 47 | "application is not yet published, check that the account you are trying to " + 48 | "sign in with is listed as a tester account. See logs for more information.", 49 | "*License check failed." 50 | }; 51 | 52 | private final static int[] RES_IDS = { 53 | R.string.gamehelper_unknown_error, R.string.gamehelper_sign_in_failed, 54 | R.string.gamehelper_app_misconfigured, R.string.gamehelper_license_failed 55 | }; 56 | 57 | static String activityResponseCodeToString(int respCode) { 58 | switch (respCode) { 59 | case Activity.RESULT_OK: 60 | return "RESULT_OK"; 61 | case Activity.RESULT_CANCELED: 62 | return "RESULT_CANCELED"; 63 | case GamesActivityResultCodes.RESULT_APP_MISCONFIGURED: 64 | return "RESULT_APP_MISCONFIGURED"; 65 | case GamesActivityResultCodes.RESULT_LEFT_ROOM: 66 | return "RESULT_LEFT_ROOM"; 67 | case GamesActivityResultCodes.RESULT_LICENSE_FAILED: 68 | return "RESULT_LICENSE_FAILED"; 69 | case GamesActivityResultCodes.RESULT_RECONNECT_REQUIRED: 70 | return "RESULT_RECONNECT_REQUIRED"; 71 | case GamesActivityResultCodes.RESULT_SIGN_IN_FAILED: 72 | return "SIGN_IN_FAILED"; 73 | default: 74 | return String.valueOf(respCode); 75 | } 76 | } 77 | 78 | static String errorCodeToString(int errorCode) { 79 | switch (errorCode) { 80 | case ConnectionResult.DEVELOPER_ERROR: 81 | return "DEVELOPER_ERROR(" + errorCode + ")"; 82 | case ConnectionResult.INTERNAL_ERROR: 83 | return "INTERNAL_ERROR(" + errorCode + ")"; 84 | case ConnectionResult.INVALID_ACCOUNT: 85 | return "INVALID_ACCOUNT(" + errorCode + ")"; 86 | case ConnectionResult.LICENSE_CHECK_FAILED: 87 | return "LICENSE_CHECK_FAILED(" + errorCode + ")"; 88 | case ConnectionResult.NETWORK_ERROR: 89 | return "NETWORK_ERROR(" + errorCode + ")"; 90 | case ConnectionResult.RESOLUTION_REQUIRED: 91 | return "RESOLUTION_REQUIRED(" + errorCode + ")"; 92 | case ConnectionResult.SERVICE_DISABLED: 93 | return "SERVICE_DISABLED(" + errorCode + ")"; 94 | case ConnectionResult.SERVICE_INVALID: 95 | return "SERVICE_INVALID(" + errorCode + ")"; 96 | case ConnectionResult.SERVICE_MISSING: 97 | return "SERVICE_MISSING(" + errorCode + ")"; 98 | case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED: 99 | return "SERVICE_VERSION_UPDATE_REQUIRED(" + errorCode + ")"; 100 | case ConnectionResult.SIGN_IN_REQUIRED: 101 | return "SIGN_IN_REQUIRED(" + errorCode + ")"; 102 | case ConnectionResult.SUCCESS: 103 | return "SUCCESS(" + errorCode + ")"; 104 | default: 105 | return "Unknown error code " + errorCode; 106 | } 107 | } 108 | 109 | static void printMisconfiguredDebugInfo(Context ctx) { 110 | Log.w("GameHelper", "****"); 111 | Log.w("GameHelper", "****"); 112 | Log.w("GameHelper", "**** APP NOT CORRECTLY CONFIGURED TO USE GOOGLE PLAY GAME SERVICES"); 113 | Log.w("GameHelper", "**** This is usually caused by one of these reasons:"); 114 | Log.w("GameHelper", "**** (1) Your package name and certificate fingerprint do not match"); 115 | Log.w("GameHelper", "**** the client ID you registered in Developer Console."); 116 | Log.w("GameHelper", "**** (2) Your App ID was incorrectly entered."); 117 | Log.w("GameHelper", "**** (3) Your game settings have not been published and you are "); 118 | Log.w("GameHelper", "**** trying to log in with an account that is not listed as"); 119 | Log.w("GameHelper", "**** a test account."); 120 | Log.w("GameHelper", "****"); 121 | if (ctx == null) { 122 | Log.w("GameHelper", "*** (no Context, so can't print more debug info)"); 123 | return; 124 | } 125 | 126 | Log.w("GameHelper", "**** To help you debug, here is the information about this app"); 127 | Log.w("GameHelper", "**** Package name : " + ctx.getPackageName()); 128 | Log.w("GameHelper", "**** Cert SHA1 fingerprint: " + getSHA1CertFingerprint(ctx)); 129 | Log.w("GameHelper", "**** App ID from : " + getAppIdFromResource(ctx)); 130 | Log.w("GameHelper", "****"); 131 | Log.w("GameHelper", "**** Check that the above information matches your setup in "); 132 | Log.w("GameHelper", "**** Developer Console. Also, check that you're logging in with the"); 133 | Log.w("GameHelper", "**** right account (it should be listed in the Testers section if"); 134 | Log.w("GameHelper", "**** your project is not yet published)."); 135 | Log.w("GameHelper", "****"); 136 | Log.w("GameHelper", "**** For more information, refer to the troubleshooting guide:"); 137 | Log.w("GameHelper", "**** http://developers.google.com/games/services/android/troubleshooting"); 138 | } 139 | 140 | static String getAppIdFromResource(Context ctx) { 141 | try { 142 | Resources res = ctx.getResources(); 143 | String pkgName = ctx.getPackageName(); 144 | int res_id = res.getIdentifier("app_id", "string", pkgName); 145 | return res.getString(res_id); 146 | } catch (Exception ex) { 147 | ex.printStackTrace(); 148 | return "??? (failed to retrieve APP ID)"; 149 | } 150 | } 151 | 152 | static String getSHA1CertFingerprint(Context ctx) { 153 | try { 154 | Signature[] sigs = ctx.getPackageManager().getPackageInfo( 155 | ctx.getPackageName(), PackageManager.GET_SIGNATURES).signatures; 156 | if (sigs.length == 0) { 157 | return "ERROR: NO SIGNATURE."; 158 | } else if (sigs.length > 1) { 159 | return "ERROR: MULTIPLE SIGNATURES"; 160 | } 161 | byte[] digest = MessageDigest.getInstance("SHA1").digest(sigs[0].toByteArray()); 162 | StringBuilder hexString = new StringBuilder(); 163 | for (int i = 0; i < digest.length; ++i) { 164 | if (i > 0) { 165 | hexString.append(":"); 166 | } 167 | byteToString(hexString, digest[i]); 168 | } 169 | return hexString.toString(); 170 | 171 | } catch (PackageManager.NameNotFoundException ex) { 172 | ex.printStackTrace(); 173 | return "(ERROR: package not found)"; 174 | } catch (NoSuchAlgorithmException ex) { 175 | ex.printStackTrace(); 176 | return "(ERROR: SHA1 algorithm not found)"; 177 | } 178 | } 179 | 180 | static void byteToString(StringBuilder sb, byte b) { 181 | int unsigned_byte = b < 0 ? b + 256 : b; 182 | int hi = unsigned_byte / 16; 183 | int lo = unsigned_byte % 16; 184 | sb.append("0123456789ABCDEF".substring(hi, hi + 1)); 185 | sb.append("0123456789ABCDEF".substring(lo, lo + 1)); 186 | } 187 | 188 | static String getString(Context ctx, int whichString) { 189 | whichString = whichString >= 0 && whichString < RES_IDS.length ? whichString : 0; 190 | int resId = RES_IDS[whichString]; 191 | try { 192 | return ctx.getString(resId); 193 | } catch (Exception ex) { 194 | ex.printStackTrace(); 195 | Log.w(GameHelper.TAG, "*** GameHelper could not found resource id #" + resId + ". " + 196 | "This probably happened because you included it as a stand-alone JAR. " + 197 | "BaseGameUtils should be compiled as a LIBRARY PROJECT, so that it can access " + 198 | "its resources. Using a fallback string."); 199 | return FALLBACK_STRINGS[whichString]; 200 | } 201 | } 202 | } 203 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | mavenCentral() 4 | mavenLocal() 5 | } 6 | dependencies { 7 | classpath 'com.android.tools.build:gradle:1.0.0' 8 | } 9 | } 10 | 11 | allprojects { 12 | apply plugin: "eclipse" 13 | apply plugin: "idea" 14 | 15 | version = '1.0' 16 | ext { 17 | appName = 'Martian Run!' 18 | gdxVersion = '1.1.0' 19 | roboVMVersion = '0.0.13' 20 | } 21 | 22 | repositories { 23 | mavenLocal() 24 | mavenCentral() 25 | maven { url "https://oss.sonatype.org/content/repositories/snapshots/" } 26 | maven { url "https://oss.sonatype.org/content/repositories/releases/" } 27 | } 28 | } 29 | 30 | project(":desktop") { 31 | apply plugin: "java" 32 | 33 | 34 | dependencies { 35 | compile project(":core") 36 | compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion" 37 | compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop" 38 | compile "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop" 39 | compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop" 40 | } 41 | } 42 | 43 | project(":android") { 44 | apply plugin: "com.android.application" 45 | 46 | configurations { natives } 47 | 48 | dependencies { 49 | compile project(":core") 50 | compile fileTree(dir: 'libs', include: '*.jar') 51 | compile "com.google.android.gms:play-services:4.4.52" 52 | compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion" 53 | natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi" 54 | natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a" 55 | natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86" 56 | compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion" 57 | natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi" 58 | natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi-v7a" 59 | natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86" 60 | compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion" 61 | natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi" 62 | natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi-v7a" 63 | natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86" 64 | } 65 | } 66 | 67 | project(":core") { 68 | apply plugin: "java" 69 | 70 | 71 | dependencies { 72 | compile "com.badlogicgames.gdx:gdx:$gdxVersion" 73 | compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion" 74 | compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion" 75 | } 76 | } 77 | 78 | tasks.eclipse.doLast { 79 | delete ".project" 80 | } -------------------------------------------------------------------------------- /core/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: "java" 2 | 3 | sourceCompatibility = 1.6 4 | 5 | sourceSets.main.java.srcDirs = [ "src/" ] 6 | 7 | eclipse.project { 8 | name = appName + "-core" 9 | } 10 | -------------------------------------------------------------------------------- /core/src/MartianRun.gwt.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /core/src/com/gamestudio24/martianrun/MartianRun.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015. William Mora 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.gamestudio24.martianrun; 18 | 19 | import com.badlogic.gdx.Game; 20 | import com.gamestudio24.martianrun.screens.GameScreen; 21 | import com.gamestudio24.martianrun.utils.AssetsManager; 22 | import com.gamestudio24.martianrun.utils.AudioUtils; 23 | import com.gamestudio24.martianrun.utils.GameEventListener; 24 | import com.gamestudio24.martianrun.utils.GameManager; 25 | 26 | public class MartianRun extends Game { 27 | 28 | public MartianRun(GameEventListener listener) { 29 | GameManager.getInstance().setGameEventListener(listener); 30 | } 31 | 32 | @Override 33 | public void create() { 34 | AssetsManager.loadAssets(); 35 | setScreen(new GameScreen()); 36 | } 37 | 38 | @Override 39 | public void dispose() { 40 | super.dispose(); 41 | AudioUtils.dispose(); 42 | AssetsManager.dispose(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /core/src/com/gamestudio24/martianrun/actors/Background.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014. William Mora 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.gamestudio24.martianrun.actors; 18 | 19 | import com.badlogic.gdx.graphics.g2d.Batch; 20 | import com.badlogic.gdx.graphics.g2d.TextureRegion; 21 | import com.badlogic.gdx.math.Rectangle; 22 | import com.badlogic.gdx.scenes.scene2d.Actor; 23 | import com.gamestudio24.martianrun.enums.GameState; 24 | import com.gamestudio24.martianrun.utils.AssetsManager; 25 | import com.gamestudio24.martianrun.utils.Constants; 26 | import com.gamestudio24.martianrun.utils.GameManager; 27 | 28 | public class Background extends Actor { 29 | 30 | private final TextureRegion textureRegion; 31 | private Rectangle textureRegionBounds1; 32 | private Rectangle textureRegionBounds2; 33 | private int speed = 100; 34 | 35 | public Background() { 36 | textureRegion = AssetsManager.getTextureRegion(Constants.BACKGROUND_ASSETS_ID); 37 | textureRegionBounds1 = new Rectangle(0 - Constants.APP_WIDTH / 2, 0, Constants.APP_WIDTH, Constants.APP_HEIGHT); 38 | textureRegionBounds2 = new Rectangle(Constants.APP_WIDTH / 2, 0, Constants.APP_WIDTH, Constants.APP_HEIGHT); 39 | } 40 | 41 | @Override 42 | public void act(float delta) { 43 | 44 | if (GameManager.getInstance().getGameState() != GameState.RUNNING) { 45 | return; 46 | } 47 | 48 | if (leftBoundsReached(delta)) { 49 | resetBounds(); 50 | } else { 51 | updateXBounds(-delta); 52 | } 53 | } 54 | 55 | @Override 56 | public void draw(Batch batch, float parentAlpha) { 57 | super.draw(batch, parentAlpha); 58 | batch.draw(textureRegion, textureRegionBounds1.x, textureRegionBounds1.y, Constants.APP_WIDTH, 59 | Constants.APP_HEIGHT); 60 | batch.draw(textureRegion, textureRegionBounds2.x, textureRegionBounds2.y, Constants.APP_WIDTH, 61 | Constants.APP_HEIGHT); 62 | } 63 | 64 | private boolean leftBoundsReached(float delta) { 65 | return (textureRegionBounds2.x - (delta * speed)) <= 0; 66 | } 67 | 68 | private void updateXBounds(float delta) { 69 | textureRegionBounds1.x += delta * speed; 70 | textureRegionBounds2.x += delta * speed; 71 | } 72 | 73 | private void resetBounds() { 74 | textureRegionBounds1 = textureRegionBounds2; 75 | textureRegionBounds2 = new Rectangle(Constants.APP_WIDTH, 0, Constants.APP_WIDTH, Constants.APP_HEIGHT); 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /core/src/com/gamestudio24/martianrun/actors/Enemy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014. William Mora 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.gamestudio24.martianrun.actors; 18 | 19 | import com.badlogic.gdx.Gdx; 20 | import com.badlogic.gdx.graphics.g2d.Animation; 21 | import com.badlogic.gdx.graphics.g2d.Batch; 22 | import com.badlogic.gdx.physics.box2d.Body; 23 | import com.gamestudio24.martianrun.box2d.EnemyUserData; 24 | import com.gamestudio24.martianrun.enums.GameState; 25 | import com.gamestudio24.martianrun.utils.AssetsManager; 26 | import com.gamestudio24.martianrun.utils.GameManager; 27 | 28 | public class Enemy extends GameActor { 29 | 30 | private Animation animation; 31 | private float stateTime; 32 | 33 | public Enemy(Body body) { 34 | super(body); 35 | animation = AssetsManager.getAnimation(getUserData().getAnimationAssetId()); 36 | stateTime = 0f; 37 | } 38 | 39 | @Override 40 | public EnemyUserData getUserData() { 41 | return (EnemyUserData) userData; 42 | } 43 | 44 | @Override 45 | public void act(float delta) { 46 | super.act(delta); 47 | body.setLinearVelocity(getUserData().getLinearVelocity()); 48 | } 49 | 50 | @Override 51 | public void draw(Batch batch, float parentAlpha) { 52 | super.draw(batch, parentAlpha); 53 | 54 | if (GameManager.getInstance().getGameState() != GameState.PAUSED) { 55 | stateTime += Gdx.graphics.getDeltaTime(); 56 | } 57 | 58 | batch.draw(animation.getKeyFrame(stateTime, true), (screenRectangle.x - (screenRectangle.width * 0.1f)), 59 | screenRectangle.y, screenRectangle.width * 1.2f, screenRectangle.height * 1.1f); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /core/src/com/gamestudio24/martianrun/actors/GameActor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014. William Mora 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.gamestudio24.martianrun.actors; 18 | 19 | import com.badlogic.gdx.math.Rectangle; 20 | import com.badlogic.gdx.physics.box2d.Body; 21 | import com.badlogic.gdx.scenes.scene2d.Actor; 22 | import com.gamestudio24.martianrun.box2d.UserData; 23 | import com.gamestudio24.martianrun.enums.GameState; 24 | import com.gamestudio24.martianrun.utils.Constants; 25 | import com.gamestudio24.martianrun.utils.GameManager; 26 | 27 | public abstract class GameActor extends Actor { 28 | 29 | protected Body body; 30 | protected UserData userData; 31 | protected Rectangle screenRectangle; 32 | 33 | public GameActor(Body body) { 34 | this.body = body; 35 | this.userData = (UserData) body.getUserData(); 36 | screenRectangle = new Rectangle(); 37 | } 38 | 39 | @Override 40 | public void act(float delta) { 41 | super.act(delta); 42 | 43 | if (GameManager.getInstance().getGameState() == GameState.PAUSED) { 44 | return; 45 | } 46 | 47 | if (body.getUserData() != null) { 48 | updateRectangle(); 49 | } else { 50 | // This means the world destroyed the body (enemy or runner went out of bounds) 51 | remove(); 52 | } 53 | 54 | } 55 | 56 | public abstract UserData getUserData(); 57 | 58 | private void updateRectangle() { 59 | screenRectangle.x = transformToScreen(body.getPosition().x - userData.getWidth() / 2); 60 | screenRectangle.y = transformToScreen(body.getPosition().y - userData.getHeight() / 2); 61 | screenRectangle.width = transformToScreen(userData.getWidth()); 62 | screenRectangle.height = transformToScreen(userData.getHeight()); 63 | } 64 | 65 | protected float transformToScreen(float n) { 66 | return Constants.WORLD_TO_SCREEN * n; 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /core/src/com/gamestudio24/martianrun/actors/Ground.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014. William Mora 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.gamestudio24.martianrun.actors; 18 | 19 | import com.badlogic.gdx.graphics.g2d.Batch; 20 | import com.badlogic.gdx.graphics.g2d.TextureRegion; 21 | import com.badlogic.gdx.math.Rectangle; 22 | import com.badlogic.gdx.physics.box2d.Body; 23 | import com.gamestudio24.martianrun.box2d.GroundUserData; 24 | import com.gamestudio24.martianrun.enums.GameState; 25 | import com.gamestudio24.martianrun.utils.AssetsManager; 26 | import com.gamestudio24.martianrun.utils.Constants; 27 | import com.gamestudio24.martianrun.utils.GameManager; 28 | 29 | public class Ground extends GameActor { 30 | 31 | private final TextureRegion textureRegion; 32 | private Rectangle textureRegionBounds1; 33 | private Rectangle textureRegionBounds2; 34 | private int speed = 10; 35 | 36 | public Ground(Body body) { 37 | super(body); 38 | textureRegion = AssetsManager.getTextureRegion(Constants.GROUND_ASSETS_ID); 39 | textureRegionBounds1 = new Rectangle(0 - getUserData().getWidth() / 2, 0, getUserData().getWidth(), 40 | getUserData().getHeight()); 41 | textureRegionBounds2 = new Rectangle(getUserData().getWidth() / 2, 0, getUserData().getWidth(), 42 | getUserData().getHeight()); 43 | } 44 | 45 | @Override 46 | public GroundUserData getUserData() { 47 | return (GroundUserData) userData; 48 | } 49 | 50 | @Override 51 | public void act(float delta) { 52 | super.act(delta); 53 | 54 | if (GameManager.getInstance().getGameState() != GameState.RUNNING) { 55 | return; 56 | } 57 | 58 | if (leftBoundsReached(delta)) { 59 | resetBounds(); 60 | } else { 61 | updateXBounds(-delta); 62 | } 63 | } 64 | 65 | @Override 66 | public void draw(Batch batch, float parentAlpha) { 67 | super.draw(batch, parentAlpha); 68 | batch.draw(textureRegion, textureRegionBounds1.x, screenRectangle.y, screenRectangle.getWidth(), 69 | screenRectangle.getHeight()); 70 | batch.draw(textureRegion, textureRegionBounds2.x, screenRectangle.y, screenRectangle.getWidth(), 71 | screenRectangle.getHeight()); 72 | } 73 | 74 | private boolean leftBoundsReached(float delta) { 75 | return (textureRegionBounds2.x - transformToScreen(delta * speed)) <= 0; 76 | } 77 | 78 | private void updateXBounds(float delta) { 79 | textureRegionBounds1.x += transformToScreen(delta * speed); 80 | textureRegionBounds2.x += transformToScreen(delta * speed); 81 | } 82 | 83 | private void resetBounds() { 84 | textureRegionBounds1 = textureRegionBounds2; 85 | textureRegionBounds2 = new Rectangle(textureRegionBounds1.x + screenRectangle.width, 0, screenRectangle.width, 86 | screenRectangle.height); 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /core/src/com/gamestudio24/martianrun/actors/Runner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014. William Mora 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.gamestudio24.martianrun.actors; 18 | 19 | import com.badlogic.gdx.Gdx; 20 | import com.badlogic.gdx.audio.Sound; 21 | import com.badlogic.gdx.graphics.g2d.Animation; 22 | import com.badlogic.gdx.graphics.g2d.Batch; 23 | import com.badlogic.gdx.graphics.g2d.TextureRegion; 24 | import com.badlogic.gdx.physics.box2d.Body; 25 | import com.gamestudio24.martianrun.box2d.RunnerUserData; 26 | import com.gamestudio24.martianrun.enums.Difficulty; 27 | import com.gamestudio24.martianrun.enums.GameState; 28 | import com.gamestudio24.martianrun.utils.AssetsManager; 29 | import com.gamestudio24.martianrun.utils.AudioUtils; 30 | import com.gamestudio24.martianrun.utils.Constants; 31 | import com.gamestudio24.martianrun.utils.GameManager; 32 | 33 | public class Runner extends GameActor { 34 | 35 | private boolean dodging; 36 | private boolean jumping; 37 | private boolean hit; 38 | private Animation runningAnimation; 39 | private TextureRegion jumpingTexture; 40 | private TextureRegion dodgingTexture; 41 | private TextureRegion hitTexture; 42 | private float stateTime; 43 | 44 | private Sound jumpSound; 45 | private Sound hitSound; 46 | 47 | private int jumpCount; 48 | 49 | public Runner(Body body) { 50 | super(body); 51 | jumpCount = 0; 52 | runningAnimation = AssetsManager.getAnimation(Constants.RUNNER_RUNNING_ASSETS_ID); 53 | stateTime = 0f; 54 | jumpingTexture = AssetsManager.getTextureRegion(Constants.RUNNER_JUMPING_ASSETS_ID); 55 | dodgingTexture = AssetsManager.getTextureRegion(Constants.RUNNER_DODGING_ASSETS_ID); 56 | hitTexture = AssetsManager.getTextureRegion(Constants.RUNNER_HIT_ASSETS_ID); 57 | jumpSound = AudioUtils.getInstance().getJumpSound(); 58 | hitSound = AudioUtils.getInstance().getHitSound(); 59 | } 60 | 61 | @Override 62 | public void draw(Batch batch, float parentAlpha) { 63 | super.draw(batch, parentAlpha); 64 | 65 | float x = screenRectangle.x - (screenRectangle.width * 0.1f); 66 | float y = screenRectangle.y; 67 | float width = screenRectangle.width * 1.2f; 68 | 69 | if (dodging) { 70 | batch.draw(dodgingTexture, x, y + screenRectangle.height / 4, width, screenRectangle.height * 3 / 4); 71 | } else if (hit) { 72 | // When he's hit we also want to apply rotation if the body has been rotated 73 | batch.draw(hitTexture, x, y, width * 0.5f, screenRectangle.height * 0.5f, width, screenRectangle.height, 1f, 74 | 1f, (float) Math.toDegrees(body.getAngle())); 75 | } else if (jumping) { 76 | batch.draw(jumpingTexture, x, y, width, screenRectangle.height); 77 | } else { 78 | // Running 79 | if (GameManager.getInstance().getGameState() == GameState.RUNNING) { 80 | stateTime += Gdx.graphics.getDeltaTime(); 81 | } 82 | batch.draw(runningAnimation.getKeyFrame(stateTime, true), x, y, width, screenRectangle.height); 83 | } 84 | } 85 | 86 | @Override 87 | public RunnerUserData getUserData() { 88 | return (RunnerUserData) userData; 89 | } 90 | 91 | public void jump() { 92 | 93 | if (!(jumping || dodging || hit)) { 94 | body.applyLinearImpulse(getUserData().getJumpingLinearImpulse(), body.getWorldCenter(), true); 95 | jumping = true; 96 | AudioUtils.getInstance().playSound(jumpSound); 97 | jumpCount++; 98 | } 99 | 100 | } 101 | 102 | public void landed() { 103 | jumping = false; 104 | } 105 | 106 | public void dodge() { 107 | if (!(jumping || hit)) { 108 | body.setTransform(getUserData().getDodgePosition(), getUserData().getDodgeAngle()); 109 | dodging = true; 110 | } 111 | } 112 | 113 | public void stopDodge() { 114 | dodging = false; 115 | // If the runner is hit don't force him back to the running position 116 | if (!hit) { 117 | body.setTransform(getUserData().getRunningPosition(), 0f); 118 | } 119 | } 120 | 121 | public boolean isDodging() { 122 | return dodging; 123 | } 124 | 125 | public void hit() { 126 | body.applyAngularImpulse(getUserData().getHitAngularImpulse(), true); 127 | hit = true; 128 | AudioUtils.getInstance().playSound(hitSound); 129 | } 130 | 131 | public boolean isHit() { 132 | return hit; 133 | } 134 | 135 | public void onDifficultyChange(Difficulty newDifficulty) { 136 | setGravityScale(newDifficulty.getRunnerGravityScale()); 137 | getUserData().setJumpingLinearImpulse(newDifficulty.getRunnerJumpingLinearImpulse()); 138 | } 139 | 140 | public void setGravityScale(float gravityScale) { 141 | body.setGravityScale(gravityScale); 142 | body.resetMassData(); 143 | } 144 | 145 | public int getJumpCount() { 146 | return jumpCount; 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /core/src/com/gamestudio24/martianrun/actors/Score.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014. William Mora 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.gamestudio24.martianrun.actors; 18 | 19 | import com.badlogic.gdx.graphics.g2d.Batch; 20 | import com.badlogic.gdx.graphics.g2d.BitmapFont; 21 | import com.badlogic.gdx.math.Rectangle; 22 | import com.badlogic.gdx.scenes.scene2d.Actor; 23 | import com.gamestudio24.martianrun.enums.GameState; 24 | import com.gamestudio24.martianrun.utils.AssetsManager; 25 | import com.gamestudio24.martianrun.utils.GameManager; 26 | 27 | public class Score extends Actor { 28 | 29 | private float score; 30 | private int multiplier; 31 | private Rectangle bounds; 32 | private BitmapFont font; 33 | 34 | public Score(Rectangle bounds) { 35 | this.bounds = bounds; 36 | setWidth(bounds.width); 37 | setHeight(bounds.height); 38 | score = 0; 39 | multiplier = 5; 40 | font = AssetsManager.getSmallFont(); 41 | } 42 | 43 | @Override 44 | public void act(float delta) { 45 | super.act(delta); 46 | if (GameManager.getInstance().getGameState() != GameState.RUNNING) { 47 | return; 48 | } 49 | score += multiplier * delta; 50 | } 51 | 52 | @Override 53 | public void draw(Batch batch, float parentAlpha) { 54 | super.draw(batch, parentAlpha); 55 | if (getScore() == 0) { 56 | return; 57 | } 58 | font.drawWrapped(batch, String.format("%d", getScore()), bounds.x, bounds.y, bounds.width, BitmapFont.HAlignment.RIGHT); 59 | } 60 | 61 | public int getScore() { 62 | return (int) Math.floor(score); 63 | } 64 | 65 | public void setMultiplier(int multiplier) { 66 | this.multiplier = multiplier; 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /core/src/com/gamestudio24/martianrun/actors/menu/AboutButton.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014. William Mora 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.gamestudio24.martianrun.actors.menu; 18 | 19 | import com.badlogic.gdx.math.Rectangle; 20 | import com.gamestudio24.martianrun.enums.GameState; 21 | import com.gamestudio24.martianrun.utils.Constants; 22 | import com.gamestudio24.martianrun.utils.GameManager; 23 | 24 | public class AboutButton extends GameButton { 25 | 26 | public interface AboutButtonListener { 27 | public void onAbout(); 28 | } 29 | 30 | private AboutButtonListener listener; 31 | 32 | public AboutButton(Rectangle bounds, AboutButtonListener listener) { 33 | super(bounds); 34 | this.listener = listener; 35 | } 36 | 37 | @Override 38 | protected String getRegionName() { 39 | return GameManager.getInstance().getGameState() == GameState.ABOUT ? Constants.CLOSE_REGION_NAME : 40 | Constants.ABOUT_REGION_NAME; 41 | } 42 | 43 | @Override 44 | public void touched() { 45 | listener.onAbout(); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /core/src/com/gamestudio24/martianrun/actors/menu/AboutLabel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014. William Mora 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.gamestudio24.martianrun.actors.menu; 18 | 19 | import com.badlogic.gdx.graphics.g2d.Batch; 20 | import com.badlogic.gdx.graphics.g2d.BitmapFont; 21 | import com.badlogic.gdx.math.Rectangle; 22 | import com.badlogic.gdx.scenes.scene2d.Actor; 23 | import com.gamestudio24.martianrun.utils.AssetsManager; 24 | import com.gamestudio24.martianrun.utils.Constants; 25 | 26 | public class AboutLabel extends Actor { 27 | 28 | private Rectangle bounds; 29 | private BitmapFont font; 30 | 31 | public AboutLabel(Rectangle bounds) { 32 | this.bounds = bounds; 33 | setWidth(bounds.width); 34 | setHeight(bounds.height); 35 | font = AssetsManager.getSmallFont(); 36 | } 37 | 38 | @Override 39 | public void draw(Batch batch, float parentAlpha) { 40 | super.draw(batch, parentAlpha); 41 | font.drawWrapped(batch, Constants.ABOUT_TEXT, bounds.x, bounds.y, bounds.width, BitmapFont.HAlignment.CENTER); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /core/src/com/gamestudio24/martianrun/actors/menu/AchievementsButton.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014. William Mora 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.gamestudio24.martianrun.actors.menu; 18 | 19 | import com.badlogic.gdx.math.Rectangle; 20 | import com.gamestudio24.martianrun.utils.Constants; 21 | 22 | public class AchievementsButton extends GameButton { 23 | 24 | public interface AchievementsButtonListener { 25 | public void onAchievements(); 26 | } 27 | 28 | private AchievementsButtonListener listener; 29 | 30 | public AchievementsButton(Rectangle bounds, AchievementsButtonListener listener) { 31 | super(bounds); 32 | this.listener = listener; 33 | } 34 | 35 | @Override 36 | protected String getRegionName() { 37 | return Constants.ACHIEVEMENTS_REGION_NAME; 38 | } 39 | 40 | @Override 41 | public void touched() { 42 | listener.onAchievements(); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /core/src/com/gamestudio24/martianrun/actors/menu/GameButton.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014. William Mora 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.gamestudio24.martianrun.actors.menu; 18 | 19 | import com.badlogic.gdx.math.Rectangle; 20 | import com.badlogic.gdx.scenes.scene2d.InputEvent; 21 | import com.badlogic.gdx.scenes.scene2d.ui.Button; 22 | import com.badlogic.gdx.scenes.scene2d.ui.Skin; 23 | import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; 24 | import com.gamestudio24.martianrun.utils.AssetsManager; 25 | 26 | public abstract class GameButton extends Button { 27 | 28 | protected Rectangle bounds; 29 | private Skin skin; 30 | 31 | 32 | public GameButton(Rectangle bounds) { 33 | this.bounds = bounds; 34 | setWidth(bounds.width); 35 | setHeight(bounds.height); 36 | setBounds(bounds.x, bounds.y, bounds.width, bounds.height); 37 | skin = new Skin(); 38 | skin.addRegions(AssetsManager.getTextureAtlas()); 39 | loadTextureRegion(); 40 | addListener(new ClickListener() { 41 | @Override 42 | public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { 43 | touched(); 44 | loadTextureRegion(); 45 | return true; 46 | } 47 | }); 48 | } 49 | 50 | protected void loadTextureRegion() { 51 | ButtonStyle style = new ButtonStyle(); 52 | style.up = skin.getDrawable(getRegionName()); 53 | setStyle(style); 54 | } 55 | 56 | protected abstract String getRegionName(); 57 | 58 | public abstract void touched(); 59 | 60 | public Rectangle getBounds() { 61 | return bounds; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /core/src/com/gamestudio24/martianrun/actors/menu/GameLabel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014. William Mora 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.gamestudio24.martianrun.actors.menu; 18 | 19 | import com.badlogic.gdx.graphics.g2d.Batch; 20 | import com.badlogic.gdx.graphics.g2d.BitmapFont; 21 | import com.badlogic.gdx.math.Rectangle; 22 | import com.badlogic.gdx.scenes.scene2d.Actor; 23 | import com.gamestudio24.martianrun.utils.AssetsManager; 24 | import com.gamestudio24.martianrun.utils.Constants; 25 | 26 | public class GameLabel extends Actor { 27 | 28 | private Rectangle bounds; 29 | private BitmapFont font; 30 | 31 | public GameLabel(Rectangle bounds) { 32 | this.bounds = bounds; 33 | setWidth(bounds.width); 34 | setHeight(bounds.height); 35 | font = AssetsManager.getLargeFont(); 36 | } 37 | 38 | @Override 39 | public void draw(Batch batch, float parentAlpha) { 40 | super.draw(batch, parentAlpha); 41 | font.drawWrapped(batch, Constants.GAME_NAME, bounds.x, bounds.y, bounds.width, BitmapFont.HAlignment.CENTER); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /core/src/com/gamestudio24/martianrun/actors/menu/LeaderboardButton.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014. William Mora 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.gamestudio24.martianrun.actors.menu; 18 | 19 | import com.badlogic.gdx.math.Rectangle; 20 | import com.gamestudio24.martianrun.enums.GameState; 21 | import com.gamestudio24.martianrun.utils.Constants; 22 | import com.gamestudio24.martianrun.utils.GameManager; 23 | 24 | public class LeaderboardButton extends GameButton { 25 | 26 | public interface LeaderboardButtonListener { 27 | public void onLeaderboard(); 28 | } 29 | 30 | private LeaderboardButtonListener listener; 31 | 32 | public LeaderboardButton(Rectangle bounds, LeaderboardButtonListener listener) { 33 | super(bounds); 34 | this.listener = listener; 35 | } 36 | 37 | @Override 38 | protected String getRegionName() { 39 | return Constants.LEADERBOARD_REGION_NAME; 40 | } 41 | 42 | @Override 43 | public void act(float delta) { 44 | super.act(delta); 45 | if (GameManager.getInstance().getGameState() != GameState.OVER) { 46 | remove(); 47 | } 48 | } 49 | 50 | @Override 51 | public void touched() { 52 | listener.onLeaderboard(); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /core/src/com/gamestudio24/martianrun/actors/menu/MusicButton.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014. William Mora 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.gamestudio24.martianrun.actors.menu; 18 | 19 | import com.badlogic.gdx.math.Rectangle; 20 | import com.gamestudio24.martianrun.utils.AudioUtils; 21 | 22 | public class MusicButton extends GameButton { 23 | 24 | public MusicButton(Rectangle bounds) { 25 | super(bounds); 26 | } 27 | 28 | protected String getRegionName() { 29 | return AudioUtils.getInstance().getMusicRegionName(); 30 | } 31 | 32 | public void touched() { 33 | if (AudioUtils.getInstance().getMusic().isPlaying()) { 34 | AudioUtils.getInstance().pauseMusic(); 35 | } 36 | AudioUtils.getInstance().toggleMusic(); 37 | AudioUtils.getInstance().playMusic(); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /core/src/com/gamestudio24/martianrun/actors/menu/PauseButton.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014. William Mora 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.gamestudio24.martianrun.actors.menu; 18 | 19 | import com.badlogic.gdx.math.Rectangle; 20 | import com.gamestudio24.martianrun.enums.GameState; 21 | import com.gamestudio24.martianrun.utils.Constants; 22 | import com.gamestudio24.martianrun.utils.GameManager; 23 | 24 | public class PauseButton extends GameButton { 25 | 26 | public interface PauseButtonListener { 27 | public void onPause(); 28 | 29 | public void onResume(); 30 | } 31 | 32 | private PauseButtonListener listener; 33 | 34 | public PauseButton(Rectangle bounds, PauseButtonListener listener) { 35 | super(bounds); 36 | this.listener = listener; 37 | } 38 | 39 | @Override 40 | protected String getRegionName() { 41 | return GameManager.getInstance().getGameState() == GameState.PAUSED ? Constants.PLAY_REGION_NAME : Constants.PAUSE_REGION_NAME; 42 | } 43 | 44 | @Override 45 | public void act(float delta) { 46 | super.act(delta); 47 | if (GameManager.getInstance().getGameState() == GameState.OVER) { 48 | remove(); 49 | } 50 | } 51 | 52 | @Override 53 | public void touched() { 54 | if (GameManager.getInstance().getGameState() == GameState.PAUSED) { 55 | listener.onResume(); 56 | } else { 57 | listener.onPause(); 58 | } 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /core/src/com/gamestudio24/martianrun/actors/menu/PausedLabel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014. William Mora 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.gamestudio24.martianrun.actors.menu; 18 | 19 | import com.badlogic.gdx.graphics.g2d.Batch; 20 | import com.badlogic.gdx.graphics.g2d.BitmapFont; 21 | import com.badlogic.gdx.math.Rectangle; 22 | import com.badlogic.gdx.scenes.scene2d.Actor; 23 | import com.gamestudio24.martianrun.enums.GameState; 24 | import com.gamestudio24.martianrun.utils.AssetsManager; 25 | import com.gamestudio24.martianrun.utils.Constants; 26 | import com.gamestudio24.martianrun.utils.GameManager; 27 | 28 | public class PausedLabel extends Actor { 29 | 30 | private Rectangle bounds; 31 | private BitmapFont font; 32 | 33 | public PausedLabel(Rectangle bounds) { 34 | this.bounds = bounds; 35 | setWidth(bounds.width); 36 | setHeight(bounds.height); 37 | font = AssetsManager.getSmallFont(); 38 | } 39 | 40 | @Override 41 | public void draw(Batch batch, float parentAlpha) { 42 | super.draw(batch, parentAlpha); 43 | if (GameManager.getInstance().getGameState() == GameState.PAUSED) { 44 | font.drawWrapped(batch, Constants.PAUSED_LABEL, bounds.x, bounds.y, bounds.width, 45 | BitmapFont.HAlignment.CENTER); 46 | } 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /core/src/com/gamestudio24/martianrun/actors/menu/ShareButton.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014. William Mora 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.gamestudio24.martianrun.actors.menu; 18 | 19 | import com.badlogic.gdx.math.Rectangle; 20 | import com.gamestudio24.martianrun.utils.Constants; 21 | 22 | public class ShareButton extends GameButton { 23 | 24 | public interface ShareButtonListener { 25 | public void onShare(); 26 | } 27 | 28 | private ShareButtonListener listener; 29 | 30 | public ShareButton(Rectangle bounds, ShareButtonListener listener) { 31 | super(bounds); 32 | this.listener = listener; 33 | } 34 | 35 | @Override 36 | protected String getRegionName() { 37 | return Constants.SHARE_REGION_NAME; 38 | } 39 | 40 | @Override 41 | public void touched() { 42 | listener.onShare(); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /core/src/com/gamestudio24/martianrun/actors/menu/SoundButton.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014. William Mora 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.gamestudio24.martianrun.actors.menu; 18 | 19 | import com.badlogic.gdx.math.Rectangle; 20 | import com.gamestudio24.martianrun.utils.AudioUtils; 21 | 22 | public class SoundButton extends GameButton { 23 | 24 | public SoundButton(Rectangle bounds) { 25 | super(bounds); 26 | } 27 | 28 | @Override 29 | protected String getRegionName() { 30 | return AudioUtils.getInstance().getSoundRegionName(); 31 | } 32 | 33 | @Override 34 | public void touched() { 35 | AudioUtils.getInstance().toggleSound(); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /core/src/com/gamestudio24/martianrun/actors/menu/StartButton.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014. William Mora 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.gamestudio24.martianrun.actors.menu; 18 | 19 | import com.badlogic.gdx.math.Rectangle; 20 | import com.gamestudio24.martianrun.enums.GameState; 21 | import com.gamestudio24.martianrun.utils.Constants; 22 | import com.gamestudio24.martianrun.utils.GameManager; 23 | 24 | public class StartButton extends GameButton { 25 | 26 | public interface StartButtonListener { 27 | public void onStart(); 28 | } 29 | 30 | private StartButtonListener listener; 31 | 32 | public StartButton(Rectangle bounds, StartButtonListener listener) { 33 | super(bounds); 34 | this.listener = listener; 35 | } 36 | 37 | @Override 38 | protected String getRegionName() { 39 | return Constants.BIG_PLAY_REGION_NAME; 40 | } 41 | 42 | @Override 43 | public void act(float delta) { 44 | super.act(delta); 45 | if (GameManager.getInstance().getGameState() != GameState.OVER) { 46 | remove(); 47 | } 48 | } 49 | 50 | @Override 51 | public void touched() { 52 | listener.onStart(); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /core/src/com/gamestudio24/martianrun/actors/menu/Tutorial.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014. William Mora 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.gamestudio24.martianrun.actors.menu; 18 | 19 | import com.badlogic.gdx.graphics.g2d.Batch; 20 | import com.badlogic.gdx.graphics.g2d.BitmapFont; 21 | import com.badlogic.gdx.graphics.g2d.TextureRegion; 22 | import com.badlogic.gdx.math.Rectangle; 23 | import com.badlogic.gdx.scenes.scene2d.Actor; 24 | import com.badlogic.gdx.scenes.scene2d.actions.Actions; 25 | import com.badlogic.gdx.scenes.scene2d.actions.SequenceAction; 26 | import com.gamestudio24.martianrun.enums.GameState; 27 | import com.gamestudio24.martianrun.utils.AssetsManager; 28 | import com.gamestudio24.martianrun.utils.GameManager; 29 | 30 | public class Tutorial extends Actor { 31 | 32 | private TextureRegion textureRegion; 33 | private Rectangle bounds; 34 | private BitmapFont font; 35 | private String text; 36 | 37 | public Tutorial(Rectangle bounds, String assetsId, String text) { 38 | this.bounds = bounds; 39 | this.text = text; 40 | textureRegion = AssetsManager.getTextureRegion(assetsId); 41 | SequenceAction sequenceAction = new SequenceAction(); 42 | sequenceAction.addAction(Actions.delay(4f)); 43 | sequenceAction.addAction(Actions.removeActor()); 44 | addAction(sequenceAction); 45 | font = AssetsManager.getSmallestFont(); 46 | setWidth(bounds.width); 47 | setHeight(bounds.height); 48 | } 49 | 50 | @Override 51 | public void act(float delta) { 52 | super.act(delta); 53 | if (GameManager.getInstance().getGameState() == GameState.OVER) { 54 | remove(); 55 | } 56 | } 57 | 58 | @Override 59 | public void draw(Batch batch, float parentAlpha) { 60 | super.draw(batch, parentAlpha); 61 | batch.draw(textureRegion, bounds.x, bounds.y, bounds.width, bounds.height); 62 | font.drawWrapped(batch, text, bounds.x, bounds.y, bounds.width, 63 | BitmapFont.HAlignment.CENTER); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /core/src/com/gamestudio24/martianrun/box2d/EnemyUserData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014. William Mora 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.gamestudio24.martianrun.box2d; 18 | 19 | import com.badlogic.gdx.math.Vector2; 20 | import com.gamestudio24.martianrun.enums.UserDataType; 21 | import com.gamestudio24.martianrun.utils.Constants; 22 | 23 | public class EnemyUserData extends UserData { 24 | 25 | private Vector2 linearVelocity; 26 | private String animationAssetId; 27 | 28 | public EnemyUserData(float width, float height, String animationAssetId) { 29 | super(width, height); 30 | userDataType = UserDataType.ENEMY; 31 | linearVelocity = Constants.ENEMY_LINEAR_VELOCITY; 32 | this.animationAssetId = animationAssetId; 33 | } 34 | 35 | public void setLinearVelocity(Vector2 linearVelocity) { 36 | this.linearVelocity = linearVelocity; 37 | } 38 | 39 | public Vector2 getLinearVelocity() { 40 | return linearVelocity; 41 | } 42 | 43 | public String getAnimationAssetId() { 44 | return animationAssetId; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /core/src/com/gamestudio24/martianrun/box2d/GroundUserData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014. William Mora 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.gamestudio24.martianrun.box2d; 18 | 19 | import com.gamestudio24.martianrun.enums.UserDataType; 20 | 21 | public class GroundUserData extends UserData { 22 | 23 | public GroundUserData(float width, float height) { 24 | super(width, height); 25 | userDataType = UserDataType.GROUND; 26 | } 27 | 28 | } -------------------------------------------------------------------------------- /core/src/com/gamestudio24/martianrun/box2d/RunnerUserData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014. William Mora 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.gamestudio24.martianrun.box2d; 18 | 19 | import com.badlogic.gdx.math.Vector2; 20 | import com.gamestudio24.martianrun.enums.UserDataType; 21 | import com.gamestudio24.martianrun.utils.Constants; 22 | 23 | public class RunnerUserData extends UserData { 24 | 25 | private final Vector2 runningPosition = new Vector2(Constants.RUNNER_X, Constants.RUNNER_Y); 26 | private final Vector2 dodgePosition = new Vector2(Constants.RUNNER_DODGE_X, Constants.RUNNER_DODGE_Y); 27 | private Vector2 jumpingLinearImpulse; 28 | 29 | public RunnerUserData(float width, float height) { 30 | super(width, height); 31 | jumpingLinearImpulse = Constants.RUNNER_JUMPING_LINEAR_IMPULSE; 32 | userDataType = UserDataType.RUNNER; 33 | } 34 | 35 | public Vector2 getJumpingLinearImpulse() { 36 | return jumpingLinearImpulse; 37 | } 38 | 39 | public void setJumpingLinearImpulse(Vector2 jumpingLinearImpulse) { 40 | this.jumpingLinearImpulse = jumpingLinearImpulse; 41 | } 42 | 43 | public float getDodgeAngle() { 44 | // In radians 45 | return (float) (-90f * (Math.PI / 180f)); 46 | } 47 | 48 | public Vector2 getRunningPosition() { 49 | return runningPosition; 50 | } 51 | 52 | public Vector2 getDodgePosition() { 53 | return dodgePosition; 54 | } 55 | 56 | public float getHitAngularImpulse() { 57 | return Constants.RUNNER_HIT_ANGULAR_IMPULSE; 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /core/src/com/gamestudio24/martianrun/box2d/UserData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014. William Mora 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.gamestudio24.martianrun.box2d; 18 | 19 | import com.gamestudio24.martianrun.enums.UserDataType; 20 | 21 | public abstract class UserData { 22 | 23 | protected UserDataType userDataType; 24 | protected float width; 25 | protected float height; 26 | 27 | public UserData() { 28 | 29 | } 30 | 31 | public UserData(float width, float height) { 32 | this.width = width; 33 | this.height = height; 34 | } 35 | 36 | public UserDataType getUserDataType() { 37 | return userDataType; 38 | } 39 | 40 | public float getWidth() { 41 | return width; 42 | } 43 | 44 | public void setWidth(float width) { 45 | this.width = width; 46 | } 47 | 48 | public float getHeight() { 49 | return height; 50 | } 51 | 52 | public void setHeight(float height) { 53 | this.height = height; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /core/src/com/gamestudio24/martianrun/enums/Difficulty.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014. William Mora 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.gamestudio24.martianrun.enums; 18 | 19 | import com.badlogic.gdx.math.Vector2; 20 | import com.gamestudio24.martianrun.utils.Constants; 21 | 22 | public enum Difficulty { 23 | 24 | DIFFICULTY_1(1, Constants.ENEMY_LINEAR_VELOCITY, Constants.RUNNER_GRAVITY_SCALE, Constants.RUNNER_JUMPING_LINEAR_IMPULSE, 5), 25 | DIFFICULTY_2(2, new Vector2(-12f, 0f), Constants.RUNNER_GRAVITY_SCALE * 1.1f, new Vector2(0, 13f), 10), 26 | DIFFICULTY_3(3, new Vector2(-14f, 0f), Constants.RUNNER_GRAVITY_SCALE * 1.1f, new Vector2(0, 13f), 20), 27 | DIFFICULTY_4(4, new Vector2(-16f, 0f), Constants.RUNNER_GRAVITY_SCALE * 1.1f, new Vector2(0, 13f), 40), 28 | DIFFICULTY_5(5, new Vector2(-18f, 0f), Constants.RUNNER_GRAVITY_SCALE * 1.1f, new Vector2(0, 13f), 80), 29 | DIFFICULTY_6(6, new Vector2(-20f, 0f), Constants.RUNNER_GRAVITY_SCALE * 1.3f, new Vector2(0, 14f), 120), 30 | DIFFICULTY_7(7, new Vector2(-22f, 0f), Constants.RUNNER_GRAVITY_SCALE * 1.3f, new Vector2(0, 14f), 160), 31 | DIFFICULTY_8(8, new Vector2(-24f, 0f), Constants.RUNNER_GRAVITY_SCALE * 1.3f, new Vector2(0, 14f), 200), 32 | DIFFICULTY_9(9, new Vector2(-26f, 0f), Constants.RUNNER_GRAVITY_SCALE * 1.5f, new Vector2(0, 15f), 250), 33 | DIFFICULTY_10(10, new Vector2(-28f, 0f), Constants.RUNNER_GRAVITY_SCALE * 1.5f, new Vector2(0, 15f), 300), 34 | DIFFICULTY_11(11, new Vector2(-30f, 0f), Constants.RUNNER_GRAVITY_SCALE * 1.6f, new Vector2(0, 15f), 350), 35 | DIFFICULTY_12(12, new Vector2(-32f, 0f), Constants.RUNNER_GRAVITY_SCALE * 1.7f, new Vector2(0, 16f), 400), 36 | DIFFICULTY_13(13, new Vector2(-34f, 0f), Constants.RUNNER_GRAVITY_SCALE * 2.1f, new Vector2(0, 18f), 500); 37 | 38 | private int level; 39 | private Vector2 enemyLinearVelocity; 40 | private float runnerGravityScale; 41 | private Vector2 runnerJumpingLinearImpulse; 42 | private int scoreMultiplier; 43 | 44 | Difficulty(int level, Vector2 obstacleLinearVelocity, float runnerGravityScale, Vector2 runnerJumpingLinearImpulse, 45 | int scoreMultiplier) { 46 | this.level = level; 47 | this.enemyLinearVelocity = obstacleLinearVelocity; 48 | this.runnerGravityScale = runnerGravityScale; 49 | this.runnerJumpingLinearImpulse = runnerJumpingLinearImpulse; 50 | this.scoreMultiplier = scoreMultiplier; 51 | } 52 | 53 | public int getLevel() { 54 | return level; 55 | } 56 | 57 | public Vector2 getEnemyLinearVelocity() { 58 | return enemyLinearVelocity; 59 | } 60 | 61 | public float getRunnerGravityScale() { 62 | return runnerGravityScale; 63 | } 64 | 65 | public Vector2 getRunnerJumpingLinearImpulse() { 66 | return runnerJumpingLinearImpulse; 67 | } 68 | 69 | public int getScoreMultiplier() { 70 | return scoreMultiplier; 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /core/src/com/gamestudio24/martianrun/enums/EnemyType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014. William Mora 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.gamestudio24.martianrun.enums; 18 | 19 | import com.gamestudio24.martianrun.utils.Constants; 20 | 21 | public enum EnemyType { 22 | 23 | RUNNING_SMALL(1f, 1f, Constants.ENEMY_X, Constants.RUNNING_SHORT_ENEMY_Y, Constants.ENEMY_DENSITY, 24 | Constants.RUNNING_SMALL_ENEMY_ASSETS_ID), 25 | RUNNING_WIDE(2f, 1f, Constants.ENEMY_X, Constants.RUNNING_SHORT_ENEMY_Y, Constants.ENEMY_DENSITY, 26 | Constants.RUNNING_WIDE_ENEMY_ASSETS_ID), 27 | RUNNING_LONG(1f, 2f, Constants.ENEMY_X, Constants.RUNNING_LONG_ENEMY_Y, Constants.ENEMY_DENSITY, 28 | Constants.RUNNING_LONG_ENEMY_ASSETS_ID), 29 | RUNNING_BIG(2f, 2f, Constants.ENEMY_X, Constants.RUNNING_LONG_ENEMY_Y, Constants.ENEMY_DENSITY, 30 | Constants.RUNNING_BIG_ENEMY_ASSETS_ID), 31 | FLYING_SMALL(1f, 1f, Constants.ENEMY_X, Constants.FLYING_ENEMY_Y, Constants.ENEMY_DENSITY, 32 | Constants.FLYING_SMALL_ENEMY_ASSETS_ID), 33 | FLYING_WIDE(2f, 1f, Constants.ENEMY_X, Constants.FLYING_ENEMY_Y, Constants.ENEMY_DENSITY, 34 | Constants.FLYING_WIDE_ENEMY_ASSETS_ID); 35 | 36 | private float width; 37 | private float height; 38 | private float x; 39 | private float y; 40 | private float density; 41 | private String animationAssetsId; 42 | 43 | EnemyType(float width, float height, float x, float y, float density, String animationAssetsId) { 44 | this.width = width; 45 | this.height = height; 46 | this.x = x; 47 | this.y = y; 48 | this.density = density; 49 | this.animationAssetsId = animationAssetsId; 50 | } 51 | 52 | public float getWidth() { 53 | return width; 54 | } 55 | 56 | public float getHeight() { 57 | return height; 58 | } 59 | 60 | public float getX() { 61 | return x; 62 | } 63 | 64 | public float getY() { 65 | return y; 66 | } 67 | 68 | public float getDensity() { 69 | return density; 70 | } 71 | 72 | public String getAnimationAssetId() { 73 | return animationAssetsId; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /core/src/com/gamestudio24/martianrun/enums/GameState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014. William Mora 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.gamestudio24.martianrun.enums; 18 | 19 | public enum GameState { 20 | 21 | RUNNING, 22 | PAUSED, 23 | OVER, 24 | ABOUT 25 | 26 | } 27 | -------------------------------------------------------------------------------- /core/src/com/gamestudio24/martianrun/enums/UserDataType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014. William Mora 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.gamestudio24.martianrun.enums; 18 | 19 | public enum UserDataType { 20 | 21 | GROUND, 22 | RUNNER, 23 | ENEMY 24 | 25 | } 26 | -------------------------------------------------------------------------------- /core/src/com/gamestudio24/martianrun/screens/GameScreen.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014. William Mora 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.gamestudio24.martianrun.screens; 18 | 19 | import com.badlogic.gdx.Gdx; 20 | import com.badlogic.gdx.Screen; 21 | import com.badlogic.gdx.graphics.GL20; 22 | import com.gamestudio24.martianrun.stages.GameStage; 23 | 24 | public class GameScreen implements Screen { 25 | 26 | private GameStage stage; 27 | 28 | public GameScreen() { 29 | stage = new GameStage(); 30 | } 31 | 32 | @Override 33 | public void render(float delta) { 34 | //Clear the screen 35 | Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); 36 | 37 | //Update the stage 38 | stage.draw(); 39 | stage.act(delta); 40 | } 41 | 42 | @Override 43 | public void resize(int width, int height) { 44 | 45 | } 46 | 47 | @Override 48 | public void show() { 49 | 50 | } 51 | 52 | @Override 53 | public void hide() { 54 | 55 | } 56 | 57 | @Override 58 | public void pause() { 59 | 60 | } 61 | 62 | @Override 63 | public void resume() { 64 | 65 | } 66 | 67 | @Override 68 | public void dispose() { 69 | 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /core/src/com/gamestudio24/martianrun/stages/GameStage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014. William Mora 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.gamestudio24.martianrun.stages; 18 | 19 | import com.badlogic.gdx.Gdx; 20 | import com.badlogic.gdx.graphics.OrthographicCamera; 21 | import com.badlogic.gdx.math.Rectangle; 22 | import com.badlogic.gdx.math.Vector3; 23 | import com.badlogic.gdx.physics.box2d.*; 24 | import com.badlogic.gdx.scenes.scene2d.Stage; 25 | import com.badlogic.gdx.utils.Array; 26 | import com.badlogic.gdx.utils.Scaling; 27 | import com.badlogic.gdx.utils.viewport.ScalingViewport; 28 | import com.gamestudio24.martianrun.actors.*; 29 | import com.gamestudio24.martianrun.actors.menu.*; 30 | import com.gamestudio24.martianrun.enums.Difficulty; 31 | import com.gamestudio24.martianrun.enums.GameState; 32 | import com.gamestudio24.martianrun.utils.*; 33 | 34 | public class GameStage extends Stage implements ContactListener { 35 | 36 | private static final int VIEWPORT_WIDTH = Constants.APP_WIDTH; 37 | private static final int VIEWPORT_HEIGHT = Constants.APP_HEIGHT; 38 | 39 | private World world; 40 | private Ground ground; 41 | private Runner runner; 42 | 43 | private final float TIME_STEP = 1 / 300f; 44 | private float accumulator = 0f; 45 | 46 | private OrthographicCamera camera; 47 | 48 | private Rectangle screenLeftSide; 49 | private Rectangle screenRightSide; 50 | 51 | private SoundButton soundButton; 52 | private MusicButton musicButton; 53 | private PauseButton pauseButton; 54 | private StartButton startButton; 55 | private LeaderboardButton leaderboardButton; 56 | private AboutButton aboutButton; 57 | private ShareButton shareButton; 58 | private AchievementsButton achievementsButton; 59 | 60 | private Score score; 61 | private float totalTimePassed; 62 | private boolean tutorialShown; 63 | 64 | private Vector3 touchPoint; 65 | 66 | public GameStage() { 67 | super(new ScalingViewport(Scaling.stretch, VIEWPORT_WIDTH, VIEWPORT_HEIGHT, 68 | new OrthographicCamera(VIEWPORT_WIDTH, VIEWPORT_HEIGHT))); 69 | setUpCamera(); 70 | setUpStageBase(); 71 | setUpGameLabel(); 72 | setUpMainMenu(); 73 | setUpTouchControlAreas(); 74 | Gdx.input.setInputProcessor(this); 75 | AudioUtils.getInstance().init(); 76 | onGameOver(); 77 | } 78 | 79 | private void setUpStageBase() { 80 | setUpWorld(); 81 | setUpFixedMenu(); 82 | } 83 | 84 | private void setUpGameLabel() { 85 | Rectangle gameLabelBounds = new Rectangle(0, getCamera().viewportHeight * 7 / 8, 86 | getCamera().viewportWidth, getCamera().viewportHeight / 4); 87 | addActor(new GameLabel(gameLabelBounds)); 88 | } 89 | 90 | private void setUpAboutText() { 91 | Rectangle gameLabelBounds = new Rectangle(0, getCamera().viewportHeight * 5 / 8, 92 | getCamera().viewportWidth, getCamera().viewportHeight / 4); 93 | addActor(new AboutLabel(gameLabelBounds)); 94 | } 95 | 96 | /** 97 | * These menu buttons are always displayed 98 | */ 99 | private void setUpFixedMenu() { 100 | setUpSound(); 101 | setUpMusic(); 102 | setUpScore(); 103 | } 104 | 105 | private void setUpSound() { 106 | Rectangle soundButtonBounds = new Rectangle(getCamera().viewportWidth / 64, 107 | getCamera().viewportHeight * 13 / 20, getCamera().viewportHeight / 10, 108 | getCamera().viewportHeight / 10); 109 | soundButton = new SoundButton(soundButtonBounds); 110 | addActor(soundButton); 111 | } 112 | 113 | private void setUpMusic() { 114 | Rectangle musicButtonBounds = new Rectangle(getCamera().viewportWidth / 64, 115 | getCamera().viewportHeight * 4 / 5, getCamera().viewportHeight / 10, 116 | getCamera().viewportHeight / 10); 117 | musicButton = new MusicButton(musicButtonBounds); 118 | addActor(musicButton); 119 | } 120 | 121 | private void setUpScore() { 122 | Rectangle scoreBounds = new Rectangle(getCamera().viewportWidth * 47 / 64, 123 | getCamera().viewportHeight * 57 / 64, getCamera().viewportWidth / 4, 124 | getCamera().viewportHeight / 8); 125 | score = new Score(scoreBounds); 126 | addActor(score); 127 | } 128 | 129 | private void setUpPause() { 130 | Rectangle pauseButtonBounds = new Rectangle(getCamera().viewportWidth / 64, 131 | getCamera().viewportHeight * 1 / 2, getCamera().viewportHeight / 10, 132 | getCamera().viewportHeight / 10); 133 | pauseButton = new PauseButton(pauseButtonBounds, new GamePauseButtonListener()); 134 | addActor(pauseButton); 135 | } 136 | 137 | /** 138 | * These menu buttons are only displayed when the game is over 139 | */ 140 | private void setUpMainMenu() { 141 | setUpStart(); 142 | setUpLeaderboard(); 143 | setUpAbout(); 144 | setUpShare(); 145 | setUpAchievements(); 146 | } 147 | 148 | private void setUpStart() { 149 | Rectangle startButtonBounds = new Rectangle(getCamera().viewportWidth * 3 / 16, 150 | getCamera().viewportHeight / 4, getCamera().viewportWidth / 4, 151 | getCamera().viewportWidth / 4); 152 | startButton = new StartButton(startButtonBounds, new GameStartButtonListener()); 153 | addActor(startButton); 154 | } 155 | 156 | private void setUpLeaderboard() { 157 | Rectangle leaderboardButtonBounds = new Rectangle(getCamera().viewportWidth * 9 / 16, 158 | getCamera().viewportHeight / 4, getCamera().viewportWidth / 4, 159 | getCamera().viewportWidth / 4); 160 | leaderboardButton = new LeaderboardButton(leaderboardButtonBounds, 161 | new GameLeaderboardButtonListener()); 162 | addActor(leaderboardButton); 163 | } 164 | 165 | private void setUpAbout() { 166 | Rectangle aboutButtonBounds = new Rectangle(getCamera().viewportWidth * 23 / 25, 167 | getCamera().viewportHeight * 13 / 20, getCamera().viewportHeight / 10, 168 | getCamera().viewportHeight / 10); 169 | aboutButton = new AboutButton(aboutButtonBounds, new GameAboutButtonListener()); 170 | addActor(aboutButton); 171 | } 172 | 173 | private void setUpShare() { 174 | Rectangle shareButtonBounds = new Rectangle(getCamera().viewportWidth / 64, 175 | getCamera().viewportHeight / 2, getCamera().viewportHeight / 10, 176 | getCamera().viewportHeight / 10); 177 | shareButton = new ShareButton(shareButtonBounds, new GameShareButtonListener()); 178 | addActor(shareButton); 179 | } 180 | 181 | private void setUpAchievements() { 182 | Rectangle achievementsButtonBounds = new Rectangle(getCamera().viewportWidth * 23 / 25, 183 | getCamera().viewportHeight / 2, getCamera().viewportHeight / 10, 184 | getCamera().viewportHeight / 10); 185 | achievementsButton = new AchievementsButton(achievementsButtonBounds, 186 | new GameAchievementsButtonListener()); 187 | addActor(achievementsButton); 188 | } 189 | 190 | private void setUpWorld() { 191 | world = WorldUtils.createWorld(); 192 | world.setContactListener(this); 193 | setUpBackground(); 194 | setUpGround(); 195 | } 196 | 197 | private void setUpBackground() { 198 | addActor(new Background()); 199 | } 200 | 201 | private void setUpGround() { 202 | ground = new Ground(WorldUtils.createGround(world)); 203 | addActor(ground); 204 | } 205 | 206 | private void setUpCharacters() { 207 | setUpRunner(); 208 | setUpPauseLabel(); 209 | createEnemy(); 210 | } 211 | 212 | private void setUpRunner() { 213 | if (runner != null) { 214 | runner.remove(); 215 | } 216 | runner = new Runner(WorldUtils.createRunner(world)); 217 | addActor(runner); 218 | } 219 | 220 | private void setUpCamera() { 221 | camera = new OrthographicCamera(VIEWPORT_WIDTH, VIEWPORT_HEIGHT); 222 | camera.position.set(camera.viewportWidth / 2, camera.viewportHeight / 2, 0f); 223 | camera.update(); 224 | } 225 | 226 | private void setUpTouchControlAreas() { 227 | touchPoint = new Vector3(); 228 | screenLeftSide = new Rectangle(0, 0, getCamera().viewportWidth / 2, 229 | getCamera().viewportHeight); 230 | screenRightSide = new Rectangle(getCamera().viewportWidth / 2, 0, 231 | getCamera().viewportWidth / 2, getCamera().viewportHeight); 232 | } 233 | 234 | private void setUpPauseLabel() { 235 | Rectangle pauseLabelBounds = new Rectangle(0, getCamera().viewportHeight * 7 / 8, 236 | getCamera().viewportWidth, getCamera().viewportHeight / 4); 237 | addActor(new PausedLabel(pauseLabelBounds)); 238 | } 239 | 240 | private void setUpTutorial() { 241 | if (tutorialShown) { 242 | return; 243 | } 244 | setUpLeftTutorial(); 245 | setUpRightTutorial(); 246 | tutorialShown = true; 247 | } 248 | 249 | private void setUpLeftTutorial() { 250 | float width = getCamera().viewportHeight / 4; 251 | float x = getCamera().viewportWidth / 4 - width / 2; 252 | Rectangle leftTutorialBounds = new Rectangle(x, getCamera().viewportHeight * 9 / 20, width, 253 | width); 254 | addActor(new Tutorial(leftTutorialBounds, Constants.TUTORIAL_LEFT_REGION_NAME, 255 | Constants.TUTORIAL_LEFT_TEXT)); 256 | } 257 | 258 | private void setUpRightTutorial() { 259 | float width = getCamera().viewportHeight / 4; 260 | float x = getCamera().viewportWidth * 3 / 4 - width / 2; 261 | Rectangle rightTutorialBounds = new Rectangle(x, getCamera().viewportHeight * 9 / 20, width, 262 | width); 263 | addActor(new Tutorial(rightTutorialBounds, Constants.TUTORIAL_RIGHT_REGION_NAME, 264 | Constants.TUTORIAL_RIGHT_TEXT)); 265 | } 266 | 267 | @Override 268 | public void act(float delta) { 269 | super.act(delta); 270 | 271 | if (GameManager.getInstance().getGameState() == GameState.PAUSED) return; 272 | 273 | if (GameManager.getInstance().getGameState() == GameState.RUNNING) { 274 | totalTimePassed += delta; 275 | updateDifficulty(); 276 | } 277 | 278 | Array bodies = new Array(world.getBodyCount()); 279 | world.getBodies(bodies); 280 | 281 | for (Body body : bodies) { 282 | update(body); 283 | } 284 | 285 | // Fixed timestep 286 | accumulator += delta; 287 | 288 | while (accumulator >= delta) { 289 | world.step(TIME_STEP, 6, 2); 290 | accumulator -= TIME_STEP; 291 | } 292 | 293 | //TODO: Implement interpolation 294 | 295 | } 296 | 297 | private void update(Body body) { 298 | if (!BodyUtils.bodyInBounds(body)) { 299 | if (BodyUtils.bodyIsEnemy(body) && !runner.isHit()) { 300 | createEnemy(); 301 | } 302 | world.destroyBody(body); 303 | } 304 | } 305 | 306 | private void createEnemy() { 307 | Enemy enemy = new Enemy(WorldUtils.createEnemy(world)); 308 | enemy.getUserData().setLinearVelocity( 309 | GameManager.getInstance().getDifficulty().getEnemyLinearVelocity()); 310 | addActor(enemy); 311 | } 312 | 313 | @Override 314 | public boolean touchDown(int x, int y, int pointer, int button) { 315 | 316 | // Need to get the actual coordinates 317 | translateScreenToWorldCoordinates(x, y); 318 | 319 | // If a menu control was touched ignore the rest 320 | if (menuControlTouched(touchPoint.x, touchPoint.y)) { 321 | return super.touchDown(x, y, pointer, button); 322 | } 323 | 324 | if (GameManager.getInstance().getGameState() != GameState.RUNNING) { 325 | return super.touchDown(x, y, pointer, button); 326 | } 327 | 328 | if (rightSideTouched(touchPoint.x, touchPoint.y)) { 329 | runner.jump(); 330 | } else if (leftSideTouched(touchPoint.x, touchPoint.y)) { 331 | runner.dodge(); 332 | } 333 | 334 | return super.touchDown(x, y, pointer, button); 335 | } 336 | 337 | @Override 338 | public boolean touchUp(int screenX, int screenY, int pointer, int button) { 339 | 340 | if (GameManager.getInstance().getGameState() != GameState.RUNNING) { 341 | return super.touchUp(screenX, screenY, pointer, button); 342 | } 343 | 344 | if (runner.isDodging()) { 345 | runner.stopDodge(); 346 | } 347 | 348 | return super.touchUp(screenX, screenY, pointer, button); 349 | } 350 | 351 | private boolean menuControlTouched(float x, float y) { 352 | boolean touched = false; 353 | 354 | switch (GameManager.getInstance().getGameState()) { 355 | case OVER: 356 | touched = startButton.getBounds().contains(x, y) 357 | || leaderboardButton.getBounds().contains(x, y) 358 | || aboutButton.getBounds().contains(x, y); 359 | break; 360 | case RUNNING: 361 | case PAUSED: 362 | touched = pauseButton.getBounds().contains(x, y); 363 | break; 364 | } 365 | 366 | return touched || soundButton.getBounds().contains(x, y) 367 | || musicButton.getBounds().contains(x, y); 368 | } 369 | 370 | private boolean rightSideTouched(float x, float y) { 371 | return screenRightSide.contains(x, y); 372 | } 373 | 374 | private boolean leftSideTouched(float x, float y) { 375 | return screenLeftSide.contains(x, y); 376 | } 377 | 378 | /** 379 | * Helper function to get the actual coordinates in my world 380 | * 381 | * @param x 382 | * @param y 383 | */ 384 | private void translateScreenToWorldCoordinates(int x, int y) { 385 | getCamera().unproject(touchPoint.set(x, y, 0)); 386 | } 387 | 388 | @Override 389 | public void beginContact(Contact contact) { 390 | 391 | Body a = contact.getFixtureA().getBody(); 392 | Body b = contact.getFixtureB().getBody(); 393 | 394 | if ((BodyUtils.bodyIsRunner(a) && BodyUtils.bodyIsEnemy(b)) || 395 | (BodyUtils.bodyIsEnemy(a) && BodyUtils.bodyIsRunner(b))) { 396 | if (runner.isHit()) { 397 | return; 398 | } 399 | runner.hit(); 400 | displayAd(); 401 | GameManager.getInstance().submitScore(score.getScore()); 402 | onGameOver(); 403 | GameManager.getInstance().addGamePlayed(); 404 | GameManager.getInstance().addJumpCount(runner.getJumpCount()); 405 | } else if ((BodyUtils.bodyIsRunner(a) && BodyUtils.bodyIsGround(b)) || 406 | (BodyUtils.bodyIsGround(a) && BodyUtils.bodyIsRunner(b))) { 407 | runner.landed(); 408 | } 409 | 410 | } 411 | 412 | private void updateDifficulty() { 413 | 414 | if (GameManager.getInstance().isMaxDifficulty()) { 415 | return; 416 | } 417 | 418 | Difficulty currentDifficulty = GameManager.getInstance().getDifficulty(); 419 | 420 | if (totalTimePassed > GameManager.getInstance().getDifficulty().getLevel() * 5) { 421 | 422 | int nextDifficulty = currentDifficulty.getLevel() + 1; 423 | String difficultyName = "DIFFICULTY_" + nextDifficulty; 424 | GameManager.getInstance().setDifficulty(Difficulty.valueOf(difficultyName)); 425 | 426 | runner.onDifficultyChange(GameManager.getInstance().getDifficulty()); 427 | score.setMultiplier(GameManager.getInstance().getDifficulty().getScoreMultiplier()); 428 | 429 | displayAd(); 430 | } 431 | 432 | } 433 | 434 | private void displayAd() { 435 | GameManager.getInstance().displayAd(); 436 | } 437 | 438 | @Override 439 | public void endContact(Contact contact) { 440 | 441 | } 442 | 443 | @Override 444 | public void preSolve(Contact contact, Manifold oldManifold) { 445 | 446 | } 447 | 448 | @Override 449 | public void postSolve(Contact contact, ContactImpulse impulse) { 450 | 451 | } 452 | 453 | private class GamePauseButtonListener implements PauseButton.PauseButtonListener { 454 | 455 | @Override 456 | public void onPause() { 457 | onGamePaused(); 458 | } 459 | 460 | @Override 461 | public void onResume() { 462 | onGameResumed(); 463 | } 464 | 465 | } 466 | 467 | private class GameStartButtonListener implements StartButton.StartButtonListener { 468 | 469 | @Override 470 | public void onStart() { 471 | clear(); 472 | setUpStageBase(); 473 | setUpCharacters(); 474 | setUpPause(); 475 | setUpTutorial(); 476 | onGameResumed(); 477 | } 478 | 479 | } 480 | 481 | private class GameLeaderboardButtonListener 482 | implements LeaderboardButton.LeaderboardButtonListener { 483 | 484 | @Override 485 | public void onLeaderboard() { 486 | GameManager.getInstance().displayLeaderboard(); 487 | } 488 | 489 | } 490 | 491 | private class GameAboutButtonListener implements AboutButton.AboutButtonListener { 492 | 493 | @Override 494 | public void onAbout() { 495 | if (GameManager.getInstance().getGameState() == GameState.OVER) { 496 | onGameAbout(); 497 | } else { 498 | clear(); 499 | setUpStageBase(); 500 | setUpGameLabel(); 501 | onGameOver(); 502 | } 503 | } 504 | 505 | } 506 | 507 | private class GameShareButtonListener implements ShareButton.ShareButtonListener { 508 | 509 | @Override 510 | public void onShare() { 511 | GameManager.getInstance().share(); 512 | } 513 | 514 | } 515 | 516 | private class GameAchievementsButtonListener 517 | implements AchievementsButton.AchievementsButtonListener { 518 | 519 | @Override 520 | public void onAchievements() { 521 | GameManager.getInstance().displayAchievements(); 522 | } 523 | 524 | } 525 | 526 | private void onGamePaused() { 527 | GameManager.getInstance().setGameState(GameState.PAUSED); 528 | } 529 | 530 | private void onGameResumed() { 531 | GameManager.getInstance().setGameState(GameState.RUNNING); 532 | } 533 | 534 | private void onGameOver() { 535 | GameManager.getInstance().setGameState(GameState.OVER); 536 | GameManager.getInstance().resetDifficulty(); 537 | totalTimePassed = 0; 538 | setUpMainMenu(); 539 | } 540 | 541 | private void onGameAbout() { 542 | GameManager.getInstance().setGameState(GameState.ABOUT); 543 | clear(); 544 | setUpStageBase(); 545 | setUpGameLabel(); 546 | setUpAboutText(); 547 | setUpAbout(); 548 | } 549 | 550 | } -------------------------------------------------------------------------------- /core/src/com/gamestudio24/martianrun/utils/AssetsManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014. William Mora 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.gamestudio24.martianrun.utils; 18 | 19 | import com.badlogic.gdx.Gdx; 20 | import com.badlogic.gdx.graphics.Texture; 21 | import com.badlogic.gdx.graphics.g2d.Animation; 22 | import com.badlogic.gdx.graphics.g2d.BitmapFont; 23 | import com.badlogic.gdx.graphics.g2d.TextureAtlas; 24 | import com.badlogic.gdx.graphics.g2d.TextureRegion; 25 | import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator; 26 | 27 | import java.util.HashMap; 28 | 29 | public class AssetsManager { 30 | 31 | private static HashMap texturesMap = new HashMap(); 32 | private static HashMap animationsMap = new HashMap(); 33 | private static TextureAtlas textureAtlas; 34 | private static BitmapFont smallFont; 35 | private static BitmapFont smallestFont; 36 | private static BitmapFont largeFont; 37 | 38 | private AssetsManager() { 39 | 40 | } 41 | 42 | public static void loadAssets() { 43 | 44 | // Background 45 | texturesMap.put(Constants.BACKGROUND_ASSETS_ID, 46 | new TextureRegion(new Texture(Gdx.files.internal(Constants.BACKGROUND_IMAGE_PATH)))); 47 | 48 | // Ground 49 | texturesMap.put(Constants.GROUND_ASSETS_ID, 50 | new TextureRegion(new Texture(Gdx.files.internal(Constants.GROUND_IMAGE_PATH)))); 51 | 52 | textureAtlas = new TextureAtlas(Constants.SPRITES_ATLAS_PATH); 53 | 54 | // Runner 55 | texturesMap.put(Constants.RUNNER_JUMPING_ASSETS_ID, 56 | textureAtlas.findRegion(Constants.RUNNER_JUMPING_REGION_NAME)); 57 | texturesMap.put(Constants.RUNNER_DODGING_ASSETS_ID, 58 | textureAtlas.findRegion(Constants.RUNNER_DODGING_REGION_NAME)); 59 | texturesMap.put(Constants.RUNNER_HIT_ASSETS_ID, 60 | textureAtlas.findRegion(Constants.RUNNER_HIT_REGION_NAME)); 61 | animationsMap.put(Constants.RUNNER_RUNNING_ASSETS_ID, createAnimation(textureAtlas, 62 | Constants.RUNNER_RUNNING_REGION_NAMES)); 63 | 64 | // Enemies 65 | animationsMap.put(Constants.RUNNING_SMALL_ENEMY_ASSETS_ID, createAnimation(textureAtlas, 66 | Constants.RUNNING_SMALL_ENEMY_REGION_NAMES)); 67 | animationsMap.put(Constants.RUNNING_BIG_ENEMY_ASSETS_ID, createAnimation(textureAtlas, 68 | Constants.RUNNING_BIG_ENEMY_REGION_NAMES)); 69 | animationsMap.put(Constants.RUNNING_LONG_ENEMY_ASSETS_ID, createAnimation(textureAtlas, 70 | Constants.RUNNING_LONG_ENEMY_REGION_NAMES)); 71 | animationsMap.put(Constants.RUNNING_WIDE_ENEMY_ASSETS_ID, createAnimation(textureAtlas, 72 | Constants.RUNNING_WIDE_ENEMY_REGION_NAMES)); 73 | animationsMap.put(Constants.FLYING_SMALL_ENEMY_ASSETS_ID, createAnimation(textureAtlas, 74 | Constants.FLYING_SMALL_ENEMY_REGION_NAMES)); 75 | animationsMap.put(Constants.FLYING_WIDE_ENEMY_ASSETS_ID, createAnimation(textureAtlas, 76 | Constants.FLYING_WIDE_ENEMY_REGION_NAMES)); 77 | 78 | // Tutorial 79 | texturesMap.put(Constants.TUTORIAL_LEFT_REGION_NAME, 80 | textureAtlas.findRegion(Constants.TUTORIAL_LEFT_REGION_NAME)); 81 | texturesMap.put(Constants.TUTORIAL_RIGHT_REGION_NAME, 82 | textureAtlas.findRegion(Constants.TUTORIAL_RIGHT_REGION_NAME)); 83 | 84 | // Fonts 85 | FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal(Constants.FONT_NAME)); 86 | FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter(); 87 | parameter.size = 36; 88 | smallFont = generator.generateFont(parameter); 89 | smallFont.setColor(.21f, .22f, .21f, 1f); 90 | parameter.size = 72; 91 | largeFont = generator.generateFont(parameter); 92 | largeFont.setColor(.21f, .22f, .21f, 1f); 93 | parameter.size = 24; 94 | smallestFont = generator.generateFont(parameter); 95 | smallestFont.setColor(.21f, .22f, .21f, 1f); 96 | generator.dispose(); 97 | 98 | } 99 | 100 | public static TextureRegion getTextureRegion(String key) { 101 | return texturesMap.get(key); 102 | } 103 | 104 | public static Animation getAnimation(String key) { 105 | return animationsMap.get(key); 106 | } 107 | 108 | private static Animation createAnimation(TextureAtlas textureAtlas, String[] regionNames) { 109 | 110 | TextureRegion[] runningFrames = new TextureRegion[regionNames.length]; 111 | 112 | for (int i = 0; i < regionNames.length; i++) { 113 | String path = regionNames[i]; 114 | runningFrames[i] = textureAtlas.findRegion(path); 115 | } 116 | 117 | return new Animation(0.1f, runningFrames); 118 | 119 | } 120 | 121 | public static TextureAtlas getTextureAtlas() { 122 | return textureAtlas; 123 | } 124 | 125 | public static BitmapFont getSmallFont() { 126 | return smallFont; 127 | } 128 | 129 | public static BitmapFont getLargeFont() { 130 | return largeFont; 131 | } 132 | 133 | public static BitmapFont getSmallestFont() { 134 | return smallestFont; 135 | } 136 | 137 | public static void dispose() { 138 | textureAtlas.dispose(); 139 | smallestFont.dispose(); 140 | smallFont.dispose(); 141 | largeFont.dispose(); 142 | texturesMap.clear(); 143 | animationsMap.clear(); 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /core/src/com/gamestudio24/martianrun/utils/AudioUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014. William Mora 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.gamestudio24.martianrun.utils; 18 | 19 | import com.badlogic.gdx.Gdx; 20 | import com.badlogic.gdx.Preferences; 21 | import com.badlogic.gdx.audio.Music; 22 | import com.badlogic.gdx.audio.Sound; 23 | 24 | public class AudioUtils { 25 | 26 | private static AudioUtils ourInstance = new AudioUtils(); 27 | private static Music music; 28 | private static Sound jumpSound; 29 | private static Sound hitSound; 30 | 31 | private static final String MUSIC_ON_PREFERENCE = "music_on"; 32 | private static final String SOUND_ON_PREFERENCE = "sound_on"; 33 | 34 | private AudioUtils() { 35 | } 36 | 37 | public static AudioUtils getInstance() { 38 | return ourInstance; 39 | } 40 | 41 | public Music getMusic() { 42 | return music; 43 | } 44 | 45 | private Preferences getPreferences() { 46 | return Gdx.app.getPreferences(GameManager.PREFERENCES_NAME); 47 | } 48 | 49 | public void init() { 50 | music = Gdx.audio.newMusic(Gdx.files.internal(Constants.GAME_MUSIC)); 51 | music.setLooping(true); 52 | playMusic(); 53 | jumpSound = createSound(Constants.RUNNER_JUMPING_SOUND); 54 | hitSound = createSound(Constants.RUNNER_HIT_SOUND); 55 | } 56 | 57 | public Sound createSound(String soundFileName) { 58 | return Gdx.audio.newSound(Gdx.files.internal(soundFileName)); 59 | } 60 | 61 | public void playMusic() { 62 | boolean musicOn = getPreferences().getBoolean(MUSIC_ON_PREFERENCE, true); 63 | if (musicOn) { 64 | music.play(); 65 | } 66 | } 67 | 68 | public void playSound(Sound sound) { 69 | boolean soundOn = getPreferences().getBoolean(SOUND_ON_PREFERENCE, true); 70 | if (soundOn) { 71 | sound.play(); 72 | } 73 | } 74 | 75 | public void toggleMusic() { 76 | saveBoolean(MUSIC_ON_PREFERENCE, !getPreferences().getBoolean(MUSIC_ON_PREFERENCE, true)); 77 | } 78 | 79 | public void toggleSound() { 80 | saveBoolean(SOUND_ON_PREFERENCE, !getPreferences().getBoolean(SOUND_ON_PREFERENCE, true)); 81 | } 82 | 83 | private void saveBoolean(String key, boolean value) { 84 | Preferences preferences = getPreferences(); 85 | preferences.putBoolean(key, value); 86 | preferences.flush(); 87 | } 88 | 89 | public static void dispose() { 90 | music.dispose(); 91 | jumpSound.dispose(); 92 | hitSound.dispose(); 93 | } 94 | 95 | public void pauseMusic() { 96 | music.pause(); 97 | } 98 | 99 | public String getSoundRegionName() { 100 | boolean soundOn = getPreferences().getBoolean(SOUND_ON_PREFERENCE, true); 101 | return soundOn ? Constants.SOUND_ON_REGION_NAME : Constants.SOUND_OFF_REGION_NAME; 102 | } 103 | 104 | public String getMusicRegionName() { 105 | boolean musicOn = getPreferences().getBoolean(MUSIC_ON_PREFERENCE, true); 106 | return musicOn ? Constants.MUSIC_ON_REGION_NAME : Constants.MUSIC_OFF_REGION_NAME; 107 | } 108 | 109 | public Sound getJumpSound() { 110 | return jumpSound; 111 | } 112 | 113 | public Sound getHitSound() { 114 | return hitSound; 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /core/src/com/gamestudio24/martianrun/utils/BodyUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014. William Mora 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.gamestudio24.martianrun.utils; 18 | 19 | import com.badlogic.gdx.physics.box2d.Body; 20 | import com.gamestudio24.martianrun.box2d.UserData; 21 | import com.gamestudio24.martianrun.enums.UserDataType; 22 | 23 | public class BodyUtils { 24 | 25 | public static boolean bodyInBounds(Body body) { 26 | UserData userData = (UserData) body.getUserData(); 27 | 28 | switch (userData.getUserDataType()) { 29 | case RUNNER: 30 | case ENEMY: 31 | return body.getPosition().x + userData.getWidth() / 2 > 0; 32 | } 33 | 34 | return true; 35 | } 36 | 37 | public static boolean bodyIsEnemy(Body body) { 38 | UserData userData = (UserData) body.getUserData(); 39 | 40 | return userData != null && userData.getUserDataType() == UserDataType.ENEMY; 41 | } 42 | 43 | public static boolean bodyIsRunner(Body body) { 44 | UserData userData = (UserData) body.getUserData(); 45 | 46 | return userData != null && userData.getUserDataType() == UserDataType.RUNNER; 47 | } 48 | 49 | public static boolean bodyIsGround(Body body) { 50 | UserData userData = (UserData) body.getUserData(); 51 | 52 | return userData != null && userData.getUserDataType() == UserDataType.GROUND; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /core/src/com/gamestudio24/martianrun/utils/Constants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014. William Mora 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.gamestudio24.martianrun.utils; 18 | 19 | import com.badlogic.gdx.math.Vector2; 20 | 21 | public class Constants { 22 | 23 | public static final String GAME_NAME = "Martian Run!"; 24 | 25 | public static final int APP_WIDTH = 800; 26 | public static final int APP_HEIGHT = 480; 27 | public static final float WORLD_TO_SCREEN = 32; 28 | 29 | public static final Vector2 WORLD_GRAVITY = new Vector2(0, -10); 30 | 31 | public static final float GROUND_X = 0; 32 | public static final float GROUND_Y = 0; 33 | public static final float GROUND_WIDTH = 25f; 34 | public static final float GROUND_HEIGHT = 2f; 35 | public static final float GROUND_DENSITY = 0f; 36 | 37 | public static final float RUNNER_X = 2; 38 | public static final float RUNNER_Y = GROUND_Y + GROUND_HEIGHT; 39 | public static final float RUNNER_WIDTH = 1f; 40 | public static final float RUNNER_HEIGHT = 2f; 41 | public static final float RUNNER_GRAVITY_SCALE = 3f; 42 | public static final float RUNNER_DENSITY = 0.5f; 43 | public static final float RUNNER_DODGE_X = 2f; 44 | public static final float RUNNER_DODGE_Y = 1.5f; 45 | public static final Vector2 RUNNER_JUMPING_LINEAR_IMPULSE = new Vector2(0, 13f); 46 | public static final float RUNNER_HIT_ANGULAR_IMPULSE = 10f; 47 | 48 | public static final float ENEMY_X = 25f; 49 | public static final float ENEMY_DENSITY = RUNNER_DENSITY; 50 | public static final float RUNNING_SHORT_ENEMY_Y = 1.5f; 51 | public static final float RUNNING_LONG_ENEMY_Y = 2f; 52 | public static final float FLYING_ENEMY_Y = 3f; 53 | public static final Vector2 ENEMY_LINEAR_VELOCITY = new Vector2(-10f, 0); 54 | 55 | public static final String BACKGROUND_ASSETS_ID = "background"; 56 | public static final String GROUND_ASSETS_ID = "ground"; 57 | public static final String RUNNER_RUNNING_ASSETS_ID = "runner_running"; 58 | public static final String RUNNER_DODGING_ASSETS_ID = "runner_dodging"; 59 | public static final String RUNNER_HIT_ASSETS_ID = "runner_hit"; 60 | public static final String RUNNER_JUMPING_ASSETS_ID = "runner_jumping"; 61 | public static final String RUNNING_SMALL_ENEMY_ASSETS_ID = "running_small_enemy"; 62 | public static final String RUNNING_LONG_ENEMY_ASSETS_ID = "running_long_enemy"; 63 | public static final String RUNNING_BIG_ENEMY_ASSETS_ID = "running_big_enemy"; 64 | public static final String RUNNING_WIDE_ENEMY_ASSETS_ID = "running_wide_enemy"; 65 | public static final String FLYING_SMALL_ENEMY_ASSETS_ID = "flying_small_enemy"; 66 | public static final String FLYING_WIDE_ENEMY_ASSETS_ID = "flying_wide_enemy"; 67 | 68 | public static final String BACKGROUND_IMAGE_PATH = "background.png"; 69 | public static final String GROUND_IMAGE_PATH = "ground.png"; 70 | public static final String SPRITES_ATLAS_PATH = "sprites.txt"; 71 | public static final String[] RUNNER_RUNNING_REGION_NAMES = new String[] {"alienBeige_run1", "alienBeige_run2"}; 72 | public static final String RUNNER_DODGING_REGION_NAME = "alienBeige_dodge"; 73 | public static final String RUNNER_HIT_REGION_NAME = "alienBeige_hit"; 74 | public static final String RUNNER_JUMPING_REGION_NAME = "alienBeige_jump"; 75 | 76 | public static final String[] RUNNING_SMALL_ENEMY_REGION_NAMES = new String[] {"ladyBug_walk1", "ladyBug_walk2"}; 77 | public static final String[] RUNNING_LONG_ENEMY_REGION_NAMES = new String[] {"barnacle_bite1", "barnacle_bite2"}; 78 | public static final String[] RUNNING_BIG_ENEMY_REGION_NAMES = new String[] {"spider_walk1", "spider_walk2"}; 79 | public static final String[] RUNNING_WIDE_ENEMY_REGION_NAMES = new String[] {"worm_walk1", "worm_walk2"}; 80 | public static final String[] FLYING_SMALL_ENEMY_REGION_NAMES = new String[] {"bee_fly1", "bee_fly2"}; 81 | public static final String[] FLYING_WIDE_ENEMY_REGION_NAMES = new String[] {"fly_fly1", "fly_fly2"}; 82 | 83 | public static final String SOUND_ON_REGION_NAME = "sound_on"; 84 | public static final String SOUND_OFF_REGION_NAME = "sound_off"; 85 | public static final String MUSIC_ON_REGION_NAME = "music_on"; 86 | public static final String MUSIC_OFF_REGION_NAME = "music_off"; 87 | public static final String PAUSE_REGION_NAME = "pause"; 88 | public static final String PLAY_REGION_NAME = "play"; 89 | public static final String BIG_PLAY_REGION_NAME = "play_big"; 90 | public static final String LEADERBOARD_REGION_NAME = "leaderboard"; 91 | public static final String ABOUT_REGION_NAME = "about"; 92 | public static final String CLOSE_REGION_NAME = "close"; 93 | public static final String SHARE_REGION_NAME = "share"; 94 | public static final String ACHIEVEMENTS_REGION_NAME = "star"; 95 | 96 | public static final String TUTORIAL_LEFT_REGION_NAME = "tutorial_left"; 97 | public static final String TUTORIAL_RIGHT_REGION_NAME = "tutorial_right"; 98 | public static final String TUTORIAL_LEFT_TEXT = "\nTap left to dodge"; 99 | public static final String TUTORIAL_RIGHT_TEXT = "\nTap right to jump"; 100 | 101 | public static final String RUNNER_JUMPING_SOUND = "jump.wav"; 102 | public static final String RUNNER_HIT_SOUND = "hit.wav"; 103 | public static final String GAME_MUSIC = "fun_in_a_bottle.mp3"; 104 | 105 | public static final String FONT_NAME = "roboto_bold.ttf"; 106 | 107 | public static final String ABOUT_TEXT = "Developed by: @gamestudio24\nPowered by: " + 108 | "@libgdx\nGraphics: @kenneywings\nMusic: @kmacleod"; 109 | public static final String SHARE_MESSAGE_PREFIX = "Check out " + GAME_NAME + " %s"; 110 | public static final String SHARE_TITLE = "Share!"; 111 | public static final String PAUSED_LABEL = "Paused"; 112 | 113 | } 114 | -------------------------------------------------------------------------------- /core/src/com/gamestudio24/martianrun/utils/GameEventListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014. William Mora 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.gamestudio24.martianrun.utils; 18 | 19 | /** 20 | * Game events that are platform specific (i.e. submitting a score or displaying an ad inn an 21 | * Android app is different than doing the same in a desktop app). 22 | */ 23 | public interface GameEventListener { 24 | 25 | /** 26 | * Displays an ad 27 | */ 28 | public void displayAd(); 29 | 30 | /** 31 | * Hides an ad 32 | */ 33 | public void hideAd(); 34 | 35 | /** 36 | * Submits a given score. Used every time the game is over 37 | * 38 | * @param score 39 | */ 40 | public void submitScore(int score); 41 | 42 | /** 43 | * Displays the scores leaderboard 44 | */ 45 | public void displayLeaderboard(); 46 | 47 | /** 48 | * Displays the game's achievements 49 | */ 50 | public void displayAchievements(); 51 | 52 | /** 53 | * Shares the game's website 54 | */ 55 | public void share(); 56 | 57 | /** 58 | * Unlocks an achievement with the given ID 59 | * 60 | * @param id achievement ID 61 | * @see Google Play Game Services 62 | */ 63 | public void unlockAchievement(String id); 64 | 65 | /** 66 | * Increments an achievement with the given ID 67 | * 68 | * @param id achievement ID 69 | * @param steps incremental steps 70 | * @see Google Play Game Services 71 | */ 72 | public void incrementAchievement(String id, int steps); 73 | 74 | /** 75 | * The following are getters for specific achievement IDs used in this game 76 | */ 77 | 78 | /** 79 | * @return "Getting Started" achievement ID 80 | */ 81 | public String getGettingStartedAchievementId(); 82 | 83 | /** 84 | * @return "Like a Rover" achievement ID 85 | */ 86 | public String getLikeARoverAchievementId(); 87 | 88 | /** 89 | * @return "Spirit" achievement ID 90 | */ 91 | public String getSpiritAchievementId(); 92 | 93 | /** 94 | * @return "Curiosity" achievement ID 95 | */ 96 | public String getCuriosityAchievementId(); 97 | 98 | /** 99 | * @return "5k Club" achievement ID 100 | */ 101 | public String get5kClubAchievementId(); 102 | 103 | /** 104 | * @return "10k Club" achievement ID 105 | */ 106 | public String get10kClubAchievementId(); 107 | 108 | /** 109 | * @return "25k Club" achievement ID 110 | */ 111 | public String get25kClubAchievementId(); 112 | 113 | /** 114 | * @return "50k Club" achievement ID 115 | */ 116 | public String get50kClubAchievementId(); 117 | 118 | /** 119 | * @return "10 Jump Street" achievement ID 120 | */ 121 | public String get10JumpStreetAchievementId(); 122 | 123 | /** 124 | * @return "100 Jump Street" achievement ID 125 | */ 126 | public String get100JumpStreetAchievementId(); 127 | 128 | /** 129 | * @return "500 Jump Street" achievement ID 130 | */ 131 | public String get500JumpStreetAchievementId(); 132 | 133 | } 134 | -------------------------------------------------------------------------------- /core/src/com/gamestudio24/martianrun/utils/GameManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014. William Mora 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.gamestudio24.martianrun.utils; 18 | 19 | import com.badlogic.gdx.Gdx; 20 | import com.badlogic.gdx.Preferences; 21 | import com.gamestudio24.martianrun.enums.Difficulty; 22 | import com.gamestudio24.martianrun.enums.GameState; 23 | 24 | /** 25 | * A utility singleton that holds the current {@link com.gamestudio24.martianrun.enums.Difficulty} 26 | * and {@link com.gamestudio24.martianrun.enums.GameState} of the game as well as the 27 | * {@link com.gamestudio24.martianrun.utils.GameEventListener} instance responsible for dispatching 28 | * all game events for the platform running the game 29 | */ 30 | public class GameManager implements GameEventListener { 31 | private static GameManager ourInstance = new GameManager(); 32 | 33 | public static final String PREFERENCES_NAME = "preferences"; 34 | private static final String MAX_SCORE_PREFERENCE = "max_score"; 35 | private static final String ACHIEVEMENT_COUNT_PREFERENCE_SUFFIX = "_count"; 36 | private static final String ACHIEVEMENT_UNLOCKED_PREFERENCE_SUFFIX = "_unlocked"; 37 | 38 | private GameState gameState; 39 | private Difficulty difficulty; 40 | private GameEventListener gameEventListener; 41 | 42 | public static GameManager getInstance() { 43 | return ourInstance; 44 | } 45 | 46 | private GameManager() { 47 | gameState = GameState.OVER; 48 | } 49 | 50 | public GameState getGameState() { 51 | return gameState; 52 | } 53 | 54 | public void setGameState(GameState gameState) { 55 | this.gameState = gameState; 56 | } 57 | 58 | public Difficulty getDifficulty() { 59 | return difficulty; 60 | } 61 | 62 | public void setDifficulty(Difficulty difficulty) { 63 | this.difficulty = difficulty; 64 | } 65 | 66 | public boolean isMaxDifficulty() { 67 | return difficulty == Difficulty.values()[Difficulty.values().length - 1]; 68 | } 69 | 70 | public void resetDifficulty() { 71 | setDifficulty(Difficulty.values()[0]); 72 | } 73 | 74 | public void setGameEventListener(GameEventListener gameEventListener) { 75 | this.gameEventListener = gameEventListener; 76 | } 77 | 78 | @Override 79 | public void displayAd() { 80 | gameEventListener.displayAd(); 81 | } 82 | 83 | @Override 84 | public void hideAd() { 85 | gameEventListener.hideAd(); 86 | } 87 | 88 | /** 89 | * Submits a score and unlocks a score-based achievement depending on the total 90 | */ 91 | @Override 92 | public void submitScore(int score) { 93 | gameEventListener.submitScore(score); 94 | 95 | if (score > 5000 && !isAchievementUnlocked(get5kClubAchievementId())) { 96 | unlockAchievement(get5kClubAchievementId()); 97 | } 98 | 99 | if (score > 10000 && !isAchievementUnlocked(get10kClubAchievementId())) { 100 | unlockAchievement(get10kClubAchievementId()); 101 | } 102 | 103 | if (score > 25000 && !isAchievementUnlocked(get25kClubAchievementId())) { 104 | unlockAchievement(get25kClubAchievementId()); 105 | } 106 | 107 | if (score > 50000 && !isAchievementUnlocked(get50kClubAchievementId())) { 108 | unlockAchievement(get50kClubAchievementId()); 109 | } 110 | } 111 | 112 | @Override 113 | public void displayLeaderboard() { 114 | gameEventListener.displayLeaderboard(); 115 | } 116 | 117 | @Override 118 | public void displayAchievements() { 119 | gameEventListener.displayAchievements(); 120 | } 121 | 122 | @Override 123 | public void share() { 124 | gameEventListener.share(); 125 | } 126 | 127 | @Override 128 | public void unlockAchievement(String id) { 129 | gameEventListener.unlockAchievement(id); 130 | } 131 | 132 | @Override 133 | public void incrementAchievement(String id, int steps) { 134 | gameEventListener.incrementAchievement(id, steps); 135 | } 136 | 137 | @Override 138 | public String getGettingStartedAchievementId() { 139 | return gameEventListener.getGettingStartedAchievementId(); 140 | } 141 | 142 | @Override 143 | public String getLikeARoverAchievementId() { 144 | return gameEventListener.getLikeARoverAchievementId(); 145 | } 146 | 147 | @Override 148 | public String getSpiritAchievementId() { 149 | return gameEventListener.getSpiritAchievementId(); 150 | } 151 | 152 | @Override 153 | public String getCuriosityAchievementId() { 154 | return gameEventListener.getCuriosityAchievementId(); 155 | } 156 | 157 | @Override 158 | public String get5kClubAchievementId() { 159 | return gameEventListener.get5kClubAchievementId(); 160 | } 161 | 162 | @Override 163 | public String get10kClubAchievementId() { 164 | return gameEventListener.get10kClubAchievementId(); 165 | } 166 | 167 | @Override 168 | public String get25kClubAchievementId() { 169 | return gameEventListener.get25kClubAchievementId(); 170 | } 171 | 172 | @Override 173 | public String get50kClubAchievementId() { 174 | return gameEventListener.get50kClubAchievementId(); 175 | } 176 | 177 | @Override 178 | public String get10JumpStreetAchievementId() { 179 | return gameEventListener.get10JumpStreetAchievementId(); 180 | } 181 | 182 | @Override 183 | public String get100JumpStreetAchievementId() { 184 | return gameEventListener.get100JumpStreetAchievementId(); 185 | } 186 | 187 | @Override 188 | public String get500JumpStreetAchievementId() { 189 | return gameEventListener.get500JumpStreetAchievementId(); 190 | } 191 | 192 | private Preferences getPreferences() { 193 | return Gdx.app.getPreferences(PREFERENCES_NAME); 194 | } 195 | 196 | public void saveScore(int score) { 197 | Preferences preferences = getPreferences(); 198 | int maxScore = preferences.getInteger(MAX_SCORE_PREFERENCE, 0); 199 | if (score > maxScore) { 200 | preferences.putInteger(MAX_SCORE_PREFERENCE, score); 201 | preferences.flush(); 202 | } 203 | } 204 | 205 | public boolean hasSavedMaxScore() { 206 | return getPreferences().getInteger(MAX_SCORE_PREFERENCE, 0) > 0; 207 | } 208 | 209 | public void submitSavedMaxScore() { 210 | Preferences preferences = getPreferences(); 211 | submitScore(preferences.getInteger(MAX_SCORE_PREFERENCE, 0)); 212 | preferences.remove(MAX_SCORE_PREFERENCE); 213 | preferences.flush(); 214 | } 215 | 216 | public void addGamePlayed() { 217 | 218 | // No need to keep counting if all achievements have been unlocked 219 | if (getAchievementCount(getCuriosityAchievementId()) > 500) { 220 | return; 221 | } 222 | 223 | if (!isAchievementUnlocked(getGettingStartedAchievementId())) { 224 | unlockAchievement(getGettingStartedAchievementId()); 225 | } 226 | 227 | if (getAchievementCount(getLikeARoverAchievementId()) <= 10) { 228 | incrementAchievement(getLikeARoverAchievementId(), 1); 229 | } 230 | 231 | if (getAchievementCount(getSpiritAchievementId()) <= 100) { 232 | incrementAchievement(getSpiritAchievementId(), 1); 233 | } 234 | 235 | incrementAchievement(getCuriosityAchievementId(), 1); 236 | 237 | } 238 | 239 | public void addJumpCount(int count) { 240 | 241 | if (count <= 0) { 242 | return; 243 | } 244 | 245 | if (getAchievementCount(get500JumpStreetAchievementId()) > 500) { 246 | return; 247 | } 248 | 249 | if (getAchievementCount(get500JumpStreetAchievementId()) <= 10) { 250 | incrementAchievement(get10JumpStreetAchievementId(), count); 251 | } 252 | 253 | if (getAchievementCount(get500JumpStreetAchievementId()) <= 100) { 254 | incrementAchievement(get100JumpStreetAchievementId(), count); 255 | } 256 | 257 | incrementAchievement(get500JumpStreetAchievementId(), count); 258 | 259 | } 260 | 261 | public void setAchievementUnlocked(String id) { 262 | getPreferences().putBoolean(getAchievementUnlockedId(id), true); 263 | } 264 | 265 | public void incrementAchievementCount(String id, int steps) { 266 | Preferences preferences = getPreferences(); 267 | int count = preferences.getInteger(getAchievementCountId(id), 0); 268 | count += steps; 269 | preferences.putInteger(getAchievementCountId(id), count); 270 | preferences.flush(); 271 | } 272 | 273 | private int getAchievementCount(String id) { 274 | return getPreferences().getInteger(getAchievementCountId(id), 0); 275 | } 276 | 277 | private boolean isAchievementUnlocked(String id) { 278 | return getPreferences().getBoolean(getAchievementUnlockedId(id), false); 279 | } 280 | 281 | private String getAchievementCountId(String id) { 282 | return id + ACHIEVEMENT_COUNT_PREFERENCE_SUFFIX; 283 | } 284 | 285 | private String getAchievementUnlockedId(String id) { 286 | return id + ACHIEVEMENT_UNLOCKED_PREFERENCE_SUFFIX; 287 | } 288 | } 289 | -------------------------------------------------------------------------------- /core/src/com/gamestudio24/martianrun/utils/RandomUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014. William Mora 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.gamestudio24.martianrun.utils; 18 | 19 | import com.gamestudio24.martianrun.enums.EnemyType; 20 | 21 | import java.util.Random; 22 | 23 | public class RandomUtils { 24 | 25 | /** 26 | * @return a random {@link com.gamestudio24.martianrun.enums.EnemyType} 27 | */ 28 | public static EnemyType getRandomEnemyType() { 29 | RandomEnum randomEnum = new RandomEnum(EnemyType.class); 30 | return randomEnum.random(); 31 | } 32 | 33 | /** 34 | * @see Stack Overflow 35 | */ 36 | private static class RandomEnum { 37 | 38 | private static final Random RND = new Random(); 39 | private final E[] values; 40 | 41 | public RandomEnum(Class token) { 42 | values = token.getEnumConstants(); 43 | } 44 | 45 | /** 46 | * @return a random value for the given enum 47 | */ 48 | public E random() { 49 | return values[RND.nextInt(values.length)]; 50 | } 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /core/src/com/gamestudio24/martianrun/utils/WorldUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014. William Mora 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.gamestudio24.martianrun.utils; 18 | 19 | import com.badlogic.gdx.math.Vector2; 20 | import com.badlogic.gdx.physics.box2d.Body; 21 | import com.badlogic.gdx.physics.box2d.BodyDef; 22 | import com.badlogic.gdx.physics.box2d.PolygonShape; 23 | import com.badlogic.gdx.physics.box2d.World; 24 | import com.gamestudio24.martianrun.box2d.EnemyUserData; 25 | import com.gamestudio24.martianrun.box2d.GroundUserData; 26 | import com.gamestudio24.martianrun.box2d.RunnerUserData; 27 | import com.gamestudio24.martianrun.enums.EnemyType; 28 | 29 | public class WorldUtils { 30 | 31 | public static World createWorld() { 32 | return new World(Constants.WORLD_GRAVITY, true); 33 | } 34 | 35 | public static Body createGround(World world) { 36 | BodyDef bodyDef = new BodyDef(); 37 | bodyDef.position.set(new Vector2(Constants.GROUND_X, Constants.GROUND_Y)); 38 | Body body = world.createBody(bodyDef); 39 | PolygonShape shape = new PolygonShape(); 40 | shape.setAsBox(Constants.GROUND_WIDTH / 2, Constants.GROUND_HEIGHT / 2); 41 | body.createFixture(shape, Constants.GROUND_DENSITY); 42 | body.setUserData(new GroundUserData(Constants.GROUND_WIDTH, Constants.GROUND_HEIGHT)); 43 | shape.dispose(); 44 | return body; 45 | } 46 | 47 | public static Body createRunner(World world) { 48 | BodyDef bodyDef = new BodyDef(); 49 | bodyDef.type = BodyDef.BodyType.DynamicBody; 50 | bodyDef.position.set(new Vector2(Constants.RUNNER_X, Constants.RUNNER_Y)); 51 | PolygonShape shape = new PolygonShape(); 52 | shape.setAsBox(Constants.RUNNER_WIDTH / 2, Constants.RUNNER_HEIGHT / 2); 53 | Body body = world.createBody(bodyDef); 54 | body.setGravityScale(Constants.RUNNER_GRAVITY_SCALE); 55 | body.createFixture(shape, Constants.RUNNER_DENSITY); 56 | body.resetMassData(); 57 | body.setUserData(new RunnerUserData(Constants.RUNNER_WIDTH, Constants.RUNNER_HEIGHT)); 58 | shape.dispose(); 59 | return body; 60 | } 61 | 62 | public static Body createEnemy(World world) { 63 | EnemyType enemyType = RandomUtils.getRandomEnemyType(); 64 | BodyDef bodyDef = new BodyDef(); 65 | bodyDef.type = BodyDef.BodyType.KinematicBody; 66 | bodyDef.position.set(new Vector2(enemyType.getX(), enemyType.getY())); 67 | PolygonShape shape = new PolygonShape(); 68 | shape.setAsBox(enemyType.getWidth() / 2, enemyType.getHeight() / 2); 69 | Body body = world.createBody(bodyDef); 70 | body.createFixture(shape, enemyType.getDensity()); 71 | body.resetMassData(); 72 | EnemyUserData userData = new EnemyUserData(enemyType.getWidth(), enemyType.getHeight(), 73 | enemyType.getAnimationAssetId()); 74 | body.setUserData(userData); 75 | shape.dispose(); 76 | return body; 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /desktop/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: "java" 2 | 3 | sourceCompatibility = 1.6 4 | sourceSets.main.java.srcDirs = [ "src/" ] 5 | 6 | project.ext.mainClassName = "com.gamestudio24.martianrun.desktop.DesktopLauncher" 7 | project.ext.assetsDir = new File("../android/assets"); 8 | 9 | task run(dependsOn: classes, type: JavaExec) { 10 | main = project.mainClassName 11 | classpath = sourceSets.main.runtimeClasspath 12 | standardInput = System.in 13 | workingDir = project.assetsDir 14 | ignoreExitValue = true 15 | } 16 | 17 | task dist(type: Jar) { 18 | from files(sourceSets.main.output.classesDir) 19 | from files(sourceSets.main.output.resourcesDir) 20 | from {configurations.compile.collect {zipTree(it)}} 21 | from files(project.assetsDir); 22 | 23 | manifest { 24 | attributes 'Main-Class': project.mainClassName 25 | } 26 | } 27 | 28 | dist.dependsOn classes 29 | 30 | eclipse { 31 | project { 32 | name = appName + "-desktop" 33 | linkedResource name: 'assets', type: '2', location: 'PARENT-1-PROJECT_LOC/android/assets' 34 | } 35 | } 36 | 37 | task afterEclipseImport(description: "Post processing after project generation", group: "IDE") { 38 | doLast { 39 | def classpath = new XmlParser().parse(file(".classpath")) 40 | new Node(classpath, "classpathentry", [ kind: 'src', path: 'assets' ]); 41 | def writer = new FileWriter(file(".classpath")) 42 | def printer = new XmlNodePrinter(new PrintWriter(writer)) 43 | printer.setPreserveWhitespace(true) 44 | printer.print(classpath) 45 | } 46 | } -------------------------------------------------------------------------------- /desktop/src/com/gamestudio24/martianrun/desktop/DesktopLauncher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014. William Mora 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.gamestudio24.martianrun.desktop; 18 | 19 | import com.badlogic.gdx.Gdx; 20 | import com.badlogic.gdx.backends.lwjgl.LwjglApplication; 21 | import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration; 22 | import com.gamestudio24.martianrun.MartianRun; 23 | import com.gamestudio24.martianrun.utils.Constants; 24 | import com.gamestudio24.martianrun.utils.GameEventListener; 25 | 26 | public class DesktopLauncher { 27 | public static void main (String[] arg) { 28 | LwjglApplicationConfiguration config = new LwjglApplicationConfiguration(); 29 | config.width = Constants.APP_WIDTH; 30 | config.height = Constants.APP_HEIGHT; 31 | new LwjglApplication(new MartianRun(new GameEventListener() { 32 | @Override 33 | public void displayAd() { 34 | Gdx.app.log(GameEventListener.class.getSimpleName(), "displayAd"); 35 | } 36 | 37 | @Override 38 | public void hideAd() { 39 | Gdx.app.log(GameEventListener.class.getSimpleName(), "hideAd"); 40 | } 41 | 42 | @Override 43 | public void submitScore(int score) { 44 | Gdx.app.log(GameEventListener.class.getSimpleName(), "submitScore"); 45 | } 46 | 47 | @Override 48 | public void displayLeaderboard() { 49 | Gdx.app.log(GameEventListener.class.getSimpleName(), "displayLeaderboard"); 50 | } 51 | 52 | @Override 53 | public void displayAchievements() { 54 | Gdx.app.log(GameEventListener.class.getSimpleName(), "displayAchievements"); 55 | } 56 | 57 | @Override 58 | public void share() { 59 | Gdx.app.log(GameEventListener.class.getSimpleName(), "share"); 60 | } 61 | 62 | @Override 63 | public void unlockAchievement(String id) { 64 | 65 | } 66 | 67 | @Override 68 | public void incrementAchievement(String id, int steps) { 69 | 70 | } 71 | 72 | @Override 73 | public String getGettingStartedAchievementId() { 74 | return null; 75 | } 76 | 77 | @Override 78 | public String getLikeARoverAchievementId() { 79 | return null; 80 | } 81 | 82 | @Override 83 | public String getSpiritAchievementId() { 84 | return null; 85 | } 86 | 87 | @Override 88 | public String getCuriosityAchievementId() { 89 | return null; 90 | } 91 | 92 | @Override 93 | public String get5kClubAchievementId() { 94 | return null; 95 | } 96 | 97 | @Override 98 | public String get10kClubAchievementId() { 99 | return null; 100 | } 101 | 102 | @Override 103 | public String get25kClubAchievementId() { 104 | return null; 105 | } 106 | 107 | @Override 108 | public String get50kClubAchievementId() { 109 | return null; 110 | } 111 | 112 | @Override 113 | public String get10JumpStreetAchievementId() { 114 | return null; 115 | } 116 | 117 | @Override 118 | public String get100JumpStreetAchievementId() { 119 | return null; 120 | } 121 | 122 | @Override 123 | public String get500JumpStreetAchievementId() { 124 | return null; 125 | } 126 | 127 | }), config); 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wmora/martianrun/1ed66436cd49c60101d557bcfa2454c5185785a5/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat May 31 17:49:50 GMT-03:00 2014 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include 'desktop', 'android', 'core' --------------------------------------------------------------------------------