├── settings.gradle ├── android ├── highscores.sav ├── android-release.apk ├── assets │ ├── badlogic.jpg │ ├── highscores.sav │ ├── sounds │ │ ├── explode.ogg │ │ ├── shoot.ogg │ │ ├── extralife.ogg │ │ ├── pulsehigh.ogg │ │ ├── pulselow.ogg │ │ ├── thruster.ogg │ │ ├── largesaucer.ogg │ │ ├── saucershoot.ogg │ │ └── smallsaucer.ogg │ └── fonts │ │ └── Hyperspace Bold.ttf ├── ic_launcher-web.png ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── res │ ├── drawable-hdpi │ │ └── ic_launcher.png │ ├── drawable-mdpi │ │ └── ic_launcher.png │ ├── drawable-xhdpi │ │ └── ic_launcher.png │ └── values │ │ ├── strings.xml │ │ └── styles.xml ├── project.properties ├── src │ └── ro │ │ └── xzya │ │ └── game │ │ └── android │ │ └── AndroidLauncher.java ├── AndroidManifest.xml ├── proguard-project.txt ├── manifest-merger-release-report.txt ├── gradlew.bat ├── build.gradle └── gradlew ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── core ├── build.gradle └── src │ └── ro │ └── xzya │ ├── gamestates │ ├── GameState.java │ ├── HighscoreState.java │ ├── MenuState.java │ ├── GameOver.java │ └── PlayState.java │ ├── managers │ ├── Point2D.java │ ├── Jukebox.java │ ├── GameStateManager.java │ ├── GameData.java │ ├── Save.java │ └── GUI.java │ ├── entities │ ├── Particle.java │ ├── Bullet.java │ ├── SpaceObject.java │ ├── Asteroid.java │ ├── FlyingSaucer.java │ └── Player.java │ └── game │ └── Game.java ├── README.md ├── desktop ├── src │ └── ro │ │ └── xzya │ │ └── game │ │ └── desktop │ │ └── DesktopLauncher.java └── build.gradle ├── .gitignore ├── gradlew.bat └── gradlew /settings.gradle: -------------------------------------------------------------------------------- 1 | include 'desktop', 'android', 'core' -------------------------------------------------------------------------------- /android/highscores.sav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/Asteroids/master/android/highscores.sav -------------------------------------------------------------------------------- /android/android-release.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/Asteroids/master/android/android-release.apk -------------------------------------------------------------------------------- /android/assets/badlogic.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/Asteroids/master/android/assets/badlogic.jpg -------------------------------------------------------------------------------- /android/ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/Asteroids/master/android/ic_launcher-web.png -------------------------------------------------------------------------------- /android/assets/highscores.sav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/Asteroids/master/android/assets/highscores.sav -------------------------------------------------------------------------------- /android/assets/sounds/explode.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/Asteroids/master/android/assets/sounds/explode.ogg -------------------------------------------------------------------------------- /android/assets/sounds/shoot.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/Asteroids/master/android/assets/sounds/shoot.ogg -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.daemon=true 2 | org.gradle.jvmargs=-Xms128m -Xmx512m 3 | org.gradle.configureondemand=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/Asteroids/master/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /android/assets/sounds/extralife.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/Asteroids/master/android/assets/sounds/extralife.ogg -------------------------------------------------------------------------------- /android/assets/sounds/pulsehigh.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/Asteroids/master/android/assets/sounds/pulsehigh.ogg -------------------------------------------------------------------------------- /android/assets/sounds/pulselow.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/Asteroids/master/android/assets/sounds/pulselow.ogg -------------------------------------------------------------------------------- /android/assets/sounds/thruster.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/Asteroids/master/android/assets/sounds/thruster.ogg -------------------------------------------------------------------------------- /android/assets/sounds/largesaucer.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/Asteroids/master/android/assets/sounds/largesaucer.ogg -------------------------------------------------------------------------------- /android/assets/sounds/saucershoot.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/Asteroids/master/android/assets/sounds/saucershoot.ogg -------------------------------------------------------------------------------- /android/assets/sounds/smallsaucer.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/Asteroids/master/android/assets/sounds/smallsaucer.ogg -------------------------------------------------------------------------------- /android/assets/fonts/Hyperspace Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/Asteroids/master/android/assets/fonts/Hyperspace Bold.ttf -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/Asteroids/master/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /android/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/Asteroids/master/android/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/Asteroids/master/android/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/Asteroids/master/android/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Asteroids 5 | 6 | 7 | -------------------------------------------------------------------------------- /core/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: "java" 2 | 3 | sourceCompatibility = 1.6 4 | [compileJava, compileTestJava]*.options*.encoding = 'UTF-8' 5 | 6 | sourceSets.main.java.srcDirs = [ "src/" ] 7 | 8 | 9 | eclipse.project { 10 | name = appName + "-core" 11 | } 12 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat Sep 21 13:08:26 CEST 2013 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=http\://services.gradle.org/distributions/gradle-2.2-all.zip 7 | -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Apr 10 15:27:10 PDT 2013 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Asteroids 2 | Multi platform Asteroids Game 3 | [Link to Amazon App Store](http://www.amazon.com/gp/product/B00UC2KIC6) 4 | ![Imgur](http://i.imgur.com/4cTejO4.png) 5 | ![Screenshot](http://ecx.images-amazon.com/images/I/51eKL0u-UUL.png) 6 | ![Screenshot](http://ecx.images-amazon.com/images/I/51WpM2K1pQL.png) 7 | -------------------------------------------------------------------------------- /desktop/src/ro/xzya/game/desktop/DesktopLauncher.java: -------------------------------------------------------------------------------- 1 | package ro.xzya.game.desktop; 2 | 3 | import com.badlogic.gdx.backends.lwjgl.LwjglApplication; 4 | import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration; 5 | import ro.xzya.game.Game; 6 | 7 | public class DesktopLauncher { 8 | public static void main (String[] arg) { 9 | LwjglApplicationConfiguration config = new LwjglApplicationConfiguration(); 10 | config.width = 500; 11 | config.height = 400; 12 | new LwjglApplication(new Game(null), config); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /android/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /core/src/ro/xzya/gamestates/GameState.java: -------------------------------------------------------------------------------- 1 | package ro.xzya.gamestates; 2 | 3 | 4 | import ro.xzya.managers.GameStateManager; 5 | 6 | /** 7 | * Created by Xzya on 4/3/2015. 8 | */ 9 | public abstract class GameState { 10 | 11 | protected GameStateManager gsm; 12 | 13 | protected GameState(GameStateManager _gsm) { 14 | gsm = _gsm; 15 | init(); 16 | } 17 | 18 | public abstract void init(); 19 | 20 | public abstract void update(float dt); 21 | 22 | public abstract void draw(); 23 | 24 | public abstract void handleInput(); 25 | 26 | public abstract void dispose(); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /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/src/ro/xzya/game/android/AndroidLauncher.java: -------------------------------------------------------------------------------- 1 | package ro.xzya.game.android; 2 | 3 | import android.os.Bundle; 4 | import android.os.Environment; 5 | 6 | import com.badlogic.gdx.backends.android.AndroidApplication; 7 | import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration; 8 | 9 | import ro.xzya.game.Game; 10 | 11 | public class AndroidLauncher extends AndroidApplication { 12 | @Override 13 | protected void onCreate (Bundle savedInstanceState) { 14 | super.onCreate(savedInstanceState); 15 | AndroidApplicationConfiguration config = new AndroidApplicationConfiguration(); 16 | initialize(new Game(Environment.getExternalStorageDirectory()), config); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /core/src/ro/xzya/managers/Point2D.java: -------------------------------------------------------------------------------- 1 | package ro.xzya.managers; 2 | 3 | /** 4 | * Created by Xzya on 5/3/2015. 5 | * 6 | * This is a replacement for the default Point2D and Line2D 7 | * because android doesn't support it 8 | */ 9 | public class Point2D { 10 | 11 | public float x1; 12 | public float x2; 13 | public float y1; 14 | public float y2; 15 | 16 | public Point2D() { 17 | 18 | } 19 | 20 | public Point2D(float x1, float y1){ 21 | this.x1 = x1; 22 | this.y1 = y1; 23 | } 24 | 25 | public Point2D(float x1, float y1, float x2, float y2){ 26 | this.x1 = x1; 27 | this.x2 = x2; 28 | this.y1 = y1; 29 | this.y2 = y2; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /.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 | 32 | ## Eclipse 33 | .classpath 34 | .project 35 | .metadata 36 | **/bin/ 37 | tmp/ 38 | *.tmp 39 | *.bak 40 | *.swp 41 | *~.nib 42 | local.properties 43 | .settings/ 44 | .loadpath 45 | .externalToolBuilders/ 46 | *.launch 47 | 48 | ## NetBeans 49 | **/nbproject/private/ 50 | build/ 51 | nbbuild/ 52 | dist/ 53 | nbdist/ 54 | nbactions.xml 55 | nb-configuration.xml 56 | 57 | ## Gradle 58 | 59 | .gradle 60 | gradle-app.setting 61 | build/ 62 | 63 | ## OS Specific 64 | .DS_Store 65 | -------------------------------------------------------------------------------- /core/src/ro/xzya/managers/Jukebox.java: -------------------------------------------------------------------------------- 1 | package ro.xzya.managers; 2 | 3 | import com.badlogic.gdx.Gdx; 4 | import com.badlogic.gdx.audio.Sound; 5 | 6 | import java.util.HashMap; 7 | 8 | /** 9 | * Created by Xzya on 4/3/2015. 10 | */ 11 | public class Jukebox { 12 | 13 | private static HashMap sounds; 14 | 15 | static { 16 | sounds = new HashMap(); 17 | } 18 | 19 | public static void load(String path, String name) { 20 | Sound sound = Gdx.audio.newSound(Gdx.files.internal(path)); 21 | sounds.put(name, sound); 22 | } 23 | 24 | public static void play(String name) { 25 | sounds.get(name).play(); 26 | } 27 | 28 | public static void loop(String name) { 29 | sounds.get(name).loop(); 30 | } 31 | 32 | public static void stop(String name) { 33 | sounds.get(name).stop(); 34 | } 35 | 36 | public static void stopAll() { 37 | for (Sound s : sounds.values()) { 38 | s.stop(); 39 | } 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /android/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 14 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /core/src/ro/xzya/entities/Particle.java: -------------------------------------------------------------------------------- 1 | package ro.xzya.entities; 2 | 3 | import com.badlogic.gdx.graphics.glutils.ShapeRenderer; 4 | import com.badlogic.gdx.math.MathUtils; 5 | 6 | import ro.xzya.game.Game; 7 | 8 | /** 9 | * Created by Xzya on 4/3/2015. 10 | */ 11 | public class Particle extends SpaceObject { 12 | 13 | private static final int dpSize1 = ((int)(Game.HEIGHT * 0.005)); 14 | 15 | private float timer; 16 | private float time; 17 | private boolean remove; 18 | 19 | public Particle(float x, float y) { 20 | this.x = x; 21 | this.y = y; 22 | // width = height = 2; 23 | width = height = dpSize1; 24 | 25 | speed = 50; 26 | 27 | radians = MathUtils.random(2 * 3.1415f); 28 | dx = MathUtils.cos(radians) * speed; 29 | dy = MathUtils.sin(radians) * speed; 30 | 31 | timer = 0; 32 | time = 1; 33 | } 34 | 35 | public boolean shouldRemove() { 36 | return remove; 37 | } 38 | 39 | public void update(float dt) { 40 | x += dx * dt; 41 | y += dy * dt; 42 | 43 | timer += dt; 44 | if (timer > time) { 45 | remove = true; 46 | } 47 | } 48 | 49 | public void draw(ShapeRenderer sr) { 50 | sr.setColor(1, 1, 1, 1); 51 | sr.begin(ShapeRenderer.ShapeType.Filled); 52 | sr.circle(x - width / 2, y - width / 2, width / 2); 53 | sr.end(); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /core/src/ro/xzya/managers/GameStateManager.java: -------------------------------------------------------------------------------- 1 | package ro.xzya.managers; 2 | 3 | import ro.xzya.gamestates.GameOver; 4 | import ro.xzya.gamestates.GameState; 5 | import ro.xzya.gamestates.HighscoreState; 6 | import ro.xzya.gamestates.MenuState; 7 | import ro.xzya.gamestates.PlayState; 8 | 9 | /** 10 | * Created by Xzya on 4/3/2015. 11 | */ 12 | public class GameStateManager { 13 | 14 | public static final int MENU = 0; 15 | public static final int PLAY = 1; 16 | public static final int HIGHSCORE = 2; 17 | public static final int GAME_OVER = 3; 18 | 19 | //current game state 20 | private GameState gameState; 21 | 22 | public GameStateManager() { 23 | setState(MENU); 24 | } 25 | 26 | public void setState(int state) { 27 | if (gameState != null) gameState.dispose(); 28 | if (state == MENU) { 29 | //switch to menu state 30 | gameState = new MenuState(this); 31 | } 32 | if (state == PLAY) { 33 | //switch to play state 34 | gameState = new PlayState(this); 35 | } 36 | if (state == HIGHSCORE) { 37 | //switch to highscore state 38 | gameState = new HighscoreState(this); 39 | } 40 | if (state == GAME_OVER) { 41 | gameState = new GameOver(this); 42 | } 43 | } 44 | 45 | public void update(float dt) { 46 | gameState.update(dt); 47 | } 48 | 49 | public void draw() { 50 | gameState.draw(); 51 | } 52 | 53 | 54 | } 55 | -------------------------------------------------------------------------------- /desktop/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: "java" 2 | 3 | sourceCompatibility = 1.6 4 | sourceSets.main.java.srcDirs = [ "src/" ] 5 | 6 | project.ext.mainClassName = "ro.xzya.game.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 | } -------------------------------------------------------------------------------- /core/src/ro/xzya/entities/Bullet.java: -------------------------------------------------------------------------------- 1 | package ro.xzya.entities; 2 | 3 | import com.badlogic.gdx.graphics.glutils.ShapeRenderer; 4 | import com.badlogic.gdx.math.MathUtils; 5 | 6 | import ro.xzya.game.Game; 7 | 8 | /** 9 | * Created by Xzya on 4/3/2015. 10 | */ 11 | public class Bullet extends SpaceObject { 12 | 13 | private static final int dpSize1 = ((int)(Game.WIDTH * 0.6)); 14 | 15 | private float lifeTime; 16 | private float lifeTimer; 17 | 18 | private boolean remove; 19 | 20 | /** 21 | * @param x - starting position x 22 | * @param y - starting position y 23 | * @param radians - direction 24 | */ 25 | public Bullet(float x, float y, float radians) { 26 | this.x = x; 27 | this.y = y; 28 | this.radians = radians; 29 | 30 | // float speed = 350; 31 | float speed = dpSize1; 32 | 33 | dx = MathUtils.cos(radians) * speed; 34 | dy = MathUtils.sin(radians) * speed; 35 | 36 | // width = height = 2; 37 | width = height = ((int)(Game.HEIGHT * 0.005)); 38 | 39 | lifeTimer = 0; 40 | // lifeTime = 1f; 41 | lifeTime = 1f; 42 | } 43 | 44 | public boolean shouldRemove() { 45 | return remove; 46 | } 47 | 48 | public void update(float dt) { 49 | x += dx * dt; 50 | y += dy * dt; 51 | 52 | wrap(); 53 | 54 | lifeTimer += dt; 55 | 56 | if (lifeTimer > lifeTime) { 57 | remove = true; 58 | } 59 | } 60 | 61 | public void draw(ShapeRenderer sr) { 62 | sr.setColor(1, 1, 1, 1); 63 | sr.begin(ShapeRenderer.ShapeType.Filled); 64 | sr.circle(x - width / 2, y - height / 2, width / 2); 65 | sr.end(); 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /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 | 22 | -verbose 23 | 24 | -dontwarn android.support.** 25 | -dontwarn com.badlogic.gdx.backends.android.AndroidFragmentApplication 26 | -dontwarn com.badlogic.gdx.utils.GdxBuild 27 | -dontwarn com.badlogic.gdx.physics.box2d.utils.Box2DBuild 28 | -dontwarn com.badlogic.gdx.jnigen.BuildTarget* 29 | 30 | -keepclassmembers class com.badlogic.gdx.backends.android.AndroidInput* { 31 | (com.badlogic.gdx.Application, android.content.Context, java.lang.Object, com.badlogic.gdx.backends.android.AndroidApplicationConfiguration); 32 | } 33 | 34 | -keepclassmembers class com.badlogic.gdx.physics.box2d.World { 35 | boolean contactFilter(long, long); 36 | void beginContact(long); 37 | void endContact(long); 38 | void preSolve(long, long); 39 | void postSolve(long, long); 40 | boolean reportFixture(long); 41 | float reportRayFixture(long, float, float, float, float, float); 42 | } 43 | -------------------------------------------------------------------------------- /android/manifest-merger-release-report.txt: -------------------------------------------------------------------------------- 1 | -- Merging decision tree log --- 2 | manifest 3 | ADDED from AndroidManifest.xml:2:1 4 | package 5 | ADDED from AndroidManifest.xml:3:5 6 | android:versionName 7 | ADDED from AndroidManifest.xml:5:5 8 | android:versionCode 9 | ADDED from AndroidManifest.xml:4:5 10 | INJECTED from AndroidManifest.xml:0:0 11 | INJECTED from AndroidManifest.xml:0:0 12 | xmlns:android 13 | ADDED from AndroidManifest.xml:2:11 14 | uses-sdk 15 | ADDED from AndroidManifest.xml:7:5 16 | android:targetSdkVersion 17 | ADDED from AndroidManifest.xml:7:41 18 | android:minSdkVersion 19 | ADDED from AndroidManifest.xml:7:15 20 | uses-permission#android.permission.WRITE_EXTERNAL_STORAGE 21 | ADDED from AndroidManifest.xml:8:5 22 | android:name 23 | ADDED from AndroidManifest.xml:8:22 24 | application 25 | ADDED from AndroidManifest.xml:9:5 26 | android:label 27 | ADDED from AndroidManifest.xml:12:9 28 | android:allowBackup 29 | ADDED from AndroidManifest.xml:10:9 30 | android:icon 31 | ADDED from AndroidManifest.xml:11:9 32 | android:theme 33 | ADDED from AndroidManifest.xml:13:9 34 | activity#ro.xzya.game.android.AndroidLauncher 35 | ADDED from AndroidManifest.xml:14:9 36 | android:screenOrientation 37 | ADDED from AndroidManifest.xml:17:13 38 | android:label 39 | ADDED from AndroidManifest.xml:16:13 40 | android:configChanges 41 | ADDED from AndroidManifest.xml:18:13 42 | android:name 43 | ADDED from AndroidManifest.xml:15:13 44 | intent-filter#android.intent.action.MAIN+android.intent.category.LAUNCHER 45 | ADDED from AndroidManifest.xml:19:13 46 | action#android.intent.action.MAIN 47 | ADDED from AndroidManifest.xml:20:17 48 | android:name 49 | ADDED from AndroidManifest.xml:20:25 50 | category#android.intent.category.LAUNCHER 51 | ADDED from AndroidManifest.xml:21:17 52 | android:name 53 | ADDED from AndroidManifest.xml:21:27 54 | -------------------------------------------------------------------------------- /core/src/ro/xzya/managers/GameData.java: -------------------------------------------------------------------------------- 1 | package ro.xzya.managers; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * Created by Xzya on 4/3/2015. 7 | */ 8 | public class GameData implements Serializable { 9 | 10 | private static final long serialVersionUID = 1L; 11 | 12 | private final int MAX_SCORES = 10; 13 | private long[] highscores; 14 | private String[] names; 15 | 16 | private long tentativeScore; 17 | 18 | public GameData() { 19 | highscores = new long[MAX_SCORES]; 20 | names = new String[MAX_SCORES]; 21 | } 22 | 23 | //sets up an empty high scores table 24 | public void init() { 25 | for (int i = 0; i < MAX_SCORES; i++) { 26 | highscores[i] = 0; 27 | names[i] = "---"; 28 | } 29 | } 30 | 31 | public long[] getHighscores() { 32 | return highscores; 33 | } 34 | 35 | public String[] getNames() { 36 | return names; 37 | } 38 | 39 | public long getTentativeScore() { 40 | return tentativeScore; 41 | } 42 | 43 | public void setTentativeScore(long i) { 44 | tentativeScore = i; 45 | } 46 | 47 | public boolean isHighScore(long score) { 48 | return score > highscores[MAX_SCORES - 1]; 49 | } 50 | 51 | public void addHighScore(long newScore, String name) { 52 | if (isHighScore(newScore)) { 53 | highscores[MAX_SCORES - 1] = newScore; 54 | names[MAX_SCORES - 1] = name; 55 | sortHighscores(); 56 | } 57 | } 58 | 59 | private void sortHighscores() { 60 | for (int i = 0; i < MAX_SCORES; i++) { 61 | long score = highscores[i]; 62 | String name = names[i]; 63 | int j; 64 | for (j = i - 1; 65 | j >= 0 && highscores[j] < score; 66 | j--) { 67 | highscores[j + 1] = highscores[j]; 68 | names[j + 1] = names[j]; 69 | } 70 | highscores[j + 1] = score; 71 | names[j + 1] = name; 72 | } 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /core/src/ro/xzya/entities/SpaceObject.java: -------------------------------------------------------------------------------- 1 | package ro.xzya.entities; 2 | 3 | import ro.xzya.game.Game; 4 | 5 | /** 6 | * Created by Xzya on 4/3/2015. 7 | */ 8 | public class SpaceObject { 9 | 10 | //position 11 | protected float x; 12 | protected float y; 13 | 14 | //vector 15 | protected float dx; 16 | protected float dy; 17 | 18 | //direction 19 | protected float radians; 20 | 21 | //speed 22 | protected float speed; 23 | 24 | //rotation speed 25 | protected float rotationSpeed; 26 | 27 | //size 28 | protected int width; 29 | protected int height; 30 | 31 | //polygon 32 | protected float[] shapex; 33 | protected float[] shapey; 34 | 35 | //wrap 36 | protected void wrap() { 37 | if (x < 0) x = Game.WIDTH; 38 | if (x > Game.WIDTH) x = 0; 39 | if (y < 0) y = Game.HEIGHT; 40 | if (y > Game.HEIGHT) y = 0; 41 | } 42 | 43 | public void setPosition(float x, float y) { 44 | this.x = x; 45 | this.y = y; 46 | } 47 | 48 | public float getx() { 49 | return x; 50 | } 51 | 52 | public float gety() { 53 | return y; 54 | } 55 | 56 | public float[] getShapex() { 57 | return shapex; 58 | } 59 | 60 | public float[] getShapey() { 61 | return shapey; 62 | } 63 | 64 | public boolean contains(float x, float y) { 65 | boolean b = false; 66 | for (int i = 0, j = shapex.length - 1; 67 | i < shapex.length; 68 | j = i++) { 69 | if ((shapey[i] > y) != (shapey[j] > y) 70 | && (x < (shapex[j] - shapex[i]) 71 | * (y - shapey[i]) / (shapey[j] - shapey[i]) 72 | + shapex[i])) { 73 | b = !b; 74 | } 75 | } 76 | return b; 77 | } 78 | 79 | public boolean intersects(SpaceObject other) { 80 | float[] sx = other.getShapex(); 81 | float[] sy = other.getShapey(); 82 | for (int i = 0; i < sx.length; i++) { 83 | if (contains(sx[i], sy[i])) { 84 | return true; 85 | } 86 | } 87 | return false; 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /core/src/ro/xzya/managers/Save.java: -------------------------------------------------------------------------------- 1 | package ro.xzya.managers; 2 | 3 | import java.io.File; 4 | import java.io.FileInputStream; 5 | import java.io.FileOutputStream; 6 | import java.io.IOException; 7 | import java.io.ObjectInputStream; 8 | import java.io.ObjectOutputStream; 9 | 10 | import ro.xzya.game.Game; 11 | 12 | /** 13 | * Created by Xzya on 4/3/2015. 14 | */ 15 | public class Save { 16 | 17 | public static GameData gd; 18 | 19 | public static void save() { 20 | try { 21 | ObjectOutputStream out; 22 | if (!Game.isMobile) { 23 | out = new ObjectOutputStream( 24 | new FileOutputStream("highscores.sav") 25 | ); 26 | } else { 27 | out = new ObjectOutputStream( 28 | new FileOutputStream(Game.sdcard.getAbsolutePath() + "/Download/highscores.sav") 29 | ); 30 | } 31 | out.writeObject(gd); 32 | out.close(); 33 | } catch (IOException e) { 34 | e.printStackTrace(); 35 | } 36 | } 37 | 38 | public static void load() { 39 | try { 40 | if (!saveFileExists()) { 41 | init(); 42 | return; 43 | } 44 | ObjectInputStream in; 45 | if (!Game.isMobile) { 46 | in = new ObjectInputStream( 47 | new FileInputStream("highscores.sav") 48 | ); 49 | } else { 50 | in = new ObjectInputStream( 51 | new FileInputStream(Game.sdcard.getAbsolutePath() + "/Download/highscores.sav") 52 | ); 53 | } 54 | gd = (GameData) in.readObject(); 55 | in.close(); 56 | } catch (IOException e) { 57 | e.printStackTrace(); 58 | } catch (ClassNotFoundException e) { 59 | e.printStackTrace(); 60 | } 61 | } 62 | 63 | public static boolean saveFileExists() { 64 | File f; 65 | if (!Game.isMobile) { 66 | f = new File("highscores.sav"); 67 | } else { 68 | f = new File(Game.sdcard.getAbsolutePath() + "/Download/highscores.sav"); 69 | } 70 | return f.exists(); 71 | } 72 | 73 | public static void init() { 74 | gd = new GameData(); 75 | gd.init(); 76 | save(); 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /android/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 | -------------------------------------------------------------------------------- /core/src/ro/xzya/game/Game.java: -------------------------------------------------------------------------------- 1 | package ro.xzya.game; 2 | 3 | import com.badlogic.gdx.Application; 4 | import com.badlogic.gdx.ApplicationAdapter; 5 | import com.badlogic.gdx.Gdx; 6 | import com.badlogic.gdx.graphics.GL20; 7 | import com.badlogic.gdx.graphics.OrthographicCamera; 8 | import com.badlogic.gdx.graphics.Texture; 9 | import com.badlogic.gdx.graphics.g2d.SpriteBatch; 10 | 11 | import java.io.File; 12 | 13 | import ro.xzya.managers.GUI; 14 | import ro.xzya.managers.GameStateManager; 15 | import ro.xzya.managers.Jukebox; 16 | 17 | public class Game extends ApplicationAdapter { 18 | 19 | public static File sdcard; 20 | 21 | public static boolean isMobile = false; 22 | 23 | SpriteBatch batch; 24 | Texture img; 25 | 26 | public static int WIDTH; 27 | public static int HEIGHT; 28 | 29 | public static OrthographicCamera cam; 30 | public static OrthographicCamera guicam; 31 | 32 | public static volatile GUI gui; 33 | 34 | private GameStateManager gsm; 35 | 36 | public Game(File sdcard) { 37 | this.sdcard = sdcard; 38 | } 39 | 40 | @Override 41 | public void create () { 42 | 43 | Gdx.graphics.setDisplayMode(800, 600, false); 44 | WIDTH = Gdx.graphics.getWidth(); 45 | HEIGHT = Gdx.graphics.getHeight(); 46 | 47 | if (Gdx.app.getType().equals(Application.ApplicationType.Android)){ 48 | // if (true) { 49 | //init guicamera 50 | guicam = new OrthographicCamera(WIDTH, HEIGHT); 51 | guicam.translate(WIDTH/2, HEIGHT/2); 52 | guicam.update(); 53 | 54 | gui = new GUI(); 55 | 56 | isMobile = true; 57 | } 58 | 59 | //init camera 60 | cam = new OrthographicCamera(WIDTH, HEIGHT); 61 | cam.translate(WIDTH/2, HEIGHT/2); 62 | cam.update(); 63 | 64 | //load sound files 65 | loadSoundFiles(); 66 | 67 | gsm = new GameStateManager(); 68 | } 69 | 70 | @Override 71 | public void render () { 72 | Gdx.gl.glClearColor(0, 0, 0, 1); 73 | Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); 74 | 75 | gsm.update(Gdx.graphics.getDeltaTime()); 76 | gsm.draw(); 77 | 78 | } 79 | 80 | private void loadSoundFiles() { 81 | Jukebox.load("sounds/explode.ogg", "explode"); 82 | Jukebox.load("sounds/extralife.ogg", "extralife"); 83 | Jukebox.load("sounds/largesaucer.ogg", "largesaucer"); 84 | Jukebox.load("sounds/pulsehigh.ogg", "pulsehigh"); 85 | Jukebox.load("sounds/pulselow.ogg", "pulselow"); 86 | Jukebox.load("sounds/saucershoot.ogg", "saucershoot"); 87 | Jukebox.load("sounds/shoot.ogg", "shoot"); 88 | Jukebox.load("sounds/smallsaucer.ogg", "smallsaucer"); 89 | Jukebox.load("sounds/thruster.ogg", "thruster"); 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /core/src/ro/xzya/entities/Asteroid.java: -------------------------------------------------------------------------------- 1 | package ro.xzya.entities; 2 | 3 | import com.badlogic.gdx.graphics.glutils.ShapeRenderer; 4 | import com.badlogic.gdx.math.MathUtils; 5 | 6 | import ro.xzya.game.Game; 7 | 8 | /** 9 | * Created by Xzya on 4/3/2015. 10 | */ 11 | public class Asteroid extends SpaceObject { 12 | 13 | private int type; 14 | public static final int SMALL = 0; 15 | public static final int MEDIUM = 1; 16 | public static final int LARGE = 2; 17 | 18 | private int score; 19 | 20 | private int numPoints; 21 | private float[] dists; 22 | 23 | private boolean remove; 24 | 25 | public Asteroid(float x, float y, int type) { 26 | this.x = x; 27 | this.y = y; 28 | this.type = type; 29 | 30 | if (type == SMALL) { 31 | numPoints = 8; 32 | // width = height = 12; 33 | width = height = ((int)(Game.HEIGHT * 0.04)); 34 | speed = MathUtils.random(70, 100); 35 | score = 100; 36 | } else if (type == MEDIUM) { 37 | numPoints = 10; 38 | // width = height = 20; 39 | width = height = ((int)(Game.HEIGHT * 0.065)); 40 | speed = MathUtils.random(50, 60); 41 | score = 50; 42 | } else if (type == LARGE) { 43 | numPoints = 12; 44 | // width = height = 40; 45 | width = height = ((int)(Game.HEIGHT * 0.13)); 46 | speed = MathUtils.random(20, 30); 47 | score = 20; 48 | } 49 | 50 | rotationSpeed = MathUtils.random(-1, 1); 51 | 52 | radians = MathUtils.random(2 * 3.1415f); 53 | 54 | dx = MathUtils.cos(radians) * speed; 55 | dy = MathUtils.sin(radians) * speed; 56 | 57 | shapex = new float[numPoints]; 58 | shapey = new float[numPoints]; 59 | dists = new float[numPoints]; 60 | 61 | int radius = width/2; 62 | for (int i = 0; i < numPoints; i++) { 63 | dists[i] = MathUtils.random(radius/2, radius); 64 | } 65 | 66 | setShape(); 67 | } 68 | 69 | private void setShape() { 70 | float angle = 0; 71 | for (int i = 0; i < numPoints; i++) { 72 | shapex[i] = x + MathUtils.cos(angle + radians) * dists[i]; 73 | shapey[i] = y + MathUtils.sin(angle + radians) * dists[i]; 74 | angle += 2 * 3.1415f / numPoints; 75 | } 76 | } 77 | 78 | public int getType() { 79 | return type; 80 | } 81 | 82 | public int getScore() { 83 | return score; 84 | } 85 | 86 | public boolean shouldRemove() { 87 | return remove; 88 | } 89 | 90 | public void update(float dt) { 91 | x += dx * dt; 92 | y += dy * dt; 93 | 94 | radians += rotationSpeed * dt; 95 | setShape(); 96 | 97 | wrap(); 98 | } 99 | 100 | public void draw(ShapeRenderer sr) { 101 | 102 | sr.setColor(1, 1, 1, 1); 103 | sr.begin(ShapeRenderer.ShapeType.Line); 104 | for (int i = 0, j = shapex.length - 1; 105 | i < shapex.length; 106 | j = i++) { 107 | sr.line(shapex[i], shapey[i], shapex[j], shapey[j]); 108 | } 109 | sr.end(); 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | android { 2 | buildToolsVersion "21.1.2" 3 | compileSdkVersion 21 4 | sourceSets { 5 | main { 6 | manifest.srcFile 'AndroidManifest.xml' 7 | java.srcDirs = ['src'] 8 | aidl.srcDirs = ['src'] 9 | renderscript.srcDirs = ['src'] 10 | res.srcDirs = ['res'] 11 | assets.srcDirs = ['assets'] 12 | } 13 | 14 | instrumentTest.setRoot('tests') 15 | } 16 | } 17 | 18 | // needed to add JNI shared libraries to APK when compiling on CLI 19 | tasks.withType(com.android.build.gradle.tasks.PackageApplication) { pkgTask -> 20 | pkgTask.jniFolders = new HashSet() 21 | pkgTask.jniFolders.add(new File(projectDir, 'libs')) 22 | } 23 | 24 | // called every time gradle gets executed, takes the native dependencies of 25 | // the natives configuration, and extracts them to the proper libs/ folders 26 | // so they get packed with the APK. 27 | task copyAndroidNatives() { 28 | file("libs/armeabi/").mkdirs(); 29 | file("libs/armeabi-v7a/").mkdirs(); 30 | file("libs/x86/").mkdirs(); 31 | 32 | configurations.natives.files.each { jar -> 33 | def outputDir = null 34 | if(jar.name.endsWith("natives-armeabi-v7a.jar")) outputDir = file("libs/armeabi-v7a") 35 | if(jar.name.endsWith("natives-armeabi.jar")) outputDir = file("libs/armeabi") 36 | if(jar.name.endsWith("natives-x86.jar")) outputDir = file("libs/x86") 37 | if(outputDir != null) { 38 | copy { 39 | from zipTree(jar) 40 | into outputDir 41 | include "*.so" 42 | } 43 | } 44 | } 45 | } 46 | 47 | task run(type: Exec) { 48 | def path 49 | def localProperties = project.file("../local.properties") 50 | if (localProperties.exists()) { 51 | Properties properties = new Properties() 52 | localProperties.withInputStream { instr -> 53 | properties.load(instr) 54 | } 55 | def sdkDir = properties.getProperty('sdk.dir') 56 | if (sdkDir) { 57 | path = sdkDir 58 | } else { 59 | path = "$System.env.ANDROID_HOME" 60 | } 61 | } else { 62 | path = "$System.env.ANDROID_HOME" 63 | } 64 | 65 | def adb = path + "/platform-tools/adb" 66 | commandLine "$adb", 'shell', 'am', 'start', '-n', 'ro.xzya.gdx.android/ro.xzya.gdx.android.AndroidLauncher' 67 | } 68 | 69 | // sets up the Android Eclipse project, using the old Ant based build. 70 | eclipse { 71 | // need to specify Java source sets explicitely, SpringSource Gradle Eclipse plugin 72 | // ignores any nodes added in classpath.file.withXml 73 | sourceSets { 74 | main { 75 | java.srcDirs "src", 'gen' 76 | } 77 | } 78 | 79 | jdt { 80 | sourceCompatibility = 1.6 81 | targetCompatibility = 1.6 82 | } 83 | 84 | classpath { 85 | plusConfigurations += [ project.configurations.compile ] 86 | containers 'com.android.ide.eclipse.adt.ANDROID_FRAMEWORK', 'com.android.ide.eclipse.adt.LIBRARIES' 87 | } 88 | 89 | project { 90 | name = appName + "-android" 91 | natures 'com.android.ide.eclipse.adt.AndroidNature' 92 | buildCommands.clear(); 93 | buildCommand "com.android.ide.eclipse.adt.ResourceManagerBuilder" 94 | buildCommand "com.android.ide.eclipse.adt.PreCompilerBuilder" 95 | buildCommand "org.eclipse.jdt.core.javabuilder" 96 | buildCommand "com.android.ide.eclipse.adt.ApkBuilder" 97 | } 98 | } 99 | 100 | // sets up the Android Idea project, using the old Ant based build. 101 | idea { 102 | module { 103 | sourceDirs += file("src"); 104 | scopes = [ COMPILE: [plus:[project.configurations.compile]]] 105 | 106 | iml { 107 | withXml { 108 | def node = it.asNode() 109 | def builder = NodeBuilder.newInstance(); 110 | builder.current = node; 111 | builder.component(name: "FacetManager") { 112 | facet(type: "android", name: "Android") { 113 | configuration { 114 | option(name: "UPDATE_PROPERTY_FILES", value:"true") 115 | } 116 | } 117 | } 118 | } 119 | } 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /core/src/ro/xzya/gamestates/HighscoreState.java: -------------------------------------------------------------------------------- 1 | package ro.xzya.gamestates; 2 | 3 | import com.badlogic.gdx.Gdx; 4 | import com.badlogic.gdx.Input; 5 | import com.badlogic.gdx.graphics.g2d.BitmapFont; 6 | import com.badlogic.gdx.graphics.g2d.SpriteBatch; 7 | import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator; 8 | import com.badlogic.gdx.graphics.glutils.ShapeRenderer; 9 | import com.badlogic.gdx.math.Vector3; 10 | import com.badlogic.gdx.scenes.scene2d.InputEvent; 11 | import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; 12 | 13 | import ro.xzya.game.Game; 14 | import ro.xzya.managers.GameStateManager; 15 | import ro.xzya.managers.Save; 16 | 17 | /** 18 | * Created by Xzya on 4/3/2015. 19 | */ 20 | public class HighscoreState extends GameState { 21 | 22 | private static final int dpSize1 = ((int) (Game.HEIGHT * 0.75)); //300dp 23 | private static final int dpSize2 = ((int) (Game.HEIGHT * 0.675)); //270dp 24 | private static final int dpSize3 = ((int) (Game.HEIGHT * 0.05)); //20dp 25 | 26 | private Vector3 touchPoint; 27 | 28 | private SpriteBatch sb; 29 | private ShapeRenderer sr; 30 | 31 | private BitmapFont font; 32 | 33 | private long[] highScores; 34 | private String[] names; 35 | 36 | public HighscoreState(GameStateManager gsm) { 37 | super(gsm); 38 | } 39 | 40 | @Override 41 | public void init() { 42 | 43 | if (Game.isMobile) { 44 | // if (true) { 45 | setTouchInput(); 46 | } 47 | 48 | sb = new SpriteBatch(); 49 | sr = new ShapeRenderer(); 50 | 51 | FreeTypeFontGenerator gen = new FreeTypeFontGenerator( 52 | 53 | Gdx.files.internal("fonts/Hyperspace Bold.ttf") 54 | ); 55 | FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter(); 56 | parameter.size = 20; 57 | font = gen.generateFont(parameter); 58 | 59 | Save.load(); 60 | 61 | highScores = Save.gd.getHighscores(); 62 | names = Save.gd.getNames(); 63 | 64 | touchPoint = new Vector3(); 65 | } 66 | 67 | @Override 68 | public void update(float dt) { 69 | handleInput(); 70 | } 71 | 72 | @Override 73 | public void draw() { 74 | 75 | sb.setProjectionMatrix(Game.cam.combined); 76 | sb.begin(); 77 | 78 | String s; 79 | float w; 80 | 81 | s = "Highscores"; 82 | w = font.getBounds(s).width; 83 | font.draw( 84 | sb, 85 | s, 86 | (Game.WIDTH - w) / 2, 87 | // 300 88 | dpSize1 89 | ); 90 | 91 | for (int i = 0; i < highScores.length; i++) { 92 | s = String.format( 93 | "%2d. %7s %s", 94 | i + 1, 95 | highScores[i], 96 | names[i] 97 | ); 98 | w = font.getBounds(s).width; 99 | font.draw( 100 | sb, 101 | s, 102 | (Game.WIDTH - w) / 2, 103 | // 270 - 20 * i 104 | dpSize2 - dpSize3 * i 105 | ); 106 | } 107 | 108 | sb.end(); 109 | 110 | //draw on-screen controls 111 | if (Game.isMobile) { 112 | // if (true) { 113 | sr.begin(ShapeRenderer.ShapeType.Line); 114 | sr.rect(Game.gui.getWleftBounds().getX(), Game.gui.getWleftBounds().getY(), Game.gui.getWleftBounds().getWidth(), Game.gui.getWleftBounds().getHeight()); 115 | sr.rect(Game.gui.getWrightBounds().getX(), Game.gui.getWrightBounds().getY(), Game.gui.getWrightBounds().getWidth(), Game.gui.getWrightBounds().getHeight()); 116 | sr.circle(Game.gui.getA().x, Game.gui.getA().y, Game.gui.getA().radius); 117 | sr.circle(Game.gui.getB().x, Game.gui.getB().y, Game.gui.getB().radius); 118 | sr.end(); 119 | } 120 | } 121 | 122 | @Override 123 | public void handleInput() { 124 | if (!Game.isMobile) { 125 | // if (true) { 126 | if (Gdx.input.isKeyJustPressed(Input.Keys.ENTER) 127 | || Gdx.input.isKeyJustPressed(Input.Keys.ESCAPE) 128 | || Gdx.input.isKeyJustPressed(Input.Keys.SPACE)) { 129 | gsm.setState(GameStateManager.MENU); 130 | } 131 | } 132 | } 133 | 134 | private void setTouchInput() { 135 | Gdx.input.setInputProcessor(Game.gui.getStage()); 136 | //handle touch input 137 | 138 | Game.gui.getaA().addListener(new ClickListener() { 139 | @Override 140 | public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { 141 | gsm.setState(GameStateManager.MENU); 142 | return true; 143 | } 144 | }); 145 | 146 | Game.gui.getaB().addListener(new ClickListener() { 147 | @Override 148 | public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { 149 | gsm.setState(GameStateManager.MENU); 150 | return true; 151 | } 152 | }); 153 | } 154 | 155 | @Override 156 | public void dispose() { 157 | 158 | sb.dispose(); 159 | sr.dispose(); 160 | font.dispose(); 161 | 162 | if (Game.isMobile){ 163 | Game.gui.clearListeners(); 164 | } 165 | 166 | } 167 | } 168 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /android/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 | -------------------------------------------------------------------------------- /core/src/ro/xzya/entities/FlyingSaucer.java: -------------------------------------------------------------------------------- 1 | package ro.xzya.entities; 2 | 3 | import com.badlogic.gdx.graphics.glutils.ShapeRenderer; 4 | import com.badlogic.gdx.math.MathUtils; 5 | 6 | import java.util.ArrayList; 7 | 8 | import ro.xzya.game.Game; 9 | import ro.xzya.managers.Jukebox; 10 | 11 | /** 12 | * Created by Xzya on 5/3/2015. 13 | */ 14 | public class FlyingSaucer extends SpaceObject { 15 | 16 | private static final int dpSize1 = ((int)(Game.HEIGHT * 0.025)); //10px 17 | private static final int dpSize2 = ((int)(Game.HEIGHT * 0.0075)); //3px 18 | private static final int dpSize3 = ((int)(Game.HEIGHT * 0.0125)); //5px 19 | private static final int dpSize4 = ((int)(Game.HEIGHT * 0.015)); //6px 20 | private static final int dpSize5 = ((int)(Game.HEIGHT * 0.005)); //2px 21 | 22 | private ArrayList bullets; 23 | 24 | private int type; 25 | 26 | public static final int LARGE = 0; 27 | public static final int SMALL = 1; 28 | 29 | private int score; 30 | 31 | private float fireTimer; 32 | private float fireTime; 33 | 34 | private Player player; 35 | 36 | private float pathTimer; 37 | private float pathTime1; 38 | private float pathTime2; 39 | 40 | private int direction; 41 | public static final int LEFT = 0; 42 | public static final int RIGHT = 1; 43 | 44 | private boolean remove; 45 | 46 | public FlyingSaucer( 47 | int type, 48 | int direction, 49 | Player player, 50 | ArrayList bullets) { 51 | this.type = type; 52 | this.direction = direction; 53 | this.player = player; 54 | this.bullets = bullets; 55 | 56 | // speed = 70; 57 | speed = ((int)(Game.WIDTH * 0.13)); 58 | if (direction == LEFT) { 59 | dx = -speed; 60 | x = Game.WIDTH; 61 | } else if (direction == RIGHT) { 62 | dx = speed; 63 | x = 0; 64 | } 65 | y = MathUtils.random(Game.HEIGHT); 66 | 67 | shapex = new float[6]; 68 | shapey = new float[6]; 69 | setShape(); 70 | 71 | if (type == LARGE) { 72 | score = 200; 73 | Jukebox.loop("largesaucer"); 74 | } else if (type == SMALL) { 75 | score = 1000; 76 | Jukebox.loop("smallsaucer"); 77 | } 78 | 79 | fireTimer = 0; 80 | fireTime = 1; 81 | // --- 82 | pathTimer = 0; // \____ 83 | pathTime1 = 2; //goes left or right 2 seconds 84 | pathTime2 = pathTime1 + 2; //changes direction and moves for 2 seconds 85 | 86 | } 87 | 88 | private void setShape() { 89 | if (type == LARGE) { 90 | // shapex[0] = x - 10; 91 | // shapey[0] = y; 92 | // 93 | // shapex[1] = x - 3; 94 | // shapey[1] = y - 5; 95 | // 96 | // shapex[2] = x + 3; 97 | // shapey[2] = y - 5; 98 | // 99 | // shapex[3] = x + 10; 100 | // shapey[3] = y; 101 | // 102 | // shapex[4] = x + 3; 103 | // shapey[4] = y + 5; 104 | // 105 | // shapex[5] = x - 3; 106 | // shapey[5] = y + 5; 107 | 108 | shapex[0] = x - dpSize1; 109 | shapey[0] = y; 110 | 111 | shapex[1] = x - dpSize2; 112 | shapey[1] = y - dpSize3; 113 | 114 | shapex[2] = x + dpSize2; 115 | shapey[2] = y - dpSize3; 116 | 117 | shapex[3] = x + dpSize1; 118 | shapey[3] = y; 119 | 120 | shapex[4] = x + dpSize2; 121 | shapey[4] = y + dpSize3; 122 | 123 | shapex[5] = x - dpSize2; 124 | shapey[5] = y + dpSize3; 125 | 126 | } else if (type == SMALL) { 127 | // shapex[0] = x - 6; 128 | // shapey[0] = y; 129 | // 130 | // shapex[1] = x - 2; 131 | // shapey[1] = y - 3; 132 | // 133 | // shapex[2] = x + 2; 134 | // shapey[2] = y - 3; 135 | // 136 | // shapex[3] = x + 6; 137 | // shapey[3] = y; 138 | // 139 | // shapex[4] = x + 2; 140 | // shapey[4] = y + 3; 141 | // 142 | // shapex[5] = x - 2; 143 | // shapey[5] = y + 3; 144 | 145 | shapex[0] = x - dpSize4; 146 | shapey[0] = y; 147 | 148 | shapex[1] = x - dpSize5; 149 | shapey[1] = y - dpSize2; 150 | 151 | shapex[2] = x + dpSize5; 152 | shapey[2] = y - dpSize2; 153 | 154 | shapex[3] = x + dpSize4; 155 | shapey[3] = y; 156 | 157 | shapex[4] = x + dpSize5; 158 | shapey[4] = y + dpSize2; 159 | 160 | shapex[5] = x - dpSize5; 161 | shapey[5] = y + dpSize2; 162 | } 163 | } 164 | 165 | public int getScore() { 166 | return score; 167 | } 168 | 169 | public boolean shouldRemove() { 170 | return remove; 171 | } 172 | 173 | public void update(float dt) { 174 | 175 | //fire 176 | if (!player.isHit()) { 177 | fireTimer += dt; 178 | if (fireTimer > fireTime) { 179 | fireTimer = 0; 180 | if (type == LARGE) { 181 | radians = MathUtils.random(2 * 3.1415f); 182 | } else if (type == SMALL) { 183 | //use atan2 to get the angle twards the player 184 | radians = MathUtils.atan2( 185 | player.gety() - y, 186 | player.getx() - x 187 | ); 188 | } 189 | bullets.add(new Bullet(x, y, radians)); 190 | Jukebox.play("saucershoot"); 191 | } 192 | } 193 | 194 | //move along path 195 | pathTimer += dt; 196 | 197 | //move forward 198 | if (pathTimer < pathTime1) { 199 | dy = 0; 200 | } 201 | 202 | //move downward 203 | if (pathTimer > pathTime1 && pathTimer < pathTime2) { 204 | dy = -speed; 205 | } 206 | 207 | //move forward again 208 | if (pathTimer > pathTime1 + pathTime2) { 209 | dy = 0; 210 | } 211 | 212 | x += dx * dt; 213 | y += dy * dt; 214 | 215 | //screen wrap 216 | if (y < 0) y = Game.HEIGHT; 217 | 218 | //set shape 219 | setShape(); 220 | 221 | //check if remove 222 | if ((direction == RIGHT && x > Game.WIDTH) || 223 | (direction == LEFT && x < 0)){ 224 | remove = true; 225 | } 226 | 227 | } 228 | 229 | public void draw(ShapeRenderer sr) { 230 | sr.setProjectionMatrix(Game.cam.combined); 231 | sr.begin(ShapeRenderer.ShapeType.Line); 232 | 233 | for(int i = 0, j = shapex.length - 1; 234 | i < shapex.length; 235 | j = i++) { 236 | sr.line(shapex[i], shapey[i], shapex[j], shapey[j]); 237 | } 238 | 239 | sr.line(shapex[0], shapey[0], shapex[3], shapey[3]); 240 | 241 | sr.end(); 242 | } 243 | 244 | 245 | 246 | 247 | } 248 | -------------------------------------------------------------------------------- /core/src/ro/xzya/managers/GUI.java: -------------------------------------------------------------------------------- 1 | package ro.xzya.managers; 2 | 3 | import com.badlogic.gdx.math.Circle; 4 | import com.badlogic.gdx.math.Rectangle; 5 | import com.badlogic.gdx.scenes.scene2d.Actor; 6 | import com.badlogic.gdx.scenes.scene2d.EventListener; 7 | import com.badlogic.gdx.scenes.scene2d.Stage; 8 | import com.badlogic.gdx.scenes.scene2d.Touchable; 9 | import com.badlogic.gdx.utils.Array; 10 | import com.badlogic.gdx.utils.viewport.ScreenViewport; 11 | 12 | import ro.xzya.game.Game; 13 | 14 | /** 15 | * Created by Xzya on 5/3/2015. 16 | */ 17 | public class GUI { 18 | 19 | private volatile boolean pressedLeft; 20 | private volatile boolean pressedRight; 21 | private volatile boolean pressedA; 22 | private volatile boolean pressedB; 23 | private volatile boolean pressedOK; 24 | private volatile boolean pressedBack; 25 | 26 | private static final int dpSize1 = ((int)(Game.WIDTH * 0.07)); //button margin 27 | private static final int dpSize2 = ((int)(Game.HEIGHT * 0.10)); //button margin 28 | 29 | private Rectangle wleftBounds; 30 | private Rectangle wrightBounds; 31 | private Rectangle back; 32 | private Circle A; 33 | private Circle B; 34 | private Circle OK; 35 | 36 | private Actor aA; 37 | private Actor aB; 38 | private Actor aOK; 39 | private Actor aWLeftBounds; 40 | private Actor aWRightBounds; 41 | private Actor aBack; 42 | 43 | private Stage stage; 44 | 45 | public GUI() { 46 | this.wleftBounds = new Rectangle(dpSize1, dpSize1, 2 * dpSize2, 2 * dpSize2); 47 | this.wrightBounds = new Rectangle(dpSize1 + (2 * dpSize1 + dpSize2), dpSize1, 2 * dpSize2, 2 * dpSize2); 48 | // this.wleftBounds = new Rectangle(20, 20, 80, 80); 49 | // this.wrightBounds = new Rectangle(80+20, 20, 80, 80); 50 | this.A = new Circle(Game.WIDTH - 3 * dpSize1, 2 * dpSize1, dpSize1); 51 | this.B = new Circle(Game.WIDTH - 2 * dpSize1, 4 * dpSize1, dpSize1); 52 | this.OK = new Circle(Game.WIDTH - 2 * dpSize1, 7 * dpSize1, dpSize1); 53 | 54 | // back = new Rectangle(0, Game.HEIGHT - dpSize1, dpSize1, Game.HEIGHT); 55 | back = new Rectangle(Game.WIDTH - dpSize1, Game.HEIGHT - dpSize1, dpSize1, dpSize1); 56 | 57 | aWLeftBounds = new Actor(); 58 | aWLeftBounds.setX(wleftBounds.getX()); 59 | aWLeftBounds.setY(wleftBounds.getY()); 60 | aWLeftBounds.setWidth(wleftBounds.getWidth()); 61 | aWLeftBounds.setHeight(wleftBounds.getHeight()); 62 | aWLeftBounds.setTouchable(Touchable.enabled); 63 | 64 | aWRightBounds = new Actor(); 65 | aWRightBounds.setX(wrightBounds.getX()); 66 | aWRightBounds.setY(wrightBounds.getY()); 67 | aWRightBounds.setWidth(wrightBounds.getWidth()); 68 | aWRightBounds.setHeight(wrightBounds.getHeight()); 69 | aWRightBounds.setTouchable(Touchable.enabled); 70 | 71 | aA = new Actor(); 72 | aA.setX(A.x - dpSize1); 73 | aA.setY(A.y - dpSize1); 74 | aA.setWidth(A.radius * 1.8f); 75 | aA.setHeight(A.radius * 1.8f); 76 | aA.setTouchable(Touchable.enabled); 77 | 78 | aB = new Actor(); 79 | aB.setX(B.x - dpSize1); 80 | aB.setY(B.y - dpSize1); 81 | aB.setWidth(B.radius * 1.8f); 82 | aB.setHeight(B.radius * 1.8f); 83 | aB.setTouchable(Touchable.enabled); 84 | 85 | aOK = new Actor(); 86 | aOK.setX(OK.x - dpSize1); 87 | aOK.setY(OK.y - dpSize1); 88 | aOK.setWidth(OK.radius * 1.8f); 89 | aOK.setHeight(OK.radius * 1.8f); 90 | aOK.setTouchable(Touchable.enabled); 91 | 92 | aBack = new Actor(); 93 | aBack.setX(back.getX()); 94 | aBack.setY(back.getY()); 95 | aBack.setWidth(back.getWidth()); 96 | aBack.setHeight(back.getHeight()); 97 | aBack.setTouchable(Touchable.enabled); 98 | 99 | stage = new Stage(new ScreenViewport()); 100 | stage.addActor(aA); 101 | stage.addActor(aB); 102 | stage.addActor(aOK); 103 | stage.addActor(aWLeftBounds); 104 | stage.addActor(aWRightBounds); 105 | stage.addActor(aBack); 106 | 107 | pressedLeft = false; 108 | pressedRight = false; 109 | pressedA = false; 110 | pressedB = false; 111 | pressedOK = false; 112 | pressedBack = false; 113 | } 114 | 115 | public Stage getStage() { 116 | return stage; 117 | } 118 | 119 | public Actor getaA() { 120 | return aA; 121 | } 122 | 123 | public Actor getaB() { 124 | return aB; 125 | } 126 | 127 | public Actor getaOK() { 128 | return aOK; 129 | } 130 | 131 | public Actor getaWLeftBounds() { 132 | return aWLeftBounds; 133 | } 134 | 135 | public Actor getaWRightBounds() { 136 | return aWRightBounds; 137 | } 138 | 139 | public Rectangle getWleftBounds() { 140 | return wleftBounds; 141 | } 142 | 143 | public Rectangle getWrightBounds() { 144 | return wrightBounds; 145 | } 146 | 147 | public Circle getA() { 148 | return A; 149 | } 150 | 151 | public Circle getB() { 152 | return B; 153 | } 154 | 155 | public Circle getOK() { 156 | return OK; 157 | } 158 | 159 | public void clearListeners() { 160 | Array listeners = Game.gui.getaA().getListeners(); 161 | for (EventListener e : listeners) { 162 | Game.gui.getaA().removeListener(e); 163 | } 164 | listeners = Game.gui.getaB().getListeners(); 165 | for (EventListener e : listeners) { 166 | Game.gui.getaB().removeListener(e); 167 | } 168 | listeners = Game.gui.getaOK().getListeners(); 169 | for (EventListener e : listeners) { 170 | Game.gui.getaOK().removeListener(e); 171 | } 172 | listeners = Game.gui.getaWLeftBounds().getListeners(); 173 | for (EventListener e : listeners) { 174 | Game.gui.getaWLeftBounds().removeListener(e); 175 | } 176 | listeners = Game.gui.getaWRightBounds().getListeners(); 177 | for (EventListener e : listeners) { 178 | Game.gui.getaWRightBounds().removeListener(e); 179 | } 180 | listeners = Game.gui.getaBack().getListeners(); 181 | for (EventListener e : listeners) { 182 | Game.gui.getaBack().removeListener(e); 183 | } 184 | 185 | } 186 | 187 | public boolean isPressedA() { 188 | return pressedA; 189 | } 190 | 191 | public boolean isPressedB() { 192 | return pressedB; 193 | } 194 | 195 | public boolean isPressedLeft() { 196 | return pressedLeft; 197 | } 198 | 199 | public boolean isPressedRight() { 200 | return pressedRight; 201 | } 202 | 203 | public boolean isPressedOK() { 204 | return pressedOK; 205 | } 206 | 207 | public void setPressedA(boolean pressedA) { 208 | this.pressedA = pressedA; 209 | } 210 | 211 | public void setPressedB(boolean pressedB) { 212 | this.pressedB = pressedB; 213 | } 214 | 215 | public void setPressedLeft(boolean pressedLeft) { 216 | this.pressedLeft = pressedLeft; 217 | } 218 | 219 | public void setPressedRight(boolean pressedRight) { 220 | this.pressedRight = pressedRight; 221 | } 222 | 223 | public void setPressedOK(boolean pressedOK) { 224 | this.pressedOK = pressedOK; 225 | } 226 | 227 | public Actor getaBack() { 228 | return aBack; 229 | } 230 | 231 | public Rectangle getBack() { 232 | return back; 233 | } 234 | } 235 | -------------------------------------------------------------------------------- /core/src/ro/xzya/gamestates/MenuState.java: -------------------------------------------------------------------------------- 1 | package ro.xzya.gamestates; 2 | 3 | import com.badlogic.gdx.Gdx; 4 | import com.badlogic.gdx.Input; 5 | import com.badlogic.gdx.graphics.Color; 6 | import com.badlogic.gdx.graphics.g2d.BitmapFont; 7 | import com.badlogic.gdx.graphics.g2d.SpriteBatch; 8 | import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator; 9 | import com.badlogic.gdx.graphics.glutils.ShapeRenderer; 10 | import com.badlogic.gdx.math.MathUtils; 11 | import com.badlogic.gdx.math.Vector3; 12 | import com.badlogic.gdx.scenes.scene2d.InputEvent; 13 | import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; 14 | 15 | import java.util.ArrayList; 16 | 17 | import ro.xzya.entities.Asteroid; 18 | import ro.xzya.game.Game; 19 | import ro.xzya.managers.GameStateManager; 20 | import ro.xzya.managers.Save; 21 | 22 | /** 23 | * Created by Xzya on 4/3/2015. 24 | */ 25 | public class MenuState extends GameState { 26 | 27 | private static final int dpSize1 = ((int) (Game.HEIGHT * 0.14)); //56dp 28 | private static final int dpSize2 = ((int) (Game.HEIGHT * 0.05)); //20dp 29 | private static final int dpSize3 = ((int) (Game.HEIGHT * 0.75)); 30 | private static final int dpSize4 = ((int) (Game.HEIGHT * 0.45)); //180 31 | private static final int dpSize5 = ((int) (Game.HEIGHT * 0.125)); 32 | 33 | private Vector3 touchPoint; 34 | 35 | private SpriteBatch sb; 36 | private ShapeRenderer sr; 37 | 38 | private BitmapFont titleFont; 39 | private BitmapFont font; 40 | 41 | private final String title = "Asteroids"; 42 | 43 | private ArrayList asteroids; 44 | 45 | private int currentItem; 46 | private String[] menuItems; 47 | 48 | public MenuState(GameStateManager gsm) { 49 | super(gsm); 50 | } 51 | 52 | @Override 53 | public void init() { 54 | 55 | if (Game.isMobile) { 56 | // if (true) { 57 | setTouchInput(); 58 | } 59 | 60 | sb = new SpriteBatch(); 61 | sr = new ShapeRenderer(); 62 | 63 | FreeTypeFontGenerator gen = new FreeTypeFontGenerator( 64 | 65 | Gdx.files.internal("fonts/Hyperspace Bold.ttf") 66 | ); 67 | FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter(); 68 | // parameter.size = 56; 69 | parameter.size = dpSize1; 70 | 71 | titleFont = gen.generateFont(parameter); 72 | titleFont.setColor(Color.WHITE); 73 | 74 | // parameter.size = 20; 75 | parameter.size = dpSize2; 76 | font = gen.generateFont(parameter); 77 | 78 | menuItems = new String[]{ 79 | "Play", 80 | "Highscores", 81 | "Quit" 82 | }; 83 | 84 | Save.load(); 85 | 86 | //init bg asteroids 87 | asteroids = new ArrayList(); 88 | for (int i = 0; i < 6; i++) { 89 | asteroids.add(new Asteroid( 90 | MathUtils.random(Game.WIDTH), 91 | MathUtils.random(Game.HEIGHT), 92 | Asteroid.LARGE 93 | )); 94 | } 95 | 96 | //init touch points 97 | touchPoint = new Vector3(); 98 | 99 | } 100 | 101 | @Override 102 | public void update(float dt) { 103 | //handle input 104 | handleInput(); 105 | 106 | //update asteroids 107 | for (int i = 0; i < 6; i++) { 108 | asteroids.get(i).update(dt); 109 | } 110 | 111 | } 112 | 113 | @Override 114 | public void draw() { 115 | 116 | sb.setProjectionMatrix(Game.cam.combined); 117 | sr.setProjectionMatrix(Game.cam.combined); 118 | 119 | //draw asteroids 120 | for (int i = 0; i < 6; i++) { 121 | asteroids.get(i).draw(sr); 122 | } 123 | 124 | //draw title 125 | sb.begin(); 126 | float width = titleFont.getBounds(title).width; 127 | titleFont.draw( 128 | sb, 129 | title, 130 | (Game.WIDTH - width) / 2, 131 | dpSize3 132 | ); 133 | 134 | //draw menu 135 | for (int i = 0; i < menuItems.length; i++) { 136 | width = font.getBounds(menuItems[i]).width; 137 | if (currentItem == i) font.setColor(Color.RED); 138 | else font.setColor(Color.WHITE); 139 | font.draw( 140 | sb, 141 | menuItems[i], 142 | (Game.WIDTH - width) / 2, 143 | // 180 - 50 * i 144 | dpSize4 - dpSize5 * i 145 | ); 146 | } 147 | sb.end(); 148 | 149 | //draw on-screen controls 150 | if (Game.isMobile) { 151 | // if (true) { 152 | sr.begin(ShapeRenderer.ShapeType.Line); 153 | sr.rect(Game.gui.getWleftBounds().getX(), Game.gui.getWleftBounds().getY(), Game.gui.getWleftBounds().getWidth(), Game.gui.getWleftBounds().getHeight()); 154 | sr.rect(Game.gui.getWrightBounds().getX(), Game.gui.getWrightBounds().getY(), Game.gui.getWrightBounds().getWidth(), Game.gui.getWrightBounds().getHeight()); 155 | sr.circle(Game.gui.getA().x, Game.gui.getA().y, Game.gui.getA().radius); 156 | sr.circle(Game.gui.getB().x, Game.gui.getB().y, Game.gui.getB().radius); 157 | sr.end(); 158 | } 159 | } 160 | 161 | @Override 162 | public void handleInput() { 163 | if (!Game.isMobile) { 164 | // if (true) { 165 | if (Gdx.input.isKeyJustPressed(Input.Keys.UP) 166 | || Gdx.input.isKeyJustPressed(Input.Keys.W)) { 167 | if (currentItem > 0) { 168 | currentItem--; 169 | } 170 | } 171 | if (Gdx.input.isKeyJustPressed(Input.Keys.DOWN) 172 | || Gdx.input.isKeyJustPressed(Input.Keys.S)) { 173 | if (currentItem < menuItems.length - 1) { 174 | currentItem++; 175 | } 176 | } 177 | if (Gdx.input.isKeyJustPressed(Input.Keys.ENTER) 178 | || Gdx.input.isKeyJustPressed(Input.Keys.SPACE)) { 179 | select(); 180 | } 181 | } 182 | } 183 | 184 | private void setTouchInput() { 185 | Gdx.input.setInputProcessor(Game.gui.getStage()); 186 | //handle touch input 187 | 188 | Game.gui.getaWLeftBounds().addListener(new ClickListener() { 189 | @Override 190 | public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { 191 | if (currentItem > 0) { 192 | currentItem--; 193 | } 194 | return true; 195 | } 196 | }); 197 | 198 | Game.gui.getaWRightBounds().addListener(new ClickListener() { 199 | @Override 200 | public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { 201 | if (currentItem < menuItems.length - 1) { 202 | currentItem++; 203 | } 204 | return true; 205 | } 206 | }); 207 | 208 | Game.gui.getaA().addListener(new ClickListener() { 209 | @Override 210 | public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { 211 | select(); 212 | return true; 213 | } 214 | }); 215 | } 216 | 217 | private void select() { 218 | //play 219 | if (currentItem == 0) { 220 | gsm.setState(GameStateManager.PLAY); 221 | } else if (currentItem == 1) { 222 | gsm.setState(GameStateManager.HIGHSCORE); 223 | } else if (currentItem == 2) { 224 | Gdx.app.exit(); 225 | } 226 | } 227 | 228 | @Override 229 | public void dispose() { 230 | 231 | sb.dispose(); 232 | sr.dispose(); 233 | titleFont.dispose(); 234 | font.dispose(); 235 | 236 | if (Game.isMobile){ 237 | Game.gui.clearListeners(); 238 | } 239 | } 240 | 241 | } 242 | -------------------------------------------------------------------------------- /core/src/ro/xzya/gamestates/GameOver.java: -------------------------------------------------------------------------------- 1 | package ro.xzya.gamestates; 2 | 3 | import com.badlogic.gdx.Gdx; 4 | import com.badlogic.gdx.Input; 5 | import com.badlogic.gdx.graphics.g2d.BitmapFont; 6 | import com.badlogic.gdx.graphics.g2d.SpriteBatch; 7 | import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator; 8 | import com.badlogic.gdx.graphics.glutils.ShapeRenderer; 9 | import com.badlogic.gdx.math.Vector3; 10 | import com.badlogic.gdx.scenes.scene2d.InputEvent; 11 | import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; 12 | 13 | import ro.xzya.game.Game; 14 | import ro.xzya.managers.GameStateManager; 15 | import ro.xzya.managers.Save; 16 | 17 | /** 18 | * Created by Xzya on 4/3/2015. 19 | */ 20 | public class GameOver extends GameState { 21 | 22 | private static final int dpSize1 = ((int) (Game.HEIGHT * 0.05)); //20dp 23 | private static final int dpSize2 = ((int) (Game.HEIGHT * 0.08)); //32dp 24 | private static final int dpSize3 = ((int) (Game.HEIGHT * 0.55)); //220dp 25 | private static final int dpSize4 = ((int) (Game.HEIGHT * 0.45)); //220dp 26 | private static final int dpSize5 = ((int) (Game.WIDTH * 0.44)); 27 | private static final int dpSize6 = ((int) (Game.WIDTH * 0.023)); //14 28 | private static final int dpSize7 = ((int) (Game.HEIGHT * 0.3)); //120 29 | private static final int dpSize8 = ((int) (Game.HEIGHT * 0.25)); //100 30 | private static final int dpSize9 = ((int) (Game.WIDTH * 0.45396)); //244 31 | 32 | private Vector3 touchPoint; 33 | 34 | private SpriteBatch sb; 35 | private ShapeRenderer sr; 36 | 37 | private BitmapFont gameOverFont; 38 | private BitmapFont font; 39 | 40 | private boolean newHighScore; 41 | private char[] newName; 42 | private int currentChar; 43 | 44 | public GameOver(GameStateManager gsm) { 45 | super(gsm); 46 | } 47 | 48 | 49 | @Override 50 | public void init() { 51 | 52 | if (Game.isMobile) { 53 | // if (true) { 54 | setTouchInput(); 55 | } 56 | 57 | sb = new SpriteBatch(); 58 | sr = new ShapeRenderer(); 59 | 60 | newHighScore = Save.gd.isHighScore(Save.gd.getTentativeScore()); 61 | if (newHighScore) { 62 | newName = new char[]{'A', 'A', 'A'}; 63 | currentChar = 0; 64 | } 65 | 66 | FreeTypeFontGenerator gen = new FreeTypeFontGenerator( 67 | 68 | Gdx.files.internal("fonts/Hyperspace Bold.ttf") 69 | ); 70 | FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter(); 71 | // parameter.size = 20; 72 | parameter.size = dpSize1; 73 | font = gen.generateFont(parameter); 74 | // parameter.size = 32; 75 | parameter.size = dpSize2; 76 | gameOverFont = gen.generateFont(parameter); 77 | 78 | touchPoint = new Vector3(); 79 | 80 | } 81 | 82 | @Override 83 | public void update(float dt) { 84 | handleInput(); 85 | 86 | } 87 | 88 | @Override 89 | public void draw() { 90 | sb.setProjectionMatrix(Game.cam.combined); 91 | sb.begin(); 92 | 93 | String s; 94 | float w; 95 | 96 | s = "Game Over"; 97 | w = gameOverFont.getBounds(s).width; 98 | gameOverFont.draw( 99 | sb, 100 | s, 101 | (Game.WIDTH - w) / 2, 102 | // 220 103 | dpSize3 104 | ); 105 | 106 | if (!newHighScore) { 107 | sb.end(); 108 | return; 109 | } 110 | 111 | s = "New High Score: " + Save.gd.getTentativeScore(); 112 | w = font.getBounds(s).width; 113 | font.draw( 114 | sb, 115 | s, 116 | (Game.WIDTH - w) / 2, 117 | // 180 118 | dpSize4 119 | ); 120 | 121 | for (int i = 0; i < newName.length; i++) { 122 | font.draw( 123 | sb, 124 | Character.toString(newName[i]), 125 | // 230 + 14 * i, 126 | dpSize5 + dpSize6 * i, 127 | // 120 128 | dpSize7 129 | ); 130 | } 131 | 132 | sb.end(); 133 | 134 | sr.begin(ShapeRenderer.ShapeType.Line); 135 | sr.line( 136 | // 230 + 14 * currentChar, 137 | dpSize5 + dpSize6 * currentChar, 138 | // 100, 139 | dpSize8, 140 | // 244 + 14 * currentChar, 141 | dpSize9 + dpSize6 * currentChar, 142 | // 100 143 | dpSize8 144 | ); 145 | 146 | //draw on-screen controls 147 | if (Game.isMobile) { 148 | // if (true) { 149 | sr.rect(Game.gui.getWleftBounds().getX(), Game.gui.getWleftBounds().getY(), Game.gui.getWleftBounds().getWidth(), Game.gui.getWleftBounds().getHeight()); 150 | sr.rect(Game.gui.getWrightBounds().getX(), Game.gui.getWrightBounds().getY(), Game.gui.getWrightBounds().getWidth(), Game.gui.getWrightBounds().getHeight()); 151 | sr.circle(Game.gui.getA().x, Game.gui.getA().y, Game.gui.getA().radius); 152 | sr.circle(Game.gui.getB().x, Game.gui.getB().y, Game.gui.getB().radius); 153 | sr.circle(Game.gui.getOK().x, Game.gui.getOK().y, Game.gui.getOK().radius); 154 | } 155 | sr.end(); 156 | } 157 | 158 | @Override 159 | public void handleInput() { 160 | if (!Game.isMobile) { 161 | // if (true) { 162 | if (Gdx.input.isKeyJustPressed(Input.Keys.ENTER) 163 | || Gdx.input.isKeyJustPressed(Input.Keys.SPACE)) { 164 | if (newHighScore) { 165 | Save.gd.addHighScore(Save.gd.getTentativeScore(), new String(newName)); 166 | Save.save(); 167 | } 168 | gsm.setState(GameStateManager.MENU); 169 | } 170 | if (Gdx.input.isKeyJustPressed(Input.Keys.UP) 171 | || Gdx.input.isKeyJustPressed(Input.Keys.W)) { 172 | if (newName[currentChar] == ' ') { 173 | newName[currentChar] = 'Z'; 174 | } else { 175 | newName[currentChar]--; 176 | if (newName[currentChar] < 'A') { 177 | newName[currentChar] = ' '; 178 | } 179 | } 180 | } 181 | if (Gdx.input.isKeyJustPressed(Input.Keys.DOWN) 182 | || Gdx.input.isKeyJustPressed(Input.Keys.S)) { 183 | if (newName[currentChar] == ' ') { 184 | newName[currentChar] = 'A'; 185 | } else { 186 | newName[currentChar]++; 187 | if (newName[currentChar] > 'Z') { 188 | newName[currentChar] = ' '; 189 | } 190 | } 191 | } 192 | if (Gdx.input.isKeyJustPressed(Input.Keys.RIGHT) 193 | || Gdx.input.isKeyJustPressed(Input.Keys.D)) { 194 | if (currentChar < newName.length - 1) { 195 | currentChar++; 196 | } 197 | } 198 | if (Gdx.input.isKeyJustPressed(Input.Keys.LEFT) 199 | || Gdx.input.isKeyJustPressed(Input.Keys.A)) { 200 | if (currentChar > 0) { 201 | currentChar--; 202 | } 203 | } 204 | } 205 | } 206 | 207 | private void setTouchInput() { 208 | Gdx.input.setInputProcessor(Game.gui.getStage()); 209 | //handle touch input 210 | 211 | Game.gui.getaWLeftBounds().addListener(new ClickListener() { 212 | @Override 213 | public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { 214 | if (currentChar > 0) { 215 | currentChar--; 216 | } 217 | return true; 218 | } 219 | }); 220 | 221 | Game.gui.getaWRightBounds().addListener(new ClickListener() { 222 | @Override 223 | public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { 224 | if (currentChar < newName.length - 1) { 225 | currentChar++; 226 | } 227 | return true; 228 | } 229 | }); 230 | 231 | Game.gui.getaA().addListener(new ClickListener() { 232 | @Override 233 | public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { 234 | if (newName[currentChar] == ' ') { 235 | newName[currentChar] = 'A'; 236 | } else { 237 | newName[currentChar]++; 238 | if (newName[currentChar] > 'Z') { 239 | newName[currentChar] = ' '; 240 | } 241 | } 242 | return true; 243 | } 244 | }); 245 | 246 | Game.gui.getaB().addListener(new ClickListener() { 247 | @Override 248 | public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { 249 | if (newName[currentChar] == ' ') { 250 | newName[currentChar] = 'Z'; 251 | } else { 252 | newName[currentChar]--; 253 | if (newName[currentChar] < 'A') { 254 | newName[currentChar] = ' '; 255 | } 256 | } 257 | return true; 258 | } 259 | }); 260 | 261 | Game.gui.getaOK().addListener(new ClickListener() { 262 | @Override 263 | public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { 264 | if (newHighScore) { 265 | Save.gd.addHighScore(Save.gd.getTentativeScore(), new String(newName)); 266 | Save.save(); 267 | } 268 | gsm.setState(GameStateManager.MENU); 269 | return true; 270 | } 271 | }); 272 | } 273 | 274 | @Override 275 | public void dispose() { 276 | sb.dispose(); 277 | sr.dispose(); 278 | font.dispose(); 279 | gameOverFont.dispose(); 280 | 281 | if (Game.isMobile){ 282 | Game.gui.clearListeners(); 283 | } 284 | } 285 | } 286 | -------------------------------------------------------------------------------- /core/src/ro/xzya/entities/Player.java: -------------------------------------------------------------------------------- 1 | package ro.xzya.entities; 2 | 3 | 4 | import com.badlogic.gdx.graphics.glutils.ShapeRenderer; 5 | import com.badlogic.gdx.math.MathUtils; 6 | 7 | import java.util.ArrayList; 8 | 9 | import ro.xzya.game.Game; 10 | import ro.xzya.managers.Jukebox; 11 | import ro.xzya.managers.Point2D; 12 | 13 | /** 14 | * Created by Xzya on 4/3/2015. 15 | */ 16 | public class Player extends SpaceObject { 17 | 18 | private static final float Pi = 3.1415f; 19 | private static final int dpSize1 = ((int)(Game.HEIGHT * 0.02)); 20 | private static final int dpSize2 = ((int)(Game.HEIGHT * 0.0125)); 21 | private static final int dpSize3 = ((int)(Game.HEIGHT * 0.015)); 22 | 23 | private final int MAX_BULLETS = 4; 24 | private ArrayList bullets; 25 | 26 | private float[] flamex; 27 | private float[] flamey; 28 | 29 | private boolean left; 30 | private boolean right; 31 | private boolean up; 32 | 33 | private float maxSpeed; 34 | private float acceleration; 35 | private float deceleration; 36 | private float accelerationTimer; 37 | 38 | private boolean hit; 39 | private boolean dead; 40 | 41 | private float hitTimer; 42 | private float hitTime; 43 | 44 | private Point2D[] hitLines; 45 | private Point2D[] hitLinesVector; 46 | 47 | private long score; 48 | private int extraLives; 49 | private long requiredScore; 50 | 51 | public Player(ArrayList bullets) { 52 | 53 | this.bullets = bullets; 54 | 55 | x = Game.WIDTH / 2; 56 | y = Game.HEIGHT / 2; 57 | 58 | maxSpeed = 400; 59 | acceleration = 300; 60 | deceleration = 10; 61 | 62 | shapex = new float[4]; 63 | shapey = new float[4]; 64 | 65 | flamex = new float[3]; 66 | flamey = new float[3]; 67 | 68 | hitLines = new Point2D[4]; 69 | hitLinesVector = new Point2D[4]; 70 | 71 | radians = Pi / 2; 72 | rotationSpeed = 3; 73 | 74 | hit = false; 75 | dead = false; 76 | hitTimer = 0; 77 | hitTime = 2; 78 | 79 | score = 0; 80 | extraLives = 3; 81 | requiredScore = 10000; 82 | 83 | } 84 | 85 | private void setShape() { 86 | // shapex[0] = x + MathUtils.cos(radians) * 8; 87 | // shapey[0] = y + MathUtils.sin(radians) * 8; 88 | // 89 | // shapex[1] = x + MathUtils.cos(radians - 4 * Pi / 5) * 8; 90 | // shapey[1] = y + MathUtils.sin(radians - 4 * Pi / 5) * 8; 91 | // 92 | // shapex[2] = x + MathUtils.cos(radians + Pi) * 5; 93 | // shapey[2] = y + MathUtils.sin(radians + Pi) * 5; 94 | // 95 | // shapex[3] = x + MathUtils.cos(radians + 4 * Pi / 5) * 8; 96 | // shapey[3] = y + MathUtils.sin(radians + 4 * Pi / 5) * 8; 97 | 98 | shapex[0] = x + MathUtils.cos(radians) * dpSize1; 99 | shapey[0] = y + MathUtils.sin(radians) * dpSize1; 100 | 101 | shapex[1] = x + MathUtils.cos(radians - 4 * Pi / 5) * dpSize1; 102 | shapey[1] = y + MathUtils.sin(radians - 4 * Pi / 5) * dpSize1; 103 | 104 | shapex[2] = x + MathUtils.cos(radians + Pi) * dpSize2; 105 | shapey[2] = y + MathUtils.sin(radians + Pi) * dpSize2; 106 | 107 | shapex[3] = x + MathUtils.cos(radians + 4 * Pi / 5) * dpSize1; 108 | shapey[3] = y + MathUtils.sin(radians + 4 * Pi / 5) * dpSize1; 109 | } 110 | 111 | private void setFlame() { 112 | // flamex[0] = x + MathUtils.cos(radians - 5 * Pi / 6) * 5; 113 | // flamey[0] = y + MathUtils.sin(radians - 5 * Pi / 6) * 5; 114 | // 115 | // flamex[1] = x + MathUtils.cos(radians - Pi) * (6 + accelerationTimer * 50); 116 | // flamey[1] = y + MathUtils.sin(radians - Pi) * (6 + accelerationTimer * 50); 117 | // 118 | // flamex[2] = x + MathUtils.cos(radians + 5 * Pi / 6) * 5; 119 | // flamey[2] = y + MathUtils.sin(radians + 5 * Pi / 6) * 5; 120 | 121 | flamex[0] = x + MathUtils.cos(radians - 5 * Pi / 6) * dpSize2; 122 | flamey[0] = y + MathUtils.sin(radians - 5 * Pi / 6) * dpSize2; 123 | 124 | flamex[1] = x + MathUtils.cos(radians - Pi) * (dpSize3 + accelerationTimer * 50); 125 | flamey[1] = y + MathUtils.sin(radians - Pi) * (dpSize3 + accelerationTimer * 50); 126 | 127 | flamex[2] = x + MathUtils.cos(radians + 5 * Pi / 6) * dpSize2; 128 | flamey[2] = y + MathUtils.sin(radians + 5 * Pi / 6) * dpSize2; 129 | } 130 | 131 | public void setLeft(boolean b) { 132 | left = b; 133 | } 134 | 135 | public void setRight(boolean b) { 136 | right = b; 137 | } 138 | 139 | public void setUp(boolean b) { 140 | if (b && !up && !hit) { 141 | Jukebox.loop("thruster"); 142 | } else if (!b) { 143 | Jukebox.stop("thruster"); 144 | } 145 | up = b; 146 | } 147 | 148 | public void reset() { 149 | x = Game.WIDTH / 2; 150 | y = Game.HEIGHT / 2; 151 | setShape(); 152 | hit = dead = false; 153 | } 154 | 155 | @Override 156 | public void setPosition(float x, float y) { 157 | super.setPosition(x, y); 158 | setShape(); 159 | } 160 | 161 | public boolean isHit() { 162 | return hit; 163 | } 164 | 165 | public boolean isDead() { 166 | return dead; 167 | } 168 | 169 | public long getScore() { 170 | return score; 171 | } 172 | 173 | public int getLives() { 174 | return extraLives; 175 | } 176 | 177 | public boolean isLeft() { 178 | return left; 179 | } 180 | 181 | public boolean isRight() { 182 | return right; 183 | } 184 | 185 | public boolean isUp() { 186 | return up; 187 | } 188 | 189 | public void loseLife() { 190 | extraLives--; 191 | } 192 | 193 | public void incrementScore(long l) { 194 | score += l; 195 | } 196 | 197 | public void shoot() { 198 | if ((bullets.size() == MAX_BULLETS) || hit) { 199 | return; 200 | } 201 | bullets.add(new Bullet(x, y, radians)); 202 | Jukebox.play("shoot"); 203 | } 204 | 205 | public void hit() { 206 | 207 | if (hit) return; 208 | 209 | hit = true; 210 | 211 | dx = dy = 0; 212 | left = right = up = false; 213 | Jukebox.stop("thruster"); 214 | 215 | for (int i = 0, j = hitLines.length - 1; 216 | i < hitLines.length; 217 | j = i++) { 218 | hitLines[i] = new Point2D( 219 | shapex[i], shapey[i], 220 | shapex[j], shapey[j] 221 | ); 222 | } 223 | 224 | hitLinesVector[0] = new Point2D( 225 | MathUtils.cos(radians + 1.5f), 226 | MathUtils.sin(radians + 1.5f) 227 | ); 228 | hitLinesVector[1] = new Point2D( 229 | MathUtils.cos(radians - 1.5f), 230 | MathUtils.sin(radians - 1.5f) 231 | ); 232 | hitLinesVector[2] = new Point2D( 233 | MathUtils.cos(radians - 2.8f), 234 | MathUtils.sin(radians - 2.8f) 235 | ); 236 | hitLinesVector[3] = new Point2D( 237 | MathUtils.cos(radians + 2.8f), 238 | MathUtils.sin(radians + 2.8f) 239 | ); 240 | } 241 | 242 | public void update(float dt) { 243 | 244 | //check if hit 245 | if (hit) { 246 | hitTimer += dt; 247 | if (hitTimer > hitTime) { 248 | dead = true; 249 | hitTimer = 0; 250 | } 251 | for (int i = 0; i < hitLines.length; i++) { 252 | hitLines[i].x1 = hitLines[i].x1 + hitLinesVector[i].x1 * 10 * dt; 253 | hitLines[i].y1 = hitLines[i].y1 + hitLinesVector[i].y1 * 10 * dt; 254 | hitLines[i].x2 = hitLines[i].x2 + hitLinesVector[i].x1 * 10 * dt; 255 | hitLines[i].y2 = hitLines[i].y2 + hitLinesVector[i].y1 * 10 * dt; 256 | } 257 | return; 258 | } 259 | 260 | //check extra lives 261 | if (score >= requiredScore) { 262 | extraLives++; 263 | requiredScore += 10000; 264 | Jukebox.play("extralife"); 265 | } 266 | 267 | //turning 268 | if (left) { 269 | radians += rotationSpeed * dt; 270 | } else if (right) { 271 | radians -= rotationSpeed * dt; 272 | } 273 | 274 | //accelerating 275 | if (up) { 276 | dx += MathUtils.cos(radians) * acceleration * dt; 277 | dy += MathUtils.sin(radians) * acceleration * dt; 278 | accelerationTimer += dt; 279 | if (accelerationTimer > 0.1f) { 280 | accelerationTimer = 0; 281 | } 282 | } else { 283 | accelerationTimer = 0; 284 | } 285 | 286 | //deceleration 287 | float vec = (float) Math.sqrt(dx * dx + dy * dy); 288 | if (vec > 0) { 289 | dx -= (dx / vec) * deceleration * dt; 290 | dy -= (dy / vec) * deceleration * dt; 291 | } 292 | if (vec > maxSpeed) { 293 | dx = (dx / vec) * maxSpeed; 294 | dy = (dy / vec) * maxSpeed; 295 | } 296 | 297 | //set position 298 | x += dx * dt; 299 | y += dy * dt; 300 | 301 | //set shape 302 | setShape(); 303 | 304 | //set flame 305 | if (up) { 306 | setFlame(); 307 | } 308 | 309 | //screen wrap 310 | wrap(); 311 | } 312 | 313 | public void draw(ShapeRenderer sr) { 314 | sr.setColor(1, 1, 1, 1); 315 | 316 | sr.begin(ShapeRenderer.ShapeType.Line); 317 | 318 | //check if hit 319 | if (hit) { 320 | for (int i = 0; i < hitLines.length; i++) { 321 | sr.line( 322 | hitLines[i].x1, 323 | hitLines[i].y1, 324 | hitLines[i].x2, 325 | hitLines[i].y2 326 | ); 327 | } 328 | sr.end(); 329 | return; 330 | } 331 | 332 | //draw player 333 | for (int i = 0, j = shapex.length - 1; 334 | i < shapex.length; 335 | j = i++) { 336 | sr.line(shapex[i], shapey[i], shapex[j], shapey[j]); 337 | } 338 | 339 | //draw flames 340 | if (up) { 341 | for (int i = 0, j = flamex.length - 1; 342 | i < flamex.length; 343 | j = i++) { 344 | sr.line(flamex[i], flamey[i], flamex[j], flamey[j]); 345 | } 346 | } 347 | 348 | sr.end(); 349 | } 350 | 351 | 352 | } 353 | -------------------------------------------------------------------------------- /core/src/ro/xzya/gamestates/PlayState.java: -------------------------------------------------------------------------------- 1 | package ro.xzya.gamestates; 2 | 3 | import com.badlogic.gdx.Gdx; 4 | import com.badlogic.gdx.Input; 5 | import com.badlogic.gdx.graphics.g2d.BitmapFont; 6 | import com.badlogic.gdx.graphics.g2d.SpriteBatch; 7 | import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator; 8 | import com.badlogic.gdx.graphics.glutils.ShapeRenderer; 9 | import com.badlogic.gdx.math.MathUtils; 10 | import com.badlogic.gdx.math.Vector3; 11 | import com.badlogic.gdx.scenes.scene2d.InputEvent; 12 | import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; 13 | 14 | import java.util.ArrayList; 15 | 16 | import ro.xzya.entities.Asteroid; 17 | import ro.xzya.entities.Bullet; 18 | import ro.xzya.entities.FlyingSaucer; 19 | import ro.xzya.entities.Particle; 20 | import ro.xzya.entities.Player; 21 | import ro.xzya.game.Game; 22 | import ro.xzya.managers.GameStateManager; 23 | import ro.xzya.managers.Jukebox; 24 | import ro.xzya.managers.Save; 25 | 26 | /** 27 | * Created by Xzya on 4/3/2015. 28 | */ 29 | public class PlayState extends GameState { 30 | 31 | private static final int dpSize1 = ((int) (Game.WIDTH * 0.08));//40 32 | private static final int dpSize2 = ((int) (Game.HEIGHT * 0.975));//390 33 | private static final int dpSize3 = ((int) (Game.WIDTH * 0.02));//10 34 | private static final int dpSize4 = ((int) (Game.HEIGHT * 0.9));//360 35 | 36 | private final int multiTouch = 4; 37 | private Vector3 touchPoint[]; 38 | 39 | private SpriteBatch sb; 40 | private ShapeRenderer sr; 41 | 42 | private BitmapFont font; 43 | private Player hudPlayer; 44 | 45 | private Player player; 46 | private float shootTimer; 47 | private float shootTime; 48 | 49 | private ArrayList bullets; 50 | private ArrayList asteroids; 51 | private ArrayList enemyBullets; 52 | 53 | private FlyingSaucer flyingSaucer; 54 | private float fsTimer; 55 | private float fsTime; 56 | 57 | private ArrayList particles; 58 | 59 | private int level; 60 | private int totalAsteroids; 61 | private int numAsteroidsLeft; 62 | 63 | private float maxDelay; 64 | private float minDelay; 65 | private float currentDelay; 66 | private float bgTimer; 67 | private boolean playLowPulse; 68 | 69 | public PlayState(GameStateManager _gsm) { 70 | super(_gsm); 71 | } 72 | 73 | @Override 74 | public void init() { 75 | 76 | if (Game.isMobile) { 77 | // if (true) { 78 | setTouchInput(); 79 | } 80 | 81 | sb = new SpriteBatch(); 82 | sr = new ShapeRenderer(); 83 | 84 | //set font 85 | FreeTypeFontGenerator gen = new FreeTypeFontGenerator( 86 | 87 | Gdx.files.internal("fonts/Hyperspace Bold.ttf") 88 | ); 89 | FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter(); 90 | // parameter.size = 20; 91 | parameter.size = ((int) (Game.HEIGHT * 0.05)); 92 | font = gen.generateFont(parameter); 93 | 94 | bullets = new ArrayList(); 95 | 96 | player = new Player(bullets); 97 | shootTimer = 0; 98 | shootTime = 0.2f; 99 | 100 | asteroids = new ArrayList(); 101 | 102 | particles = new ArrayList(); 103 | 104 | level = 1; 105 | spawnAsteroids(); 106 | 107 | hudPlayer = new Player(null); 108 | 109 | fsTimer = 0; 110 | fsTime = 15; 111 | enemyBullets = new ArrayList(); 112 | 113 | //set up bg music 114 | maxDelay = 1; 115 | minDelay = 0.25f; 116 | currentDelay = maxDelay; 117 | bgTimer = maxDelay; 118 | playLowPulse = true; 119 | 120 | //init touch points 121 | touchPoint = new Vector3[multiTouch]; 122 | for (int i = 0; i < multiTouch; i++) { 123 | touchPoint[i] = new Vector3(); 124 | } 125 | } 126 | 127 | private void createParticles(float x, float y) { 128 | for (int i = 0; i < 6; i++) { 129 | particles.add(new Particle(x, y)); 130 | } 131 | } 132 | 133 | private void spawnAsteroids() { 134 | asteroids.clear(); 135 | 136 | int numToSpawn = 4 + level - 1; 137 | totalAsteroids = numToSpawn * 7; //because they split when destroyed 138 | numAsteroidsLeft = totalAsteroids; 139 | currentDelay = maxDelay; 140 | 141 | for (int i = 0; i < numToSpawn; i++) { 142 | float x, y, dx, dy, dist; 143 | 144 | do { 145 | x = MathUtils.random(Game.WIDTH); 146 | y = MathUtils.random(Game.HEIGHT); 147 | dx = x - player.getx(); 148 | dy = y - player.gety(); 149 | dist = (float) Math.sqrt(dx * dx + dy * dy); 150 | } while (dist < 100); 151 | asteroids.add(new Asteroid(x, y, Asteroid.LARGE)); 152 | 153 | } 154 | 155 | } 156 | 157 | @Override 158 | public void update(float dt) { 159 | 160 | //get user input 161 | handleInput(); 162 | 163 | //next level 164 | if (asteroids.size() == 0) { 165 | level++; 166 | spawnAsteroids(); 167 | } 168 | 169 | //update player 170 | player.update(dt); 171 | if (player.isDead()) { 172 | if (player.getLives() == 0) { 173 | Jukebox.stopAll(); 174 | Save.gd.setTentativeScore(player.getScore()); 175 | gsm.setState(GameStateManager.GAME_OVER); 176 | return; 177 | } 178 | player.reset(); 179 | player.loseLife(); 180 | flyingSaucer = null; 181 | Jukebox.stop("smallsaucer"); 182 | Jukebox.stop("largesaucer"); 183 | return; 184 | } 185 | 186 | //update player bullets 187 | for (int i = 0; i < bullets.size(); i++) { 188 | bullets.get(i).update(dt); 189 | if (bullets.get(i).shouldRemove()) { 190 | bullets.remove(i); 191 | i--; 192 | } 193 | } 194 | 195 | //update flying saucer 196 | if (flyingSaucer == null) { 197 | fsTimer += dt; 198 | if (fsTimer >= fsTime) { 199 | fsTimer = 0; 200 | int type = MathUtils.random() < 0.5 ? 201 | FlyingSaucer.SMALL : FlyingSaucer.LARGE; 202 | int direction = MathUtils.random() < 0.5 ? 203 | FlyingSaucer.RIGHT : FlyingSaucer.LEFT; 204 | flyingSaucer = new FlyingSaucer( 205 | type, 206 | direction, 207 | player, 208 | enemyBullets 209 | ); 210 | } 211 | } 212 | //if there is a flying saucer already 213 | else { 214 | flyingSaucer.update(dt); 215 | if (flyingSaucer.shouldRemove()) { 216 | flyingSaucer = null; 217 | Jukebox.stop("smallsaucer"); 218 | Jukebox.stop("largesaucer"); 219 | } 220 | } 221 | 222 | //update fs bullets 223 | for (int i = 0; i < enemyBullets.size(); i++) { 224 | enemyBullets.get(i).update(dt); 225 | if (enemyBullets.get(i).shouldRemove()) { 226 | enemyBullets.remove(i); 227 | i--; 228 | } 229 | } 230 | 231 | //update asteroids 232 | for (int i = 0; i < asteroids.size(); i++) { 233 | asteroids.get(i).update(dt); 234 | if (asteroids.get(i).shouldRemove()) { 235 | asteroids.remove(i); 236 | i--; 237 | } 238 | } 239 | 240 | //update particles 241 | for (int i = 0; i < particles.size(); i++) { 242 | particles.get(i).update(dt); 243 | if (particles.get(i).shouldRemove()) { 244 | particles.remove(i); 245 | i--; 246 | } 247 | } 248 | 249 | //check collisions 250 | checkCollisions(); 251 | 252 | //play bg music 253 | bgTimer += dt; 254 | if (!player.isHit() && bgTimer >= currentDelay) { 255 | if (playLowPulse) { 256 | Jukebox.play("pulselow"); 257 | } else { 258 | Jukebox.play("pulsehigh"); 259 | } 260 | playLowPulse = !playLowPulse; 261 | bgTimer = 0; 262 | } 263 | 264 | 265 | } 266 | 267 | private void checkCollisions() { 268 | //player-asteroid collision 269 | if (!player.isHit()) { 270 | for (int i = 0; i < asteroids.size(); i++) { 271 | Asteroid a = asteroids.get(i); 272 | //if player intersects asteroid 273 | if (a.intersects(player)) { 274 | player.hit(); 275 | asteroids.remove(i); 276 | i--; 277 | splitAsteroids(a); 278 | 279 | Jukebox.play("explode"); 280 | 281 | break; 282 | } 283 | } 284 | } 285 | 286 | //bullet-asteroid collision 287 | for (int i = 0; i < bullets.size(); i++) { 288 | Bullet b = bullets.get(i); 289 | for (int j = 0; j < asteroids.size(); j++) { 290 | Asteroid a = asteroids.get(j); 291 | //if the asteroid polygon contains the point b 292 | if (a.contains(b.getx(), b.gety())) { 293 | bullets.remove(i); 294 | i--; 295 | asteroids.remove(j); 296 | j--; 297 | splitAsteroids(a); 298 | 299 | //increment player score 300 | player.incrementScore(a.getScore()); 301 | 302 | Jukebox.play("explode"); 303 | 304 | break; 305 | } 306 | } 307 | } 308 | 309 | //player-flying saucer collision 310 | if (flyingSaucer != null) { 311 | if (player.intersects(flyingSaucer)) { 312 | player.hit(); 313 | createParticles(player.getx(), player.gety()); 314 | createParticles(flyingSaucer.getx(), flyingSaucer.gety()); 315 | flyingSaucer = null; 316 | Jukebox.stop("smallsaucer"); 317 | Jukebox.stop("largesaucer"); 318 | Jukebox.stop("explode"); 319 | } 320 | } 321 | 322 | //bullet-flying saucer collision 323 | if (flyingSaucer != null) { 324 | for (int i = 0; i < bullets.size(); i++) { 325 | Bullet b = bullets.get(i); 326 | if (flyingSaucer.contains(b.getx(), b.gety())) { 327 | bullets.remove(i); 328 | i--; 329 | createParticles(flyingSaucer.getx(), flyingSaucer.gety()); 330 | player.incrementScore(flyingSaucer.getScore()); 331 | flyingSaucer = null; 332 | Jukebox.stop("smallsaucer"); 333 | Jukebox.stop("largesaucer"); 334 | Jukebox.stop("explode"); 335 | break; 336 | } 337 | } 338 | } 339 | 340 | //player-enemy bullets collision 341 | if (!player.isHit()) { 342 | for (int i = 0; i < enemyBullets.size(); i++) { 343 | Bullet b = enemyBullets.get(i); 344 | if (player.contains(b.getx(), b.gety())) { 345 | player.hit(); 346 | enemyBullets.remove(i); 347 | i--; 348 | Jukebox.play("explode"); 349 | break; 350 | } 351 | } 352 | } 353 | 354 | //flying saucer-asteroids collision 355 | if (flyingSaucer != null) { 356 | for (int i = 0; i < asteroids.size(); i++) { 357 | Asteroid a = asteroids.get(i); 358 | if (a.intersects(flyingSaucer)) { 359 | asteroids.remove(i); 360 | i--; 361 | splitAsteroids(a); 362 | createParticles(a.getx(), a.gety()); 363 | createParticles(flyingSaucer.getx(), flyingSaucer.gety()); 364 | flyingSaucer = null; 365 | Jukebox.stop("smallsaucer"); 366 | Jukebox.stop("largesaucer"); 367 | Jukebox.stop("explode"); 368 | break; 369 | } 370 | } 371 | } 372 | 373 | //asteroids-enemy bullets collision 374 | for (int i = 0; i < enemyBullets.size(); i++) { 375 | Bullet b = enemyBullets.get(i); 376 | for (int j = 0; j < asteroids.size(); j++) { 377 | Asteroid a = asteroids.get(j); 378 | if (a.contains(b.getx(), b.gety())) { 379 | asteroids.remove(j); 380 | j--; 381 | splitAsteroids(a); 382 | enemyBullets.remove(i); 383 | i--; 384 | createParticles(a.getx(), a.gety()); 385 | Jukebox.stop("explode"); 386 | break; 387 | } 388 | } 389 | } 390 | 391 | 392 | } 393 | 394 | private void splitAsteroids(Asteroid a) { 395 | createParticles(a.getx(), a.gety()); 396 | 397 | numAsteroidsLeft--; 398 | currentDelay = ((maxDelay - minDelay) * numAsteroidsLeft / totalAsteroids) + minDelay; 399 | if (a.getType() == Asteroid.LARGE) { 400 | asteroids.add(new Asteroid(a.getx(), a.gety(), Asteroid.MEDIUM)); 401 | asteroids.add(new Asteroid(a.getx(), a.gety(), Asteroid.MEDIUM)); 402 | } else if (a.getType() == Asteroid.MEDIUM) { 403 | asteroids.add(new Asteroid(a.getx(), a.gety(), Asteroid.SMALL)); 404 | asteroids.add(new Asteroid(a.getx(), a.gety(), Asteroid.SMALL)); 405 | } 406 | } 407 | 408 | @Override 409 | public void draw() { 410 | 411 | sb.setProjectionMatrix(Game.cam.combined); 412 | sr.setProjectionMatrix(Game.cam.combined); 413 | 414 | //draw player 415 | player.draw(sr); 416 | 417 | //draw player bullets 418 | for (int i = 0; i < bullets.size(); i++) { 419 | bullets.get(i).draw(sr); 420 | } 421 | 422 | //draw flying saucer 423 | if (flyingSaucer != null) { 424 | flyingSaucer.draw(sr); 425 | } 426 | 427 | //draw fs bullets 428 | for (int i = 0; i < enemyBullets.size(); i++) { 429 | enemyBullets.get(i).draw(sr); 430 | } 431 | 432 | //draw asteroids 433 | for (int i = 0; i < asteroids.size(); i++) { 434 | asteroids.get(i).draw(sr); 435 | } 436 | 437 | //draw particles 438 | for (int i = 0; i < particles.size(); i++) { 439 | particles.get(i).draw(sr); 440 | } 441 | 442 | //draw score 443 | sb.setColor(1, 1, 1, 1); 444 | sb.begin(); 445 | // font.draw(sb, Long.toString(player.getScore()), 40, 390); 446 | font.draw(sb, Long.toString(player.getScore()), dpSize1, dpSize2); 447 | sb.end(); 448 | 449 | //draw lives 450 | for (int i = 0; i < player.getLives(); i++) { 451 | // hudPlayer.setPosition(40 + i * 10, 360); 452 | hudPlayer.setPosition(dpSize1 + i * dpSize3, dpSize4); 453 | hudPlayer.draw(sr); 454 | } 455 | 456 | //draw on-screen controls 457 | if (Game.isMobile) { 458 | // if (true) { 459 | sr.begin(ShapeRenderer.ShapeType.Line); 460 | sr.rect(Game.gui.getWleftBounds().getX(), Game.gui.getWleftBounds().getY(), Game.gui.getWleftBounds().getWidth(), Game.gui.getWleftBounds().getHeight()); 461 | sr.rect(Game.gui.getWrightBounds().getX(), Game.gui.getWrightBounds().getY(), Game.gui.getWrightBounds().getWidth(), Game.gui.getWrightBounds().getHeight()); 462 | sr.rect(Game.gui.getBack().getX(), Game.gui.getBack().getY(), Game.gui.getBack().getWidth(), Game.gui.getBack().getHeight()); 463 | sr.circle(Game.gui.getA().x, Game.gui.getA().y, Game.gui.getA().radius); 464 | sr.circle(Game.gui.getB().x, Game.gui.getB().y, Game.gui.getB().radius); 465 | sr.end(); 466 | } 467 | 468 | } 469 | 470 | @Override 471 | public void handleInput() { 472 | if (!Game.isMobile) { 473 | // if (true) { 474 | if (!player.isHit()) { 475 | player.setLeft(Gdx.input.isKeyPressed(Input.Keys.LEFT) 476 | || Gdx.input.isKeyPressed(Input.Keys.A)); 477 | player.setRight(Gdx.input.isKeyPressed(Input.Keys.RIGHT) 478 | || Gdx.input.isKeyPressed(Input.Keys.D)); 479 | player.setUp(Gdx.input.isKeyPressed(Input.Keys.UP) 480 | || Gdx.input.isKeyPressed(Input.Keys.W)); 481 | if (Gdx.input.isKeyJustPressed(Input.Keys.SPACE)) { 482 | player.shoot(); 483 | } 484 | } 485 | if (Gdx.input.isKeyJustPressed(Input.Keys.ESCAPE)) { 486 | Jukebox.stopAll(); 487 | gsm.setState(GameStateManager.MENU); 488 | } 489 | } 490 | 491 | 492 | 493 | //handle touch input 494 | if (Game.isMobile) { 495 | // if (true) { 496 | shootTimer += Gdx.graphics.getDeltaTime(); 497 | player.setLeft(Game.gui.isPressedLeft()); 498 | player.setRight(Game.gui.isPressedRight()); 499 | player.setUp(Game.gui.isPressedB()); 500 | if (Game.gui.isPressedA()) { 501 | if (shootTimer >= shootTime) { 502 | shootTimer = 0; 503 | player.shoot(); 504 | } 505 | } 506 | } 507 | 508 | } 509 | 510 | private void setTouchInput() { 511 | Gdx.input.setInputProcessor(Game.gui.getStage()); 512 | //handle touch input 513 | 514 | Game.gui.getaWLeftBounds().addListener(new ClickListener() { 515 | @Override 516 | public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { 517 | Game.gui.setPressedLeft(true); 518 | return true; 519 | } 520 | 521 | @Override 522 | public void touchUp(InputEvent event, float x, float y, int pointer, int button) { 523 | Game.gui.setPressedLeft(false); 524 | } 525 | }); 526 | 527 | Game.gui.getaWRightBounds().addListener(new ClickListener() { 528 | @Override 529 | public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { 530 | Game.gui.setPressedRight(true); 531 | return true; 532 | } 533 | 534 | @Override 535 | public void touchUp(InputEvent event, float x, float y, int pointer, int button) { 536 | Game.gui.setPressedRight(false); 537 | } 538 | }); 539 | 540 | Game.gui.getaA().addListener(new ClickListener() { 541 | @Override 542 | public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { 543 | Game.gui.setPressedA(true); 544 | return true; 545 | } 546 | 547 | @Override 548 | public void touchUp(InputEvent event, float x, float y, int pointer, int button) { 549 | Game.gui.setPressedA(false); 550 | } 551 | }); 552 | 553 | Game.gui.getaB().addListener(new ClickListener() { 554 | @Override 555 | public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { 556 | Game.gui.setPressedB(true); 557 | return true; 558 | } 559 | 560 | @Override 561 | public void touchUp(InputEvent event, float x, float y, int pointer, int button) { 562 | Game.gui.setPressedB(false); 563 | } 564 | }); 565 | 566 | Game.gui.getaBack().addListener(new ClickListener() { 567 | @Override 568 | public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { 569 | Jukebox.stopAll(); 570 | gsm.setState(GameStateManager.MENU); 571 | return true; 572 | } 573 | }); 574 | 575 | } 576 | 577 | @Override 578 | public void dispose() { 579 | 580 | sb.dispose(); 581 | sr.dispose(); 582 | font.dispose(); 583 | 584 | if (Game.isMobile){ 585 | Game.gui.clearListeners(); 586 | } 587 | 588 | } 589 | } 590 | --------------------------------------------------------------------------------