E-Book, Englisch, 298 Seiten
Silva Pro Android Games
1. ed
ISBN: 978-1-4302-2648-2
Verlag: Apress
Format: PDF
Kopierschutz: 1 - PDF Watermark
E-Book, Englisch, 298 Seiten
ISBN: 978-1-4302-2648-2
Verlag: Apress
Format: PDF
Kopierschutz: 1 - PDF Watermark
Do you remember landmark games like Wolfenstein 3D, Doom, and Asteroids? Well, here's an exciting opportunity to build and/or port these games to one of the hottest mobile and netbooks platforms today: Google's Android. Pro Android Games teaches you how to build cool games like Space Blaster and the classic Asteroids from scratch on the latest Android platform. This book also shows you how to port other classic freeware/shareware games like Doom and Wolfenstein 3D from C using the Java Native Interface (JNI) for Android. This book is all about a unique perspective in Android game development: a well-balanced, powerful combination of pure Java and hybrid game development, mixing Java and C. By combining the elegant object-oriented features of Java and the raw power of C, there is no limit to the types of games that you can build for the platform. With actionable real-world source code in hand, this book allows you to dive right into games development on Android. You'll definitely have fun, and perhaps you'll even make some money. Enjoy!
Vladimir Silva holds a master's degree in computer science from Middle Tennessee State University. He worked for four years at IBM as a research engineer, where he acquired extensive experience in distributed and grid computing research. Vladimir is a highly technical, focus-based individual and team player. He belongs to two national honor societies, has published many computer science articles for IBM, and is author of Grid Computing for Developers (Charles River Media, 2005) and RCP Practical Projects (Apress, 2008).
Autoren/Hrsg.
Weitere Infos & Material
1;Table of contents ;4
2;About the Author;11
3;About the Technical Reviewer;12
4;Introduction;13
4.1;What Software Will You Need?;13
4.1.1;A Windows or Linux PC with a Java SDK Properly Installed;13
4.1.2;Eclipse IDE and Android SDK Properly Installed;13
4.1.3;GNU C Compiler for ARM Processors;15
4.1.4;Chapter Source;15
4.2;What Makes This Book Unique?;15
4.3;Android SDK Compatibility;15
4.3.1;Chapter 1;16
4.3.2;Chapter 2;16
4.3.3;Chapter 3;16
4.3.4;Chapter 4;16
4.3.5;Chapter 5;17
4.3.6;Chapter 6;17
4.3.7;Chapter 7;17
5;CHAPTER 1 Welcome to Android Gaming;18
5.1;What Skills Do You Need?;18
5.1.1;A Solid Foundation of Android;18
5.1.2;A Basic Knowledge of Linux and Shell Scripting;20
5.2;What Software Tools Do You Need?;21
5.3;Setting Up Your Machine;21
5.3.1;Getting the Android Source;22
5.3.2;Extracting Native Android Libraries;24
5.3.3;Installing the GNU Toolchain for ARM Processors;25
5.3.4;Writing Custom Compilation Scripts;28
5.3.4.1;The Traditional Linux Compilation Process;28
5.3.4.2;An Android Compilation Script;30
5.3.4.3;An Android Linker Script;33
5.3.4.4;Testing the Scripts;35
5.4;Setting Up Your Development Environment;35
5.5;You Have Taken the First Step;43
6;CHAPTER 2 Compiling Native Code in Android;44
6.1;Your First Native Android App;44
6.1.1;Creating an AVD;44
6.1.2;Creating the Android Project;47
6.1.3;Application Architecture;49
6.1.3.1;Main Activity;51
6.1.3.2;Native Interface;53
6.1.3.3;Native Library;54
6.1.3.4;Converting a Java Array to a C Array;60
6.1.3.5;Getting the Size of a Java Array;61
6.1.3.6;Invoking a Java Static Void Method;61
6.1.3.7;Defining a Variable-Arguments Function in C;61
6.2;Compiling and Testing the Shared Library;62
6.2.1;Troubleshooting Missing Symbols;65
6.2.2;Testing the Dynamic Library on the Device;66
6.2.3;Debugging with strace;67
6.2.4;Compiling Statically;68
6.3;Testing the Native Application;69
6.4;What’s Next?;71
7;CHAPTER 3 Building a Java Game from Scratch;72
7.1;Android Gaming vs. Java ME Gaming;72
7.2;Creating Space Blaster, Your First Java Game;73
7.2.1;Understanding Game Architecture;74
7.2.2;Creating the Project;76
7.2.3;Creating the Game’s Activity Class;77
7.2.4;Creating the Game Layout;78
7.2.5;Implementing the Game;83
7.2.5.1;Initializing Sprites and Sounds;85
7.2.5.2;Loading Bitmap Sprites;87
7.2.5.3;Creating the Star Field;88
7.2.5.4;Playing Audio Clips;89
7.2.5.5;About Native Sound;92
7.2.6;Handling Key and Touch Events;93
7.3;Testing on the Emulator;96
7.4;What’s Next?;97
8;CHAPTER 4 Java Games Continued: Fun with Polygons;98
8.1;About the Chapter Layout;98
8.2;Understanding the Caveats of Drawing Polygons in Android;98
8.3;Understanding the Caveats of Drawing Rectangles;100
8.4;Creating a Polygon Class for Asteroids;102
8.5;Creating a PolygonSprite Class for Asteroids;108
8.6;Understanding the Game’s Architecture;112
8.7;Creating the Project;112
8.7.1;Creating the Game Layout;114
8.7.2;Looking at the Resources;114
8.7.3;Understanding the Game Life Cycle;116
8.7.3.1;Initializing the Game;118
8.7.3.2;Drawing Sprites;120
8.7.3.3;Updating Game Physics;123
8.7.3.4;Getting Scores;126
8.7.4;Responding to Key Press and Touch Events;127
8.8;Testing Asteroids on the Emulator;130
8.9;What’s Next?;132
9;CHAPTER 5 Hybrid 3D Graphics with OpenGL and JNI;133
9.1;The Power of Mobile Devices;134
9.2;OpenGL the Java Way;135
9.2.1;Java Main Activity;139
9.2.2;Surface View;140
9.2.3;GL Thread;143
9.2.4;Cube Renderer;146
9.2.5;Cube Class;150
9.3;OpenGL the Native Way;152
9.3.1;Main Activity;154
9.3.2;Native Interface Class;156
9.3.3;Changes to the Original Sample;158
9.3.4;Native Cube Renderer;159
9.3.4.1;Scene Initialization;160
9.3.4.2;Drawing Frames;161
9.3.4.3;Java Callbacks;163
9.3.4.4;Native Interface Call;166
9.3.5;Native Cube;167
9.3.6;Compiling and Running the Sample;168
9.4;Caveats of Porting OpenGL Games to Android;174
9.5;The Veil Has Been Lifted;175
10;CHAPTER 6 3D Shooters Episode I: Wolfenstein 3D for Android;176
10.1;Gathering Your Tools;176
10.1.1;Downloading the Chapter Source Code;176
10.2;Introducing Wolf 3D;177
10.3;Understanding the Game Architecture;180
10.4;Understanding the Java Classes for Wolf 3D;182
10.4.1;Creating the Main WolfLauncher Class;183
10.4.1.1;Main Activity Layout;184
10.4.1.2;Main Activity Class (WolfLauncher);184
10.4.2;Creating the Wolf 3D Main Menu;187
10.4.3;Handling Key and Touch Events;189
10.4.4;Creating the Game Loop;190
10.4.5;Making Native Callbacks;192
10.4.6;Creating Sound and Music Handlers;194
10.4.7;Creating Movement Controller Handlers;195
10.4.8;Creating the Movement Controller;197
10.4.8.1;Controller Layout;198
10.4.8.2;Controller Class;200
10.4.9;Sound Classes;205
10.4.9.1;Mapping Sound Names to Raw Sound Resources;207
10.4.9.2;Creating the Audio Manager;208
10.4.9.3;Creating the Audio Clip;212
10.4.10;Native Interface Class;215
10.5;Coding the Native Layer;218
10.5.1;Initializing the Game Loop;219
10.5.2;Cascading Messages with C to Java Callbacks;221
10.5.2.1;Initializing Graphics;221
10.5.2.2;Cascading Video Buffers;223
10.5.2.3;Cascading Sound and Music Requests;226
10.6;Compiling the Native Library;228
10.6.1;Writing the Makefile;228
10.6.2;Generating JNI Headers;230
10.7;Testing Wolf 3D in the Emulator;230
10.8;What’s Next?;233
11;CHAPTER 7 3D Shooters Episode II: Doom for Android;235
11.1;The Sky Is the Limit with the Java/C Power Combo;235
11.2;Bringing Doom to a Mobile Device;237
11.3;Game Architecture for Doom;239
11.4;Java Main Activity;241
11.4.1;Creation Handler;241
11.4.2;Game Layout;242
11.4.3;Menu and Selection Handlers;245
11.4.4;Key and Touch Event Handlers;247
11.4.5;Native Callback Handlers;248
11.4.5.1;Graphics Initialization Handler;248
11.4.5.2;Image Update Handler;249
11.4.5.3;Message Updates;250
11.4.5.4;Fatal Error Handler;250
11.4.5.5;Audio Request Handlers;251
11.4.6;Navigation Controls;252
11.5;Audio Classes;254
11.6;Native Interface Class;255
11.6.1;Callback Listener;255
11.6.2;Native Methods;256
11.6.3;C to Java Callbacks;257
11.7;Native Layer;259
11.7.1;Native Method Implementations;260
11.7.1.1;Native Game Loop;261
11.7.1.2;Key and Motion Events;263
11.7.1.3;C to Java Callbacks;264
11.7.1.3.1;Graphics Initialization;265
11.7.1.3.2;Video Buffer Callback;266
11.7.1.3.3;Sound and Music Callbacks;267
11.7.1.3.4;Fatal Errors;270
11.7.2;Original Game Changes;272
11.7.2.1;Renaming main;272
11.7.2.2;Inserting the Fatal Error Callback;273
11.7.2.3;Commenting SDL Occurrences;273
11.7.2.4;Sound System Changes;274
11.7.2.5;Video Buffer Changes;275
11.8;Doom Library (DSO) Compilation;278
11.9;Testing Doom for Android in the Emulator;280
11.10;You Have Done It;283
12;APPENDIX Deployment and Compilation Tips;284
12.1;Signing Your Application;284
12.1.1;Creating a Key Store;284
12.1.2;Signing the Application;285
12.2;Using the Android NDK to Compile Libraries from Chapters 6 and 7;289
12.2.1;Compiling Wolf 3D with the NDK 1.5;290
12.2.2;Compiling the Shared Library;292
12.2.3;Adding Support for OpenGL to the NDK 1.5;293
12.2.4;Compiling Doom with NDK 1.6;295
12.3;Final Thoughts;297
13;Index;299




