├── .gitignore
├── LICENSE
├── README.md
├── codelabs-android
├── .classpath
├── .project
├── .settings
│ └── org.eclipse.jdt.core.prefs
├── AndroidManifest.xml
├── assets
│ └── data
│ │ ├── fonts
│ │ ├── Righteous-12.fnt
│ │ ├── Righteous-16.fnt
│ │ ├── Righteous-24.fnt
│ │ └── righteous.png
│ │ ├── images
│ │ ├── codelabs_splash.png
│ │ ├── crab.png
│ │ └── github_splash.png
│ │ └── ui
│ │ ├── atlas.pack
│ │ ├── atlas.png
│ │ └── menu_skin.json
├── gen
│ └── com
│ │ └── leakedbits
│ │ └── codelabs
│ │ └── BuildConfig.java
├── ic_launcher-web.png
├── libs
│ ├── armeabi-v7a
│ │ └── libgdx.so
│ ├── armeabi
│ │ └── libgdx.so
│ ├── gdx-backend-android-sources.jar
│ ├── gdx-backend-android.jar
│ └── x86
│ │ └── libgdx.so
├── proguard.cfg
├── project.properties
├── res
│ ├── drawable-hdpi
│ │ └── ic_launcher.png
│ ├── drawable-ldpi
│ │ └── ic_launcher.png
│ ├── drawable-mdpi
│ │ └── ic_launcher.png
│ ├── drawable-xhdpi
│ │ └── ic_launcher.png
│ ├── drawable-xxhdpi
│ │ └── ic_launcher.png
│ ├── layout
│ │ └── main.xml
│ └── values
│ │ └── strings.xml
└── src
│ └── com
│ └── leakedbits
│ └── codelabs
│ └── MainActivity.java
├── codelabs-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
└── src
│ └── com
│ └── leakedbits
│ └── codelabs
│ └── Main.java
└── codelabs
├── .classpath
├── .project
├── .settings
└── org.eclipse.jdt.core.prefs
├── libs
├── gdx-sources.jar
└── gdx.jar
└── src
├── Codelabs.gwt.xml
└── com
└── leakedbits
└── codelabs
├── Codelabs.java
├── MainMenu.java
├── SplashScreen.java
├── box2d
├── BouncingBallSample.java
├── BuoyancySample.java
├── CollisionsSample.java
├── DragAndDropSample.java
├── GravityAccelerometerSample.java
├── ImpulsesSample.java
├── JumpingSample.java
├── SpawnBodiesSample.java
├── SpritesSample.java
├── controllers
│ └── BuoyancyController.java
└── utils
│ ├── Box2DFactory.java
│ ├── Box2DSamples.java
│ └── PolygonProperties.java
└── utils
├── PolygonIntersector.java
├── Sample.java
└── SampleUtils.java
/.gitignore:
--------------------------------------------------------------------------------
1 | # and2
2 | nightly/libs
3 | bitz/data/*
4 |
5 | ignore/*
6 |
7 | .DS_Store
8 | */.DS_Store
9 | **/**/.DS_Store
10 |
11 | .metadata
12 | */.metadata
13 |
14 | */bin/**
15 | */tmp/**
16 | */tmp/**/*
17 | *.tmp
18 | *.bak
19 | *.swp
20 | *~.nib
21 |
22 | RemoteSystemsTempFiles/
23 |
24 | # android specific
25 | # */gen/* ### we want these!
26 | */bin
27 |
28 | # files for the dex VM
29 | *.dex
30 |
31 | # Java class files
32 | *.class
33 |
34 | # generated GUI files
35 | *R.java
36 |
37 | ### eclipse files we DO want
38 | # local.properties
39 | # */.loadpath
40 | # classpath
41 | # settings
42 |
43 | codelabs-desktop/assets/*
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 Leakedbits
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Leakedbits Codelabs
2 | ===================
3 | All source code of our Android app, Codelabs, is stored here for you to look, download, test, fork and admire!
4 |
5 | Do you want to start coding with libGDX but it seems impossible to you? Since there are not enough examples on the Internet, we are offering them to you. So go ahead, maybe with our help you will become a succesful libGDX developer!
6 |
7 |
8 | Take a look at our [Codelabs app] (https://play.google.com/store/apps/details?id=com.leakedbits.codelabs) at Google Play and its [changelog](https://github.com/Leakedbits/Codelabs/wiki/Changelog)!
9 |
10 |
Available demos and code so far
11 |
12 | Ckeck out a further explaination of them in [our Wiki](https://github.com/Leakedbits/Codelabs/wiki)!
13 |
--------------------------------------------------------------------------------
/codelabs-android/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/codelabs-android/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | codelabs-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 |
--------------------------------------------------------------------------------
/codelabs-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 |
--------------------------------------------------------------------------------
/codelabs-android/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
12 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/codelabs-android/assets/data/fonts/Righteous-12.fnt:
--------------------------------------------------------------------------------
1 | info face="Righteous" size=12 bold=0 italic=0 charset="" unicode=1 stretchH=100 smooth=1 aa=2 padding=0,0,0,0 spacing=0,0
2 | common lineHeight=15 base=12 scaleW=256 scaleH=256 pages=1 packed=0 alphaChnl=0 redChnl=0 greenChnl=0 blueChnl=0
3 | page id=0 file="righteous.png"
4 | chars count=96
5 | char id=10 x=15 y=62 width=0 height=0 xoffset=0 yoffset=12 xadvance=3 page=0 chnl=0
6 | char id=32 x=0 y=0 width=0 height=0 xoffset=0 yoffset=0 xadvance=3 page=0 chnl=0
7 | char id=33 x=74 y=89 width=3 height=9 xoffset=0 yoffset=3 xadvance=3 page=0 chnl=0
8 | char id=34 x=104 y=35 width=5 height=3 xoffset=0 yoffset=3 xadvance=5 page=0 chnl=0
9 | char id=35 x=182 y=107 width=7 height=8 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=0
10 | char id=36 x=109 y=242 width=5 height=9 xoffset=0 yoffset=3 xadvance=6 page=0 chnl=0
11 | char id=37 x=172 y=107 width=8 height=9 xoffset=1 yoffset=3 xadvance=9 page=0 chnl=0
12 | char id=38 x=191 y=107 width=5 height=9 xoffset=1 yoffset=3 xadvance=6 page=0 chnl=0
13 | char id=39 x=32 y=76 width=3 height=3 xoffset=0 yoffset=3 xadvance=3 page=0 chnl=0
14 | char id=40 x=73 y=232 width=4 height=12 xoffset=1 yoffset=1 xadvance=5 page=0 chnl=0
15 | char id=41 x=109 y=140 width=4 height=12 xoffset=0 yoffset=1 xadvance=4 page=0 chnl=0
16 | char id=42 x=221 y=98 width=7 height=7 xoffset=0 yoffset=1 xadvance=7 page=0 chnl=0
17 | char id=43 x=214 y=98 width=5 height=5 xoffset=1 yoffset=5 xadvance=7 page=0 chnl=0
18 | char id=44 x=47 y=178 width=2 height=4 xoffset=1 yoffset=10 xadvance=3 page=0 chnl=0
19 | char id=45 x=226 y=16 width=5 height=2 xoffset=1 yoffset=6 xadvance=7 page=0 chnl=0
20 | char id=46 x=221 y=16 width=3 height=2 xoffset=0 yoffset=10 xadvance=3 page=0 chnl=0
21 | char id=47 x=109 y=220 width=6 height=9 xoffset=0 yoffset=3 xadvance=6 page=0 chnl=0
22 | char id=48 x=154 y=107 width=7 height=9 xoffset=1 yoffset=3 xadvance=8 page=0 chnl=0
23 | char id=49 x=252 y=40 width=3 height=9 xoffset=0 yoffset=3 xadvance=3 page=0 chnl=0
24 | char id=50 x=100 y=236 width=6 height=9 xoffset=1 yoffset=3 xadvance=8 page=0 chnl=0
25 | char id=51 x=109 y=107 width=6 height=9 xoffset=1 yoffset=3 xadvance=8 page=0 chnl=0
26 | char id=52 x=117 y=107 width=8 height=9 xoffset=0 yoffset=3 xadvance=8 page=0 chnl=0
27 | char id=53 x=109 y=118 width=6 height=9 xoffset=1 yoffset=3 xadvance=8 page=0 chnl=0
28 | char id=54 x=127 y=107 width=7 height=9 xoffset=1 yoffset=3 xadvance=8 page=0 chnl=0
29 | char id=55 x=109 y=129 width=6 height=9 xoffset=0 yoffset=3 xadvance=6 page=0 chnl=0
30 | char id=56 x=136 y=107 width=7 height=9 xoffset=1 yoffset=3 xadvance=8 page=0 chnl=0
31 | char id=57 x=145 y=107 width=7 height=9 xoffset=1 yoffset=3 xadvance=8 page=0 chnl=0
32 | char id=58 x=73 y=127 width=3 height=6 xoffset=0 yoffset=6 xadvance=3 page=0 chnl=0
33 | char id=59 x=73 y=118 width=3 height=7 xoffset=0 yoffset=7 xadvance=3 page=0 chnl=0
34 | char id=60 x=100 y=247 width=6 height=8 xoffset=0 yoffset=3 xadvance=6 page=0 chnl=0
35 | char id=61 x=58 y=251 width=5 height=4 xoffset=1 yoffset=5 xadvance=7 page=0 chnl=0
36 | char id=62 x=109 y=210 width=6 height=8 xoffset=0 yoffset=3 xadvance=6 page=0 chnl=0
37 | char id=63 x=163 y=107 width=7 height=9 xoffset=1 yoffset=3 xadvance=8 page=0 chnl=0
38 | char id=64 x=205 y=98 width=7 height=7 xoffset=1 yoffset=5 xadvance=9 page=0 chnl=0
39 | char id=65 x=176 y=73 width=7 height=9 xoffset=1 yoffset=3 xadvance=8 page=0 chnl=0
40 | char id=66 x=185 y=73 width=7 height=9 xoffset=1 yoffset=3 xadvance=8 page=0 chnl=0
41 | char id=67 x=194 y=73 width=8 height=9 xoffset=1 yoffset=3 xadvance=8 page=0 chnl=0
42 | char id=68 x=204 y=73 width=7 height=9 xoffset=1 yoffset=3 xadvance=8 page=0 chnl=0
43 | char id=69 x=213 y=73 width=6 height=9 xoffset=1 yoffset=3 xadvance=8 page=0 chnl=0
44 | char id=70 x=221 y=73 width=6 height=9 xoffset=1 yoffset=3 xadvance=8 page=0 chnl=0
45 | char id=71 x=229 y=73 width=7 height=9 xoffset=1 yoffset=3 xadvance=9 page=0 chnl=0
46 | char id=72 x=238 y=73 width=7 height=9 xoffset=1 yoffset=3 xadvance=8 page=0 chnl=0
47 | char id=73 x=47 y=147 width=2 height=9 xoffset=1 yoffset=3 xadvance=3 page=0 chnl=0
48 | char id=74 x=247 y=73 width=5 height=9 xoffset=0 yoffset=3 xadvance=5 page=0 chnl=0
49 | char id=75 x=235 y=84 width=7 height=9 xoffset=1 yoffset=3 xadvance=8 page=0 chnl=0
50 | char id=76 x=244 y=84 width=6 height=9 xoffset=1 yoffset=3 xadvance=8 page=0 chnl=0
51 | char id=77 x=89 y=98 width=9 height=9 xoffset=1 yoffset=3 xadvance=10 page=0 chnl=0
52 | char id=78 x=89 y=109 width=7 height=9 xoffset=1 yoffset=3 xadvance=8 page=0 chnl=0
53 | char id=79 x=89 y=120 width=9 height=9 xoffset=1 yoffset=3 xadvance=10 page=0 chnl=0
54 | char id=80 x=89 y=131 width=7 height=9 xoffset=1 yoffset=3 xadvance=8 page=0 chnl=0
55 | char id=81 x=89 y=142 width=9 height=11 xoffset=1 yoffset=3 xadvance=10 page=0 chnl=0
56 | char id=82 x=89 y=155 width=7 height=9 xoffset=1 yoffset=3 xadvance=8 page=0 chnl=0
57 | char id=83 x=89 y=166 width=7 height=9 xoffset=1 yoffset=3 xadvance=8 page=0 chnl=0
58 | char id=84 x=89 y=177 width=7 height=9 xoffset=1 yoffset=3 xadvance=9 page=0 chnl=0
59 | char id=85 x=89 y=188 width=7 height=9 xoffset=1 yoffset=3 xadvance=8 page=0 chnl=0
60 | char id=86 x=89 y=199 width=8 height=9 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=0
61 | char id=87 x=89 y=210 width=9 height=9 xoffset=1 yoffset=3 xadvance=10 page=0 chnl=0
62 | char id=88 x=89 y=221 width=8 height=9 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=0
63 | char id=89 x=89 y=232 width=7 height=9 xoffset=1 yoffset=3 xadvance=8 page=0 chnl=0
64 | char id=90 x=89 y=243 width=7 height=9 xoffset=1 yoffset=3 xadvance=8 page=0 chnl=0
65 | char id=91 x=109 y=154 width=4 height=12 xoffset=1 yoffset=1 xadvance=5 page=0 chnl=0
66 | char id=92 x=109 y=231 width=6 height=9 xoffset=0 yoffset=3 xadvance=6 page=0 chnl=0
67 | char id=93 x=109 y=168 width=4 height=12 xoffset=0 yoffset=1 xadvance=4 page=0 chnl=0
68 | char id=94 x=52 y=251 width=4 height=4 xoffset=0 yoffset=2 xadvance=4 page=0 chnl=0
69 | char id=95 x=236 y=16 width=5 height=2 xoffset=1 yoffset=13 xadvance=7 page=0 chnl=0
70 | char id=96 x=32 y=56 width=3 height=4 xoffset=0 yoffset=2 xadvance=3 page=0 chnl=0
71 | char id=97 x=100 y=98 width=7 height=7 xoffset=1 yoffset=5 xadvance=8 page=0 chnl=0
72 | char id=98 x=100 y=107 width=7 height=9 xoffset=1 yoffset=3 xadvance=8 page=0 chnl=0
73 | char id=99 x=109 y=98 width=6 height=7 xoffset=1 yoffset=5 xadvance=7 page=0 chnl=0
74 | char id=100 x=100 y=118 width=7 height=9 xoffset=1 yoffset=3 xadvance=8 page=0 chnl=0
75 | char id=101 x=117 y=98 width=6 height=7 xoffset=0 yoffset=5 xadvance=6 page=0 chnl=0
76 | char id=102 x=100 y=129 width=5 height=10 xoffset=1 yoffset=2 xadvance=6 page=0 chnl=0
77 | char id=103 x=100 y=141 width=7 height=10 xoffset=1 yoffset=5 xadvance=8 page=0 chnl=0
78 | char id=104 x=100 y=153 width=6 height=9 xoffset=1 yoffset=3 xadvance=7 page=0 chnl=0
79 | char id=105 x=47 y=209 width=3 height=9 xoffset=0 yoffset=3 xadvance=3 page=0 chnl=0
80 | char id=106 x=100 y=164 width=5 height=12 xoffset=-2 yoffset=3 xadvance=3 page=0 chnl=0
81 | char id=107 x=100 y=178 width=6 height=9 xoffset=1 yoffset=3 xadvance=7 page=0 chnl=0
82 | char id=108 x=47 y=220 width=2 height=9 xoffset=1 yoffset=3 xadvance=3 page=0 chnl=0
83 | char id=109 x=125 y=98 width=8 height=7 xoffset=1 yoffset=5 xadvance=9 page=0 chnl=0
84 | char id=110 x=135 y=98 width=6 height=7 xoffset=1 yoffset=5 xadvance=7 page=0 chnl=0
85 | char id=111 x=143 y=98 width=7 height=7 xoffset=1 yoffset=5 xadvance=8 page=0 chnl=0
86 | char id=112 x=100 y=189 width=7 height=10 xoffset=1 yoffset=5 xadvance=8 page=0 chnl=0
87 | char id=113 x=100 y=201 width=7 height=10 xoffset=1 yoffset=5 xadvance=8 page=0 chnl=0
88 | char id=114 x=251 y=59 width=4 height=7 xoffset=1 yoffset=5 xadvance=6 page=0 chnl=0
89 | char id=115 x=152 y=98 width=6 height=7 xoffset=1 yoffset=5 xadvance=7 page=0 chnl=0
90 | char id=116 x=100 y=213 width=5 height=9 xoffset=1 yoffset=3 xadvance=7 page=0 chnl=0
91 | char id=117 x=160 y=98 width=6 height=7 xoffset=1 yoffset=5 xadvance=7 page=0 chnl=0
92 | char id=118 x=168 y=98 width=7 height=7 xoffset=0 yoffset=5 xadvance=6 page=0 chnl=0
93 | char id=119 x=177 y=98 width=9 height=7 xoffset=1 yoffset=5 xadvance=10 page=0 chnl=0
94 | char id=120 x=188 y=98 width=8 height=7 xoffset=-1 yoffset=5 xadvance=6 page=0 chnl=0
95 | char id=121 x=100 y=224 width=6 height=10 xoffset=1 yoffset=5 xadvance=7 page=0 chnl=0
96 | char id=122 x=198 y=98 width=5 height=7 xoffset=1 yoffset=5 xadvance=7 page=0 chnl=0
97 | char id=123 x=109 y=182 width=6 height=12 xoffset=0 yoffset=1 xadvance=6 page=0 chnl=0
98 | char id=124 x=61 y=181 width=2 height=12 xoffset=1 yoffset=1 xadvance=3 page=0 chnl=0
99 | char id=125 x=109 y=196 width=6 height=12 xoffset=0 yoffset=1 xadvance=6 page=0 chnl=0
100 | char id=126 x=111 y=35 width=5 height=3 xoffset=0 yoffset=5 xadvance=5 page=0 chnl=0
101 | kernings count=21
102 | kerning first=34 second=44 amount=-2
103 | kerning first=34 second=46 amount=-2
104 | kerning first=39 second=44 amount=-2
105 | kerning first=39 second=46 amount=-2
106 | kerning first=40 second=106 amount=1
107 | kerning first=44 second=34 amount=-2
108 | kerning first=44 second=39 amount=-2
109 | kerning first=44 second=106 amount=1
110 | kerning first=46 second=34 amount=-2
111 | kerning first=46 second=39 amount=-2
112 | kerning first=47 second=47 amount=-2
113 | kerning first=59 second=106 amount=1
114 | kerning first=76 second=34 amount=-2
115 | kerning first=76 second=39 amount=-2
116 | kerning first=76 second=42 amount=-2
117 | kerning first=76 second=84 amount=-2
118 | kerning first=76 second=89 amount=-2
119 | kerning first=91 second=106 amount=1
120 | kerning first=113 second=106 amount=1
121 | kerning first=123 second=106 amount=1
122 | kerning first=124 second=106 amount=1
123 |
--------------------------------------------------------------------------------
/codelabs-android/assets/data/fonts/Righteous-16.fnt:
--------------------------------------------------------------------------------
1 | info face="Righteous" size=16 bold=0 italic=0 charset="" unicode=1 stretchH=100 smooth=1 aa=2 padding=0,0,0,0 spacing=0,0
2 | common lineHeight=20 base=16 scaleW=256 scaleH=256 pages=1 packed=0 alphaChnl=0 redChnl=0 greenChnl=0 blueChnl=0
3 | page id=0 file="righteous.png"
4 | chars count=96
5 | char id=10 x=15 y=60 width=0 height=0 xoffset=0 yoffset=16 xadvance=4 page=0 chnl=0
6 | char id=32 x=0 y=0 width=0 height=0 xoffset=0 yoffset=0 xadvance=4 page=0 chnl=0
7 | char id=33 x=32 y=118 width=3 height=13 xoffset=1 yoffset=4 xadvance=4 page=0 chnl=0
8 | char id=34 x=28 y=178 width=6 height=4 xoffset=0 yoffset=4 xadvance=7 page=0 chnl=0
9 | char id=35 x=153 y=73 width=9 height=8 xoffset=0 yoffset=7 xadvance=9 page=0 chnl=0
10 | char id=36 x=206 y=84 width=7 height=12 xoffset=0 yoffset=4 xadvance=7 page=0 chnl=0
11 | char id=37 x=215 y=84 width=10 height=12 xoffset=1 yoffset=4 xadvance=12 page=0 chnl=0
12 | char id=38 x=227 y=84 width=6 height=12 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=0
13 | char id=39 x=31 y=219 width=4 height=4 xoffset=0 yoffset=4 xadvance=4 page=0 chnl=0
14 | char id=40 x=79 y=154 width=5 height=15 xoffset=1 yoffset=3 xadvance=6 page=0 chnl=0
15 | char id=41 x=79 y=171 width=6 height=15 xoffset=0 yoffset=3 xadvance=6 page=0 chnl=0
16 | char id=42 x=164 y=73 width=10 height=9 xoffset=0 yoffset=2 xadvance=10 page=0 chnl=0
17 | char id=43 x=135 y=73 width=7 height=7 xoffset=1 yoffset=6 xadvance=9 page=0 chnl=0
18 | char id=44 x=31 y=225 width=3 height=5 xoffset=1 yoffset=14 xadvance=4 page=0 chnl=0
19 | char id=45 x=67 y=35 width=7 height=3 xoffset=1 yoffset=8 xadvance=9 page=0 chnl=0
20 | char id=46 x=12 y=148 width=3 height=3 xoffset=1 yoffset=14 xadvance=4 page=0 chnl=0
21 | char id=47 x=186 y=84 width=8 height=12 xoffset=0 yoffset=4 xadvance=8 page=0 chnl=0
22 | char id=48 x=145 y=84 width=9 height=12 xoffset=1 yoffset=4 xadvance=11 page=0 chnl=0
23 | char id=49 x=79 y=98 width=5 height=12 xoffset=0 yoffset=4 xadvance=5 page=0 chnl=0
24 | char id=50 x=79 y=112 width=8 height=12 xoffset=1 yoffset=4 xadvance=10 page=0 chnl=0
25 | char id=51 x=79 y=126 width=8 height=12 xoffset=1 yoffset=4 xadvance=10 page=0 chnl=0
26 | char id=52 x=89 y=84 width=10 height=12 xoffset=0 yoffset=4 xadvance=10 page=0 chnl=0
27 | char id=53 x=101 y=84 width=9 height=12 xoffset=1 yoffset=4 xadvance=10 page=0 chnl=0
28 | char id=54 x=112 y=84 width=9 height=12 xoffset=1 yoffset=4 xadvance=11 page=0 chnl=0
29 | char id=55 x=79 y=140 width=8 height=12 xoffset=0 yoffset=4 xadvance=8 page=0 chnl=0
30 | char id=56 x=123 y=84 width=9 height=12 xoffset=1 yoffset=4 xadvance=11 page=0 chnl=0
31 | char id=57 x=134 y=84 width=9 height=12 xoffset=1 yoffset=4 xadvance=11 page=0 chnl=0
32 | char id=58 x=47 y=137 width=3 height=8 xoffset=1 yoffset=9 xadvance=4 page=0 chnl=0
33 | char id=59 x=32 y=234 width=3 height=10 xoffset=1 yoffset=9 xadvance=4 page=0 chnl=0
34 | char id=60 x=167 y=84 width=7 height=11 xoffset=0 yoffset=4 xadvance=8 page=0 chnl=0
35 | char id=61 x=144 y=73 width=7 height=6 xoffset=1 yoffset=7 xadvance=9 page=0 chnl=0
36 | char id=62 x=176 y=84 width=8 height=11 xoffset=0 yoffset=4 xadvance=8 page=0 chnl=0
37 | char id=63 x=156 y=84 width=9 height=12 xoffset=1 yoffset=4 xadvance=10 page=0 chnl=0
38 | char id=64 x=124 y=73 width=9 height=9 xoffset=1 yoffset=7 xadvance=11 page=0 chnl=0
39 | char id=65 x=241 y=40 width=9 height=12 xoffset=1 yoffset=4 xadvance=11 page=0 chnl=0
40 | char id=66 x=52 y=83 width=9 height=12 xoffset=1 yoffset=4 xadvance=11 page=0 chnl=0
41 | char id=67 x=52 y=97 width=10 height=12 xoffset=1 yoffset=4 xadvance=11 page=0 chnl=0
42 | char id=68 x=52 y=111 width=9 height=12 xoffset=1 yoffset=4 xadvance=11 page=0 chnl=0
43 | char id=69 x=52 y=125 width=8 height=12 xoffset=1 yoffset=4 xadvance=9 page=0 chnl=0
44 | char id=70 x=52 y=139 width=8 height=12 xoffset=1 yoffset=4 xadvance=10 page=0 chnl=0
45 | char id=71 x=52 y=153 width=10 height=12 xoffset=1 yoffset=4 xadvance=11 page=0 chnl=0
46 | char id=72 x=52 y=167 width=9 height=12 xoffset=1 yoffset=4 xadvance=11 page=0 chnl=0
47 | char id=73 x=12 y=134 width=3 height=12 xoffset=1 yoffset=4 xadvance=4 page=0 chnl=0
48 | char id=74 x=52 y=181 width=7 height=12 xoffset=0 yoffset=4 xadvance=7 page=0 chnl=0
49 | char id=75 x=52 y=195 width=9 height=12 xoffset=1 yoffset=4 xadvance=10 page=0 chnl=0
50 | char id=76 x=52 y=209 width=8 height=12 xoffset=1 yoffset=4 xadvance=10 page=0 chnl=0
51 | char id=77 x=65 y=59 width=12 height=12 xoffset=1 yoffset=4 xadvance=14 page=0 chnl=0
52 | char id=78 x=52 y=223 width=9 height=12 xoffset=1 yoffset=4 xadvance=11 page=0 chnl=0
53 | char id=79 x=79 y=59 width=12 height=12 xoffset=1 yoffset=4 xadvance=13 page=0 chnl=0
54 | char id=80 x=52 y=237 width=9 height=12 xoffset=1 yoffset=4 xadvance=11 page=0 chnl=0
55 | char id=81 x=65 y=73 width=12 height=14 xoffset=1 yoffset=4 xadvance=13 page=0 chnl=0
56 | char id=82 x=93 y=59 width=9 height=12 xoffset=1 yoffset=4 xadvance=11 page=0 chnl=0
57 | char id=83 x=104 y=59 width=9 height=12 xoffset=1 yoffset=4 xadvance=11 page=0 chnl=0
58 | char id=84 x=115 y=59 width=9 height=12 xoffset=1 yoffset=4 xadvance=11 page=0 chnl=0
59 | char id=85 x=126 y=59 width=9 height=12 xoffset=1 yoffset=4 xadvance=11 page=0 chnl=0
60 | char id=86 x=137 y=59 width=10 height=12 xoffset=0 yoffset=4 xadvance=10 page=0 chnl=0
61 | char id=87 x=149 y=59 width=12 height=12 xoffset=1 yoffset=4 xadvance=14 page=0 chnl=0
62 | char id=88 x=163 y=59 width=10 height=12 xoffset=0 yoffset=4 xadvance=10 page=0 chnl=0
63 | char id=89 x=175 y=59 width=9 height=12 xoffset=1 yoffset=4 xadvance=10 page=0 chnl=0
64 | char id=90 x=186 y=59 width=9 height=12 xoffset=1 yoffset=4 xadvance=10 page=0 chnl=0
65 | char id=91 x=79 y=188 width=5 height=15 xoffset=1 yoffset=3 xadvance=6 page=0 chnl=0
66 | char id=92 x=196 y=84 width=8 height=12 xoffset=0 yoffset=4 xadvance=8 page=0 chnl=0
67 | char id=93 x=79 y=205 width=5 height=15 xoffset=1 yoffset=3 xadvance=6 page=0 chnl=0
68 | char id=94 x=190 y=53 width=5 height=4 xoffset=0 yoffset=4 xadvance=5 page=0 chnl=0
69 | char id=95 x=78 y=35 width=7 height=3 xoffset=2 yoffset=17 xadvance=11 page=0 chnl=0
70 | char id=96 x=31 y=197 width=4 height=4 xoffset=0 yoffset=4 xadvance=4 page=0 chnl=0
71 | char id=97 x=197 y=59 width=9 height=9 xoffset=1 yoffset=7 xadvance=10 page=0 chnl=0
72 | char id=98 x=208 y=59 width=9 height=12 xoffset=1 yoffset=4 xadvance=10 page=0 chnl=0
73 | char id=99 x=216 y=47 width=8 height=9 xoffset=1 yoffset=7 xadvance=9 page=0 chnl=0
74 | char id=100 x=219 y=59 width=9 height=12 xoffset=1 yoffset=4 xadvance=10 page=0 chnl=0
75 | char id=101 x=230 y=59 width=8 height=9 xoffset=1 yoffset=7 xadvance=9 page=0 chnl=0
76 | char id=102 x=65 y=89 width=7 height=13 xoffset=1 yoffset=3 xadvance=7 page=0 chnl=0
77 | char id=103 x=240 y=59 width=9 height=12 xoffset=1 yoffset=7 xadvance=10 page=0 chnl=0
78 | char id=104 x=65 y=104 width=8 height=12 xoffset=1 yoffset=4 xadvance=9 page=0 chnl=0
79 | char id=105 x=32 y=42 width=3 height=12 xoffset=1 yoffset=4 xadvance=4 page=0 chnl=0
80 | char id=106 x=65 y=118 width=6 height=15 xoffset=-2 yoffset=4 xadvance=4 page=0 chnl=0
81 | char id=107 x=65 y=135 width=8 height=12 xoffset=1 yoffset=4 xadvance=9 page=0 chnl=0
82 | char id=108 x=32 y=62 width=3 height=12 xoffset=1 yoffset=4 xadvance=4 page=0 chnl=0
83 | char id=109 x=65 y=149 width=11 height=9 xoffset=1 yoffset=7 xadvance=12 page=0 chnl=0
84 | char id=110 x=65 y=160 width=8 height=9 xoffset=1 yoffset=7 xadvance=9 page=0 chnl=0
85 | char id=111 x=65 y=171 width=9 height=9 xoffset=1 yoffset=7 xadvance=10 page=0 chnl=0
86 | char id=112 x=65 y=182 width=9 height=12 xoffset=1 yoffset=7 xadvance=10 page=0 chnl=0
87 | char id=113 x=65 y=196 width=9 height=12 xoffset=1 yoffset=7 xadvance=10 page=0 chnl=0
88 | char id=114 x=65 y=210 width=6 height=9 xoffset=1 yoffset=7 xadvance=7 page=0 chnl=0
89 | char id=115 x=65 y=221 width=8 height=9 xoffset=1 yoffset=7 xadvance=9 page=0 chnl=0
90 | char id=116 x=65 y=232 width=6 height=12 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=0
91 | char id=117 x=65 y=246 width=8 height=9 xoffset=1 yoffset=7 xadvance=9 page=0 chnl=0
92 | char id=118 x=79 y=73 width=9 height=9 xoffset=0 yoffset=7 xadvance=9 page=0 chnl=0
93 | char id=119 x=90 y=73 width=11 height=9 xoffset=1 yoffset=7 xadvance=12 page=0 chnl=0
94 | char id=120 x=103 y=73 width=10 height=9 xoffset=-1 yoffset=7 xadvance=8 page=0 chnl=0
95 | char id=121 x=79 y=84 width=8 height=12 xoffset=1 yoffset=7 xadvance=9 page=0 chnl=0
96 | char id=122 x=115 y=73 width=7 height=9 xoffset=1 yoffset=7 xadvance=9 page=0 chnl=0
97 | char id=123 x=79 y=222 width=7 height=15 xoffset=1 yoffset=3 xadvance=8 page=0 chnl=0
98 | char id=124 x=47 y=161 width=3 height=15 xoffset=1 yoffset=3 xadvance=4 page=0 chnl=0
99 | char id=125 x=79 y=239 width=7 height=15 xoffset=1 yoffset=3 xadvance=8 page=0 chnl=0
100 | char id=126 x=197 y=53 width=6 height=4 xoffset=1 yoffset=7 xadvance=8 page=0 chnl=0
101 | kernings count=76
102 | kerning first=34 second=44 amount=-2
103 | kerning first=34 second=46 amount=-2
104 | kerning first=34 second=74 amount=-2
105 | kerning first=39 second=44 amount=-2
106 | kerning first=39 second=46 amount=-2
107 | kerning first=39 second=74 amount=-2
108 | kerning first=40 second=106 amount=2
109 | kerning first=42 second=74 amount=-2
110 | kerning first=44 second=34 amount=-2
111 | kerning first=44 second=39 amount=-2
112 | kerning first=44 second=84 amount=-2
113 | kerning first=44 second=89 amount=-2
114 | kerning first=44 second=106 amount=1
115 | kerning first=45 second=74 amount=-2
116 | kerning first=45 second=84 amount=-2
117 | kerning first=46 second=34 amount=-2
118 | kerning first=46 second=39 amount=-2
119 | kerning first=46 second=84 amount=-2
120 | kerning first=46 second=89 amount=-2
121 | kerning first=47 second=47 amount=-3
122 | kerning first=58 second=84 amount=-2
123 | kerning first=59 second=84 amount=-2
124 | kerning first=59 second=106 amount=1
125 | kerning first=70 second=44 amount=-2
126 | kerning first=70 second=46 amount=-2
127 | kerning first=70 second=74 amount=-2
128 | kerning first=70 second=97 amount=-2
129 | kerning first=70 second=99 amount=-2
130 | kerning first=70 second=100 amount=-2
131 | kerning first=70 second=101 amount=-2
132 | kerning first=70 second=103 amount=-2
133 | kerning first=70 second=111 amount=-2
134 | kerning first=70 second=113 amount=-2
135 | kerning first=70 second=115 amount=-2
136 | kerning first=76 second=34 amount=-2
137 | kerning first=76 second=39 amount=-2
138 | kerning first=76 second=42 amount=-2
139 | kerning first=76 second=45 amount=-2
140 | kerning first=76 second=84 amount=-2
141 | kerning first=76 second=86 amount=-2
142 | kerning first=76 second=89 amount=-2
143 | kerning first=76 second=92 amount=-2
144 | kerning first=76 second=118 amount=-2
145 | kerning first=80 second=74 amount=-2
146 | kerning first=81 second=106 amount=1
147 | kerning first=84 second=44 amount=-2
148 | kerning first=84 second=45 amount=-2
149 | kerning first=84 second=46 amount=-2
150 | kerning first=84 second=58 amount=-2
151 | kerning first=84 second=59 amount=-2
152 | kerning first=84 second=74 amount=-2
153 | kerning first=84 second=97 amount=-2
154 | kerning first=84 second=99 amount=-2
155 | kerning first=84 second=100 amount=-2
156 | kerning first=84 second=101 amount=-2
157 | kerning first=84 second=103 amount=-2
158 | kerning first=84 second=111 amount=-2
159 | kerning first=84 second=113 amount=-2
160 | kerning first=84 second=115 amount=-2
161 | kerning first=84 second=117 amount=-2
162 | kerning first=84 second=119 amount=-2
163 | kerning first=84 second=121 amount=-2
164 | kerning first=84 second=122 amount=-2
165 | kerning first=86 second=74 amount=-2
166 | kerning first=89 second=44 amount=-2
167 | kerning first=89 second=46 amount=-2
168 | kerning first=89 second=74 amount=-2
169 | kerning first=91 second=106 amount=1
170 | kerning first=103 second=106 amount=1
171 | kerning first=106 second=106 amount=1
172 | kerning first=113 second=106 amount=1
173 | kerning first=114 second=44 amount=-2
174 | kerning first=114 second=46 amount=-2
175 | kerning first=121 second=106 amount=1
176 | kerning first=123 second=106 amount=1
177 | kerning first=124 second=106 amount=1
178 |
--------------------------------------------------------------------------------
/codelabs-android/assets/data/fonts/Righteous-24.fnt:
--------------------------------------------------------------------------------
1 | info face="Righteous" size=24 bold=0 italic=0 charset="" unicode=1 stretchH=100 smooth=1 aa=2 padding=0,0,0,0 spacing=0,0
2 | common lineHeight=30 base=24 scaleW=256 scaleH=256 pages=1 packed=0 alphaChnl=0 redChnl=0 greenChnl=0 blueChnl=0
3 | page id=0 file="righteous.png"
4 | chars count=96
5 | char id=10 x=15 y=58 width=0 height=0 xoffset=0 yoffset=24 xadvance=7 page=0 chnl=0
6 | char id=32 x=0 y=0 width=0 height=0 xoffset=0 yoffset=0 xadvance=7 page=0 chnl=0
7 | char id=33 x=28 y=158 width=4 height=18 xoffset=1 yoffset=7 xadvance=6 page=0 chnl=0
8 | char id=34 x=1 y=248 width=8 height=5 xoffset=1 yoffset=7 xadvance=10 page=0 chnl=0
9 | char id=35 x=190 y=40 width=13 height=11 xoffset=0 yoffset=10 xadvance=13 page=0 chnl=0
10 | char id=36 x=137 y=40 width=10 height=17 xoffset=1 yoffset=7 xadvance=11 page=0 chnl=0
11 | char id=37 x=161 y=40 width=15 height=17 xoffset=1 yoffset=7 xadvance=17 page=0 chnl=0
12 | char id=38 x=205 y=40 width=9 height=17 xoffset=1 yoffset=7 xadvance=11 page=0 chnl=0
13 | char id=39 x=11 y=248 width=4 height=5 xoffset=1 yoffset=7 xadvance=6 page=0 chnl=0
14 | char id=40 x=37 y=137 width=8 height=22 xoffset=1 yoffset=4 xadvance=8 page=0 chnl=0
15 | char id=41 x=37 y=161 width=8 height=22 xoffset=0 yoffset=4 xadvance=8 page=0 chnl=0
16 | char id=42 x=226 y=40 width=13 height=13 xoffset=0 yoffset=4 xadvance=14 page=0 chnl=0
17 | char id=43 x=149 y=46 width=10 height=10 xoffset=1 yoffset=10 xadvance=12 page=0 chnl=0
18 | char id=44 x=250 y=7 width=4 height=7 xoffset=1 yoffset=21 xadvance=6 page=0 chnl=0
19 | char id=45 x=149 y=40 width=10 height=4 xoffset=1 yoffset=13 xadvance=12 page=0 chnl=0
20 | char id=46 x=250 y=1 width=4 height=4 xoffset=1 yoffset=21 xadvance=6 page=0 chnl=0
21 | char id=47 x=93 y=40 width=12 height=17 xoffset=0 yoffset=7 xadvance=12 page=0 chnl=0
22 | char id=48 x=52 y=40 width=14 height=17 xoffset=1 yoffset=7 xadvance=15 page=0 chnl=0
23 | char id=49 x=7 y=115 width=6 height=17 xoffset=0 yoffset=7 xadvance=7 page=0 chnl=0
24 | char id=50 x=194 y=20 width=12 height=17 xoffset=1 yoffset=7 xadvance=14 page=0 chnl=0
25 | char id=51 x=208 y=20 width=13 height=17 xoffset=1 yoffset=7 xadvance=14 page=0 chnl=0
26 | char id=52 x=223 y=20 width=14 height=17 xoffset=0 yoffset=7 xadvance=15 page=0 chnl=0
27 | char id=53 x=239 y=20 width=13 height=17 xoffset=1 yoffset=7 xadvance=14 page=0 chnl=0
28 | char id=54 x=37 y=40 width=13 height=17 xoffset=1 yoffset=7 xadvance=15 page=0 chnl=0
29 | char id=55 x=37 y=59 width=12 height=17 xoffset=1 yoffset=7 xadvance=12 page=0 chnl=0
30 | char id=56 x=37 y=78 width=13 height=18 xoffset=1 yoffset=6 xadvance=15 page=0 chnl=0
31 | char id=57 x=37 y=98 width=13 height=18 xoffset=1 yoffset=6 xadvance=15 page=0 chnl=0
32 | char id=58 x=31 y=184 width=4 height=11 xoffset=1 yoffset=14 xadvance=6 page=0 chnl=0
33 | char id=59 x=31 y=82 width=4 height=13 xoffset=1 yoffset=14 xadvance=6 page=0 chnl=0
34 | char id=60 x=68 y=40 width=11 height=15 xoffset=0 yoffset=7 xadvance=11 page=0 chnl=0
35 | char id=61 x=178 y=40 width=10 height=8 xoffset=2 yoffset=11 xadvance=14 page=0 chnl=0
36 | char id=62 x=81 y=40 width=10 height=15 xoffset=1 yoffset=7 xadvance=11 page=0 chnl=0
37 | char id=63 x=37 y=118 width=13 height=17 xoffset=0 yoffset=7 xadvance=14 page=0 chnl=0
38 | char id=64 x=107 y=40 width=14 height=13 xoffset=1 yoffset=11 xadvance=15 page=0 chnl=0
39 | char id=65 x=1 y=1 width=14 height=17 xoffset=1 yoffset=7 xadvance=16 page=0 chnl=0
40 | char id=66 x=1 y=20 width=14 height=17 xoffset=2 yoffset=7 xadvance=16 page=0 chnl=0
41 | char id=67 x=17 y=1 width=15 height=17 xoffset=1 yoffset=7 xadvance=16 page=0 chnl=0
42 | char id=68 x=1 y=39 width=14 height=17 xoffset=2 yoffset=7 xadvance=16 page=0 chnl=0
43 | char id=69 x=1 y=58 width=12 height=17 xoffset=2 yoffset=7 xadvance=14 page=0 chnl=0
44 | char id=70 x=1 y=77 width=12 height=17 xoffset=2 yoffset=7 xadvance=15 page=0 chnl=0
45 | char id=71 x=34 y=1 width=15 height=17 xoffset=1 yoffset=7 xadvance=16 page=0 chnl=0
46 | char id=72 x=1 y=96 width=14 height=17 xoffset=2 yoffset=7 xadvance=17 page=0 chnl=0
47 | char id=73 x=1 y=115 width=4 height=17 xoffset=2 yoffset=7 xadvance=7 page=0 chnl=0
48 | char id=74 x=1 y=134 width=9 height=17 xoffset=1 yoffset=7 xadvance=11 page=0 chnl=0
49 | char id=75 x=1 y=153 width=14 height=17 xoffset=2 yoffset=7 xadvance=15 page=0 chnl=0
50 | char id=76 x=1 y=172 width=12 height=17 xoffset=2 yoffset=7 xadvance=15 page=0 chnl=0
51 | char id=77 x=51 y=1 width=17 height=17 xoffset=1 yoffset=7 xadvance=19 page=0 chnl=0
52 | char id=78 x=1 y=191 width=14 height=17 xoffset=2 yoffset=7 xadvance=17 page=0 chnl=0
53 | char id=79 x=70 y=1 width=18 height=17 xoffset=1 yoffset=7 xadvance=19 page=0 chnl=0
54 | char id=80 x=1 y=210 width=14 height=17 xoffset=2 yoffset=7 xadvance=16 page=0 chnl=0
55 | char id=81 x=17 y=20 width=18 height=20 xoffset=1 yoffset=7 xadvance=19 page=0 chnl=0
56 | char id=82 x=1 y=229 width=14 height=17 xoffset=2 yoffset=7 xadvance=16 page=0 chnl=0
57 | char id=83 x=90 y=1 width=14 height=17 xoffset=1 yoffset=7 xadvance=15 page=0 chnl=0
58 | char id=84 x=106 y=1 width=13 height=17 xoffset=1 yoffset=7 xadvance=15 page=0 chnl=0
59 | char id=85 x=121 y=1 width=14 height=17 xoffset=1 yoffset=7 xadvance=16 page=0 chnl=0
60 | char id=86 x=137 y=1 width=15 height=17 xoffset=0 yoffset=7 xadvance=14 page=0 chnl=0
61 | char id=87 x=154 y=1 width=17 height=17 xoffset=1 yoffset=7 xadvance=19 page=0 chnl=0
62 | char id=88 x=173 y=1 width=15 height=17 xoffset=0 yoffset=7 xadvance=15 page=0 chnl=0
63 | char id=89 x=190 y=1 width=14 height=17 xoffset=1 yoffset=7 xadvance=15 page=0 chnl=0
64 | char id=90 x=206 y=1 width=13 height=17 xoffset=1 yoffset=7 xadvance=15 page=0 chnl=0
65 | char id=91 x=37 y=185 width=7 height=22 xoffset=2 yoffset=4 xadvance=10 page=0 chnl=0
66 | char id=92 x=123 y=40 width=12 height=17 xoffset=0 yoffset=7 xadvance=12 page=0 chnl=0
67 | char id=93 x=37 y=209 width=8 height=22 xoffset=0 yoffset=4 xadvance=9 page=0 chnl=0
68 | char id=94 x=25 y=249 width=8 height=6 xoffset=0 yoffset=7 xadvance=7 page=0 chnl=0
69 | char id=95 x=178 y=50 width=10 height=4 xoffset=2 yoffset=26 xadvance=14 page=0 chnl=0
70 | char id=96 x=17 y=249 width=6 height=6 xoffset=0 yoffset=7 xadvance=5 page=0 chnl=0
71 | char id=97 x=221 y=1 width=13 height=13 xoffset=1 yoffset=11 xadvance=15 page=0 chnl=0
72 | char id=98 x=17 y=42 width=13 height=18 xoffset=1 yoffset=6 xadvance=15 page=0 chnl=0
73 | char id=99 x=236 y=1 width=12 height=13 xoffset=1 yoffset=11 xadvance=13 page=0 chnl=0
74 | char id=100 x=17 y=62 width=13 height=18 xoffset=1 yoffset=6 xadvance=15 page=0 chnl=0
75 | char id=101 x=17 y=82 width=12 height=13 xoffset=1 yoffset=11 xadvance=13 page=0 chnl=0
76 | char id=102 x=17 y=97 width=10 height=19 xoffset=1 yoffset=5 xadvance=10 page=0 chnl=0
77 | char id=103 x=17 y=118 width=13 height=18 xoffset=1 yoffset=11 xadvance=15 page=0 chnl=0
78 | char id=104 x=17 y=138 width=12 height=18 xoffset=1 yoffset=6 xadvance=13 page=0 chnl=0
79 | char id=105 x=29 y=97 width=4 height=19 xoffset=1 yoffset=5 xadvance=6 page=0 chnl=0
80 | char id=106 x=17 y=158 width=9 height=24 xoffset=-4 yoffset=5 xadvance=6 page=0 chnl=0
81 | char id=107 x=17 y=184 width=12 height=18 xoffset=1 yoffset=6 xadvance=13 page=0 chnl=0
82 | char id=108 x=31 y=138 width=4 height=18 xoffset=1 yoffset=6 xadvance=5 page=0 chnl=0
83 | char id=109 x=17 y=204 width=16 height=13 xoffset=1 yoffset=11 xadvance=17 page=0 chnl=0
84 | char id=110 x=17 y=219 width=12 height=13 xoffset=1 yoffset=11 xadvance=13 page=0 chnl=0
85 | char id=111 x=17 y=234 width=13 height=13 xoffset=1 yoffset=11 xadvance=15 page=0 chnl=0
86 | char id=112 x=37 y=20 width=13 height=18 xoffset=1 yoffset=11 xadvance=15 page=0 chnl=0
87 | char id=113 x=52 y=20 width=13 height=18 xoffset=1 yoffset=11 xadvance=15 page=0 chnl=0
88 | char id=114 x=67 y=20 width=9 height=13 xoffset=1 yoffset=11 xadvance=10 page=0 chnl=0
89 | char id=115 x=78 y=20 width=12 height=13 xoffset=1 yoffset=11 xadvance=13 page=0 chnl=0
90 | char id=116 x=92 y=20 width=10 height=18 xoffset=1 yoffset=6 xadvance=12 page=0 chnl=0
91 | char id=117 x=104 y=20 width=12 height=13 xoffset=1 yoffset=11 xadvance=13 page=0 chnl=0
92 | char id=118 x=118 y=20 width=13 height=13 xoffset=0 yoffset=11 xadvance=13 page=0 chnl=0
93 | char id=119 x=133 y=20 width=16 height=13 xoffset=1 yoffset=11 xadvance=17 page=0 chnl=0
94 | char id=120 x=151 y=20 width=14 height=13 xoffset=-1 yoffset=11 xadvance=13 page=0 chnl=0
95 | char id=121 x=167 y=20 width=12 height=18 xoffset=1 yoffset=11 xadvance=13 page=0 chnl=0
96 | char id=122 x=181 y=20 width=11 height=13 xoffset=1 yoffset=11 xadvance=12 page=0 chnl=0
97 | char id=123 x=37 y=233 width=10 height=22 xoffset=1 yoffset=4 xadvance=12 page=0 chnl=0
98 | char id=124 x=46 y=185 width=4 height=22 xoffset=2 yoffset=4 xadvance=7 page=0 chnl=0
99 | char id=125 x=52 y=59 width=11 height=22 xoffset=0 yoffset=4 xadvance=11 page=0 chnl=0
100 | char id=126 x=216 y=40 width=8 height=5 xoffset=1 yoffset=12 xadvance=10 page=0 chnl=0
101 | kernings count=314
102 | kerning first=34 second=44 amount=-4
103 | kerning first=34 second=46 amount=-4
104 | kerning first=34 second=47 amount=-2
105 | kerning first=34 second=74 amount=-2
106 | kerning first=39 second=44 amount=-4
107 | kerning first=39 second=46 amount=-4
108 | kerning first=39 second=47 amount=-2
109 | kerning first=39 second=74 amount=-2
110 | kerning first=40 second=48 amount=-2
111 | kerning first=40 second=54 amount=-2
112 | kerning first=40 second=56 amount=-2
113 | kerning first=40 second=57 amount=-2
114 | kerning first=40 second=67 amount=-2
115 | kerning first=40 second=71 amount=-2
116 | kerning first=40 second=79 amount=-2
117 | kerning first=40 second=81 amount=-2
118 | kerning first=40 second=97 amount=-2
119 | kerning first=40 second=99 amount=-2
120 | kerning first=40 second=100 amount=-2
121 | kerning first=40 second=101 amount=-2
122 | kerning first=40 second=103 amount=-2
123 | kerning first=40 second=106 amount=4
124 | kerning first=40 second=111 amount=-2
125 | kerning first=40 second=113 amount=-2
126 | kerning first=40 second=117 amount=-2
127 | kerning first=40 second=118 amount=-2
128 | kerning first=40 second=119 amount=-2
129 | kerning first=40 second=121 amount=-2
130 | kerning first=40 second=123 amount=-2
131 | kerning first=42 second=74 amount=-2
132 | kerning first=42 second=86 amount=1
133 | kerning first=44 second=34 amount=-4
134 | kerning first=44 second=39 amount=-4
135 | kerning first=44 second=57 amount=-2
136 | kerning first=44 second=84 amount=-2
137 | kerning first=44 second=86 amount=-2
138 | kerning first=44 second=89 amount=-2
139 | kerning first=44 second=106 amount=2
140 | kerning first=44 second=118 amount=-2
141 | kerning first=45 second=51 amount=-2
142 | kerning first=45 second=55 amount=-2
143 | kerning first=45 second=74 amount=-2
144 | kerning first=45 second=84 amount=-2
145 | kerning first=45 second=88 amount=-2
146 | kerning first=45 second=90 amount=-2
147 | kerning first=46 second=34 amount=-4
148 | kerning first=46 second=39 amount=-4
149 | kerning first=46 second=57 amount=-2
150 | kerning first=46 second=84 amount=-2
151 | kerning first=46 second=86 amount=-2
152 | kerning first=46 second=89 amount=-2
153 | kerning first=46 second=118 amount=-2
154 | kerning first=47 second=47 amount=-6
155 | kerning first=47 second=74 amount=-2
156 | kerning first=47 second=97 amount=-2
157 | kerning first=47 second=99 amount=-2
158 | kerning first=47 second=100 amount=-2
159 | kerning first=47 second=101 amount=-2
160 | kerning first=47 second=103 amount=-2
161 | kerning first=47 second=111 amount=-2
162 | kerning first=47 second=113 amount=-2
163 | kerning first=47 second=115 amount=-2
164 | kerning first=48 second=41 amount=-2
165 | kerning first=51 second=41 amount=-2
166 | kerning first=54 second=41 amount=-2
167 | kerning first=54 second=55 amount=-2
168 | kerning first=54 second=84 amount=-2
169 | kerning first=54 second=92 amount=-2
170 | kerning first=55 second=44 amount=-2
171 | kerning first=55 second=46 amount=-2
172 | kerning first=55 second=47 amount=-2
173 | kerning first=55 second=74 amount=-2
174 | kerning first=55 second=86 amount=1
175 | kerning first=55 second=88 amount=1
176 | kerning first=56 second=41 amount=-2
177 | kerning first=57 second=41 amount=-2
178 | kerning first=58 second=84 amount=-2
179 | kerning first=58 second=86 amount=-2
180 | kerning first=59 second=84 amount=-2
181 | kerning first=59 second=86 amount=-2
182 | kerning first=59 second=106 amount=2
183 | kerning first=64 second=84 amount=-2
184 | kerning first=66 second=41 amount=-2
185 | kerning first=67 second=42 amount=1
186 | kerning first=67 second=45 amount=-2
187 | kerning first=68 second=41 amount=-2
188 | kerning first=68 second=84 amount=-2
189 | kerning first=68 second=88 amount=-2
190 | kerning first=68 second=93 amount=-2
191 | kerning first=68 second=125 amount=-2
192 | kerning first=70 second=44 amount=-3
193 | kerning first=70 second=45 amount=-2
194 | kerning first=70 second=46 amount=-3
195 | kerning first=70 second=47 amount=-2
196 | kerning first=70 second=58 amount=-2
197 | kerning first=70 second=59 amount=-2
198 | kerning first=70 second=64 amount=-2
199 | kerning first=70 second=74 amount=-3
200 | kerning first=70 second=97 amount=-2
201 | kerning first=70 second=99 amount=-2
202 | kerning first=70 second=100 amount=-2
203 | kerning first=70 second=101 amount=-2
204 | kerning first=70 second=103 amount=-2
205 | kerning first=70 second=109 amount=-2
206 | kerning first=70 second=110 amount=-2
207 | kerning first=70 second=111 amount=-2
208 | kerning first=70 second=112 amount=-2
209 | kerning first=70 second=113 amount=-2
210 | kerning first=70 second=114 amount=-2
211 | kerning first=70 second=115 amount=-2
212 | kerning first=70 second=117 amount=-2
213 | kerning first=70 second=119 amount=-2
214 | kerning first=70 second=121 amount=-2
215 | kerning first=75 second=45 amount=-2
216 | kerning first=75 second=67 amount=-2
217 | kerning first=75 second=71 amount=-2
218 | kerning first=75 second=79 amount=-2
219 | kerning first=75 second=81 amount=-2
220 | kerning first=75 second=97 amount=-2
221 | kerning first=75 second=99 amount=-2
222 | kerning first=75 second=100 amount=-2
223 | kerning first=75 second=101 amount=-2
224 | kerning first=75 second=103 amount=-2
225 | kerning first=75 second=111 amount=-2
226 | kerning first=75 second=113 amount=-2
227 | kerning first=75 second=117 amount=-2
228 | kerning first=75 second=118 amount=-2
229 | kerning first=75 second=119 amount=-2
230 | kerning first=75 second=121 amount=-2
231 | kerning first=76 second=34 amount=-3
232 | kerning first=76 second=39 amount=-3
233 | kerning first=76 second=42 amount=-3
234 | kerning first=76 second=45 amount=-3
235 | kerning first=76 second=55 amount=-2
236 | kerning first=76 second=57 amount=-2
237 | kerning first=76 second=63 amount=-2
238 | kerning first=76 second=67 amount=-2
239 | kerning first=76 second=71 amount=-2
240 | kerning first=76 second=79 amount=-2
241 | kerning first=76 second=81 amount=-2
242 | kerning first=76 second=84 amount=-3
243 | kerning first=76 second=85 amount=-2
244 | kerning first=76 second=86 amount=-3
245 | kerning first=76 second=89 amount=-3
246 | kerning first=76 second=92 amount=-2
247 | kerning first=76 second=98 amount=-2
248 | kerning first=76 second=116 amount=-2
249 | kerning first=76 second=118 amount=-3
250 | kerning first=79 second=41 amount=-2
251 | kerning first=79 second=84 amount=-2
252 | kerning first=79 second=93 amount=-2
253 | kerning first=79 second=125 amount=-2
254 | kerning first=80 second=41 amount=-2
255 | kerning first=80 second=44 amount=-2
256 | kerning first=80 second=46 amount=-2
257 | kerning first=80 second=74 amount=-2
258 | kerning first=81 second=41 amount=-2
259 | kerning first=81 second=84 amount=-2
260 | kerning first=81 second=93 amount=-2
261 | kerning first=81 second=106 amount=1
262 | kerning first=81 second=125 amount=-2
263 | kerning first=84 second=44 amount=-2
264 | kerning first=84 second=45 amount=-2
265 | kerning first=84 second=46 amount=-2
266 | kerning first=84 second=47 amount=-2
267 | kerning first=84 second=58 amount=-2
268 | kerning first=84 second=59 amount=-2
269 | kerning first=84 second=64 amount=-2
270 | kerning first=84 second=67 amount=-2
271 | kerning first=84 second=71 amount=-2
272 | kerning first=84 second=74 amount=-3
273 | kerning first=84 second=79 amount=-2
274 | kerning first=84 second=81 amount=-2
275 | kerning first=84 second=97 amount=-3
276 | kerning first=84 second=99 amount=-3
277 | kerning first=84 second=100 amount=-3
278 | kerning first=84 second=101 amount=-3
279 | kerning first=84 second=103 amount=-3
280 | kerning first=84 second=109 amount=-2
281 | kerning first=84 second=110 amount=-2
282 | kerning first=84 second=111 amount=-3
283 | kerning first=84 second=112 amount=-2
284 | kerning first=84 second=113 amount=-3
285 | kerning first=84 second=114 amount=-2
286 | kerning first=84 second=115 amount=-3
287 | kerning first=84 second=117 amount=-3
288 | kerning first=84 second=118 amount=-2
289 | kerning first=84 second=119 amount=-3
290 | kerning first=84 second=120 amount=-2
291 | kerning first=84 second=121 amount=-3
292 | kerning first=84 second=122 amount=-2
293 | kerning first=86 second=42 amount=1
294 | kerning first=86 second=44 amount=-2
295 | kerning first=86 second=46 amount=-2
296 | kerning first=86 second=47 amount=-2
297 | kerning first=86 second=58 amount=-2
298 | kerning first=86 second=59 amount=-2
299 | kerning first=86 second=74 amount=-2
300 | kerning first=86 second=97 amount=-2
301 | kerning first=86 second=99 amount=-2
302 | kerning first=86 second=100 amount=-2
303 | kerning first=86 second=101 amount=-2
304 | kerning first=86 second=103 amount=-2
305 | kerning first=86 second=109 amount=-2
306 | kerning first=86 second=110 amount=-2
307 | kerning first=86 second=111 amount=-2
308 | kerning first=86 second=112 amount=-2
309 | kerning first=86 second=113 amount=-2
310 | kerning first=86 second=114 amount=-2
311 | kerning first=86 second=115 amount=-2
312 | kerning first=88 second=45 amount=-2
313 | kerning first=88 second=97 amount=-2
314 | kerning first=88 second=99 amount=-2
315 | kerning first=88 second=100 amount=-2
316 | kerning first=88 second=101 amount=-2
317 | kerning first=88 second=103 amount=-2
318 | kerning first=88 second=111 amount=-2
319 | kerning first=88 second=113 amount=-2
320 | kerning first=88 second=117 amount=-2
321 | kerning first=88 second=118 amount=-2
322 | kerning first=88 second=119 amount=-2
323 | kerning first=88 second=121 amount=-2
324 | kerning first=89 second=44 amount=-2
325 | kerning first=89 second=46 amount=-2
326 | kerning first=89 second=47 amount=-2
327 | kerning first=89 second=74 amount=-2
328 | kerning first=90 second=45 amount=-2
329 | kerning first=90 second=118 amount=-2
330 | kerning first=91 second=67 amount=-2
331 | kerning first=91 second=71 amount=-2
332 | kerning first=91 second=79 amount=-2
333 | kerning first=91 second=81 amount=-2
334 | kerning first=91 second=97 amount=-2
335 | kerning first=91 second=99 amount=-2
336 | kerning first=91 second=100 amount=-2
337 | kerning first=91 second=101 amount=-2
338 | kerning first=91 second=103 amount=-2
339 | kerning first=91 second=106 amount=3
340 | kerning first=91 second=111 amount=-2
341 | kerning first=91 second=113 amount=-2
342 | kerning first=91 second=118 amount=-2
343 | kerning first=91 second=123 amount=-2
344 | kerning first=92 second=34 amount=-2
345 | kerning first=92 second=39 amount=-2
346 | kerning first=92 second=57 amount=-2
347 | kerning first=92 second=84 amount=-2
348 | kerning first=92 second=86 amount=-2
349 | kerning first=92 second=89 amount=-2
350 | kerning first=92 second=118 amount=-2
351 | kerning first=98 second=41 amount=-2
352 | kerning first=98 second=63 amount=-2
353 | kerning first=98 second=92 amount=-2
354 | kerning first=98 second=93 amount=-2
355 | kerning first=98 second=125 amount=-2
356 | kerning first=102 second=42 amount=1
357 | kerning first=102 second=44 amount=-2
358 | kerning first=102 second=46 amount=-2
359 | kerning first=102 second=47 amount=-2
360 | kerning first=102 second=92 amount=1
361 | kerning first=103 second=106 amount=2
362 | kerning first=104 second=92 amount=-2
363 | kerning first=106 second=106 amount=2
364 | kerning first=109 second=92 amount=-2
365 | kerning first=110 second=92 amount=-2
366 | kerning first=111 second=41 amount=-2
367 | kerning first=111 second=63 amount=-2
368 | kerning first=111 second=92 amount=-2
369 | kerning first=111 second=93 amount=-2
370 | kerning first=111 second=125 amount=-2
371 | kerning first=112 second=41 amount=-2
372 | kerning first=112 second=63 amount=-2
373 | kerning first=112 second=92 amount=-2
374 | kerning first=112 second=93 amount=-2
375 | kerning first=112 second=125 amount=-2
376 | kerning first=113 second=106 amount=3
377 | kerning first=114 second=41 amount=-2
378 | kerning first=114 second=44 amount=-2
379 | kerning first=114 second=46 amount=-2
380 | kerning first=114 second=47 amount=-2
381 | kerning first=114 second=93 amount=-2
382 | kerning first=114 second=125 amount=-2
383 | kerning first=118 second=41 amount=-2
384 | kerning first=118 second=44 amount=-2
385 | kerning first=118 second=46 amount=-2
386 | kerning first=118 second=47 amount=-2
387 | kerning first=118 second=93 amount=-2
388 | kerning first=118 second=125 amount=-2
389 | kerning first=119 second=41 amount=-2
390 | kerning first=120 second=97 amount=-2
391 | kerning first=120 second=99 amount=-2
392 | kerning first=120 second=100 amount=-2
393 | kerning first=120 second=101 amount=-2
394 | kerning first=120 second=103 amount=-2
395 | kerning first=120 second=111 amount=-2
396 | kerning first=120 second=113 amount=-2
397 | kerning first=121 second=106 amount=2
398 | kerning first=123 second=67 amount=-2
399 | kerning first=123 second=71 amount=-2
400 | kerning first=123 second=79 amount=-2
401 | kerning first=123 second=81 amount=-2
402 | kerning first=123 second=97 amount=-2
403 | kerning first=123 second=99 amount=-2
404 | kerning first=123 second=100 amount=-2
405 | kerning first=123 second=101 amount=-2
406 | kerning first=123 second=103 amount=-2
407 | kerning first=123 second=106 amount=3
408 | kerning first=123 second=111 amount=-2
409 | kerning first=123 second=113 amount=-2
410 | kerning first=123 second=118 amount=-2
411 | kerning first=123 second=123 amount=-2
412 | kerning first=124 second=106 amount=3
413 | kerning first=125 second=41 amount=-2
414 | kerning first=125 second=93 amount=-2
415 | kerning first=125 second=125 amount=-2
416 |
--------------------------------------------------------------------------------
/codelabs-android/assets/data/fonts/righteous.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Leakedbits/Codelabs/67d62e139964425e4995cc1913f416929d995122/codelabs-android/assets/data/fonts/righteous.png
--------------------------------------------------------------------------------
/codelabs-android/assets/data/images/codelabs_splash.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Leakedbits/Codelabs/67d62e139964425e4995cc1913f416929d995122/codelabs-android/assets/data/images/codelabs_splash.png
--------------------------------------------------------------------------------
/codelabs-android/assets/data/images/crab.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Leakedbits/Codelabs/67d62e139964425e4995cc1913f416929d995122/codelabs-android/assets/data/images/crab.png
--------------------------------------------------------------------------------
/codelabs-android/assets/data/images/github_splash.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Leakedbits/Codelabs/67d62e139964425e4995cc1913f416929d995122/codelabs-android/assets/data/images/github_splash.png
--------------------------------------------------------------------------------
/codelabs-android/assets/data/ui/atlas.pack:
--------------------------------------------------------------------------------
1 |
2 | atlas.png
3 | format: RGBA8888
4 | filter: Nearest,Nearest
5 | repeat: none
6 | btn_over_blue
7 | rotate: false
8 | xy: 1, 1
9 | size: 32, 32
10 | split: 10, 10, 10, 10
11 | orig: 32, 32
12 | offset: 0, 0
13 | index: -1
14 | btn_over_red
15 | rotate: false
16 | xy: 35, 1
17 | size: 32, 32
18 | split: 10, 10, 10, 10
19 | orig: 32, 32
20 | offset: 0, 0
21 | index: -1
22 | btn_down_blue
23 | rotate: false
24 | xy: 69, 1
25 | size: 32, 32
26 | split: 10, 10, 10, 10
27 | orig: 32, 32
28 | offset: 0, 0
29 | index: -1
30 | btn_down_red
31 | rotate: false
32 | xy: 103, 1
33 | size: 32, 32
34 | split: 10, 10, 10, 10
35 | orig: 32, 32
36 | offset: 0, 0
37 | index: -1
38 | btn_up_blue
39 | rotate: false
40 | xy: 137, 1
41 | size: 32, 32
42 | split: 10, 10, 10, 10
43 | orig: 32, 32
44 | offset: 0, 0
45 | index: -1
46 | btn_up_red
47 | rotate: false
48 | xy: 171, 1
49 | size: 32, 32
50 | split: 10, 10, 10, 10
51 | orig: 32, 32
52 | offset: 0, 0
53 | index: -1
54 |
--------------------------------------------------------------------------------
/codelabs-android/assets/data/ui/atlas.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Leakedbits/Codelabs/67d62e139964425e4995cc1913f416929d995122/codelabs-android/assets/data/ui/atlas.png
--------------------------------------------------------------------------------
/codelabs-android/assets/data/ui/menu_skin.json:
--------------------------------------------------------------------------------
1 | {
2 | "com.badlogic.gdx.graphics.Color": {
3 | "white": { "r": 1, "g": 1, "b": 1, "a": 1 },
4 | "white": { "r": 0, "g": 0, "b": 0, "a": 1 }
5 | },
6 | "com.badlogic.gdx.graphics.g2d.BitmapFont": {
7 | "righteous-12": { "file": "data/fonts/Righteous-12.fnt" },
8 | "righteous-16": { "file": "data/fonts/Righteous-16.fnt" },
9 | "righteous-24": { "file": "data/fonts/Righteous-24.fnt" }
10 | },
11 | "com.badlogic.gdx.scenes.scene2d.ui.TextButton$TextButtonStyle": {
12 | "blue": {
13 | "up": "btn_up_blue",
14 | "down": "btn_down_blue",
15 | "over": "btn_over_blue",
16 | "font": righteous-16
17 | },
18 | "red": {
19 | "up": "btn_up_red",
20 | "down": "btn_down_red",
21 | "over": "btn_over_red",
22 | "font": righteous-16
23 | }
24 | }
25 | }
--------------------------------------------------------------------------------
/codelabs-android/gen/com/leakedbits/codelabs/BuildConfig.java:
--------------------------------------------------------------------------------
1 | /** Automatically generated file. DO NOT MODIFY */
2 | package com.leakedbits.codelabs;
3 |
4 | public final class BuildConfig {
5 | public final static boolean DEBUG = true;
6 | }
--------------------------------------------------------------------------------
/codelabs-android/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Leakedbits/Codelabs/67d62e139964425e4995cc1913f416929d995122/codelabs-android/ic_launcher-web.png
--------------------------------------------------------------------------------
/codelabs-android/libs/armeabi-v7a/libgdx.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Leakedbits/Codelabs/67d62e139964425e4995cc1913f416929d995122/codelabs-android/libs/armeabi-v7a/libgdx.so
--------------------------------------------------------------------------------
/codelabs-android/libs/armeabi/libgdx.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Leakedbits/Codelabs/67d62e139964425e4995cc1913f416929d995122/codelabs-android/libs/armeabi/libgdx.so
--------------------------------------------------------------------------------
/codelabs-android/libs/gdx-backend-android-sources.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Leakedbits/Codelabs/67d62e139964425e4995cc1913f416929d995122/codelabs-android/libs/gdx-backend-android-sources.jar
--------------------------------------------------------------------------------
/codelabs-android/libs/gdx-backend-android.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Leakedbits/Codelabs/67d62e139964425e4995cc1913f416929d995122/codelabs-android/libs/gdx-backend-android.jar
--------------------------------------------------------------------------------
/codelabs-android/libs/x86/libgdx.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Leakedbits/Codelabs/67d62e139964425e4995cc1913f416929d995122/codelabs-android/libs/x86/libgdx.so
--------------------------------------------------------------------------------
/codelabs-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 |
--------------------------------------------------------------------------------
/codelabs-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-19
12 |
--------------------------------------------------------------------------------
/codelabs-android/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Leakedbits/Codelabs/67d62e139964425e4995cc1913f416929d995122/codelabs-android/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/codelabs-android/res/drawable-ldpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Leakedbits/Codelabs/67d62e139964425e4995cc1913f416929d995122/codelabs-android/res/drawable-ldpi/ic_launcher.png
--------------------------------------------------------------------------------
/codelabs-android/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Leakedbits/Codelabs/67d62e139964425e4995cc1913f416929d995122/codelabs-android/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/codelabs-android/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Leakedbits/Codelabs/67d62e139964425e4995cc1913f416929d995122/codelabs-android/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/codelabs-android/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Leakedbits/Codelabs/67d62e139964425e4995cc1913f416929d995122/codelabs-android/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/codelabs-android/res/layout/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
--------------------------------------------------------------------------------
/codelabs-android/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Codelabs
4 |
--------------------------------------------------------------------------------
/codelabs-android/src/com/leakedbits/codelabs/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.leakedbits.codelabs;
2 |
3 | import android.os.Bundle;
4 |
5 | import com.badlogic.gdx.backends.android.AndroidApplication;
6 | import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
7 |
8 | public class MainActivity extends AndroidApplication {
9 | @Override
10 | public void onCreate(Bundle savedInstanceState) {
11 | super.onCreate(savedInstanceState);
12 |
13 | AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
14 | cfg.useGL20 = false;
15 |
16 | initialize(new Codelabs(), cfg);
17 | }
18 | }
--------------------------------------------------------------------------------
/codelabs-desktop/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/codelabs-desktop/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | codelabs-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/codelabs-android/assets
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/codelabs-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 |
--------------------------------------------------------------------------------
/codelabs-desktop/libs/gdx-backend-lwjgl-natives.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Leakedbits/Codelabs/67d62e139964425e4995cc1913f416929d995122/codelabs-desktop/libs/gdx-backend-lwjgl-natives.jar
--------------------------------------------------------------------------------
/codelabs-desktop/libs/gdx-backend-lwjgl-sources.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Leakedbits/Codelabs/67d62e139964425e4995cc1913f416929d995122/codelabs-desktop/libs/gdx-backend-lwjgl-sources.jar
--------------------------------------------------------------------------------
/codelabs-desktop/libs/gdx-backend-lwjgl.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Leakedbits/Codelabs/67d62e139964425e4995cc1913f416929d995122/codelabs-desktop/libs/gdx-backend-lwjgl.jar
--------------------------------------------------------------------------------
/codelabs-desktop/libs/gdx-natives.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Leakedbits/Codelabs/67d62e139964425e4995cc1913f416929d995122/codelabs-desktop/libs/gdx-natives.jar
--------------------------------------------------------------------------------
/codelabs-desktop/src/com/leakedbits/codelabs/Main.java:
--------------------------------------------------------------------------------
1 | package com.leakedbits.codelabs;
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 = Codelabs.TITLE + " (" + Codelabs.VERSION + ")";
10 | cfg.useGL20 = false;
11 | cfg.width = 800;
12 | cfg.height = 600;
13 |
14 | new LwjglApplication(new Codelabs(), cfg);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/codelabs/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/codelabs/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | codelabs
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 |
--------------------------------------------------------------------------------
/codelabs/.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 |
--------------------------------------------------------------------------------
/codelabs/libs/gdx-sources.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Leakedbits/Codelabs/67d62e139964425e4995cc1913f416929d995122/codelabs/libs/gdx-sources.jar
--------------------------------------------------------------------------------
/codelabs/libs/gdx.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Leakedbits/Codelabs/67d62e139964425e4995cc1913f416929d995122/codelabs/libs/gdx.jar
--------------------------------------------------------------------------------
/codelabs/src/Codelabs.gwt.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/codelabs/src/com/leakedbits/codelabs/Codelabs.java:
--------------------------------------------------------------------------------
1 | package com.leakedbits.codelabs;
2 |
3 | import com.badlogic.gdx.Game;
4 |
5 | public class Codelabs extends Game {
6 |
7 | public static final String TITLE = "Codelabs";
8 | public static final String VERSION = "v0.6.0";
9 |
10 | public static final float TARGET_WIDTH = 800;
11 |
12 | @Override
13 | public void create() {
14 | setScreen(new SplashScreen());
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/codelabs/src/com/leakedbits/codelabs/MainMenu.java:
--------------------------------------------------------------------------------
1 | package com.leakedbits.codelabs;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import com.badlogic.gdx.Game;
7 | import com.badlogic.gdx.Gdx;
8 | import com.badlogic.gdx.Screen;
9 | import com.badlogic.gdx.graphics.GL20;
10 | import com.badlogic.gdx.graphics.g2d.TextureAtlas;
11 | import com.badlogic.gdx.math.Interpolation;
12 | import com.badlogic.gdx.scenes.scene2d.EventListener;
13 | import com.badlogic.gdx.scenes.scene2d.InputEvent;
14 | import com.badlogic.gdx.scenes.scene2d.Stage;
15 | import com.badlogic.gdx.scenes.scene2d.actions.Actions;
16 | import com.badlogic.gdx.scenes.scene2d.ui.Skin;
17 | import com.badlogic.gdx.scenes.scene2d.ui.Table;
18 | import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
19 | import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
20 | import com.leakedbits.codelabs.box2d.utils.Box2DSamples;
21 | import com.leakedbits.codelabs.utils.Sample;
22 | import com.leakedbits.codelabs.utils.SampleUtils;
23 |
24 | public class MainMenu implements Screen {
25 |
26 | private static final int MAX_TABLE_COLUMNS = 2;
27 |
28 | private Skin skin;
29 | private Stage stage;
30 | private Table table;
31 | private TextureAtlas atlas;
32 |
33 | @Override
34 | public void render(float delta) {
35 | Gdx.gl.glClearColor(1, 1, 1, 1);
36 | Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
37 |
38 | stage.act(delta);
39 | stage.draw();
40 | }
41 |
42 | @Override
43 | public void resize(int width, int height) {
44 |
45 | }
46 |
47 | @Override
48 | public void show() {
49 | stage = new Stage();
50 |
51 | stage.setViewport(Codelabs.TARGET_WIDTH, Codelabs.TARGET_WIDTH
52 | * (Gdx.graphics.getHeight() / (float) Gdx.graphics.getWidth()));
53 |
54 | Gdx.input.setInputProcessor(stage);
55 |
56 | atlas = new TextureAtlas("data/ui/atlas.pack");
57 |
58 | skin = new Skin(Gdx.files.internal("data/ui/menu_skin.json"), atlas);
59 |
60 | table = new Table(skin);
61 | table.setFillParent(true);
62 | table.defaults().uniformX().pad(3);
63 |
64 | List textButtons = new ArrayList();
65 |
66 | for (String name : SampleUtils.getNames(Box2DSamples.SAMPLES, false)) {
67 | final Sample sample = SampleUtils.instantiateSample(
68 | Box2DSamples.SAMPLES, name);
69 | textButtons.add(createTextButton(sample.getName(), skin, "blue",
70 | new ClickListener() {
71 | @Override
72 | public void clicked(InputEvent event, float x, float y) {
73 | ((Game) Gdx.app.getApplicationListener())
74 | .setScreen(sample);
75 | }
76 | }));
77 | }
78 |
79 | addSampleButtons(textButtons);
80 |
81 | TextButton exitButton = createTextButton("Exit", skin, "red",
82 | new ClickListener() {
83 | @Override
84 | public void clicked(InputEvent event, float x, float y) {
85 | dispose();
86 | Gdx.app.exit();
87 | }
88 | });
89 |
90 | table.add(exitButton).colspan(MAX_TABLE_COLUMNS).fill();
91 |
92 | // float displacement = Codelabs.TARGET_WIDTH - table.getWidth() / 2;
93 | // table.addAction(Actions.sequence(Actions.moveBy(displacement, 0),
94 | // Actions.delay(1, Actions.moveBy(-displacement, 0, 1,
95 | // Interpolation.swingOut))));
96 |
97 | stage.addActor(table);
98 |
99 | }
100 |
101 | @Override
102 | public void hide() {
103 |
104 | }
105 |
106 | @Override
107 | public void pause() {
108 |
109 | }
110 |
111 | @Override
112 | public void resume() {
113 |
114 | }
115 |
116 | @Override
117 | public void dispose() {
118 | skin.dispose();
119 | atlas.dispose();
120 | stage.dispose();
121 | }
122 |
123 | private void addSampleButtons(List textButtons) {
124 | int columnCounter = 0;
125 |
126 | for (TextButton textButton : textButtons) {
127 | table.add(textButton).fill();
128 |
129 | if (++columnCounter >= MAX_TABLE_COLUMNS) {
130 | columnCounter = 0;
131 | table.row();
132 | }
133 | }
134 |
135 | }
136 |
137 | private TextButton createTextButton(String text, Skin skin,
138 | String styleName, EventListener listener) {
139 | TextButton textButton = new TextButton(text, skin, styleName);
140 | textButton.pad(10);
141 | textButton.addListener(listener);
142 |
143 | return textButton;
144 | }
145 | }
146 |
--------------------------------------------------------------------------------
/codelabs/src/com/leakedbits/codelabs/SplashScreen.java:
--------------------------------------------------------------------------------
1 | package com.leakedbits.codelabs;
2 |
3 | import com.badlogic.gdx.Game;
4 | import com.badlogic.gdx.Gdx;
5 | import com.badlogic.gdx.Screen;
6 | import com.badlogic.gdx.graphics.GL20;
7 | import com.badlogic.gdx.graphics.Texture;
8 | import com.badlogic.gdx.math.Interpolation;
9 | import com.badlogic.gdx.scenes.scene2d.Stage;
10 | import com.badlogic.gdx.scenes.scene2d.actions.Actions;
11 | import com.badlogic.gdx.scenes.scene2d.ui.Image;
12 |
13 | public class SplashScreen implements Screen {
14 |
15 | private Image codelabsImage;
16 | private Image githubImage;
17 | private Stage stage;
18 |
19 | @Override
20 | public void render(float delta) {
21 | Gdx.gl.glClearColor(1, 1, 1, 1);
22 | Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
23 |
24 | stage.act();
25 |
26 | stage.draw();
27 | }
28 |
29 | @Override
30 | public void resize(int width, int height) {
31 |
32 | }
33 |
34 | @Override
35 | public void show() {
36 | stage = new Stage();
37 |
38 | /* Load splash image */
39 | codelabsImage = new Image(new Texture(
40 | Gdx.files.internal("data/images/codelabs_splash.png")));
41 |
42 | githubImage = new Image(new Texture(
43 | Gdx.files.internal("data/images/github_splash.png")));
44 |
45 | /* Set the splash image in the center of the screen */
46 | float width = Gdx.graphics.getWidth();
47 | float height = Gdx.graphics.getHeight();
48 |
49 | codelabsImage.setPosition((width - codelabsImage.getWidth()) / 2,
50 | (height - codelabsImage.getHeight()) / 2);
51 |
52 | /* Fade in the image and then swing it down */
53 | codelabsImage.getColor().a = 0f;
54 | codelabsImage.addAction(Actions.sequence(Actions.fadeIn(0.5f), Actions
55 | .delay(1, Actions.fadeOut(0.5f))));
56 |
57 | githubImage.setPosition((width - githubImage.getWidth()) / 2,
58 | (height - githubImage.getHeight()) / 2);
59 |
60 | /* Fade in the image and then swing it down */
61 | githubImage.getColor().a = 0f;
62 | githubImage.addAction(Actions.delay(2, Actions.sequence(Actions.fadeIn(0.5f), Actions
63 | .delay(1, Actions.moveBy(0,
64 | -(height - githubImage.getHeight() / 2), 1,
65 | Interpolation.swingIn)), Actions.run(new Runnable() {
66 | @Override
67 | public void run() {
68 |
69 | /* Show main menu after swing out */
70 | ((Game) Gdx.app.getApplicationListener())
71 | .setScreen(new MainMenu());
72 | }
73 | }))));
74 |
75 | stage.addActor(codelabsImage);
76 | stage.addActor(githubImage);
77 | }
78 |
79 | @Override
80 | public void hide() {
81 |
82 | }
83 |
84 | @Override
85 | public void pause() {
86 |
87 | }
88 |
89 | @Override
90 | public void resume() {
91 |
92 | }
93 |
94 | @Override
95 | public void dispose() {
96 | stage.dispose();
97 | }
98 |
99 | }
--------------------------------------------------------------------------------
/codelabs/src/com/leakedbits/codelabs/box2d/BouncingBallSample.java:
--------------------------------------------------------------------------------
1 | package com.leakedbits.codelabs.box2d;
2 |
3 | import com.badlogic.gdx.Gdx;
4 | import com.badlogic.gdx.graphics.GL20;
5 | import com.badlogic.gdx.graphics.OrthographicCamera;
6 | import com.badlogic.gdx.math.Vector2;
7 | import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
8 | import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer;
9 | import com.badlogic.gdx.physics.box2d.FixtureDef;
10 | import com.badlogic.gdx.physics.box2d.Shape;
11 | import com.badlogic.gdx.physics.box2d.World;
12 | import com.leakedbits.codelabs.box2d.utils.Box2DFactory;
13 | import com.leakedbits.codelabs.utils.Sample;
14 |
15 | public class BouncingBallSample extends Sample {
16 |
17 | /* Use Box2DDebugRenderer, which is a model renderer for debug purposes */
18 | private Box2DDebugRenderer debugRenderer;
19 |
20 | /* As always, we need a camera to be able to see the objects */
21 | private OrthographicCamera camera;
22 |
23 | /* Define a world to hold all bodies and simulate reactions between them */
24 | private World world;
25 |
26 | /**
27 | * Main constructor used to update test name.
28 | */
29 | public BouncingBallSample() {
30 | name = "Bouncing ball";
31 | }
32 |
33 | @Override
34 | public void render(float delta) {
35 | /* Clear screen with a black background */
36 | Gdx.gl.glClearColor(0, 0, 0, 1);
37 | Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
38 |
39 | /* Render all graphics before do physics step */
40 | debugRenderer.render(world, camera.combined);
41 |
42 | /* Step the simulation with a fixed time step of 1/60 of a second */
43 | world.step(1 / 60f, 6, 2);
44 | }
45 |
46 | @Override
47 | public void show() {
48 | /*
49 | * This line is found in every sample but is not necessary for the sample
50 | * functionality. calls Sample.show() method. That method set the sample to
51 | * receive all touch and key input events. Also prevents the app from be
52 | * closed whenever the user press back button and instead returns to
53 | * main menu.
54 | */
55 | super.show();
56 |
57 | /*
58 | * Create world with a common gravity vector (9.81 m/s2 downwards force)
59 | * and tell world that we want objects to sleep. This last value
60 | * conserves CPU usage.
61 | */
62 | world = new World(new Vector2(0, -9.81f), true);
63 |
64 | /* Create renderer */
65 | debugRenderer = new Box2DDebugRenderer();
66 |
67 | /*
68 | * Define camera viewport. Box2D uses meters internally so the camera
69 | * must be defined also in meters. We set a desired width and adjust
70 | * height to different resolutions.
71 | */
72 | camera = new OrthographicCamera(20,
73 | 20 * (Gdx.graphics.getHeight() / (float) Gdx.graphics
74 | .getWidth()));
75 |
76 | /* Create the ball */
77 | Shape shape = Box2DFactory.createCircleShape(0.5f);
78 | FixtureDef fixtureDef = Box2DFactory.createFixture(shape, 2.5f, 0.25f, 0.75f, false);
79 | Box2DFactory.createBody(world, BodyType.DynamicBody, fixtureDef, new Vector2(6, 5));
80 |
81 | /* Create the ramp */
82 | Vector2[] rampVertices = new Vector2[] { new Vector2(-2.5f, -1), new Vector2(2.5f, 1) };
83 | shape = Box2DFactory.createChainShape(rampVertices);
84 | fixtureDef = Box2DFactory.createFixture(shape, 0, 0.3f, 0.3f, false);
85 | Box2DFactory.createBody(world, BodyType.StaticBody, fixtureDef, new Vector2(6.5f, 0));
86 |
87 | /* Create the walls */
88 | Box2DFactory.createWalls(world, camera.viewportWidth, camera.viewportHeight, 1);
89 | }
90 |
91 | @Override
92 | public void dispose() {
93 | debugRenderer.dispose();
94 | world.dispose();
95 | }
96 |
97 | }
98 |
--------------------------------------------------------------------------------
/codelabs/src/com/leakedbits/codelabs/box2d/BuoyancySample.java:
--------------------------------------------------------------------------------
1 | package com.leakedbits.codelabs.box2d;
2 |
3 | import com.badlogic.gdx.Gdx;
4 | import com.badlogic.gdx.graphics.GL20;
5 | import com.badlogic.gdx.graphics.OrthographicCamera;
6 | import com.badlogic.gdx.math.Vector2;
7 | import com.badlogic.gdx.math.Vector3;
8 | import com.badlogic.gdx.physics.box2d.Body;
9 | import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
10 | import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer;
11 | import com.badlogic.gdx.physics.box2d.Contact;
12 | import com.badlogic.gdx.physics.box2d.ContactImpulse;
13 | import com.badlogic.gdx.physics.box2d.ContactListener;
14 | import com.badlogic.gdx.physics.box2d.Fixture;
15 | import com.badlogic.gdx.physics.box2d.FixtureDef;
16 | import com.badlogic.gdx.physics.box2d.Manifold;
17 | import com.badlogic.gdx.physics.box2d.Shape;
18 | import com.badlogic.gdx.physics.box2d.World;
19 | import com.leakedbits.codelabs.box2d.controllers.BuoyancyController;
20 | import com.leakedbits.codelabs.box2d.utils.Box2DFactory;
21 | import com.leakedbits.codelabs.utils.Sample;
22 |
23 | public class BuoyancySample extends Sample implements ContactListener {
24 |
25 | /* Max number of bodies to be spawned */
26 | private static final int MAX_SPAWNED_BODIES = 20;
27 |
28 | /* Use Box2DDebugRenderer, which is a model renderer for debug purposes */
29 | private Box2DDebugRenderer debugRenderer;
30 |
31 | /* As always, we need a camera to be able to see the objects */
32 | private OrthographicCamera camera;
33 |
34 | /* Define a world to hold all bodies and simulate reactions between them */
35 | private World world;
36 |
37 | private BuoyancyController buoyancyController;
38 |
39 | /* Counter to know how many bodies have been spawned */
40 | private int spawnedBodies;
41 |
42 | public BuoyancySample() {
43 | name = "Buoyancy";
44 | }
45 |
46 | @Override
47 | public void render(float delta) {
48 | /* Clear screen with a black background */
49 | Gdx.gl.glClearColor(0, 0, 0, 1);
50 | Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
51 |
52 | /* Render all graphics before do physics step */
53 | debugRenderer.render(world, camera.combined);
54 |
55 | /* Step the simulation with a fixed time step of 1/60 of a second */
56 | world.step(1 / 60f, 6, 2);
57 | // buoyancyController.step(1 / 60f);
58 |
59 | buoyancyController.step();
60 | }
61 |
62 | @Override
63 | public void show() {
64 | /*
65 | * This line is found in every sample but is not necessary for the
66 | * sample functionality. calls Sample.show() method. That method set the
67 | * sample to receive all touch and key input events. Also prevents the
68 | * app from be closed whenever the user press back button and instead
69 | * returns to main menu.
70 | */
71 | super.show();
72 |
73 | /*
74 | * Create world with a common gravity vector (9.81 m/s2 downwards force)
75 | * and tell world that we want objects to sleep. This last value
76 | * conserves CPU usage.
77 | */
78 | world = new World(new Vector2(0, -9.81f), true);
79 |
80 | /* Create renderer */
81 | debugRenderer = new Box2DDebugRenderer();
82 |
83 | /*
84 | * Define camera viewport. Box2D uses meters internally so the camera
85 | * must be defined also in meters. We set a desired width and adjust
86 | * height to different resolutions.
87 | */
88 | camera = new OrthographicCamera(20,
89 | 20 * (Gdx.graphics.getHeight() / (float) Gdx.graphics
90 | .getWidth()));
91 |
92 | /*
93 | * Next line must remain commented because we do this in its parent (See
94 | * Sample class). In case you are not using Sample class, uncomment this
95 | * line to set input processor to handle events.
96 | */
97 | // Gdx.input.setInputProcessor(this);
98 |
99 | Box2DFactory.createWalls(world, camera.viewportWidth,
100 | camera.viewportHeight, 1);
101 |
102 | /* Create the water */
103 | Shape shape = Box2DFactory.createBoxShape(
104 | (camera.viewportWidth / 2 - 1),
105 | (camera.viewportHeight / 2 - 2) / 2, new Vector2(0, 0), 0);
106 | FixtureDef fixtureDef = Box2DFactory.createFixture(shape, 1, 0.1f, 0,
107 | true);
108 | Body water = Box2DFactory.createBody(world, BodyType.StaticBody,
109 | fixtureDef, new Vector2(0,
110 | -(camera.viewportHeight / 2 - 1) / 2 - 0.5f));
111 |
112 | /*
113 | * Create a buoyancy controller using the previous body as a fluid
114 | * sensor
115 | */
116 | buoyancyController = new BuoyancyController(world, water
117 | .getFixtureList().first());
118 |
119 | world.setContactListener(this);
120 | }
121 |
122 | @Override
123 | public void dispose() {
124 | debugRenderer.dispose();
125 | world.dispose();
126 | }
127 |
128 | @Override
129 | public void beginContact(Contact contact) {
130 | Fixture fixtureA = contact.getFixtureA();
131 | Fixture fixtureB = contact.getFixtureB();
132 |
133 | if (fixtureA.isSensor()
134 | && fixtureB.getBody().getType() == BodyType.DynamicBody) {
135 | buoyancyController.addBody(fixtureB);
136 | } else if (fixtureB.isSensor()
137 | && fixtureA.getBody().getType() == BodyType.DynamicBody) {
138 | buoyancyController.addBody(fixtureA);
139 | }
140 | }
141 |
142 | @Override
143 | public void endContact(Contact contact) {
144 | Fixture fixtureA = contact.getFixtureA();
145 | Fixture fixtureB = contact.getFixtureB();
146 |
147 | if (fixtureA.isSensor()
148 | && fixtureB.getBody().getType() == BodyType.DynamicBody) {
149 | buoyancyController.removeBody(fixtureB);
150 | } else if (fixtureB.isSensor()
151 | && fixtureA.getBody().getType() == BodyType.DynamicBody) {
152 | if (fixtureA.getBody().getWorldCenter().y > -1) {
153 | buoyancyController.removeBody(fixtureA);
154 | }
155 | }
156 | }
157 |
158 | @Override
159 | public void preSolve(Contact contact, Manifold oldManifold) {
160 |
161 | }
162 |
163 | @Override
164 | public void postSolve(Contact contact, ContactImpulse impulse) {
165 |
166 | }
167 |
168 | @Override
169 | public boolean touchUp(int screenX, int screenY, int pointer, int button) {
170 |
171 | /* Checks whether the max amount of balls were spawned */
172 | if (spawnedBodies < MAX_SPAWNED_BODIES) {
173 | spawnedBodies++;
174 |
175 | /* Translate camera point to world point */
176 | Vector3 unprojectedVector = new Vector3();
177 | camera.unproject(unprojectedVector.set(screenX, screenY, 0));
178 |
179 | /* Create a new box */
180 | if (Math.random() >= 0.5) {
181 | Shape shape = Box2DFactory.createBoxShape(1, 1, new Vector2(0,
182 | 0), 0);
183 | FixtureDef fixtureDef = Box2DFactory.createFixture(shape, 0.5f,
184 | 0.5f, 0.5f, false);
185 | Box2DFactory.createBody(world, BodyType.DynamicBody,
186 | fixtureDef, new Vector2(unprojectedVector.x,
187 | unprojectedVector.y));
188 | } else {
189 | /* Create a new triangle */
190 | Shape shape = Box2DFactory.createTriangleShape(1, 1);
191 | FixtureDef fixtureDef = Box2DFactory.createFixture(shape, 0.5f,
192 | 0.5f, 0.5f, false);
193 | Box2DFactory.createBody(world, BodyType.DynamicBody,
194 | fixtureDef, new Vector2(unprojectedVector.x,
195 | unprojectedVector.y));
196 | }
197 | }
198 |
199 | return true;
200 | }
201 |
202 | }
203 |
--------------------------------------------------------------------------------
/codelabs/src/com/leakedbits/codelabs/box2d/CollisionsSample.java:
--------------------------------------------------------------------------------
1 | package com.leakedbits.codelabs.box2d;
2 |
3 | import com.badlogic.gdx.Gdx;
4 | import com.badlogic.gdx.graphics.GL20;
5 | import com.badlogic.gdx.graphics.OrthographicCamera;
6 | import com.badlogic.gdx.math.Vector2;
7 | import com.badlogic.gdx.physics.box2d.Body;
8 | import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
9 | import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer;
10 | import com.badlogic.gdx.physics.box2d.Contact;
11 | import com.badlogic.gdx.physics.box2d.ContactImpulse;
12 | import com.badlogic.gdx.physics.box2d.ContactListener;
13 | import com.badlogic.gdx.physics.box2d.Fixture;
14 | import com.badlogic.gdx.physics.box2d.FixtureDef;
15 | import com.badlogic.gdx.physics.box2d.Manifold;
16 | import com.badlogic.gdx.physics.box2d.Shape;
17 | import com.badlogic.gdx.physics.box2d.World;
18 | import com.leakedbits.codelabs.box2d.utils.Box2DFactory;
19 | import com.leakedbits.codelabs.utils.Sample;
20 |
21 | public class CollisionsSample extends Sample implements ContactListener {
22 |
23 | /* Use Box2DDebugRenderer, which is a model renderer for debug purposes */
24 | private Box2DDebugRenderer debugRenderer;
25 |
26 | /* As always, we need a camera to be able to see the objects */
27 | private OrthographicCamera camera;
28 |
29 | /* Define a world to hold all bodies and simulate reactions between them */
30 | private World world;
31 |
32 | private Body walls;
33 |
34 | private boolean ballTouchedWall;
35 | private boolean ballTouchedBox;
36 |
37 | /* Fields to store previous accelerometer values in each iteration */
38 | private float prevAccelX;
39 | private float prevAccelY;
40 |
41 | /**
42 | * Main constructor used to update sample name.
43 | */
44 | public CollisionsSample() {
45 | name = "Collisions";
46 | }
47 |
48 | @Override
49 | public void render(float delta) {
50 | /*
51 | * Clear screen with a black background. Use red instead if the ball
52 | * touched a wall or blue if touched the box.
53 | */
54 | if (ballTouchedWall) {
55 | Gdx.gl.glClearColor(0.6f, 0, 0, 1);
56 | } else if (ballTouchedBox) {
57 | Gdx.gl.glClearColor(0, 0, 0.6f, 1);
58 | } else {
59 | Gdx.gl.glClearColor(0, 0, 0, 1);
60 | }
61 | Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
62 |
63 | /* Check if we should change the gravity */
64 | processAccelerometer();
65 |
66 | /* Render all graphics before do physics step */
67 | debugRenderer.render(world, camera.combined);
68 |
69 | /* Step the simulation with a fixed time step of 1/60 of a second */
70 | world.step(1 / 60f, 6, 2);
71 | }
72 |
73 | @Override
74 | public void show() {
75 | /*
76 | * This line is found in every sample but is not necessary for the
77 | * sample functionality. calls Sample.show() method. That method set the
78 | * sample to receive all touch and key input events. Also prevents the
79 | * app from be closed whenever the user press back button and instead
80 | * returns to main menu.
81 | */
82 | super.show();
83 |
84 | /*
85 | * Create world with a common gravity vector (9.81 m/s2 downwards force)
86 | * and tell world that we want objects to sleep. This last value
87 | * conserves CPU usage. As we use the accelerometer and the world
88 | * gravity to change bodies positions, we can't let bodies to sleep.
89 | */
90 | world = new World(new Vector2(0, -9.81f), false);
91 |
92 | /* Create renderer */
93 | debugRenderer = new Box2DDebugRenderer();
94 |
95 | /*
96 | * Define camera viewport. Box2D uses meters internally so the camera
97 | * must be defined also in meters. We set a desired width and adjust
98 | * height to different resolutions.
99 | */
100 | camera = new OrthographicCamera(20,
101 | 20 * (Gdx.graphics.getHeight() / (float) Gdx.graphics
102 | .getWidth()));
103 |
104 | /* Create the ball */
105 | Shape shape = Box2DFactory.createCircleShape(1);
106 | FixtureDef fixtureDef = Box2DFactory.createFixture(shape, 2.5f, 0.25f,
107 | 0.75f, false);
108 | Box2DFactory.createBody(world, BodyType.DynamicBody, fixtureDef,
109 | new Vector2(5, 0));
110 |
111 | /* Create the box */
112 | shape = Box2DFactory.createBoxShape(0.5f, 0.5f, new Vector2(0, 0), 0);
113 | fixtureDef = Box2DFactory.createFixture(shape, 1, 0.5f, 0.5f, false);
114 | Box2DFactory.createBody(world, BodyType.StaticBody, fixtureDef,
115 | new Vector2(0, 0));
116 |
117 | /* Create the walls */
118 | walls = Box2DFactory.createWalls(world, camera.viewportWidth,
119 | camera.viewportHeight, 1);
120 |
121 | world.setContactListener(this);
122 | }
123 |
124 | @Override
125 | public void dispose() {
126 | debugRenderer.dispose();
127 | world.dispose();
128 | }
129 |
130 | private void processAccelerometer() {
131 |
132 | /* Get accelerometer values */
133 | float y = Gdx.input.getAccelerometerY();
134 | float x = Gdx.input.getAccelerometerX();
135 |
136 | /*
137 | * If accelerometer values have changed since previous processing,
138 | * change world gravity.
139 | */
140 | if (prevAccelX != x || prevAccelY != y) {
141 |
142 | /* Negative on the x axis but not in the y */
143 | world.setGravity(new Vector2(y, -x));
144 |
145 | /* Store new accelerometer values */
146 | prevAccelX = x;
147 | prevAccelY = y;
148 | }
149 | }
150 |
151 | @Override
152 | public void beginContact(Contact contact) {
153 | Fixture fixtureA = contact.getFixtureA();
154 | Fixture fixtureB = contact.getFixtureB();
155 |
156 | /*
157 | * If one of the fixture contacting is an static body, and is the wall,
158 | * set ballTouchedWall to true.
159 | */
160 | if (fixtureA.getBody().getType() == BodyType.StaticBody) {
161 | if (fixtureA.getBody().equals(walls)) {
162 | ballTouchedBox = false;
163 | ballTouchedWall = true;
164 | } else {
165 | ballTouchedBox = true;
166 | ballTouchedWall = false;
167 | }
168 | } else if (fixtureB.getBody().getType() == BodyType.StaticBody) {
169 | if (fixtureA.getBody().equals(walls)) {
170 | ballTouchedBox = false;
171 | ballTouchedWall = true;
172 | } else {
173 | ballTouchedBox = true;
174 | ballTouchedWall = false;
175 | }
176 | }
177 | }
178 |
179 | @Override
180 | public void endContact(Contact contact) {
181 |
182 | }
183 |
184 | @Override
185 | public void preSolve(Contact contact, Manifold oldManifold) {
186 |
187 | }
188 |
189 | @Override
190 | public void postSolve(Contact contact, ContactImpulse impulse) {
191 |
192 | }
193 |
194 | }
195 |
--------------------------------------------------------------------------------
/codelabs/src/com/leakedbits/codelabs/box2d/DragAndDropSample.java:
--------------------------------------------------------------------------------
1 | package com.leakedbits.codelabs.box2d;
2 |
3 | import com.badlogic.gdx.Gdx;
4 | import com.badlogic.gdx.graphics.GL20;
5 | import com.badlogic.gdx.graphics.OrthographicCamera;
6 | import com.badlogic.gdx.math.Vector2;
7 | import com.badlogic.gdx.math.Vector3;
8 | import com.badlogic.gdx.physics.box2d.Body;
9 | import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
10 | import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer;
11 | import com.badlogic.gdx.physics.box2d.Fixture;
12 | import com.badlogic.gdx.physics.box2d.FixtureDef;
13 | import com.badlogic.gdx.physics.box2d.QueryCallback;
14 | import com.badlogic.gdx.physics.box2d.Shape;
15 | import com.badlogic.gdx.physics.box2d.World;
16 | import com.badlogic.gdx.physics.box2d.joints.MouseJoint;
17 | import com.badlogic.gdx.physics.box2d.joints.MouseJointDef;
18 | import com.leakedbits.codelabs.box2d.utils.Box2DFactory;
19 | import com.leakedbits.codelabs.utils.Sample;
20 |
21 | public class DragAndDropSample extends Sample {
22 |
23 | /* Use Box2DDebugRenderer, which is a model renderer for debug purposes */
24 | private Box2DDebugRenderer debugRenderer;
25 |
26 | /* As always, we need a camera to be able to see the objects */
27 | private OrthographicCamera camera;
28 |
29 | /* Define a world to hold all bodies and simulate reactions between them */
30 | private World world;
31 |
32 | /*
33 | * Used to define a mouse joint for a body. This point will track a
34 | * specified world point.
35 | */
36 | private MouseJoint mouseJoint;
37 | private MouseJointDef mouseJointDef;
38 |
39 | /* Store the position of the last touch or mouse click */
40 | private Vector3 touchPosition;
41 |
42 | /**
43 | * Main constructor used to update sample name.
44 | */
45 | public DragAndDropSample() {
46 | name = "Drag and drop";
47 | }
48 |
49 | @Override
50 | public void render(float delta) {
51 | /* Clear screen with a black background */
52 | Gdx.gl.glClearColor(0, 0, 0, 1);
53 | Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
54 |
55 | /* Render all graphics before do physics step */
56 | debugRenderer.render(world, camera.combined);
57 |
58 | /* Step the simulation with a fixed time step of 1/60 of a second */
59 | world.step(1 / 60f, 6, 2);
60 | }
61 |
62 | @Override
63 | public void show() {
64 | /*
65 | * This line is found in every sample but is not necessary for the
66 | * sample functionality. calls Sample.show() method. That method set the
67 | * sample to receive all touch and key input events. Also prevents the
68 | * app from be closed whenever the user press back button and instead
69 | * returns to main menu.
70 | */
71 | super.show();
72 |
73 | /*
74 | * Create world with a common gravity vector (9.81 m/s2 downwards force)
75 | * and tell world that we want objects to sleep. This last value
76 | * conserves CPU usage.
77 | */
78 | world = new World(new Vector2(0, -9.81f), true);
79 |
80 | /* Create renderer */
81 | debugRenderer = new Box2DDebugRenderer();
82 |
83 | /*
84 | * Define camera viewport. Box2D uses meters internally so the camera
85 | * must be defined also in meters. We set a desired width and adjust
86 | * height to different resolutions.
87 | */
88 | camera = new OrthographicCamera(20,
89 | 20 * (Gdx.graphics.getHeight() / (float) Gdx.graphics
90 | .getWidth()));
91 |
92 | /*
93 | * Next line must remain commented because we do this in its parent (See
94 | * Sample class). In case you are not using Sample class, uncomment this
95 | * line to set input processor to handle events.
96 | */
97 | // Gdx.input.setInputProcessor(this);
98 |
99 | /*
100 | * Instantiate the vector that will be used to store click/touch
101 | * positions.
102 | */
103 | touchPosition = new Vector3();
104 |
105 | /* Create the ball */
106 | Shape shape = Box2DFactory.createCircleShape(1);
107 | FixtureDef fixtureDef = Box2DFactory.createFixture(shape, 2.5f, 0.25f,
108 | 0.75f, false);
109 | Box2DFactory.createBody(world, BodyType.DynamicBody, fixtureDef,
110 | new Vector2(0, 0));
111 |
112 | /* Create the walls */
113 | Body walls = Box2DFactory.createWalls(world, camera.viewportWidth,
114 | camera.viewportHeight, 1);
115 |
116 | /* Define the mouse joint. We use walls as the first body of the joint */
117 | createMouseJointDefinition(walls);
118 | }
119 |
120 | @Override
121 | public void dispose() {
122 | debugRenderer.dispose();
123 | world.dispose();
124 | }
125 |
126 | /**
127 | * Creates the MouseJoint definition.
128 | *
129 | * @param body
130 | * First body of the joint (i.e. ground, walls, etc.)
131 | */
132 | private void createMouseJointDefinition(Body body) {
133 | mouseJointDef = new MouseJointDef();
134 | mouseJointDef.bodyA = body;
135 | mouseJointDef.collideConnected = true;
136 | mouseJointDef.maxForce = 500;
137 | }
138 |
139 | @Override
140 | public boolean touchDown(int screenX, int screenY, int pointer, int button) {
141 | /*
142 | * Define a new QueryCallback. This callback will be used in
143 | * world.QueryAABB method.
144 | */
145 | QueryCallback queryCallback = new QueryCallback() {
146 |
147 | @Override
148 | public boolean reportFixture(Fixture fixture) {
149 | boolean testResult;
150 |
151 | /*
152 | * If the hit point is inside the fixture of the body, create a
153 | * new MouseJoint.
154 | */
155 | if (testResult = fixture.testPoint(touchPosition.x,
156 | touchPosition.y)) {
157 | mouseJointDef.bodyB = fixture.getBody();
158 | mouseJointDef.target.set(touchPosition.x, touchPosition.y);
159 | mouseJoint = (MouseJoint) world.createJoint(mouseJointDef);
160 | }
161 |
162 | return testResult;
163 | }
164 | };
165 |
166 | /* Translate camera point to world point */
167 | camera.unproject(touchPosition.set(screenX, screenY, 0));
168 |
169 | /*
170 | * Query the world for all fixtures that potentially overlap the touched
171 | * point.
172 | */
173 | world.QueryAABB(queryCallback, touchPosition.x, touchPosition.y,
174 | touchPosition.x, touchPosition.y);
175 |
176 | return true;
177 | }
178 |
179 | @Override
180 | public boolean touchUp(int screenX, int screenY, int pointer, int button) {
181 |
182 | /* Whether the input was processed */
183 | boolean processed = false;
184 |
185 | /* If a MouseJoint is defined, destroy it */
186 | if (mouseJoint != null) {
187 | world.destroyJoint(mouseJoint);
188 | mouseJoint = null;
189 | processed = true;
190 | }
191 |
192 | return processed;
193 | }
194 |
195 | @Override
196 | public boolean touchDragged(int screenX, int screenY, int pointer) {
197 |
198 | /* Whether the input was processed */
199 | boolean processed = false;
200 |
201 | /*
202 | * If a MouseJoint is defined, update its target with current position.
203 | */
204 | if (mouseJoint != null) {
205 |
206 | /* Translate camera point to world point */
207 | camera.unproject(touchPosition.set(screenX, screenY, 0));
208 | mouseJoint.setTarget(new Vector2(touchPosition.x, touchPosition.y));
209 | }
210 |
211 | return processed;
212 | }
213 |
214 | }
215 |
--------------------------------------------------------------------------------
/codelabs/src/com/leakedbits/codelabs/box2d/GravityAccelerometerSample.java:
--------------------------------------------------------------------------------
1 | package com.leakedbits.codelabs.box2d;
2 |
3 | import com.badlogic.gdx.Gdx;
4 | import com.badlogic.gdx.graphics.GL20;
5 | import com.badlogic.gdx.graphics.OrthographicCamera;
6 | import com.badlogic.gdx.math.Vector2;
7 | import com.badlogic.gdx.math.Vector3;
8 | import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
9 | import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer;
10 | import com.badlogic.gdx.physics.box2d.FixtureDef;
11 | import com.badlogic.gdx.physics.box2d.Shape;
12 | import com.badlogic.gdx.physics.box2d.World;
13 | import com.leakedbits.codelabs.box2d.utils.Box2DFactory;
14 | import com.leakedbits.codelabs.utils.Sample;
15 |
16 | public class GravityAccelerometerSample extends Sample {
17 |
18 | /* Max number of balls to be spawned */
19 | private static final int MAX_SPAWNED_BALLS = 20;
20 |
21 | /* Use Box2DDebugRenderer, which is a model renderer for debug purposes */
22 | private Box2DDebugRenderer debugRenderer;
23 |
24 | /* As always, we need a camera to be able to see the objects */
25 | private OrthographicCamera camera;
26 |
27 | /* Define a world to hold all bodies and simulate reactions between them */
28 | private World world;
29 |
30 | /* Counter to know how many ball have been spawned */
31 | private int spawnedBalls;
32 |
33 | /* Fields to store previous accelerometer values in each iteration */
34 | private float prevAccelX;
35 | private float prevAccelY;
36 |
37 | /**
38 | * Main constructor used to update sample name.
39 | */
40 | public GravityAccelerometerSample() {
41 | name = "Gravity and accelerometer";
42 | }
43 |
44 | @Override
45 | public void render(float delta) {
46 | /* Clear screen with a black background */
47 | Gdx.gl.glClearColor(0, 0, 0, 1);
48 | Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
49 |
50 | /* Check if we should change the gravity */
51 | processAccelerometer();
52 |
53 | /* Render all graphics before do physics step */
54 | debugRenderer.render(world, camera.combined);
55 |
56 | /* Step the simulation with a fixed time step of 1/60 of a second */
57 | world.step(1 / 60f, 6, 2);
58 | }
59 |
60 | @Override
61 | public void show() {
62 | /*
63 | * This line is found in every sample but is not necessary for the
64 | * sample functionality. calls Sample.show() method. That method set the
65 | * sample to receive all touch and key input events. Also prevents the
66 | * app from be closed whenever the user press back button and instead
67 | * returns to main menu.
68 | */
69 | super.show();
70 |
71 | /*
72 | * Create world with a common gravity vector (9.81 m/s2 downwards force)
73 | * and tell world that we want objects to sleep. This last value
74 | * conserves CPU usage. As we use the accelerometer and the world
75 | * gravity to change bodies positions, we can't let bodies to sleep.
76 | */
77 | world = new World(new Vector2(0, -9.81f), true);
78 |
79 | /* Create renderer */
80 | debugRenderer = new Box2DDebugRenderer();
81 |
82 | /*
83 | * Define camera viewport. Box2D uses meters internally so the camera
84 | * must be defined also in meters. We set a desired width and adjust
85 | * height to different resolutions.
86 | */
87 | camera = new OrthographicCamera(20,
88 | 20 * (Gdx.graphics.getHeight() / (float) Gdx.graphics
89 | .getWidth()));
90 |
91 | /*
92 | * Next line must remain commented because we do this in its parent (See
93 | * Sample class). In case you are not using Sample class, uncomment this
94 | * line to set input processor to handle events.
95 | */
96 | // Gdx.input.setInputProcessor(this);
97 |
98 | /* Create the walls */
99 | Box2DFactory.createWalls(world, camera.viewportWidth,
100 | camera.viewportHeight, 1);
101 | }
102 |
103 | @Override
104 | public void dispose() {
105 | debugRenderer.dispose();
106 | world.dispose();
107 | }
108 |
109 | private void processAccelerometer() {
110 |
111 | /* Get accelerometer values */
112 | float y = Gdx.input.getAccelerometerY();
113 | float x = Gdx.input.getAccelerometerX();
114 |
115 | /*
116 | * If accelerometer values have changed since previous processing,
117 | * change world gravity.
118 | */
119 | if (prevAccelX != x || prevAccelY != y) {
120 |
121 | /* Negative on the x axis but not in the y */
122 | world.setGravity(new Vector2(y, -x));
123 |
124 | /* Store new accelerometer values */
125 | prevAccelX = x;
126 | prevAccelY = y;
127 | }
128 | }
129 |
130 | /*
131 | * Input events handling. Here will process all touch events to spawn and
132 | * drag bodies.
133 | */
134 |
135 | @Override
136 | public boolean touchUp(int screenX, int screenY, int pointer, int button) {
137 |
138 | /* Checks whether the max amount of balls were spawned */
139 | if (spawnedBalls < MAX_SPAWNED_BALLS) {
140 | spawnedBalls++;
141 |
142 | /* Translate camera point to world point */
143 | Vector3 unprojectedVector = new Vector3();
144 | camera.unproject(unprojectedVector.set(screenX, screenY, 0));
145 |
146 | /* Create a new ball */
147 | Shape shape = Box2DFactory.createCircleShape(1);
148 | FixtureDef fixtureDef = Box2DFactory.createFixture(shape, 2.5f,
149 | 0.25f, 0.75f, false);
150 | Box2DFactory.createBody(world, BodyType.DynamicBody, fixtureDef,
151 | new Vector2(unprojectedVector.x, unprojectedVector.y));
152 | }
153 |
154 | return true;
155 | }
156 |
157 | }
158 |
--------------------------------------------------------------------------------
/codelabs/src/com/leakedbits/codelabs/box2d/ImpulsesSample.java:
--------------------------------------------------------------------------------
1 | package com.leakedbits.codelabs.box2d;
2 |
3 | import com.badlogic.gdx.Gdx;
4 | import com.badlogic.gdx.graphics.GL20;
5 | import com.badlogic.gdx.graphics.OrthographicCamera;
6 | import com.badlogic.gdx.math.Vector2;
7 | import com.badlogic.gdx.physics.box2d.Body;
8 | import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
9 | import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer;
10 | import com.badlogic.gdx.physics.box2d.FixtureDef;
11 | import com.badlogic.gdx.physics.box2d.Shape;
12 | import com.badlogic.gdx.physics.box2d.World;
13 | import com.leakedbits.codelabs.box2d.utils.Box2DFactory;
14 | import com.leakedbits.codelabs.utils.Sample;
15 |
16 | public class ImpulsesSample extends Sample {
17 |
18 | /* Use Box2DDebugRenderer, which is a model renderer for debug purposes */
19 | private Box2DDebugRenderer debugRenderer;
20 |
21 | /* Use a long to store current time and calculate user touches duration */
22 | private Long timer;
23 |
24 | /* As always, we need a camera to be able to see the objects */
25 | private OrthographicCamera camera;
26 |
27 | /* Define a world to hold all bodies and simulate reactions between them */
28 | private World world;
29 |
30 | /* Define a body to later apply impulses to it */
31 | private Body box;
32 |
33 | /**
34 | * Main constructor used to update sample name.
35 | */
36 | public ImpulsesSample() {
37 | name = "Impulses";
38 | }
39 |
40 | @Override
41 | public void render(float delta) {
42 | /* Clear screen with a black background */
43 | Gdx.gl.glClearColor(0, 0, 0, 1);
44 | Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
45 |
46 | /* Render all graphics before do physics step */
47 | debugRenderer.render(world, camera.combined);
48 |
49 | /* Step the simulation with a fixed time step of 1/60 of a second */
50 | world.step(1 / 60f, 6, 2);
51 | }
52 |
53 | @Override
54 | public void show() {
55 | /*
56 | * This line is found in every sample but is not necessary for the
57 | * sample functionality. calls Sample.show() method. That method set the
58 | * sample to receive all touch and key input events. Also prevents the
59 | * app from be closed whenever the user press back button and instead
60 | * returns to main menu.
61 | */
62 | super.show();
63 |
64 | /*
65 | * Create world with a common gravity vector (9.81 m/s2 downwards force)
66 | * and tell world that we want objects to sleep. This last value
67 | * conserves CPU usage.
68 | */
69 | world = new World(new Vector2(0, -9.81f), true);
70 |
71 | /* Create renderer */
72 | debugRenderer = new Box2DDebugRenderer();
73 |
74 | /*
75 | * Define camera viewport. Box2D uses meters internally so the camera
76 | * must be defined also in meters. We set a desired width and adjust
77 | * height to different resolutions.
78 | */
79 | camera = new OrthographicCamera(20,
80 | 20 * (Gdx.graphics.getHeight() / (float) Gdx.graphics
81 | .getWidth()));
82 |
83 | /*
84 | * Next line must remain commented because we do this in its parent (See
85 | * Sample class). In case you are not using Sample class, uncomment this
86 | * line to set input processor to handle events.
87 | */
88 | // Gdx.input.setInputProcessor(this);
89 |
90 | /* Create the box */
91 | Shape shape = Box2DFactory.createBoxShape(1.5f, 1.5f,
92 | new Vector2(0, 0), 0);
93 | FixtureDef fixtureDef = Box2DFactory.createFixture(shape, 0.3f, 0.5f,
94 | 0.5f, false);
95 | box = Box2DFactory.createBody(world, BodyType.DynamicBody, fixtureDef,
96 | new Vector2(0, 0));
97 |
98 | /* Create the walls */
99 | Box2DFactory.createWalls(world, camera.viewportWidth,
100 | camera.viewportHeight, 1);
101 | }
102 |
103 | @Override
104 | public void dispose() {
105 | debugRenderer.dispose();
106 | world.dispose();
107 | }
108 |
109 | /*
110 | * Input events handling. Here will start our timer, which will be used
111 | * before.
112 | */
113 | @Override
114 | public boolean touchDown(int screenX, int screenY, int pointer, int button) {
115 | /*
116 | * Get current time in milliseconds. We will use this to calculate the
117 | * time the user has touched the screen.
118 | */
119 | this.timer = System.currentTimeMillis();
120 |
121 | return true;
122 | }
123 |
124 | /*
125 | * Input events handling. Here will stop our timer, calculate the impulse
126 | * and apply it to the body.
127 | */
128 | @Override
129 | public boolean touchUp(int screenX, int screenY, int pointer, int button) {
130 |
131 | /* Calculate the time the user has touched the screen */
132 | long touchedTime = System.currentTimeMillis() - timer;
133 |
134 | /* Every second touching the screen will increment by 20 the impulse */
135 | float impulse = Math.max(10f, touchedTime / 50);
136 |
137 | /*
138 | * The impulse is applied to the body's center, and only on the Y axis.
139 | * It will aggregate the impulse to the current Y speed, so, if the
140 | * object is falling the impulse will be the difference between the
141 | * object speed and the given value.
142 | */
143 | box.applyLinearImpulse(new Vector2(0, impulse), box.getWorldCenter(),
144 | true);
145 |
146 | return true;
147 | }
148 | }
149 |
--------------------------------------------------------------------------------
/codelabs/src/com/leakedbits/codelabs/box2d/JumpingSample.java:
--------------------------------------------------------------------------------
1 | package com.leakedbits.codelabs.box2d;
2 |
3 | import com.badlogic.gdx.Gdx;
4 | import com.badlogic.gdx.graphics.GL20;
5 | import com.badlogic.gdx.graphics.OrthographicCamera;
6 | import com.badlogic.gdx.math.Vector2;
7 | import com.badlogic.gdx.physics.box2d.Body;
8 | import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
9 | import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer;
10 | import com.badlogic.gdx.physics.box2d.Contact;
11 | import com.badlogic.gdx.physics.box2d.ContactImpulse;
12 | import com.badlogic.gdx.physics.box2d.ContactListener;
13 | import com.badlogic.gdx.physics.box2d.FixtureDef;
14 | import com.badlogic.gdx.physics.box2d.Manifold;
15 | import com.badlogic.gdx.physics.box2d.Shape;
16 | import com.badlogic.gdx.physics.box2d.World;
17 | import com.leakedbits.codelabs.box2d.utils.Box2DFactory;
18 | import com.leakedbits.codelabs.utils.Sample;
19 |
20 | public class JumpingSample extends Sample implements ContactListener {
21 |
22 | /* Use Box2DDebugRenderer, which is a model renderer for debug purposes */
23 | private Box2DDebugRenderer debugRenderer;
24 |
25 | /* As always, we need a camera to be able to see the objects */
26 | private OrthographicCamera camera;
27 |
28 | /* Define a world to hold all bodies and simulate reactions between them */
29 | private World world;
30 |
31 | /* Define a body to later apply impulses to it */
32 | private Body player;
33 |
34 | /*
35 | * Boolean variables to know if the player is jumping or if he/she can
36 | * double jump.
37 | */
38 | private boolean isPlayerGrounded;
39 | private boolean hasDoubleJump;
40 |
41 | /**
42 | * Main constructor used to update sample name.
43 | */
44 | public JumpingSample() {
45 | name = "Jump and double jump";
46 | }
47 |
48 | @Override
49 | public void render(float delta) {
50 | /* Clear screen with a black background */
51 | Gdx.gl.glClearColor(0, 0, 0, 1);
52 | Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
53 |
54 | /* Render all graphics before do physics step */
55 | debugRenderer.render(world, camera.combined);
56 |
57 | /* Step the simulation with a fixed time step of 1/60 of a second */
58 | world.step(1 / 60f, 6, 2);
59 | }
60 |
61 | @Override
62 | public void show() {
63 | /*
64 | * This line is found in every sample but is not necessary for the
65 | * sample functionality. calls Sample.show() method. That method set the
66 | * sample to receive all touch and key input events. Also prevents the
67 | * app from be closed whenever the user press back button and instead
68 | * returns to main menu.
69 | */
70 | super.show();
71 |
72 | /*
73 | * Create world with a common gravity vector (9.81 m/s2 downwards force)
74 | * and tell world that we want objects to sleep. This last value
75 | * conserves CPU usage.
76 | */
77 | world = new World(new Vector2(0, -9.81f), true);
78 |
79 | /* Create renderer */
80 | debugRenderer = new Box2DDebugRenderer();
81 |
82 | /*
83 | * Define camera viewport. Box2D uses meters internally so the camera
84 | * must be defined also in meters. We set a desired width and adjust
85 | * height to different resolutions.
86 | */
87 | camera = new OrthographicCamera(20,
88 | 20 * (Gdx.graphics.getHeight() / (float) Gdx.graphics
89 | .getWidth()));
90 |
91 | /*
92 | * Next line must remain commented because we do this in its parent (See
93 | * Sample class). In case you are not using Sample class, uncomment this
94 | * line to set input processor to handle events.
95 | */
96 | // Gdx.input.setInputProcessor(this);
97 |
98 | /* Create the player */
99 | Shape shape = Box2DFactory.createBoxShape(0.35f, 1, new Vector2(0, 0),
100 | 0);
101 | FixtureDef fixtureDef = Box2DFactory.createFixture(shape, 1, 0, 0,
102 | false);
103 | player = Box2DFactory.createBody(world, BodyType.DynamicBody,
104 | fixtureDef, new Vector2(0, 0));
105 |
106 | /*
107 | * Create foot sensor. This sensor will be used to detect when the
108 | * player is standing on something.
109 | */
110 | shape = Box2DFactory.createBoxShape(0.1f, 0.1f, new Vector2(0, -1), 0);
111 | fixtureDef = Box2DFactory.createFixture(shape, 0, 0, 0, true);
112 |
113 | /*
114 | * Set user data to the player. In this case we are using an integer.
115 | * This will help us to identify the fixture during collision handling.
116 | */
117 | player.createFixture(fixtureDef).setUserData(new Integer(3));
118 |
119 | /*
120 | * Fix the rotation of player's body. We don't want our player to fall
121 | * every time he/she touch an object :)
122 | */
123 | player.setFixedRotation(true);
124 |
125 | /* Create the walls */
126 | Box2DFactory.createWalls(world, camera.viewportWidth,
127 | camera.viewportHeight, 1);
128 |
129 | world.setContactListener(this);
130 | }
131 |
132 | @Override
133 | public void dispose() {
134 | debugRenderer.dispose();
135 | world.dispose();
136 | }
137 |
138 | @Override
139 | public void beginContact(Contact contact) {
140 | /*
141 | * For each fixture contacting (A and B) check if it has user data
142 | * associated. In that case and only if it is the number 3 that we
143 | * previously associated to our player, change isPlayerGrounded and
144 | * hasDobleJump variables to true.
145 | */
146 | Object userData = contact.getFixtureA().getUserData();
147 | if (userData != null && (Integer) userData == 3) {
148 | isPlayerGrounded = true;
149 | hasDoubleJump = true;
150 | } else {
151 | userData = contact.getFixtureB().getUserData();
152 | if (userData != null && (Integer) userData == 3) {
153 | isPlayerGrounded = true;
154 | hasDoubleJump = true;
155 | }
156 | }
157 | }
158 |
159 | @Override
160 | public void endContact(Contact contact) {
161 | /*
162 | * For each fixture contacting (A and B) check if it has user data
163 | * associated. In that case and only if it is the number 3 that we
164 | * previously associated to our player, change isPlayerGrounded false to
165 | * indicate that our player is jumping.
166 | */
167 | Object userData = contact.getFixtureA().getUserData();
168 | if (userData != null && (Integer) userData == 3) {
169 | isPlayerGrounded = false;
170 | hasDoubleJump = false;
171 | } else {
172 | userData = contact.getFixtureB().getUserData();
173 | if (userData != null && (Integer) userData == 3) {
174 | isPlayerGrounded = false;
175 | }
176 | }
177 | }
178 |
179 | @Override
180 | public void preSolve(Contact contact, Manifold oldManifold) {
181 |
182 | }
183 |
184 | @Override
185 | public void postSolve(Contact contact, ContactImpulse impulse) {
186 |
187 | }
188 |
189 | /*
190 | * Input events handling. Here will stop our timer, calculate the impulse
191 | * and apply it to the body.
192 | */
193 | @Override
194 | public boolean touchDown(int screenX, int screenY, int pointer, int button) {
195 | /*
196 | * Firstly we check if the player is standing over something or if
197 | * he/she can double jump.
198 | */
199 | if (isPlayerGrounded || hasDoubleJump) {
200 |
201 | /*
202 | * If a double jump was use it, remove this hability until the
203 | * player is over something again.
204 | */
205 | if (!isPlayerGrounded && hasDoubleJump) {
206 | hasDoubleJump = false;
207 | }
208 |
209 | /*
210 | * Finally, apply a vertical linear impulse relative to the player
211 | * mass.
212 | */
213 | float impulse = player.getMass() * 5;
214 | player.applyLinearImpulse(new Vector2(0, impulse),
215 | player.getWorldCenter(), true);
216 | }
217 |
218 | return true;
219 | }
220 |
221 | }
222 |
--------------------------------------------------------------------------------
/codelabs/src/com/leakedbits/codelabs/box2d/SpawnBodiesSample.java:
--------------------------------------------------------------------------------
1 | package com.leakedbits.codelabs.box2d;
2 |
3 | import com.badlogic.gdx.Gdx;
4 | import com.badlogic.gdx.graphics.GL20;
5 | import com.badlogic.gdx.graphics.OrthographicCamera;
6 | import com.badlogic.gdx.math.Vector2;
7 | import com.badlogic.gdx.math.Vector3;
8 | import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
9 | import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer;
10 | import com.badlogic.gdx.physics.box2d.FixtureDef;
11 | import com.badlogic.gdx.physics.box2d.Shape;
12 | import com.badlogic.gdx.physics.box2d.World;
13 | import com.leakedbits.codelabs.box2d.utils.Box2DFactory;
14 | import com.leakedbits.codelabs.utils.Sample;
15 |
16 | public class SpawnBodiesSample extends Sample {
17 |
18 | /* Max number of balls to be spawned */
19 | private static final int MAX_SPAWNED_BALLS = 20;
20 |
21 | /* Use Box2DDebugRenderer, which is a model renderer for debug purposes */
22 | private Box2DDebugRenderer debugRenderer;
23 |
24 | /* As always, we need a camera to be able to see the objects */
25 | private OrthographicCamera camera;
26 |
27 | /* Define a world to hold all bodies and simulate reactions between them */
28 | private World world;
29 |
30 | /* Counter to know how many ball have been spawned */
31 | private int spawnedBalls;
32 |
33 | /**
34 | * Main constructor used to update sample name.
35 | */
36 | public SpawnBodiesSample() {
37 | name = "Spawn bodies on touch";
38 | }
39 |
40 | @Override
41 | public void render(float delta) {
42 | /* Clear screen with a black background */
43 | Gdx.gl.glClearColor(0, 0, 0, 1);
44 | Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
45 |
46 | /* Render all graphics before do physics step */
47 | debugRenderer.render(world, camera.combined);
48 |
49 | /* Step the simulation with a fixed time step of 1/60 of a second */
50 | world.step(1 / 60f, 6, 2);
51 | }
52 |
53 | @Override
54 | public void show() {
55 | /*
56 | * This line is found in every sample but is not necessary for the
57 | * sample functionality. calls Sample.show() method. That method set the
58 | * sample to receive all touch and key input events. Also prevents the
59 | * app from be closed whenever the user press back button and instead
60 | * returns to main menu.
61 | */
62 | super.show();
63 |
64 | /*
65 | * Create world with a common gravity vector (9.81 m/s2 downwards force)
66 | * and tell world that we want objects to sleep. This last value
67 | * conserves CPU usage.
68 | */
69 | world = new World(new Vector2(0, -9.81f), true);
70 |
71 | /* Create renderer */
72 | debugRenderer = new Box2DDebugRenderer();
73 |
74 | /*
75 | * Define camera viewport. Box2D uses meters internally so the camera
76 | * must be defined also in meters. We set a desired width and adjust
77 | * height to different resolutions.
78 | */
79 | camera = new OrthographicCamera(20,
80 | 20 * (Gdx.graphics.getHeight() / (float) Gdx.graphics
81 | .getWidth()));
82 |
83 | /*
84 | * Next line must remain commented because we do this in its parent (See
85 | * Sample class). In case you are not using Sample class, uncomment this
86 | * line to set input processor to handle events.
87 | */
88 | // Gdx.input.setInputProcessor(this);
89 |
90 | /* Create the walls */
91 | Box2DFactory.createWalls(world, camera.viewportWidth,
92 | camera.viewportHeight, 1);
93 | }
94 |
95 | @Override
96 | public void dispose() {
97 | debugRenderer.dispose();
98 | world.dispose();
99 | }
100 |
101 | /*
102 | * Input events handling. Here will process all touch events to spawn and
103 | * drag bodies.
104 | */
105 |
106 | @Override
107 | public boolean touchUp(int screenX, int screenY, int pointer, int button) {
108 |
109 | /* Checks whether the max amount of balls were spawned */
110 | if (spawnedBalls < MAX_SPAWNED_BALLS) {
111 | spawnedBalls++;
112 |
113 | /* Translate camera point to world point */
114 | Vector3 unprojectedVector = new Vector3();
115 | camera.unproject(unprojectedVector.set(screenX, screenY, 0));
116 |
117 | /* Create a new ball */
118 | Shape shape = Box2DFactory.createCircleShape(1);
119 | FixtureDef fixtureDef = Box2DFactory.createFixture(shape, 2.5f,
120 | 0.25f, 0.75f, false);
121 | Box2DFactory.createBody(world, BodyType.DynamicBody, fixtureDef,
122 | new Vector2(unprojectedVector.x, unprojectedVector.y));
123 | }
124 |
125 | return true;
126 | }
127 |
128 | }
129 |
--------------------------------------------------------------------------------
/codelabs/src/com/leakedbits/codelabs/box2d/SpritesSample.java:
--------------------------------------------------------------------------------
1 | package com.leakedbits.codelabs.box2d;
2 |
3 | import com.badlogic.gdx.Gdx;
4 | import com.badlogic.gdx.graphics.GL20;
5 | import com.badlogic.gdx.graphics.OrthographicCamera;
6 | import com.badlogic.gdx.graphics.Texture;
7 | import com.badlogic.gdx.graphics.g2d.Sprite;
8 | import com.badlogic.gdx.graphics.g2d.SpriteBatch;
9 | import com.badlogic.gdx.math.MathUtils;
10 | import com.badlogic.gdx.math.Vector2;
11 | import com.badlogic.gdx.physics.box2d.Body;
12 | import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
13 | import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer;
14 | import com.badlogic.gdx.physics.box2d.FixtureDef;
15 | import com.badlogic.gdx.physics.box2d.Shape;
16 | import com.badlogic.gdx.physics.box2d.World;
17 | import com.badlogic.gdx.utils.Array;
18 | import com.leakedbits.codelabs.box2d.utils.Box2DFactory;
19 | import com.leakedbits.codelabs.utils.Sample;
20 |
21 | public class SpritesSample extends Sample {
22 |
23 | /* Define a body to later apply impulses to it */
24 | private Body box;
25 |
26 | /* Use Box2DDebugRenderer, which is a model renderer for debug purposes */
27 | private Box2DDebugRenderer debugRenderer;
28 |
29 | /* Use a long to store current time and calculate user touches duration */
30 | private Long timer;
31 |
32 | /* As always, we need a camera to be able to see the objects */
33 | private OrthographicCamera camera;
34 |
35 | /* Define a world to hold all bodies and simulate reactions between them */
36 | private World world;
37 |
38 | /* New variables used to hold the sprite and draw it in the screen */
39 | private Sprite sprite;
40 | private SpriteBatch batch;
41 |
42 | /* This array will hold all the bodies of the word for rendering purposes */
43 | private Array worldBodies;
44 |
45 | /**
46 | * Main constructor used to update sample name.
47 | */
48 | public SpritesSample() {
49 | name = "Sprites";
50 | }
51 |
52 | @Override
53 | public void render(float delta) {
54 | /* Clear screen with a black background */
55 | Gdx.gl.glClearColor(1, 1, 1, 1);
56 | Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
57 |
58 | /* Render all graphics before do physics step */
59 | debugRenderer.render(world, camera.combined);
60 |
61 | /*
62 | * Set projection matrix to camera.combined, the same way we did with
63 | * the debug renderer.
64 | */
65 | batch.setProjectionMatrix(camera.combined);
66 | batch.begin();
67 |
68 | /* Get word bodies */
69 | world.getBodies(worldBodies);
70 |
71 | /*
72 | * For each body in the world we have to check if it has user data
73 | * associated and if it is an Sprite. In that case, we draw it in the
74 | * screen.
75 | */
76 | for (Body body : worldBodies) {
77 | if (body.getUserData() instanceof Sprite) {
78 | Sprite sprite = (Sprite) body.getUserData();
79 |
80 | /*
81 | * Set body position equals to box position. We also need to
82 | * center it in the box (measures are relative to body center).
83 | */
84 | Vector2 position = body.getPosition();
85 | sprite.setPosition(position.x - sprite.getWidth() / 2,
86 | position.y - sprite.getWidth() / 2);
87 |
88 | /* Set sprite rotation equals to body rotation */
89 | sprite.setRotation(body.getAngle() * MathUtils.radiansToDegrees);
90 |
91 | /* Draw the sprite on screen */
92 | sprite.draw(batch);
93 | }
94 | }
95 |
96 | batch.end();
97 |
98 | /* Step the simulation with a fixed time step of 1/60 of a second */
99 | world.step(1 / 60f, 6, 2);
100 | }
101 |
102 | @Override
103 | public void show() {
104 | /*
105 | * This line is found in every sample but is not necessary for the
106 | * sample functionality. calls Sample.show() method. That method set the
107 | * sample to receive all touch and key input events. Also prevents the
108 | * app from be closed whenever the user press back button and instead
109 | * returns to main menu.
110 | */
111 | super.show();
112 |
113 | /*
114 | * Create world with a common gravity vector (9.81 m/s2 downwards force)
115 | * and tell world that we want objects to sleep. This last value
116 | * conserves CPU usage.
117 | */
118 | world = new World(new Vector2(0, -9.81f), true);
119 |
120 | /* Create renderer */
121 | debugRenderer = new Box2DDebugRenderer();
122 |
123 | batch = new SpriteBatch();
124 |
125 | /*
126 | * Define camera viewport. Box2D uses meters internally so the camera
127 | * must be defined also in meters. We set a desired width and adjust
128 | * height to different resolutions.
129 | */
130 | camera = new OrthographicCamera(20,
131 | 20 * (Gdx.graphics.getHeight() / (float) Gdx.graphics
132 | .getWidth()));
133 |
134 | /*
135 | * Next line must remain commented because we do this in its parent (See
136 | * Sample class). In case you are not using Sample class, uncomment this
137 | * line to set input processor to handle events.
138 | */
139 | // Gdx.input.setInputProcessor(this);
140 |
141 | /* Create the box */
142 | Shape shape = Box2DFactory.createBoxShape(1.5f, 1.5f,
143 | new Vector2(0, 0), 0);
144 | FixtureDef fixtureDef = Box2DFactory.createFixture(shape, 0.3f, 0.5f,
145 | 0.5f, false);
146 | box = Box2DFactory.createBody(world, BodyType.DynamicBody, fixtureDef,
147 | new Vector2(0, 0));
148 |
149 | /* Create the walls */
150 | Box2DFactory.createWalls(world, camera.viewportWidth,
151 | camera.viewportHeight, 1);
152 |
153 | /* Set box texture */
154 | sprite = new Sprite(new Texture("data/images/crab.png"));
155 |
156 | /*
157 | * Set the size of the sprite. We have to remember that we are not
158 | * working in pixels, but with meters. The size of the sprite will be
159 | * the same as the size of the box; 2 meter wide, 2 meters tall.
160 | */
161 | sprite.setSize(3, 3);
162 |
163 | /*
164 | * Sets the origin in relation to the sprite's position for scaling and
165 | * rotation.
166 | */
167 | sprite.setOrigin(sprite.getWidth() / 2, sprite.getHeight() / 2);
168 |
169 | /* Set sprite as a user data of the body to draw it in each render step */
170 | box.setUserData(sprite);
171 |
172 | /* Instantiate the array of bodies that will be used during render step */
173 | worldBodies = new Array();
174 | }
175 |
176 | /*
177 | * Input events handling. Here will start our timer, which will be used
178 | * before.
179 | */
180 | @Override
181 | public boolean touchDown(int screenX, int screenY, int pointer, int button) {
182 | /*
183 | * Get current time in milliseconds. We will use this to calculate the
184 | * time the user has touched the screen.
185 | */
186 | this.timer = System.currentTimeMillis();
187 |
188 | return true;
189 | }
190 |
191 | /*
192 | * Input events handling. Here will stop our timer, calculate the impulse
193 | * and apply it to the body.
194 | */
195 | @Override
196 | public boolean touchUp(int screenX, int screenY, int pointer, int button) {
197 | super.touchUp(screenX, screenY, pointer, button);
198 |
199 | /* Calculate the time the user has touched the screen */
200 | long touchedTime = System.currentTimeMillis() - timer;
201 |
202 | /* Every second touching the screen will increment by 20 the impulse */
203 | float impulse = Math.max(10f, touchedTime / 50);
204 |
205 | /*
206 | * The impulse is applied to the body's center, and only on the Y axis.
207 | * It will aggregate the impulse to the current Y speed, so, if the
208 | * object is falling the impulse will be the difference between the
209 | * object speed and the given value.
210 | */
211 | box.applyLinearImpulse(new Vector2(0, impulse), box.getWorldCenter(),
212 | true);
213 |
214 | return true;
215 | }
216 | }
217 |
--------------------------------------------------------------------------------
/codelabs/src/com/leakedbits/codelabs/box2d/controllers/BuoyancyController.java:
--------------------------------------------------------------------------------
1 | package com.leakedbits.codelabs.box2d.controllers;
2 |
3 | import java.util.ArrayList;
4 | import java.util.HashSet;
5 | import java.util.List;
6 | import java.util.Set;
7 |
8 | import com.badlogic.gdx.Gdx;
9 | import com.badlogic.gdx.math.Vector2;
10 | import com.badlogic.gdx.physics.box2d.Body;
11 | import com.badlogic.gdx.physics.box2d.Fixture;
12 | import com.badlogic.gdx.physics.box2d.PolygonShape;
13 | import com.badlogic.gdx.physics.box2d.World;
14 | import com.leakedbits.codelabs.box2d.utils.PolygonProperties;
15 | import com.leakedbits.codelabs.utils.PolygonIntersector;
16 |
17 | public class BuoyancyController {
18 |
19 | private Fixture fluidSensor;
20 | private List fluidVertices;
21 | private Set fixtures;
22 | private World world;
23 |
24 | public boolean isFluidFixed = true;
25 | public float fluidDrag = 0.25f;
26 | public float fluidLift = 0.25f;
27 | public float linearDrag = 0;
28 | public float maxFluidDrag = 2000;
29 | public float maxFluidLift = 500;
30 |
31 | public BuoyancyController(World world, Fixture fluidSensor) {
32 | this.world = world;
33 | this.fluidSensor = fluidSensor;
34 | fluidVertices = getFixtureVertices(fluidSensor);
35 |
36 | fixtures = new HashSet();
37 | }
38 |
39 | public void step() {
40 | for (Fixture fixture : fixtures) {
41 | if (fixture.getBody().isAwake()) {
42 |
43 | /* Create clipPolygon */
44 | List clipPolygon = getFixtureVertices(fixture);
45 |
46 | /* Create subjectPolygon */
47 | List subjectPolygon;
48 | if (isFluidFixed) {
49 | subjectPolygon = fluidVertices;
50 | } else {
51 | subjectPolygon = getFixtureVertices(fluidSensor);
52 | }
53 |
54 | /* Get intersection polygon */
55 | List clippedPolygon = PolygonIntersector.clipPolygons(
56 | subjectPolygon, clipPolygon);
57 |
58 | if (!clippedPolygon.isEmpty()) {
59 | applyForces(fixture, clippedPolygon.toArray(new Vector2[0]));
60 | }
61 | }
62 | }
63 | }
64 |
65 | private void applyForces(Fixture fixture, Vector2[] clippedPolygon) {
66 | PolygonProperties polygonProperties = PolygonIntersector
67 | .computePolygonProperties(clippedPolygon);
68 |
69 | /* Get fixtures bodies */
70 | Body fixtureBody = fixture.getBody();
71 | Body fluidBody = fluidSensor.getBody();
72 |
73 | /* Get fluid density */
74 | float density = fluidSensor.getDensity();
75 |
76 | /* Apply buoyancy force */
77 | float displacedMass = fluidSensor.getDensity()
78 | * polygonProperties.getArea();
79 | Vector2 gravity = world.getGravity();
80 | Vector2 buoyancyForce = new Vector2(-gravity.x * displacedMass,
81 | -gravity.y * displacedMass);
82 | fixtureBody.applyForce(buoyancyForce, polygonProperties.getCentroid(),
83 | true);
84 |
85 | /* Linear drag force */
86 | if (linearDrag != 0) {
87 | fixtureBody.applyForce(gravity.rotate90(1).nor().scl(linearDrag),
88 | polygonProperties.getCentroid(), true);
89 | }
90 |
91 | /* Apply drag and lift forces */
92 | int polygonVertices = clippedPolygon.length;
93 | for (int i = 0; i < polygonVertices; i++) {
94 |
95 | /* Apply drag force */
96 |
97 | /* End points and mid point of the edge */
98 | Vector2 firstPoint = clippedPolygon[i];
99 | Vector2 secondPoint = clippedPolygon[(i + 1) % polygonVertices];
100 | Vector2 midPoint = firstPoint.cpy().add(secondPoint).scl(0.5f);
101 |
102 | /*
103 | * Find relative velocity between the object and the fluid at edge
104 | * mid point.
105 | */
106 | Vector2 velocityDirection = new Vector2(fixtureBody
107 | .getLinearVelocityFromWorldPoint(midPoint)
108 | .sub(fluidBody.getLinearVelocityFromWorldPoint(midPoint)));
109 | float velocity = velocityDirection.len();
110 | velocityDirection.nor();
111 |
112 | Vector2 edge = secondPoint.cpy().sub(firstPoint);
113 | float edgeLength = edge.len();
114 | edge.nor();
115 |
116 | Vector2 normal = new Vector2(edge.y, -edge.x);
117 | float dragDot = normal.dot(velocityDirection);
118 |
119 | if (dragDot >= 0) {
120 |
121 | /*
122 | * Normal don't point backwards. This is a leading edge. Store
123 | * the result of multiply edgeLength, density and velocity
124 | * squared
125 | */
126 | float tempProduct = edgeLength * density * velocity * velocity;
127 |
128 | float drag = dragDot * fluidDrag * tempProduct;
129 | drag = Math.min(drag, maxFluidDrag);
130 | Vector2 dragForce = velocityDirection.cpy().scl(-drag);
131 | fixtureBody.applyForce(dragForce, midPoint, true);
132 |
133 | /* Apply lift force */
134 | float liftDot = edge.dot(velocityDirection);
135 | float lift = dragDot * liftDot * fluidLift * tempProduct;
136 | lift = Math.min(lift, maxFluidLift);
137 | Vector2 liftDirection = new Vector2(-velocityDirection.y,
138 | velocityDirection.x);
139 | Vector2 liftForce = liftDirection.scl(lift);
140 | fixtureBody.applyForce(liftForce, midPoint, true);
141 | }
142 | }
143 | }
144 |
145 | public void addBody(Fixture fixture) {
146 | try {
147 | PolygonShape polygon = (PolygonShape) fixture.getShape();
148 | if (polygon.getVertexCount() > 2) {
149 | fixtures.add(fixture);
150 | }
151 | } catch (ClassCastException e) {
152 | Gdx.app.debug("BuoyancyController",
153 | "Fixture shape is not an instance of PolygonShape.");
154 | }
155 | }
156 |
157 | public void removeBody(Fixture fixture) {
158 | fixtures.remove(fixture);
159 | }
160 |
161 | private List getFixtureVertices(Fixture fixture) {
162 | PolygonShape polygon = (PolygonShape) fixture.getShape();
163 | int verticesCount = polygon.getVertexCount();
164 |
165 | List vertices = new ArrayList(verticesCount);
166 | for (int i = 0; i < verticesCount; i++) {
167 | Vector2 vertex = new Vector2();
168 | polygon.getVertex(i, vertex);
169 | vertices.add(new Vector2(fixture.getBody().getWorldPoint(vertex)));
170 | }
171 |
172 | return vertices;
173 | }
174 | }
175 |
--------------------------------------------------------------------------------
/codelabs/src/com/leakedbits/codelabs/box2d/utils/Box2DFactory.java:
--------------------------------------------------------------------------------
1 | package com.leakedbits.codelabs.box2d.utils;
2 |
3 | import com.badlogic.gdx.math.Vector2;
4 | import com.badlogic.gdx.physics.box2d.Body;
5 | import com.badlogic.gdx.physics.box2d.BodyDef;
6 | import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
7 | import com.badlogic.gdx.physics.box2d.ChainShape;
8 | import com.badlogic.gdx.physics.box2d.CircleShape;
9 | import com.badlogic.gdx.physics.box2d.FixtureDef;
10 | import com.badlogic.gdx.physics.box2d.PolygonShape;
11 | import com.badlogic.gdx.physics.box2d.Shape;
12 | import com.badlogic.gdx.physics.box2d.World;
13 |
14 | public class Box2DFactory {
15 |
16 | public static Body createBody(World world, BodyType bodyType,
17 | FixtureDef fixtureDef, Vector2 position) {
18 | BodyDef bodyDef = new BodyDef();
19 | bodyDef.type = bodyType;
20 | bodyDef.position.set(position);
21 |
22 | Body body = world.createBody(bodyDef);
23 | body.createFixture(fixtureDef);
24 |
25 | fixtureDef.shape.dispose();
26 |
27 | return body;
28 | }
29 |
30 | public static Shape createBoxShape(float halfWidth, float halfHeight, Vector2 center, float angle) {
31 | PolygonShape boxShape = new PolygonShape();
32 | boxShape.setAsBox(halfWidth, halfHeight, center, angle);
33 |
34 | return boxShape;
35 | }
36 |
37 | public static Shape createChainShape(Vector2[] vertices) {
38 | ChainShape chainShape = new ChainShape();
39 | chainShape.createChain(vertices);
40 |
41 | return chainShape;
42 | }
43 |
44 | public static Shape createCircleShape(float radius) {
45 | CircleShape circleShape = new CircleShape();
46 | circleShape.setRadius(radius);
47 |
48 | return circleShape;
49 | }
50 |
51 | public static Shape createPolygonShape(Vector2[] vertices) {
52 | PolygonShape polygonShape = new PolygonShape();
53 | polygonShape.set(vertices);
54 |
55 | return polygonShape;
56 | }
57 |
58 | public static Shape createTriangleShape(float halfWidth, float halfHeight) {
59 | PolygonShape triangleShape = new PolygonShape();
60 | triangleShape
61 | .set(new Vector2[] { new Vector2(-halfWidth, -halfHeight),
62 | new Vector2(0, halfHeight),
63 | new Vector2(halfWidth, -halfHeight) });
64 |
65 | return triangleShape;
66 | }
67 |
68 | public static FixtureDef createFixture(Shape shape, float density,
69 | float friction, float restitution, boolean isSensor) {
70 | FixtureDef fixtureDef = new FixtureDef();
71 | fixtureDef.shape = shape;
72 | fixtureDef.isSensor = isSensor;
73 | fixtureDef.density = density;
74 | fixtureDef.friction = friction;
75 | fixtureDef.restitution = restitution;
76 |
77 | return fixtureDef;
78 | }
79 |
80 | public static Body createWalls(World world, float viewportWidth,
81 | float viewportHeight, float offset) {
82 | float halfWidth = viewportWidth / 2 - offset;
83 | float halfHeight = viewportHeight / 2 - offset;
84 |
85 | Vector2[] vertices = new Vector2[] {
86 | new Vector2(-halfWidth, -halfHeight),
87 | new Vector2(halfWidth, -halfHeight),
88 | new Vector2(halfWidth, halfHeight),
89 | new Vector2(-halfWidth, halfHeight),
90 | new Vector2(-halfWidth, -halfHeight) };
91 |
92 | Shape shape = createChainShape(vertices);
93 | FixtureDef fixtureDef = createFixture(shape, 1, 0.5f, 0, false);
94 |
95 | return createBody(world, BodyType.StaticBody, fixtureDef, new Vector2(
96 | 0, 0));
97 | }
98 |
99 | }
100 |
--------------------------------------------------------------------------------
/codelabs/src/com/leakedbits/codelabs/box2d/utils/Box2DSamples.java:
--------------------------------------------------------------------------------
1 | package com.leakedbits.codelabs.box2d.utils;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Arrays;
5 | import java.util.List;
6 |
7 | import com.leakedbits.codelabs.box2d.BouncingBallSample;
8 | import com.leakedbits.codelabs.box2d.BuoyancySample;
9 | import com.leakedbits.codelabs.box2d.DragAndDropSample;
10 | import com.leakedbits.codelabs.box2d.GravityAccelerometerSample;
11 | import com.leakedbits.codelabs.box2d.ImpulsesSample;
12 | import com.leakedbits.codelabs.box2d.CollisionsSample;
13 | import com.leakedbits.codelabs.box2d.JumpingSample;
14 | import com.leakedbits.codelabs.box2d.SpawnBodiesSample;
15 | import com.leakedbits.codelabs.box2d.SpritesSample;
16 | import com.leakedbits.codelabs.utils.Sample;
17 |
18 | public class Box2DSamples {
19 |
20 | @SuppressWarnings("unchecked")
21 | public static final List> SAMPLES = new ArrayList>(
22 | Arrays.asList(
23 | BouncingBallSample.class,
24 | SpawnBodiesSample.class,
25 | DragAndDropSample.class,
26 | ImpulsesSample.class,
27 | SpritesSample.class,
28 | GravityAccelerometerSample.class,
29 | CollisionsSample.class,
30 | BuoyancySample.class,
31 | JumpingSample.class
32 | )
33 | );
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/codelabs/src/com/leakedbits/codelabs/box2d/utils/PolygonProperties.java:
--------------------------------------------------------------------------------
1 | package com.leakedbits.codelabs.box2d.utils;
2 |
3 | import com.badlogic.gdx.math.Vector2;
4 |
5 | public class PolygonProperties {
6 |
7 | private Vector2 centroid;
8 |
9 | private float area;
10 |
11 | public PolygonProperties(Vector2 centroid, float area) {
12 | this.centroid = centroid;
13 | this.area = area;
14 | }
15 |
16 | public Vector2 getCentroid() {
17 | return centroid;
18 | }
19 |
20 | public void setCentroid(Vector2 centroid) {
21 | this.centroid = centroid;
22 | }
23 |
24 | public float getArea() {
25 | return area;
26 | }
27 |
28 | public void setArea(float area) {
29 | this.area = area;
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/codelabs/src/com/leakedbits/codelabs/utils/PolygonIntersector.java:
--------------------------------------------------------------------------------
1 | package com.leakedbits.codelabs.utils;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import com.badlogic.gdx.math.Polygon;
7 | import com.badlogic.gdx.math.Vector2;
8 | import com.leakedbits.codelabs.box2d.utils.PolygonProperties;
9 |
10 | public class PolygonIntersector {
11 |
12 | /* A close to zero float epsilon value */
13 | public static final float EPSILON = 1.1920928955078125E-7f;
14 |
15 | /**
16 | * Returns true if the given point is inside the segment.
17 | *
18 | * @param point The point to check
19 | * @param start Segment's first point
20 | * @param end Segment's last point
21 | * @return Whether the point is inside the segment
22 | */
23 | public static boolean isPointInLineSegment(Vector2 point, Vector2 start,
24 | Vector2 end) {
25 | return isPointInLineSegment(point.x, point.y, start.x, start.y, end.x, end.y);
26 | }
27 |
28 | /**
29 | * Returns true if the given point is inside the segment.
30 | *
31 | * @param pointX X coordinate of the point
32 | * @param pointY Y coordinate of the point
33 | * @param startX X coordinate of the segment's first point
34 | * @param startY Y coordinate of the segment's first point
35 | * @param endX X coordinate of the segment's last point
36 | * @param endY Y coordinate of the segment's last point
37 | * @return Whether the point is inside the segment
38 | */
39 | public static boolean isPointInLineSegment(float pointX, float pointY,
40 | float startX, float startY, float endX, float endY) {
41 | return (endX - startX) * (pointY - startY) > (endY - startY)
42 | * (pointX - startX);
43 | }
44 |
45 | @Deprecated
46 | public static boolean isPointInsideEdge(Vector2 point,
47 | Vector2 edgeStartPoint, Vector2 edgeEndPoint) {
48 | return (edgeEndPoint.x - edgeStartPoint.x)
49 | * (point.y - edgeStartPoint.y) > (edgeEndPoint.y - edgeStartPoint.y)
50 | * (point.x - edgeStartPoint.x);
51 | }
52 |
53 | @Deprecated
54 | public static Vector2 getEdgesIntersection(Vector2 firstEdgeStartPoint,
55 | Vector2 firstEdgeEndPoint, Vector2 secondEdgeStartPoint,
56 | Vector2 secondEdgeEndPoint) {
57 |
58 | Vector2 firstDirectionPoint = new Vector2(firstEdgeStartPoint.x
59 | - firstEdgeEndPoint.x, firstEdgeStartPoint.y
60 | - firstEdgeEndPoint.y);
61 | Vector2 secondDirectionPoint = new Vector2(secondEdgeStartPoint.x
62 | - secondEdgeEndPoint.x, secondEdgeStartPoint.y
63 | - secondEdgeEndPoint.y);
64 |
65 | /* Cross product of each edge */
66 | float crossFirstEdge = firstEdgeStartPoint.crs(firstEdgeEndPoint);
67 | float crossSecondEdge = secondEdgeStartPoint.crs(secondEdgeEndPoint);
68 |
69 | float inversedCrossDirection = 1 / firstDirectionPoint
70 | .crs(secondDirectionPoint);
71 |
72 | return new Vector2(
73 | (crossFirstEdge * secondDirectionPoint.x - crossSecondEdge
74 | * firstDirectionPoint.x)
75 | * inversedCrossDirection, (crossFirstEdge
76 | * secondDirectionPoint.y - crossSecondEdge
77 | * firstDirectionPoint.y)
78 | * inversedCrossDirection);
79 | }
80 |
81 | public static Polygon intersectPolygons(Polygon subjectPolygon, Polygon clipPolygon) {
82 | return intersectPolygons(subjectPolygon.getVertices(), clipPolygon.getVertices());
83 | }
84 |
85 | public static Polygon intersectPolygons(float[] subjectVertices, float[] clipVertices) {
86 | return null;
87 | }
88 |
89 | public static List clipPolygons(List subjectPolygon,
90 | List clipPolygon) {
91 | List clippedPolygonVertices = new ArrayList(
92 | subjectPolygon);
93 |
94 | Vector2 clipEdgeStartPoint = clipPolygon.get(clipPolygon.size() - 1);
95 |
96 | for (Vector2 clipEdgeEndPoint : clipPolygon) {
97 | if (clippedPolygonVertices.isEmpty()) {
98 | break;
99 | }
100 |
101 | List inputList = new ArrayList(
102 | clippedPolygonVertices);
103 | clippedPolygonVertices.clear();
104 |
105 | Vector2 testEdgeStartPoint = inputList.get(inputList.size() - 1);
106 | for (Vector2 testEdgeEndPoint : inputList) {
107 | if (isPointInsideEdge(testEdgeEndPoint, clipEdgeStartPoint,
108 | clipEdgeEndPoint)) {
109 | if (!isPointInsideEdge(testEdgeStartPoint,
110 | clipEdgeStartPoint, clipEdgeEndPoint)) {
111 | clippedPolygonVertices.add(getEdgesIntersection(
112 | clipEdgeStartPoint, clipEdgeEndPoint,
113 | testEdgeStartPoint, testEdgeEndPoint));
114 | }
115 |
116 | clippedPolygonVertices.add(testEdgeEndPoint);
117 | } else if (isPointInsideEdge(testEdgeStartPoint,
118 | clipEdgeStartPoint, clipEdgeEndPoint)) {
119 | clippedPolygonVertices.add(getEdgesIntersection(
120 | clipEdgeStartPoint, clipEdgeEndPoint,
121 | testEdgeStartPoint, testEdgeEndPoint));
122 | }
123 |
124 | testEdgeStartPoint = testEdgeEndPoint;
125 | }
126 |
127 | clipEdgeStartPoint = clipEdgeEndPoint;
128 | }
129 |
130 | return clippedPolygonVertices;
131 | }
132 |
133 | public static PolygonProperties computePolygonProperties(Vector2[] polygon) {
134 | PolygonProperties polygonProperties = null;
135 |
136 | int count = polygon.length;
137 |
138 | if (count >= 3) {
139 | Vector2 centroid = new Vector2(0, 0);
140 | float area = 0;
141 |
142 | Vector2 refPoint = new Vector2(0, 0);
143 | float threeInverse = 1 / 3f;
144 |
145 | for (int i = 0; i < count; i++) {
146 | /*
147 | * Create a new vector to represent the reference point for
148 | * forming triangles. Then use refPoint, polygonVertex and
149 | * thirdTriangleVertex as vertices of a triangle.
150 | */
151 | refPoint.set(0, 0);
152 | Vector2 polygonVertex = polygon[i];
153 | Vector2 thirdTriangleVertex = i + 1 < count ? polygon[i + 1]
154 | : polygon[0];
155 |
156 | Vector2 firstDirectionVector = polygonVertex.sub(refPoint);
157 | Vector2 secondDirectionVector = thirdTriangleVertex
158 | .sub(refPoint);
159 |
160 | float triangleArea = firstDirectionVector
161 | .crs(secondDirectionVector) / 2;
162 | area += triangleArea;
163 |
164 | /* Area weighted centroid */
165 | centroid.add(refPoint.add(polygonVertex)
166 | .add(thirdTriangleVertex)
167 | .scl(triangleArea * threeInverse));
168 | }
169 |
170 | if (area > EPSILON) {
171 | centroid.scl(1 / area);
172 | } else {
173 | area = 0;
174 | }
175 |
176 | polygonProperties = new PolygonProperties(centroid, area);
177 | }
178 |
179 | return polygonProperties;
180 | }
181 |
182 | }
183 |
--------------------------------------------------------------------------------
/codelabs/src/com/leakedbits/codelabs/utils/Sample.java:
--------------------------------------------------------------------------------
1 | package com.leakedbits.codelabs.utils;
2 |
3 | import com.badlogic.gdx.Game;
4 | import com.badlogic.gdx.Gdx;
5 | import com.badlogic.gdx.Input.Keys;
6 | import com.badlogic.gdx.InputAdapter;
7 | import com.badlogic.gdx.Screen;
8 | import com.leakedbits.codelabs.MainMenu;
9 |
10 | public class Sample extends InputAdapter implements Screen {
11 |
12 | protected static String name = "Default sample name";
13 |
14 | @Override
15 | public void render(float delta) {
16 |
17 | }
18 |
19 | @Override
20 | public void resize(int width, int height) {
21 |
22 | }
23 |
24 | @Override
25 | public void show() {
26 | Gdx.input.setInputProcessor(this);
27 | Gdx.input.setCatchBackKey(true);
28 | }
29 |
30 | @Override
31 | public void hide() {
32 |
33 | }
34 |
35 | @Override
36 | public void pause() {
37 |
38 | }
39 |
40 | @Override
41 | public void resume() {
42 |
43 | }
44 |
45 | @Override
46 | public void dispose() {
47 |
48 | }
49 |
50 | public String getName() {
51 | return name;
52 | }
53 |
54 | @Override
55 | public boolean keyDown(int keycode) {
56 | if (keycode == Keys.BACK || keycode == Keys.ESCAPE) {
57 | dispose();
58 | Gdx.input.setCatchBackKey(false);
59 | ((Game) Gdx.app.getApplicationListener()).setScreen(new MainMenu());
60 | }
61 |
62 | return true;
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/codelabs/src/com/leakedbits/codelabs/utils/SampleUtils.java:
--------------------------------------------------------------------------------
1 | package com.leakedbits.codelabs.utils;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Collections;
5 | import java.util.List;
6 |
7 | public class SampleUtils {
8 | public static List getNames(List> samples,
9 | boolean sorted) {
10 | List names = new ArrayList(samples.size());
11 |
12 | for (Class extends Sample> sample : samples) {
13 | names.add(sample.getSimpleName());
14 | }
15 |
16 | if (sorted) {
17 | Collections.sort(names);
18 | }
19 |
20 | return names;
21 | }
22 |
23 | public static Sample instantiateSample(List> samples,
24 | String sampleName) {
25 | try {
26 | return forName(samples, sampleName).newInstance();
27 | } catch (InstantiationException e) {
28 | e.printStackTrace();
29 | } catch (IllegalAccessException e) {
30 | e.printStackTrace();
31 | }
32 | return null;
33 | }
34 |
35 | private static Class extends Sample> forName(
36 | List> samples, String sampleName) {
37 |
38 | Class extends Sample> requestedClass = null;
39 |
40 | for (Class extends Sample> sample : samples) {
41 | if (sample.getSimpleName().equals(sampleName)) {
42 | requestedClass = sample;
43 | }
44 | }
45 |
46 | return requestedClass;
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------