Crenox

Learning Android Game Programming NOTES

Jan 25th, 2014
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.86 KB | None | 0 0
  1. Learning Android Game Programming NOTES:
  2.  
  3. People have been playing games on computers for almost as long as electronic computers
  4. have existed, and a rich variety of games has been invented. In her book, Reality Is
  5. Broken, Jane McGonigal says that most games have four attributes:
  6.  
  7. 1) A goal: Games clearly define a goal for the players to achieve. It’s important that the
  8. goals be challenging, yet achievable. Ideally, players are always playing at the leading
  9. edge of their ability. Goals give the players a sense of purpose in playing the game.
  10.  
  11. 2) Rules: Games have rules that all the players agree to follow. The rules often make
  12. achievement of the goal difficult, which in turn encourages players to be creative.
  13.  
  14. 3) Feedback: A game has to tell the players how they are doing. Indeed, an interesting,
  15. creative feedback system is key to making a game enjoyable.
  16.  
  17. 4) Voluntary participation: It just isn't a game unless you really want to play. This aspect
  18. of games implies the players’ acceptance of the goal, rules, and feedback system.
  19. Before we create a new game, we want to think about which types of games exist, as
  20. well as which types work well on mobile devices and which don’t. We also want to
  21. take a look at the components that are common to all computer games.
  22.  
  23. Game Genres
  24. Game developers didn’t start out categorizing their games, and there is no standard list
  25. of categories. Nevertheless, over time games have been grouped into classes by different
  26. people in different ways. The categories identified in this section are not meant to be
  27. canonical, and they admittedly overlap in a number of areas. The exact categorization
  28. really isn’t important—the point is that numerous types of games can be developed.
  29.  
  30. Skill or Action Games
  31. Action game players typically have to use some real-time skill (e.g., jump a barrel
  32. at the right time, shoot at a moving target) to be successful. Subtypes with some
  33. examples include the following:
  34. - Maze games
  35. - Platform games where the player moves platforms around either to get
  36. somewhere
  37. or to stop adversaries
  38. - Tower defense games: the player defends something (the tower) from an
  39. oncoming
  40. horde of bad guys
  41. - Shooters: with the playing field either fixed, sliding, or scrolling
  42. - One-on-one fighting games: where two opponents battle it out
  43. - One-to-many fighting games: where the player fights through a gang of
  44. opponents
  45. (often martial arts related)
  46. - First-person shooters (FPS): where the player’s view is that of the shooter
  47. - Third-person shooters: same as FPS, but the point of view is that of a third
  48. person
  49.  
  50. Strategy Games
  51. Strategy games are less about reacting to real-time events, and more about devising
  52. and implementing a strategic plan to overcome obstacles. They include the following
  53. types of games:
  54. - Turn-based games: including traditional board games
  55. - Timed strategy games: where each move occurs in a fixed time
  56. - Massively multiplayer online role-playing games (MMORPs): an extension of
  57. the old Dungeons and Dragons genre, in which players assume roles and play
  58. against others online
  59.  
  60. Adventure or Storytelling Games
  61. Adventure and storytelling games are built around a rich storyline, with well-developed
  62. characters and a story that defines the player’s purpose in playing the
  63. game.
  64. - Simpler 2D story games often involve mazes and interactions with other game
  65. entities.
  66. - Complex 3D story games can show different points of view as the game is played
  67. and the story spun. Some have been turned into Hollywood movies.
  68.  
  69. Simulation Games
  70. Typically, simulation games depict some real situation, such as a vehicle that the player
  71. can operate. The games reproduce the physics of the real situation and can be good
  72. enough to use for instruction as well as for just playing a game. They include the following
  73. types of games:
  74. - Sports simulators
  75. - Flight or space simulators
  76. - Driving or racing simulators
  77. - Boat or submarine simulators
  78. - Life simulators (overlap with strategy games)
  79.  
  80. Puzzle Games
  81. Many puzzle games are direct translations of printed puzzles (e.g., crosswords), but the
  82. genre also includes matching and hidden object games. Complex games often include
  83. smaller puzzle games to solve as part of the larger game. Examples of puzzle games
  84. include those based on the following concepts:
  85. - Word based (e.g., crosswords)
  86. - Number/math based (e.g., Sudoku)
  87. - Visual matching
  88. - Hidden object (e.g., Minesweeper)
  89. - Construction from a set of pieces
  90.  
  91. Augmented-Reality Games
  92. It’s fine to play games just for the fun of it, but sometimes there’s a bigger motive. As
  93. Jane McGonigal’s Reality Is Broken points out, some games are intended to augment
  94. reality in such a way that our real lives are made easier. Examples of augmented-reality
  95. games (ARGs) include the following games:
  96. - Jetset: a game that simulates the security line at an airport (to help you pass the
  97. time while you wait in the real line)
  98. - Chore Wars: a game that turns household chores into creative competition
  99. - World Without Oil: a game that encourages energy conservation by simulating a
  100. world where oil products are in very short supply
  101.  
  102. Games for Mobile Phones
  103. With this rich variety of game types to choose from, we need to focus on those
  104. that are most appropriate for mobile platforms such as phones and tablets. We also
  105. need to focus on those games whose development by a small group of people is
  106. feasible.
  107. Given the potential size of the mobile device games market, it’s not surprising that
  108. a substantial amount of research and thought have been put into what makes a good
  109. mobile game. The usual principles of good computer game design still apply, along
  110. with special characteristics of good mobile games:
  111. - Don’t waste the player’s time.
  112. - Provide help on playing the game.
  113. - Make the game goals easy to understand.
  114. - Show game status clearly.
  115. - Mobile users typically play games in short sessions.
  116. - Players need to easily pause and resume a game, and the phone should be able to
  117. pause and resume games when necessary (e.g., for an incoming call).
  118. - Players should be able to make game progress in a short period of time.
  119. - Mobile devices have physical constraints that affect games:
  120. - Small screen size and a variety of screen sizes, resolutions, and pixel densities
  121. - Variety of user input methods (e.g., one- and two-handed operation, touch,
  122. keypad, multi-touch, keyboard, Dpad, trackball)
  123. - Limited computational power
  124. - Limited battery (a factor that limits power-intensive graphics and computing)
  125.  
  126. Even if you had the development resources to create a really snazzy 3D first-person
  127. shooter game like Halo, players are unlikely to sit with their smartphone and play it
  128. for hours the way they might with the XBox version. Users are much more likely to
  129. play mobile games in short sessions, pausing and resuming the game perhaps days later.
  130. Speaking of resources, what does it take to create a commercial game? A typical
  131. console game for a single console can easily take $10 million to develop, and two or
  132. three times that amount for multiple-console development (it has been estimated that
  133. some complex games cost as much as $100 million to create). The software development
  134. kit (SDK) and license to create a console game alone can cost thousands of dollars.
  135. If you think about what goes into a professional 3D console game, it’s easy to see
  136. where the costs mount up—3D artwork, motion capture, animation, game play, user
  137. testing, and software development are all both time consuming and expensive.
  138. This book is about you and maybe one or two friends creating your own mobile game
  139. for the Android platform. The Android SDK is free, and as of this writing, it costs only
  140. $25 to sign up for Android Market and sell your game to anyone with an Android device.
  141. We’ll stick to 2D (two-dimensional) games, which makes the artwork and the programming
  142. simpler. As you’ll see, the basic game structure and components of any 2D game are
  143. pretty much the same no matter what the genre, but we need to pick one as an example.
  144.  
  145. Components of a Typical Game
  146. Before we look at the specifics of the example game, let’s examine the general components
  147. that we need to work into the game and implement in the code. Here are some
  148. components that will be part of our game.
  149.  
  150. - Opening (Splash) Screen
  151. To maximize performance as the game is being played, the graphics needed for a game
  152. level are often loaded before the level is started. During the loading process, which can
  153. take several seconds, you don’t want to leave the user with a blank screen, so you display
  154. a splash screen. It lets the user know that the game is working as it should. Splash
  155. screens are optional, but we’ll include one in our game, just to show how it’s done.
  156.  
  157. - Menu Screen
  158. Once the game is ready to run, we’ll need a place for the user to enter various options
  159. (e.g., turn the sound on/off, get help in playing the game). This is typically done with
  160. a graphical menu screen that presents the options and either implements the option or
  161. calls another screen (such as Help) to do so.
  162.  
  163. - Music
  164. For most of us, music has strong emotional inf luence. Background music is very
  165. important for setting the mood of your game, and helping with the transitions
  166. between parts of the game.
  167.  
  168. - Sound Effects
  169. Sound effects can make a game a lot more fun. When two objects collide, players
  170. expect to hear a sound of some kind—whether it’s a clang, a thud, or a boing. Our
  171. example game also incorporates sound effects for each of the game characters. Each
  172. villain has a characteristic sound effect accompanying his or her presence in a scene.
  173.  
  174. - Time
  175. Most games will incorporate time—either clock time (scoring completion of a puzzle
  176. based on the time taken to solve the puzzle) or playing against moves the computer
  177. (or computer-driven adversaries) makes in real time. In our game Virgins Versus
  178. Vampires (V3), this factor takes the form of killing the villains before they can reach
  179. the virgins.
  180.  
  181. - Lives
  182. Games have to be challenging to be fun, so the player has to fail every once in a
  183. while. Killing the player off (in a virtual way) is a convenient way to give failure a
  184. consequence. Some games give the player multiple lives per session, whereas others
  185. (and V3) give the player only one life.
  186.  
  187. - Obstacles
  188. Obstacles are used in different ways in different games. In many games, the player is
  189. trying to achieve some goal, and obstacles are thrown in the player’s path. In tower
  190. defense games (and V3), it’s the adversaries who are trying to reach a goal, so the
  191. player throws obstacles in their paths.
  192.  
  193. - Levels
  194. Challenging games are fun, but it’s important to provide a range of challenges, so that
  195. players can start with easy challenges and gradually ramp up to higher challenges as
  196. their game-playing skills and experience improve. Levels are a proven way to achieve
  197. this effect—the player learns how to play the game in the first few levels, and his or
  198. her skills have to continue to improve as new levels are presented. This is also a great
  199. way to add some variety to the game.
  200.  
  201. - Adversaries
  202. The adversaries in a game are sometimes referred to as entities (although AndEngine
  203. uses that word to mean something else). These characters are the villains (or other
  204. players) that the player must overcome to win. They are distinct from obstacles in that
  205. they take action against the player—obstacles are more passive. We’ve listed the entities
  206. for V3 later in this chapter, along with an outline of their behavior.
  207.  
  208. - Player
  209. Of course, the player is the most important component of any game. The whole point
  210. is to keep the player engaged and interested so he or she will keep playing the game.
  211. The player has to be challenged by the game, but not too challenged to give up in
  212. frustration. The game has to include enough variety to maintain the player’s interest,
  213. and rewards have to be doled out to recognize success in playing the game.
  214.  
  215. - Scenes
  216. If you think of the game as something like a movie, each screen that is displayed to the
  217. player is something like a movie scene. Each scene has background graphics that don’t
  218. change much (although the player’s point of view might change). Animated graphics
  219. are then added to the scene to implement the entities and obstacles that interact to
  220. make the game.
  221.  
  222. Once you have a game concept outlined, the next step in designing a game is to envision
  223. the scenes needed and describe the f low among them. Screenwriters and many
  224. creative writers do this by making a storyboard with pencil and paper, using an index
  225. card or drawing a rectangle for each scene, and creating a very rough sketch of the
  226. scene and a few words to describe what’s going on there. You can show the transitions
  227. between scenes with an arrow and a brief description of when the transition
  228. takes place.
  229.  
  230. AndEngine Game Concepts
  231. The movie analogy we referred to earlier is a good way to approach AndEngine. Your
  232. game is like a movie, and the game engine includes concepts that are analogous to
  233. those involved in making a movie.
  234.  
  235. - Camera
  236. The “camera” of the game determines the view of the game that is presented to players.
  237. It is very much like a movie camera in two-dimensional space. The camera can
  238. pan and zoom across the scene to change the view presented. The panning and zooming
  239. can either be under the player’s control or be driven programmatically.
  240.  
  241. - Scene
  242. A game, like a movie, consists of a series of scenes where the action takes place. In a
  243. movie, the scenes are edited together in a fixed way. In games, the sequence of scenes
  244. is driven by the play of the game. Games are like movies edited on the f ly.
  245.  
  246. - Layer
  247. Scenes are composed of layers of graphics. The layers are superimposed on one another,
  248. much like the animation cels used to create cartoons in the old days. Layers can also
  249. be used to introduce 2½D effects, where, as the camera pans, closer layers move faster
  250. than more distant layers.
  251.  
  252. - Sprite
  253. Sprites are the visual representation of the actors in our movie, whether those actors
  254. are people or objects. Sprites can be animated or not, but they often move about the
  255. scene during the course of game play. Sprite textures are often loaded from one large
  256. image that comprises a collection of sprite images, called a sprite sheet.
  257.  
  258. - Entity
  259. In AndEngine, entities are just about anything that’s drawn to the screen. Sprites
  260. are entities, as are tiles, geometric shapes, and lines drawn on the screen. All entities
  261. have properties, such as color, rotation, scale and position, that can be changed by
  262. modifiers.
  263.  
  264. - Modifier
  265. Modifiers change the properties of an entity, and they are very powerful in
  266. AndEngine.
  267. They can be used on any entity, and the change they cause can either
  268. be immediate or occur gradually over a specified duration. In our game, we’ll use
  269. modifiers frequently to create effects with sprites and other entities.
  270.  
  271. - Texture
  272. A texture is a 2D, generally bitmapped graphic that can be applied to objects to give
  273. them, well, texture. Textures define the way entities look, and much of the OpenGL
  274. graphics environment is built around the use of textures.
  275. Texture Region
  276. A texture defines a complete bitmap graphic, and a texture region defines a subset of
  277. that region. We’ll talk a lot about performance optimizations of 2D graphics later, and
  278. using texture regions to map small pieces of a large combined bitmap is one of the key
  279. tricks used to create these optimizations.
  280.  
  281. - Engine
  282. An engine runs a scene. It takes care of letting animations and modifiers know when to
  283. update the presented graphics, coordinates the actual drawing, handles user input events
  284. (touch, keys, sensors), and generally manages the progress of the game. The engine is a
  285. lot like the producer/director of our movie, telling everyone what they need to do.
  286. - BaseGameActivity
  287. This class, which extends the Android Activity class, will be the basis of each scene
  288. in our game. BaseGameActivity does all the work common to all scenes, setting up
  289. the game engine, conforming to the Android Activity Lifecycle requirements, and
  290. enabling sensors. We’ll explore this class in more depth in Chapter 3.
  291.  
  292. - Physics Connector
  293. AndEngine includes basic physics capabilities in the base engine, but the Box2D physics
  294. engine expands greatly on those capabilities. We connect AndEngine objects with
  295. Box2D through a physics connector. If your game doesn’t use Box2D physics, you
  296. won’t have a physics connector.
  297.  
  298. Box2D Physics Engine
  299. AndEngine includes the open-source JBox2D port of the Box2D physics engine. It
  300. can be used to realistically simulate the interaction of physical objects in the following
  301. ways (among others):
  302. - Simulation of the physics of rigid bodies
  303. - Stable stacking
  304. - Gravity
  305. - User-defined units
  306. - Efficient solving for collisions/contacts
  307. - Sliding friction
  308. - Boxes, circles, and polygons
  309. - Several joint types: distance, revolute, prismatic, pulley, gear, mouse
  310. - Sleeping (removes motionless bodies from simulation until touched)
Add Comment
Please, Sign In to add comment