├── .gitignore ├── dev-images ├── car.png └── road.png ├── swipe-race-tutorial-android ├── .classpath ├── .project ├── .settings │ └── org.eclipse.jdt.core.prefs ├── AndroidManifest.xml ├── assets │ ├── images.atlas │ └── images.png ├── libs │ ├── armeabi-v7a │ │ ├── libandroidgl20.so │ │ └── libgdx.so │ ├── armeabi │ │ ├── libandroidgl20.so │ │ └── libgdx.so │ ├── gdx-backend-android-sources.jar │ └── gdx-backend-android.jar ├── proguard.cfg ├── project.properties ├── res │ ├── drawable-hdpi │ │ └── ic_launcher.png │ ├── drawable-ldpi │ │ └── ic_launcher.png │ ├── drawable-mdpi │ │ └── ic_launcher.png │ ├── layout │ │ └── main.xml │ └── values │ │ └── strings.xml └── src │ └── com │ └── theinvader360 │ └── scene2dtutorial │ └── swiperace │ └── MainActivity.java ├── swipe-race-tutorial-desktop ├── .classpath ├── .project ├── .settings │ └── org.eclipse.jdt.core.prefs ├── libs │ ├── gdx-backend-lwjgl-natives.jar │ ├── gdx-backend-lwjgl-sources.jar │ ├── gdx-backend-lwjgl.jar │ ├── gdx-natives.jar │ └── gdx-tools.jar └── src │ └── com │ └── theinvader360 │ └── scene2dtutorial │ └── swiperace │ ├── Main.java │ └── PackTextures.java ├── swipe-race-tutorial.apk └── swipe-race-tutorial ├── .classpath ├── .project ├── .settings └── org.eclipse.jdt.core.prefs ├── libs ├── gdx-sources.jar └── gdx.jar └── src ├── SwipeRaceTutorial.gwt.xml └── com └── theinvader360 └── scene2dtutorial └── swiperace ├── Assets.java ├── EnemyCar.java ├── GameScreen.java ├── InfiniteScrollBg.java ├── MyGame.java ├── PlayerCar.java └── TrafficGame.java /.gitignore: -------------------------------------------------------------------------------- 1 | /swipe-race-tutorial/bin 2 | /swipe-race-tutorial-android/bin 3 | /swipe-race-tutorial-android/gen 4 | /swipe-race-tutorial-desktop/bin 5 | -------------------------------------------------------------------------------- /dev-images/car.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheInvader360/swipe-race-tutorial/e9319048ee0d919dd70af100592bc854c73d324d/dev-images/car.png -------------------------------------------------------------------------------- /dev-images/road.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheInvader360/swipe-race-tutorial/e9319048ee0d919dd70af100592bc854c73d324d/dev-images/road.png -------------------------------------------------------------------------------- /swipe-race-tutorial-android/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /swipe-race-tutorial-android/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | swipe-race-tutorial-android 4 | 5 | 6 | 7 | 8 | 9 | com.android.ide.eclipse.adt.ResourceManagerBuilder 10 | 11 | 12 | 13 | 14 | com.android.ide.eclipse.adt.PreCompilerBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.jdt.core.javabuilder 20 | 21 | 22 | 23 | 24 | com.android.ide.eclipse.adt.ApkBuilder 25 | 26 | 27 | 28 | 29 | 30 | com.android.ide.eclipse.adt.AndroidNature 31 | org.eclipse.jdt.core.javanature 32 | 33 | 34 | -------------------------------------------------------------------------------- /swipe-race-tutorial-android/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 3 | org.eclipse.jdt.core.compiler.compliance=1.6 4 | org.eclipse.jdt.core.compiler.source=1.6 5 | -------------------------------------------------------------------------------- /swipe-race-tutorial-android/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 12 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /swipe-race-tutorial-android/assets/images.atlas: -------------------------------------------------------------------------------- 1 | 2 | images.png 3 | format: RGBA8888 4 | filter: Linear,Linear 5 | repeat: none 6 | road 7 | rotate: false 8 | xy: 1, 1 9 | size: 120, 120 10 | orig: 120, 120 11 | offset: 0, 0 12 | index: -1 13 | car 14 | rotate: false 15 | xy: 123, 57 16 | size: 120, 64 17 | orig: 120, 64 18 | offset: 0, 0 19 | index: -1 20 | -------------------------------------------------------------------------------- /swipe-race-tutorial-android/assets/images.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheInvader360/swipe-race-tutorial/e9319048ee0d919dd70af100592bc854c73d324d/swipe-race-tutorial-android/assets/images.png -------------------------------------------------------------------------------- /swipe-race-tutorial-android/libs/armeabi-v7a/libandroidgl20.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheInvader360/swipe-race-tutorial/e9319048ee0d919dd70af100592bc854c73d324d/swipe-race-tutorial-android/libs/armeabi-v7a/libandroidgl20.so -------------------------------------------------------------------------------- /swipe-race-tutorial-android/libs/armeabi-v7a/libgdx.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheInvader360/swipe-race-tutorial/e9319048ee0d919dd70af100592bc854c73d324d/swipe-race-tutorial-android/libs/armeabi-v7a/libgdx.so -------------------------------------------------------------------------------- /swipe-race-tutorial-android/libs/armeabi/libandroidgl20.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheInvader360/swipe-race-tutorial/e9319048ee0d919dd70af100592bc854c73d324d/swipe-race-tutorial-android/libs/armeabi/libandroidgl20.so -------------------------------------------------------------------------------- /swipe-race-tutorial-android/libs/armeabi/libgdx.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheInvader360/swipe-race-tutorial/e9319048ee0d919dd70af100592bc854c73d324d/swipe-race-tutorial-android/libs/armeabi/libgdx.so -------------------------------------------------------------------------------- /swipe-race-tutorial-android/libs/gdx-backend-android-sources.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheInvader360/swipe-race-tutorial/e9319048ee0d919dd70af100592bc854c73d324d/swipe-race-tutorial-android/libs/gdx-backend-android-sources.jar -------------------------------------------------------------------------------- /swipe-race-tutorial-android/libs/gdx-backend-android.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheInvader360/swipe-race-tutorial/e9319048ee0d919dd70af100592bc854c73d324d/swipe-race-tutorial-android/libs/gdx-backend-android.jar -------------------------------------------------------------------------------- /swipe-race-tutorial-android/proguard.cfg: -------------------------------------------------------------------------------- 1 | -optimizationpasses 5 2 | -dontusemixedcaseclassnames 3 | -dontskipnonpubliclibraryclasses 4 | -dontpreverify 5 | -verbose 6 | -optimizations !code/simplification/arithmetic,!field/*,!class/merging/* 7 | 8 | -keep public class * extends android.app.Activity 9 | -keep public class * extends android.app.Application 10 | -keep public class * extends android.app.Service 11 | -keep public class * extends android.content.BroadcastReceiver 12 | -keep public class * extends android.content.ContentProvider 13 | -keep public class * extends android.app.backup.BackupAgentHelper 14 | -keep public class * extends android.preference.Preference 15 | -keep public class com.android.vending.licensing.ILicensingService 16 | 17 | -keepclasseswithmembernames class * { 18 | native ; 19 | } 20 | 21 | -keepclasseswithmembers class * { 22 | public (android.content.Context, android.util.AttributeSet); 23 | } 24 | 25 | -keepclasseswithmembers class * { 26 | public (android.content.Context, android.util.AttributeSet, int); 27 | } 28 | 29 | -keepclassmembers class * extends android.app.Activity { 30 | public void *(android.view.View); 31 | } 32 | 33 | -keepclassmembers enum * { 34 | public static **[] values(); 35 | public static ** valueOf(java.lang.String); 36 | } 37 | 38 | -keep class * implements android.os.Parcelable { 39 | public static final android.os.Parcelable$Creator *; 40 | } 41 | -------------------------------------------------------------------------------- /swipe-race-tutorial-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 use, 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | 10 | # Project target. 11 | target=android-15 12 | -------------------------------------------------------------------------------- /swipe-race-tutorial-android/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheInvader360/swipe-race-tutorial/e9319048ee0d919dd70af100592bc854c73d324d/swipe-race-tutorial-android/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /swipe-race-tutorial-android/res/drawable-ldpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheInvader360/swipe-race-tutorial/e9319048ee0d919dd70af100592bc854c73d324d/swipe-race-tutorial-android/res/drawable-ldpi/ic_launcher.png -------------------------------------------------------------------------------- /swipe-race-tutorial-android/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheInvader360/swipe-race-tutorial/e9319048ee0d919dd70af100592bc854c73d324d/swipe-race-tutorial-android/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /swipe-race-tutorial-android/res/layout/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | -------------------------------------------------------------------------------- /swipe-race-tutorial-android/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | My LibGDX Game 4 | -------------------------------------------------------------------------------- /swipe-race-tutorial-android/src/com/theinvader360/scene2dtutorial/swiperace/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.theinvader360.scene2dtutorial.swiperace; 2 | 3 | import android.app.Dialog; 4 | import android.content.Intent; 5 | import android.net.Uri; 6 | import android.os.Bundle; 7 | import android.view.View; 8 | import android.view.View.OnClickListener; 9 | import android.widget.Button; 10 | import android.widget.LinearLayout; 11 | import android.widget.TableLayout; 12 | import android.widget.TableRow; 13 | import android.widget.TextView; 14 | 15 | import com.badlogic.gdx.backends.android.AndroidApplication; 16 | import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration; 17 | 18 | public class MainActivity extends AndroidApplication { 19 | @Override 20 | public void onCreate(Bundle savedInstanceState) { 21 | super.onCreate(savedInstanceState); 22 | 23 | AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration(); 24 | cfg.useGL20 = false; 25 | 26 | initialize(new MyGame(), cfg); 27 | } 28 | 29 | public void onBackPressed() { 30 | final Dialog dialog = new Dialog(this); 31 | dialog.setTitle("More by TheInvader360"); 32 | 33 | LinearLayout ll = new LinearLayout(this); 34 | ll.setOrientation(LinearLayout.VERTICAL); 35 | 36 | TableLayout tl = new TableLayout(this); 37 | TableRow tr1 = new TableRow(this); 38 | TableRow tr2 = new TableRow(this); 39 | 40 | Button b1 = new Button(this); 41 | b1.setText("Games"); 42 | b1.setOnClickListener(new OnClickListener() { 43 | public void onClick(View v) { 44 | startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=pub:TheInvader360"))); 45 | dialog.dismiss(); 46 | } 47 | }); 48 | tr1.addView(b1); 49 | 50 | Button b2 = new Button(this); 51 | b2.setText("Blog"); 52 | b2.setOnClickListener(new OnClickListener() { 53 | public void onClick(View v) { 54 | startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://theinvader360.blogspot.co.uk"))); 55 | dialog.dismiss(); 56 | } 57 | }); 58 | tr1.addView(b2); 59 | 60 | Button b3 = new Button(this); 61 | b3.setText("Github"); 62 | b3.setOnClickListener(new OnClickListener() { 63 | public void onClick(View v) { 64 | startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://github.com/theinvader360"))); 65 | dialog.dismiss(); 66 | } 67 | }); 68 | tr1.addView(b3); 69 | 70 | tl.addView(tr1); 71 | 72 | Button b4 = new Button(this); 73 | b4.setText("Facebook"); 74 | b4.setOnClickListener(new OnClickListener() { 75 | public void onClick(View v) { 76 | startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.facebook.com/TheInvader360"))); 77 | dialog.dismiss(); 78 | } 79 | }); 80 | tr2.addView(b4); 81 | 82 | Button b5 = new Button(this); 83 | b5.setText("Twitter"); 84 | b5.setOnClickListener(new OnClickListener() { 85 | public void onClick(View v) { 86 | startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://twitter.com/TheInvader360"))); 87 | dialog.dismiss(); 88 | } 89 | }); 90 | tr2.addView(b5); 91 | 92 | Button b6 = new Button(this); 93 | b6.setText("Youtube"); 94 | b6.setOnClickListener(new OnClickListener() { 95 | public void onClick(View v) { 96 | startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com/theinvader360"))); 97 | dialog.dismiss(); 98 | } 99 | }); 100 | tr2.addView(b6); 101 | 102 | tl.addView(tr2); 103 | 104 | ll.addView(tl); 105 | 106 | TextView tv = new TextView(this); 107 | tv.setText("TheInvader360 is an independent game developer making small, fun, casual games for mobile devices. Thanks for your support :)"); 108 | tv.setPadding(4, 0, 4, 10); 109 | ll.addView(tv); 110 | 111 | Button b7 = new Button(this); 112 | b7.setText("Quit"); 113 | b7.setOnClickListener(new OnClickListener() { 114 | public void onClick(View v) { 115 | finish(); 116 | } 117 | }); 118 | ll.addView(b7); 119 | 120 | dialog.setContentView(ll); 121 | dialog.show(); 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /swipe-race-tutorial-desktop/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /swipe-race-tutorial-desktop/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | swipe-race-tutorial-desktop 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | 19 | assets 20 | 2 21 | PARENT-1-PROJECT_LOC/swipe-race-tutorial-android/assets 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /swipe-race-tutorial-desktop/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 5 | org.eclipse.jdt.core.compiler.compliance=1.6 6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 11 | org.eclipse.jdt.core.compiler.source=1.6 12 | -------------------------------------------------------------------------------- /swipe-race-tutorial-desktop/libs/gdx-backend-lwjgl-natives.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheInvader360/swipe-race-tutorial/e9319048ee0d919dd70af100592bc854c73d324d/swipe-race-tutorial-desktop/libs/gdx-backend-lwjgl-natives.jar -------------------------------------------------------------------------------- /swipe-race-tutorial-desktop/libs/gdx-backend-lwjgl-sources.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheInvader360/swipe-race-tutorial/e9319048ee0d919dd70af100592bc854c73d324d/swipe-race-tutorial-desktop/libs/gdx-backend-lwjgl-sources.jar -------------------------------------------------------------------------------- /swipe-race-tutorial-desktop/libs/gdx-backend-lwjgl.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheInvader360/swipe-race-tutorial/e9319048ee0d919dd70af100592bc854c73d324d/swipe-race-tutorial-desktop/libs/gdx-backend-lwjgl.jar -------------------------------------------------------------------------------- /swipe-race-tutorial-desktop/libs/gdx-natives.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheInvader360/swipe-race-tutorial/e9319048ee0d919dd70af100592bc854c73d324d/swipe-race-tutorial-desktop/libs/gdx-natives.jar -------------------------------------------------------------------------------- /swipe-race-tutorial-desktop/libs/gdx-tools.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheInvader360/swipe-race-tutorial/e9319048ee0d919dd70af100592bc854c73d324d/swipe-race-tutorial-desktop/libs/gdx-tools.jar -------------------------------------------------------------------------------- /swipe-race-tutorial-desktop/src/com/theinvader360/scene2dtutorial/swiperace/Main.java: -------------------------------------------------------------------------------- 1 | package com.theinvader360.scene2dtutorial.swiperace; 2 | 3 | import com.badlogic.gdx.backends.lwjgl.LwjglApplication; 4 | import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration; 5 | 6 | public class Main { 7 | public static void main(String[] args) { 8 | LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration(); 9 | cfg.title = "swipe-race-tutorial"; 10 | cfg.useGL20 = false; 11 | cfg.width = 800; 12 | cfg.height = 480; 13 | 14 | new LwjglApplication(new MyGame(), cfg); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /swipe-race-tutorial-desktop/src/com/theinvader360/scene2dtutorial/swiperace/PackTextures.java: -------------------------------------------------------------------------------- 1 | package com.theinvader360.scene2dtutorial.swiperace; 2 | 3 | import com.badlogic.gdx.graphics.Texture.TextureFilter; 4 | import com.badlogic.gdx.tools.imagepacker.TexturePacker2; 5 | import com.badlogic.gdx.tools.imagepacker.TexturePacker2.Settings; 6 | 7 | public class PackTextures { 8 | public static void main(String[] args) { 9 | Settings settings = new Settings(); 10 | settings.filterMin = TextureFilter.Linear; 11 | settings.filterMag = TextureFilter.Linear; 12 | TexturePacker2.process(settings, "../dev-images", "../swipe-race-tutorial-android/assets", "images"); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /swipe-race-tutorial.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheInvader360/swipe-race-tutorial/e9319048ee0d919dd70af100592bc854c73d324d/swipe-race-tutorial.apk -------------------------------------------------------------------------------- /swipe-race-tutorial/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /swipe-race-tutorial/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | swipe-race-tutorial 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /swipe-race-tutorial/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 5 | org.eclipse.jdt.core.compiler.compliance=1.6 6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 11 | org.eclipse.jdt.core.compiler.source=1.6 12 | -------------------------------------------------------------------------------- /swipe-race-tutorial/libs/gdx-sources.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheInvader360/swipe-race-tutorial/e9319048ee0d919dd70af100592bc854c73d324d/swipe-race-tutorial/libs/gdx-sources.jar -------------------------------------------------------------------------------- /swipe-race-tutorial/libs/gdx.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheInvader360/swipe-race-tutorial/e9319048ee0d919dd70af100592bc854c73d324d/swipe-race-tutorial/libs/gdx.jar -------------------------------------------------------------------------------- /swipe-race-tutorial/src/SwipeRaceTutorial.gwt.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /swipe-race-tutorial/src/com/theinvader360/scene2dtutorial/swiperace/Assets.java: -------------------------------------------------------------------------------- 1 | package com.theinvader360.scene2dtutorial.swiperace; 2 | 3 | import com.badlogic.gdx.Gdx; 4 | import com.badlogic.gdx.graphics.g2d.TextureAtlas; 5 | import com.badlogic.gdx.graphics.g2d.TextureRegion; 6 | 7 | public class Assets { 8 | public static TextureAtlas atlas; 9 | public static TextureRegion car; 10 | public static TextureRegion road; 11 | 12 | public static void load() { 13 | atlas = new TextureAtlas(Gdx.files.internal("images.atlas")); 14 | car = atlas.findRegion("car"); 15 | road = atlas.findRegion("road"); 16 | } 17 | 18 | public static void dispose() { 19 | atlas.dispose(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /swipe-race-tutorial/src/com/theinvader360/scene2dtutorial/swiperace/EnemyCar.java: -------------------------------------------------------------------------------- 1 | package com.theinvader360.scene2dtutorial.swiperace; 2 | 3 | import static com.badlogic.gdx.scenes.scene2d.actions.Actions.*; 4 | import com.badlogic.gdx.graphics.Color; 5 | import com.badlogic.gdx.graphics.g2d.SpriteBatch; 6 | import com.badlogic.gdx.math.MathUtils; 7 | import com.badlogic.gdx.math.Rectangle; 8 | import com.badlogic.gdx.scenes.scene2d.Actor; 9 | 10 | public class EnemyCar extends Actor { 11 | private Rectangle bounds = new Rectangle(); 12 | 13 | public EnemyCar(float x, float y) { 14 | setWidth(160); 15 | setHeight(85); 16 | setPosition(x, y - getHeight()/2); 17 | 18 | int rnd = MathUtils.random(0, 3); 19 | if (rnd == 0) setColor(Color.RED); 20 | if (rnd == 1) setColor(Color.GREEN); 21 | if (rnd == 2) setColor(Color.WHITE); 22 | if (rnd == 3) setColor(Color.BLUE); 23 | 24 | addAction(moveTo(-getWidth(), getY(), MathUtils.random(4.0f, 6.0f))); 25 | } 26 | 27 | @Override 28 | public void act(float delta){ 29 | super.act(delta); 30 | updateBounds(); 31 | } 32 | 33 | @Override 34 | public void draw(SpriteBatch batch, float parentAlpha) { 35 | batch.setColor(getColor().r, getColor().g, getColor().b, getColor().a); 36 | batch.draw(Assets.car, getX(), getY(), getWidth()/2, getHeight()/2, getWidth(), getHeight(), 1, 1, getRotation()); 37 | } 38 | 39 | private void updateBounds() { 40 | bounds.set(getX(), getY(), getWidth(), getHeight()); 41 | } 42 | 43 | public void crash(boolean front, boolean above) { 44 | clearActions(); 45 | addAction(fadeOut(1f)); 46 | if (front && above) addAction(sequence(parallel(rotateBy(-360, 1.5f), moveBy(200, 200, 1.5f)), removeActor())); 47 | if (front && !above) addAction(sequence(parallel(rotateBy(360, 1.5f), moveBy(200, -200, 1.5f)), removeActor())); 48 | if (!front && above) addAction(sequence(parallel(rotateBy(360, 1.5f), moveBy(-200, 200, 1.5f)), removeActor())); 49 | if (!front && !above) addAction(sequence(parallel(rotateBy(-360, 1.5f), moveBy(-200, -200, 1.5f)), removeActor())); 50 | } 51 | 52 | public Rectangle getBounds() { 53 | return bounds; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /swipe-race-tutorial/src/com/theinvader360/scene2dtutorial/swiperace/GameScreen.java: -------------------------------------------------------------------------------- 1 | package com.theinvader360.scene2dtutorial.swiperace; 2 | 3 | import com.badlogic.gdx.Gdx; 4 | import com.badlogic.gdx.Screen; 5 | import com.badlogic.gdx.graphics.GL10; 6 | import com.badlogic.gdx.input.GestureDetector; 7 | import com.badlogic.gdx.input.GestureDetector.GestureListener; 8 | import com.badlogic.gdx.math.Vector2; 9 | import com.badlogic.gdx.scenes.scene2d.Stage; 10 | 11 | public class GameScreen implements Screen, GestureListener { 12 | private Stage stage; 13 | private TrafficGame trafficGame; 14 | 15 | public GameScreen() { 16 | stage = new Stage(); 17 | trafficGame = new TrafficGame(); 18 | stage.addActor(trafficGame); 19 | } 20 | 21 | public void resize(int width, int height) { 22 | stage.setViewport(MyGame.WIDTH, MyGame.HEIGHT, true); 23 | stage.getCamera().translate(-stage.getGutterWidth(), -stage.getGutterHeight(), 0); 24 | } 25 | 26 | @Override 27 | public void render(float delta) { 28 | Gdx.gl.glClearColor(0, 0, 0, 1); 29 | Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); 30 | stage.act(delta); 31 | stage.draw(); 32 | } 33 | 34 | @Override 35 | public void show() { 36 | Gdx.input.setInputProcessor(new GestureDetector(this)); 37 | } 38 | 39 | @Override 40 | public void hide() { 41 | Gdx.input.setInputProcessor(null); 42 | } 43 | 44 | @Override 45 | public boolean fling(float velocityX, float velocityY, int button) { 46 | if (velocityY < -100) trafficGame.playerCar.tryMoveUp(); 47 | if (velocityY > 100) trafficGame.playerCar.tryMoveDown(); 48 | return false; 49 | } 50 | 51 | @Override public void resume() {} 52 | @Override public void pause() {} 53 | @Override public void dispose() {} 54 | @Override public boolean tap(float x, float y, int count, int button) {return false;} 55 | @Override public boolean touchDown(float x, float y, int pointer, int button) {return false;} 56 | @Override public boolean longPress(float x, float y) {return false;} 57 | @Override public boolean pan(float x, float y, float deltaX, float deltaY) {return false;} 58 | @Override public boolean zoom(float initialDistance, float distance) {return false;} 59 | @Override public boolean pinch(Vector2 initialPointer1, Vector2 initialPointer2, Vector2 pointer1, Vector2 pointer2) {return false;} 60 | 61 | } 62 | -------------------------------------------------------------------------------- /swipe-race-tutorial/src/com/theinvader360/scene2dtutorial/swiperace/InfiniteScrollBg.java: -------------------------------------------------------------------------------- 1 | package com.theinvader360.scene2dtutorial.swiperace; 2 | 3 | import static com.badlogic.gdx.scenes.scene2d.actions.Actions.*; 4 | import com.badlogic.gdx.graphics.g2d.SpriteBatch; 5 | import com.badlogic.gdx.scenes.scene2d.Actor; 6 | 7 | public class InfiniteScrollBg extends Actor { 8 | public InfiniteScrollBg(float width, float height) { 9 | setWidth(width); 10 | setHeight(height); 11 | setPosition(width, 0); 12 | addAction(forever(sequence(moveTo(0, 0, 1f), moveTo(width, 0)))); 13 | } 14 | 15 | @Override 16 | public void draw(SpriteBatch batch, float parentAlpha) { 17 | super.draw(batch, parentAlpha); 18 | batch.draw(Assets.road, getX()-getWidth(), getY(), getWidth() * 2, getHeight()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /swipe-race-tutorial/src/com/theinvader360/scene2dtutorial/swiperace/MyGame.java: -------------------------------------------------------------------------------- 1 | package com.theinvader360.scene2dtutorial.swiperace; 2 | 3 | import com.badlogic.gdx.Game; 4 | 5 | public class MyGame extends Game { 6 | public final static int WIDTH = 800; 7 | public final static int HEIGHT = 480; 8 | private GameScreen gameScreen; 9 | 10 | @Override 11 | public void create() { 12 | Assets.load(); 13 | gameScreen = new GameScreen(); 14 | setScreen(gameScreen); 15 | } 16 | 17 | @Override 18 | public void dispose() { 19 | Assets.dispose(); 20 | gameScreen.dispose(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /swipe-race-tutorial/src/com/theinvader360/scene2dtutorial/swiperace/PlayerCar.java: -------------------------------------------------------------------------------- 1 | package com.theinvader360.scene2dtutorial.swiperace; 2 | 3 | import static com.badlogic.gdx.scenes.scene2d.actions.Actions.*; 4 | import com.badlogic.gdx.graphics.Color; 5 | import com.badlogic.gdx.graphics.g2d.SpriteBatch; 6 | import com.badlogic.gdx.math.Rectangle; 7 | import com.badlogic.gdx.scenes.scene2d.Actor; 8 | 9 | public class PlayerCar extends Actor { 10 | private TrafficGame trafficGame; 11 | private Rectangle bounds = new Rectangle(); 12 | private int lane; 13 | 14 | public PlayerCar(TrafficGame trafficGame) { 15 | this.trafficGame = trafficGame; 16 | setWidth(160); 17 | setHeight(85); 18 | lane = 1; 19 | setPosition(100, trafficGame.lane1 - getHeight()/2); 20 | setColor(Color.YELLOW); 21 | } 22 | 23 | @Override 24 | public void act(float delta){ 25 | super.act(delta); 26 | updateBounds(); 27 | } 28 | 29 | @Override 30 | public void draw(SpriteBatch batch, float parentAlpha) { 31 | batch.setColor(getColor().r, getColor().g, getColor().b, getColor().a); 32 | batch.draw(Assets.car, getX(), getY(), getWidth()/2, getHeight()/2, getWidth(), getHeight(), 1, 1, getRotation()); 33 | } 34 | 35 | private void updateBounds() { 36 | bounds.set(getX(), getY(), getWidth(), getHeight()); 37 | } 38 | 39 | public void tryMoveUp() { 40 | if ((getActions().size == 0) && (lane != 2)) moveToLane(lane+1); 41 | } 42 | 43 | public void tryMoveDown() { 44 | if ((getActions().size == 0) && (lane != 0)) moveToLane(lane-1); 45 | } 46 | 47 | private void moveToLane(int lane) { 48 | this.lane = lane; 49 | 50 | switch (lane) { 51 | case 0: 52 | addAction(moveTo(getX(), trafficGame.lane0 - getHeight()/2, 0.5f)); 53 | break; 54 | case 1: 55 | addAction(moveTo(getX(), trafficGame.lane1 - getHeight()/2, 0.5f)); 56 | break; 57 | case 2: 58 | addAction(moveTo(getX(), trafficGame.lane2 - getHeight()/2, 0.5f)); 59 | break; 60 | } 61 | } 62 | 63 | public Rectangle getBounds() { 64 | return bounds; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /swipe-race-tutorial/src/com/theinvader360/scene2dtutorial/swiperace/TrafficGame.java: -------------------------------------------------------------------------------- 1 | package com.theinvader360.scene2dtutorial.swiperace; 2 | 3 | import java.util.Iterator; 4 | import com.badlogic.gdx.graphics.Color; 5 | import com.badlogic.gdx.graphics.g2d.SpriteBatch; 6 | import com.badlogic.gdx.math.MathUtils; 7 | import com.badlogic.gdx.scenes.scene2d.ui.Table; 8 | import com.badlogic.gdx.utils.Array; 9 | import com.badlogic.gdx.utils.TimeUtils; 10 | 11 | public class TrafficGame extends Table { 12 | private InfiniteScrollBg backgroundRoad; 13 | private Array enemyCars; 14 | private long lastCarTime = 0; 15 | public final float lane2 = 390; 16 | public final float lane1 = 240; 17 | public final float lane0 = 90; 18 | public PlayerCar playerCar; 19 | 20 | public TrafficGame() { 21 | setBounds(0, 0, 800, 480); 22 | setClip(true); 23 | backgroundRoad = new InfiniteScrollBg(getWidth(),getHeight()); 24 | addActor(backgroundRoad); 25 | playerCar = new PlayerCar(this); 26 | addActor(playerCar); 27 | enemyCars = new Array(); 28 | } 29 | 30 | @Override 31 | public void act(float delta) { 32 | super.act(delta); 33 | 34 | if (TimeUtils.nanoTime() - lastCarTime > 3000000000f) spawnCar(); 35 | 36 | Iterator iter = enemyCars.iterator(); 37 | while (iter.hasNext()) { 38 | EnemyCar enemyCar = iter.next(); 39 | if (enemyCar.getBounds().x + enemyCar.getWidth() <= 0) { 40 | iter.remove(); 41 | removeActor(enemyCar); 42 | } 43 | if (enemyCar.getBounds().overlaps(playerCar.getBounds())) { 44 | iter.remove(); 45 | if (enemyCar.getX() > playerCar.getX()) { 46 | if (enemyCar.getY() > playerCar.getY()) enemyCar.crash(true, true); 47 | else enemyCar.crash(true, false); 48 | } 49 | else { 50 | if (enemyCar.getY() > playerCar.getY()) enemyCar.crash(false, true); 51 | else enemyCar.crash(false, false); 52 | } 53 | } 54 | } 55 | } 56 | 57 | private void spawnCar() { 58 | int lane = MathUtils.random(0, 2); 59 | float yPos = 0; 60 | if (lane == 0) yPos = lane0; 61 | if (lane == 1) yPos = lane1; 62 | if (lane == 2) yPos = lane2; 63 | EnemyCar enemyCar = new EnemyCar(getWidth(), yPos); 64 | enemyCars.add(enemyCar); 65 | addActor(enemyCar); 66 | lastCarTime = TimeUtils.nanoTime(); 67 | } 68 | 69 | @Override 70 | public void draw(SpriteBatch batch, float parentAlpha) { 71 | batch.setColor(Color.WHITE); 72 | super.draw(batch, parentAlpha); 73 | } 74 | } 75 | --------------------------------------------------------------------------------