Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Learning Android Game Programming NOTES:
- People have been playing games on computers for almost as long as electronic computers
- have existed, and a rich variety of games has been invented. In her book, Reality Is
- Broken, Jane McGonigal says that most games have four attributes:
- 1) A goal: Games clearly define a goal for the players to achieve. It’s important that the
- goals be challenging, yet achievable. Ideally, players are always playing at the leading
- edge of their ability. Goals give the players a sense of purpose in playing the game.
- 2) Rules: Games have rules that all the players agree to follow. The rules often make
- achievement of the goal difficult, which in turn encourages players to be creative.
- 3) Feedback: A game has to tell the players how they are doing. Indeed, an interesting,
- creative feedback system is key to making a game enjoyable.
- 4) Voluntary participation: It just isn't a game unless you really want to play. This aspect
- of games implies the players’ acceptance of the goal, rules, and feedback system.
- Before we create a new game, we want to think about which types of games exist, as
- well as which types work well on mobile devices and which don’t. We also want to
- take a look at the components that are common to all computer games.
- Game Genres
- Game developers didn’t start out categorizing their games, and there is no standard list
- of categories. Nevertheless, over time games have been grouped into classes by different
- people in different ways. The categories identified in this section are not meant to be
- canonical, and they admittedly overlap in a number of areas. The exact categorization
- really isn’t important—the point is that numerous types of games can be developed.
- Skill or Action Games
- Action game players typically have to use some real-time skill (e.g., jump a barrel
- at the right time, shoot at a moving target) to be successful. Subtypes with some
- examples include the following:
- - Maze games
- - Platform games where the player moves platforms around either to get
- somewhere
- or to stop adversaries
- - Tower defense games: the player defends something (the tower) from an
- oncoming
- horde of bad guys
- - Shooters: with the playing field either fixed, sliding, or scrolling
- - One-on-one fighting games: where two opponents battle it out
- - One-to-many fighting games: where the player fights through a gang of
- opponents
- (often martial arts related)
- - First-person shooters (FPS): where the player’s view is that of the shooter
- - Third-person shooters: same as FPS, but the point of view is that of a third
- person
- Strategy Games
- Strategy games are less about reacting to real-time events, and more about devising
- and implementing a strategic plan to overcome obstacles. They include the following
- types of games:
- - Turn-based games: including traditional board games
- - Timed strategy games: where each move occurs in a fixed time
- - Massively multiplayer online role-playing games (MMORPs): an extension of
- the old Dungeons and Dragons genre, in which players assume roles and play
- against others online
- Adventure or Storytelling Games
- Adventure and storytelling games are built around a rich storyline, with well-developed
- characters and a story that defines the player’s purpose in playing the
- game.
- - Simpler 2D story games often involve mazes and interactions with other game
- entities.
- - Complex 3D story games can show different points of view as the game is played
- and the story spun. Some have been turned into Hollywood movies.
- Simulation Games
- Typically, simulation games depict some real situation, such as a vehicle that the player
- can operate. The games reproduce the physics of the real situation and can be good
- enough to use for instruction as well as for just playing a game. They include the following
- types of games:
- - Sports simulators
- - Flight or space simulators
- - Driving or racing simulators
- - Boat or submarine simulators
- - Life simulators (overlap with strategy games)
- Puzzle Games
- Many puzzle games are direct translations of printed puzzles (e.g., crosswords), but the
- genre also includes matching and hidden object games. Complex games often include
- smaller puzzle games to solve as part of the larger game. Examples of puzzle games
- include those based on the following concepts:
- - Word based (e.g., crosswords)
- - Number/math based (e.g., Sudoku)
- - Visual matching
- - Hidden object (e.g., Minesweeper)
- - Construction from a set of pieces
- Augmented-Reality Games
- It’s fine to play games just for the fun of it, but sometimes there’s a bigger motive. As
- Jane McGonigal’s Reality Is Broken points out, some games are intended to augment
- reality in such a way that our real lives are made easier. Examples of augmented-reality
- games (ARGs) include the following games:
- - Jetset: a game that simulates the security line at an airport (to help you pass the
- time while you wait in the real line)
- - Chore Wars: a game that turns household chores into creative competition
- - World Without Oil: a game that encourages energy conservation by simulating a
- world where oil products are in very short supply
- Games for Mobile Phones
- With this rich variety of game types to choose from, we need to focus on those
- that are most appropriate for mobile platforms such as phones and tablets. We also
- need to focus on those games whose development by a small group of people is
- feasible.
- Given the potential size of the mobile device games market, it’s not surprising that
- a substantial amount of research and thought have been put into what makes a good
- mobile game. The usual principles of good computer game design still apply, along
- with special characteristics of good mobile games:
- - Don’t waste the player’s time.
- - Provide help on playing the game.
- - Make the game goals easy to understand.
- - Show game status clearly.
- - Mobile users typically play games in short sessions.
- - Players need to easily pause and resume a game, and the phone should be able to
- pause and resume games when necessary (e.g., for an incoming call).
- - Players should be able to make game progress in a short period of time.
- - Mobile devices have physical constraints that affect games:
- - Small screen size and a variety of screen sizes, resolutions, and pixel densities
- - Variety of user input methods (e.g., one- and two-handed operation, touch,
- keypad, multi-touch, keyboard, Dpad, trackball)
- - Limited computational power
- - Limited battery (a factor that limits power-intensive graphics and computing)
- Even if you had the development resources to create a really snazzy 3D first-person
- shooter game like Halo, players are unlikely to sit with their smartphone and play it
- for hours the way they might with the XBox version. Users are much more likely to
- play mobile games in short sessions, pausing and resuming the game perhaps days later.
- Speaking of resources, what does it take to create a commercial game? A typical
- console game for a single console can easily take $10 million to develop, and two or
- three times that amount for multiple-console development (it has been estimated that
- some complex games cost as much as $100 million to create). The software development
- kit (SDK) and license to create a console game alone can cost thousands of dollars.
- If you think about what goes into a professional 3D console game, it’s easy to see
- where the costs mount up—3D artwork, motion capture, animation, game play, user
- testing, and software development are all both time consuming and expensive.
- This book is about you and maybe one or two friends creating your own mobile game
- for the Android platform. The Android SDK is free, and as of this writing, it costs only
- $25 to sign up for Android Market and sell your game to anyone with an Android device.
- We’ll stick to 2D (two-dimensional) games, which makes the artwork and the programming
- simpler. As you’ll see, the basic game structure and components of any 2D game are
- pretty much the same no matter what the genre, but we need to pick one as an example.
- Components of a Typical Game
- Before we look at the specifics of the example game, let’s examine the general components
- that we need to work into the game and implement in the code. Here are some
- components that will be part of our game.
- - Opening (Splash) Screen
- To maximize performance as the game is being played, the graphics needed for a game
- level are often loaded before the level is started. During the loading process, which can
- take several seconds, you don’t want to leave the user with a blank screen, so you display
- a splash screen. It lets the user know that the game is working as it should. Splash
- screens are optional, but we’ll include one in our game, just to show how it’s done.
- - Menu Screen
- Once the game is ready to run, we’ll need a place for the user to enter various options
- (e.g., turn the sound on/off, get help in playing the game). This is typically done with
- a graphical menu screen that presents the options and either implements the option or
- calls another screen (such as Help) to do so.
- - Music
- For most of us, music has strong emotional inf luence. Background music is very
- important for setting the mood of your game, and helping with the transitions
- between parts of the game.
- - Sound Effects
- Sound effects can make a game a lot more fun. When two objects collide, players
- expect to hear a sound of some kind—whether it’s a clang, a thud, or a boing. Our
- example game also incorporates sound effects for each of the game characters. Each
- villain has a characteristic sound effect accompanying his or her presence in a scene.
- - Time
- Most games will incorporate time—either clock time (scoring completion of a puzzle
- based on the time taken to solve the puzzle) or playing against moves the computer
- (or computer-driven adversaries) makes in real time. In our game Virgins Versus
- Vampires (V3), this factor takes the form of killing the villains before they can reach
- the virgins.
- - Lives
- Games have to be challenging to be fun, so the player has to fail every once in a
- while. Killing the player off (in a virtual way) is a convenient way to give failure a
- consequence. Some games give the player multiple lives per session, whereas others
- (and V3) give the player only one life.
- - Obstacles
- Obstacles are used in different ways in different games. In many games, the player is
- trying to achieve some goal, and obstacles are thrown in the player’s path. In tower
- defense games (and V3), it’s the adversaries who are trying to reach a goal, so the
- player throws obstacles in their paths.
- - Levels
- Challenging games are fun, but it’s important to provide a range of challenges, so that
- players can start with easy challenges and gradually ramp up to higher challenges as
- their game-playing skills and experience improve. Levels are a proven way to achieve
- this effect—the player learns how to play the game in the first few levels, and his or
- her skills have to continue to improve as new levels are presented. This is also a great
- way to add some variety to the game.
- - Adversaries
- The adversaries in a game are sometimes referred to as entities (although AndEngine
- uses that word to mean something else). These characters are the villains (or other
- players) that the player must overcome to win. They are distinct from obstacles in that
- they take action against the player—obstacles are more passive. We’ve listed the entities
- for V3 later in this chapter, along with an outline of their behavior.
- - Player
- Of course, the player is the most important component of any game. The whole point
- is to keep the player engaged and interested so he or she will keep playing the game.
- The player has to be challenged by the game, but not too challenged to give up in
- frustration. The game has to include enough variety to maintain the player’s interest,
- and rewards have to be doled out to recognize success in playing the game.
- - Scenes
- If you think of the game as something like a movie, each screen that is displayed to the
- player is something like a movie scene. Each scene has background graphics that don’t
- change much (although the player’s point of view might change). Animated graphics
- are then added to the scene to implement the entities and obstacles that interact to
- make the game.
- Once you have a game concept outlined, the next step in designing a game is to envision
- the scenes needed and describe the f low among them. Screenwriters and many
- creative writers do this by making a storyboard with pencil and paper, using an index
- card or drawing a rectangle for each scene, and creating a very rough sketch of the
- scene and a few words to describe what’s going on there. You can show the transitions
- between scenes with an arrow and a brief description of when the transition
- takes place.
- AndEngine Game Concepts
- The movie analogy we referred to earlier is a good way to approach AndEngine. Your
- game is like a movie, and the game engine includes concepts that are analogous to
- those involved in making a movie.
- - Camera
- The “camera” of the game determines the view of the game that is presented to players.
- It is very much like a movie camera in two-dimensional space. The camera can
- pan and zoom across the scene to change the view presented. The panning and zooming
- can either be under the player’s control or be driven programmatically.
- - Scene
- A game, like a movie, consists of a series of scenes where the action takes place. In a
- movie, the scenes are edited together in a fixed way. In games, the sequence of scenes
- is driven by the play of the game. Games are like movies edited on the f ly.
- - Layer
- Scenes are composed of layers of graphics. The layers are superimposed on one another,
- much like the animation cels used to create cartoons in the old days. Layers can also
- be used to introduce 2½D effects, where, as the camera pans, closer layers move faster
- than more distant layers.
- - Sprite
- Sprites are the visual representation of the actors in our movie, whether those actors
- are people or objects. Sprites can be animated or not, but they often move about the
- scene during the course of game play. Sprite textures are often loaded from one large
- image that comprises a collection of sprite images, called a sprite sheet.
- - Entity
- In AndEngine, entities are just about anything that’s drawn to the screen. Sprites
- are entities, as are tiles, geometric shapes, and lines drawn on the screen. All entities
- have properties, such as color, rotation, scale and position, that can be changed by
- modifiers.
- - Modifier
- Modifiers change the properties of an entity, and they are very powerful in
- AndEngine.
- They can be used on any entity, and the change they cause can either
- be immediate or occur gradually over a specified duration. In our game, we’ll use
- modifiers frequently to create effects with sprites and other entities.
- - Texture
- A texture is a 2D, generally bitmapped graphic that can be applied to objects to give
- them, well, texture. Textures define the way entities look, and much of the OpenGL
- graphics environment is built around the use of textures.
- Texture Region
- A texture defines a complete bitmap graphic, and a texture region defines a subset of
- that region. We’ll talk a lot about performance optimizations of 2D graphics later, and
- using texture regions to map small pieces of a large combined bitmap is one of the key
- tricks used to create these optimizations.
- - Engine
- An engine runs a scene. It takes care of letting animations and modifiers know when to
- update the presented graphics, coordinates the actual drawing, handles user input events
- (touch, keys, sensors), and generally manages the progress of the game. The engine is a
- lot like the producer/director of our movie, telling everyone what they need to do.
- - BaseGameActivity
- This class, which extends the Android Activity class, will be the basis of each scene
- in our game. BaseGameActivity does all the work common to all scenes, setting up
- the game engine, conforming to the Android Activity Lifecycle requirements, and
- enabling sensors. We’ll explore this class in more depth in Chapter 3.
- - Physics Connector
- AndEngine includes basic physics capabilities in the base engine, but the Box2D physics
- engine expands greatly on those capabilities. We connect AndEngine objects with
- Box2D through a physics connector. If your game doesn’t use Box2D physics, you
- won’t have a physics connector.
- Box2D Physics Engine
- AndEngine includes the open-source JBox2D port of the Box2D physics engine. It
- can be used to realistically simulate the interaction of physical objects in the following
- ways (among others):
- - Simulation of the physics of rigid bodies
- - Stable stacking
- - Gravity
- - User-defined units
- - Efficient solving for collisions/contacts
- - Sliding friction
- - Boxes, circles, and polygons
- - Several joint types: distance, revolute, prismatic, pulley, gear, mouse
- - Sleeping (removes motionless bodies from simulation until touched)
Add Comment
Please, Sign In to add comment