Archive for June, 2010

Battle of Brooklyn at Come Out and Play Festival

Tuesday, June 22nd, 2010

On a sunny and hot Sunday earlier this month, June 6th to be exact, we played version 1.0 of our game, Battle of Brooklyn, at the Come Out & Play festival in New York. I’m happy to report that we had a successful play session. All players (I mean soldiers) seemed to enjoy themselves as they ran around the Boathouse battling each other for control over bridges, tunnels and other strategic locations. We also captured some really good feedback that will serve as inspiration for future improvements to the game.

Here are some pictures from the play session.

That is not to say that we did not have any problems. Here is a quick overview of our challenges: first, the day began with me running to Kmart and then Target to procure some bandanas. Next, when we arrived at the game location we were notified that 45 people had signed up to play our game even though we only had props for 36 players. After finding a solution to accommodate more players only 12 people actually showed up to play the game (this ended up being good news because I got to jump into the game as well).

Feedback and Opportunities
After the game we got a chance to capture feedback from the players from both teams – we were lucky because Eric Zimmerman (the guy who literally wrote the book about game design) was one of the judges assigned to play our game. Here is an overview of the most crucial or promising ideas we captured:

Team selection and balance: create a system that helps ensure teams are evenly balanced when selected. In this round of play we ended up using an ad hoc system that allowed friends to opt to join the same team. Unfortunately, this led to uneven distribution of skills between the two teams. Need to find a better way for doing this in the future.

Kill flag location: explore new locations to secure the kill flag from each soldier. One promising suggestion was to attach the kill flags to a wrist band so that whenever someone attacked the soldier from the other team they were also putting their own lives at risk. This would likely help equalize the balance of the game as well.

Territory capture using kill flags: explore different mechanisms to capture territory. One promising suggestion was to make it so that armies need to spend kill flags in order to capture a territory. This would solve the current issue with the game, where the army that has captured the most kill flags can always capture all territories since they are able to use the same kill flags to capture multiple locations.

Defending captured territories: we have been wanting to find a solution for running this game without the need for volunteers to work at each battlefield. One suggestion that came up was to change the rules so that an army needs to always leave at least one soldier to defend a conquered territory. Territory battles could be decided based on the number of kill flags + live soldiers – for example, if a soldier from the blue army is defending a territory with 2 kill flags, then to conquer the territory the other team must arrive with 3 kill flags and 1 soldier, 2 soldiers and 2 kills flags, or 1 kill flag and 3 soldiers.

Battle of Brooklyn Rules

Game Rules and Props
Now finally here is a detailed outline of the final game as it currently stands. The full game rules are posted as an image below next to the complete list of required props, and guidance regarding locations.

To play this game you will need the following props: each team will need two to six “nation” flags and a few maps that feature strategic battlefields. Individual players need bandanas and a flag football-style belt and flag system in their army’s color (extra flags will be needed).

Over the past few months we have tested this game in several locations. From this fieldwork we gained two important insights: First, the playing field needs to be right sized to the number of players. Since there is a lot of running in this game the field cannot be too large otherwise players get exhausted early. Secondly, it is important to find a place that has easily identifiable structures that can be used as readily-identifiable battlefields.

Thanks for the Support
Thanks to everyone who came out to play the game during the past several months. We truly appreciate your support, without it this game would not exist. A special thanks to Morgen, my partner in crime on this game.


The View Class – Learning Java for Android

Tuesday, June 8th, 2010

The view class represents the basic building block for user interface components. A View occupies a rectangular area on the screen and is responsible for drawing and event handling. Subclasses of the view class also offer fully implemented UI objects like text fields and buttons; these are often called widgets.

A View object handles its own measurement, layout, drawing, focus change, scrolling, and key/gesture interactions for the rectangular area of the screen in which it resides. As an object in the user interface, a View is also a point of interaction between the user and the activity(s) that is reacting to the interaction events.

Multiple views can be grouped together in view groups. These view groups can also contain other view groups. This arrangement can be visualized as a hierarchical tree-structure where the group view nodes are branches, and the view nodes are leaves (refer to image to right, taken from android developer guide).

One important thing to remember is that a view can refer to the canvas that contains all of the graphics on a screen, or to a single button within a menu. This structure is enables parent views to influence child views. This is important considering that the android OS runs on so many devices with such divergent specs.

Standard Views
Android applications can be built using standard views or custom views, or they can contain both. Standard views are composed of buttons and other standard elements. These types of views are easy to create but provide limited opportunities for customization. Therefore, their use is limited in the realm of mobile games.

Standard views are created using XML layout templates that are saved in the layout folder in the package resources. These standard view definitions are usually simple documents that include only a short list of attributes such as screen orientation, width and height, and text. When an activity is linked to a standard view, the attributes in the XML document determine how objects (buttons, text, etc) from that activity appear on the screen.

Sometimes classes are created to extend the functionality of a standard view. However, I will not explore any examples of this practice here.

Custom Views
Custom views can be created in many different ways. Unlike standard views, they are always defined using both XML code and class extensions. For my application I created a custom view by extending the SurfaceView class, and defining a simple view layout using XML. I initially selected this approach because I was using Matt’s sample application as my guide. Upon further investigation I’ve confirmed that this is the best approach.

Here is an overview of how this approach works. It is pretty complex, so here is a link to an official description from the android site.

SurfaceView is a special subclass of View that offers a dedicated drawing surface to an application’s secondary thread, so that the secondary thread can draw to its own Canvas at its own pace (without needing to wait for the main thread).

Here is how you set-up an application to use this class. First,  create a class that extends SurfaceView and implements the SurfaceHolder.Callback interface (named GameView in my app). This class will serve as a link between the thread class that will perform all the drawing procedures and the canvas itself.

This new view class needs to include an instance of the secondary thread (named GameThread in my app), which contains all drawing procedures. Then, to enable the secondary thread to access the drawing surface, create an instance of the SurfaceHolder object. This object functions as the connector between the view and thread classes.

Next initialize the SurfaceHolder variable so that the new view class receives callbacks related to surface activity. Lastly, we need to override all the callback methods from the SurfaceHolder.Callback interface. I know this is a lot of information to keep straight, and we’re not done yet.

Now that you’ve set-up the new view class, here is what you need to do in the thread so that it can draw to the canvas/surface. First, we need to pass the SurfaceHandler object from the view class to the thread class. Then, each time we want to draw to the canvas we need to retrieve the canvas using the lockCanvas() method from the SurfaceHandler object. Then the thread can draw to this canvas.

Once done drawing, we need to pass the updated canvas object back to the SurfaceHolder object using the callunlockCanvasAndPost() method. The Surface will now draw the Canvas.

To clear the previous state of the Canvas you need to fill it with a color using drawColo() or set a background image with drawBitmap(). Otherwise, you will see traces of the drawings that were previously performed.


The Maze on Android

Monday, June 7th, 2010

Here is an update regarding my android, currently titled The Maze. Last week I spent a lot of time porting my code from processing to java for android. I’m happy to report that I was able to make it work, for the most part at least (I still need to fix my buggy collision tracking).

To get my application to work I repurposed a lot of code from Matt’s android application example that he shared in class [add link here]. For the most part I had to copy the structure of Matt’s application. I leveraged his GameView, GameThread, GameElement, and Coods classes.

I was easily able to port over my data model classes (Shapes, Rectangles, Circles, and Maze) and activity class (Game). The updates included switching out calls to any Processing specific classes and methods, such as PVector and all draw methods, and changing the main application to be an extension of activity rather than the pApplet class.

I also used Matt’s code as the basis of my investigation into how android applications are structured. I was specifically interested in understanding the following concepts: activities, views, threads, handlers, listeners, and interfaces. I’ll start today with a brief overview regarding some of these concepts.

Over the next week I will write a series of posts that cover all of these topics. I will use the Android Developers Guide as my main source of information.

Tasks, Activities, Threads & Views

What users experience as an application android calls a task. Tasks include various components. Simple Android applications (or tasks) are usually composed of Views and Activities. There are other Android application components such as services, broadcast receivers, and content providers play important roles in more complex apps.

Android devices can run multiple tasks at once. Some application components are designed to run in the foreground, such as activities, while others run in the background, services, broadcast listeners and content providers.

Views define the visual interface of Android applications, while the activities usually define the processes that govern how foreground applications run, under the hood. An application can feature multiple different views, and many different activities. Within an application multiple activities can run simultaneously in separate processes called threads.