Thursday, December 4, 2008

Amazed Background

You may have noticed a new video has been posted on the Android Developer Blog about Amazed . The article was written awhile back when I first completed the project but it's about time I posted it. After nearly 80,000 downloads, 3.5/5 average rating and over 60% of people still have the game installed I can say my expectations for the app have been blown out of the water. What started out life as sample code for other developers has grown to the point where I am writing a sequel to feed the hungry general user.

When I was younger I received a strange wooden box containing a labyrinth as a present. The aim was to navigate a marble through the labyrinth by tilting it in various directions. Needless to say I was quickly addicted. I wanted to build a similar style game using the Accelerometer provided by Android. Again the aim is to navigate the white marble through a maze to the exit. The exit area is represented with light blue tiles. If your marble falls off the paved path into the "void" you will loose a life. The marble follows whatever direction the device is tilted, for example tilting the device left will cause the marble to roll left.

In its current state the game has 10 levels with progressive difficulty. You will notice the marble can hover over the edge of the void, it won't fall off the paved path until half the marble is over the edge. Pressing the back key will exit the application from any screen. Only portrait mode is currently supported, in landscape mode a message is displayed asking you to rotate the screen back to portrait mode.

Amazed is available now as on open source project on apps-for-android.

AmazedAcitivity is a custom Activity which serves as the entry point into the application. Upon starting, AmazedView is initialized, given focus and then displayed to the user.

AmazedView is a custom View that implements its own onDraw using Canvas methods. Gesture events are handled using onTouchEvent and onKeyDown methods. If the device orientation is changed, this event triggers onSizeChanged which determines if we are in portrait or landscape mode. A SensorManager is used to register a custom SensorListener named mSensorAccelerometer. Registering a SensorListener signifies to the OS that the application would like to be informed when the sensor changes. In this case Accelerometer values (represented by x,y and z) are reported whenever the device is moved. Using these values we know which direction the marble should be rolling to coincide with the users movement of the device. It is important to note you should always unregister listeners when you no longer require their service.

The Marble class represents the marble drawn in the maze. The x,y co-ordinate are tracked so we know where the marble should be drawn as well as other useful information such as the number of lives. At the moment the marble is drawn using the Canvas method drawCircle. If you possess any form of graphical talent I would recommend creating a custom Bitmap for a more aesthetically pleasing result.

The Maze class is used to load and draw each level as the user progresses through the game. Level data is loaded via an InpustStream, the actual level data can be found in the /assets directory. Level data is loaded via the AssetManager open(String fileName) method. If you open up one of the level text files you will see list of numbers. These numbers correspond to a tile type, currently the 3 tile types are PATH_TILE, VOID_TILE and EXIT_TILE. When drawing the maze the application knows if the tile value is 0 then it should draw a PATH_TILE, if the value is 1 draw a VOID_TILE and if the value 2 draw an EXIT_TILE tile. The comma's and whitespace in the level file are present so us humans can read the file without too much trouble. You can actually alter the level data and create your own custom levels with out any code changes, provided you adhere to the MAZE_COLS and MAZE_ROWS attributes. Both the path and exit tiles are custom Bitmaps drawn using drawBitmap while the exit tile is a simple black square drawn using drawRect after setting up a Rect with the correct parameters.

Wednesday, November 26, 2008

Amazed V2

Been awhile since my last update but its worth it. Here is the first screen shot of the sequel to Amazed. As you can see it already looks much nicer and its only going to get better. I have fixed the 2 most common complaints; backlight turning off and not being able to save your progress. A few new goodies have been thrown in for good measure. More screenshots to come once I finish designing the new levels.

Monday, November 17, 2008

Amazed: 50,000 downloads

Due to work recently, I haven't done as much programming in my spare time as I would like too. It's been awhile since I even checked how many times Amazed has been downloaded. Well to my surprise this morning Amazed had reached the next tier 50,000 ~ 250,000 downloads. So I logged into the Market back-end and the exact number is just shy of 54,000. Not bad for a simple open sourced game that lacks decent graphics.

For everyone who has been emailing me about an update. Yes I am still working on an update. Once I have some new graphics I will post a teaser screen shot.

Thursday, November 13, 2008

Nothing New

Unfortunately that thing you call a job has taken over all my spare time recently but at least it involves me using Android on a daily basis. Due to work commitments I haven't been able to make any updates to any of my side projects. Sometimes its good to take a week off, sit back and have a re-think. I've come up with some new ideas to implement into Amazed v2 (still thinking of name) as well as ideas for some other games.

People are still downloading Amazed from the Market, thanks for all the emails.

Thursday, November 6, 2008

Poker League

Since arriving in America last year I have been learning all about Texas Hold 'em. At work we have a league going where people play for points instead of money. This keeps its fun as well as encouraging new people to have a go.

The existing tracking system involved a wiki page and an excel spreadsheet. I thought this would be a perfect project to play around with databases and native widgets in Android. Until now most of my Android experience has been gaming related which revolves around drawing everything yourself. It would be a welcomed change to use native widgets and xml to build an application.

Creating a basic menu system was very easy. Most of my time has been spent learning what attributes I can use in the xml files. I will post some screen shots after I clean up the design, at the moment everything is black with white text.

Once I have it fully working the next step will be to interface with a remote database so anyone can view the poker league results.

Saturday, November 1, 2008

Amazed V2

I've decided to bite the bullet and re-write my Accelerometer game from scratch. I have received so many great suggestions it was getting difficult too merely "patch" Amazed. So with a fresh new design built from the ground up and much needed improved graphics, Amazed V2 is born (working title name).

I did have an update ready for release on the Market, however with the current Market bug (comments/info disappears) I decided against this and will release a sequel. After writing the first Accelerometer game could we see the first official Android sequel?

First version is planned for release in a couple of weeks, mid November.

Here are some of the new features
* Save/Resume
* Larger maps
* Top 5 Fastest times per level
* Enemy characters

I have more features planned but don't want to spoil the surprise too much.

Thursday, October 30, 2008

Market Back-end update

We now have a new option for our market applications, "All Current and Future Locations". This makes live easier by only having to tick one box.

Publishing options

The UK launch doesn't appear to be as successful as the US, at least in regards to news available. All the early birds must already have their Android fix.

Tuesday, October 28, 2008

UK Launch

If you have an app up on the Market you will have received an email informing you of the upcoming UK launch. If you want your app available to UK customers you need to log into the market back end and select the new check box that has appeared. As more countries release Android phones I imagine you will have a seperate option for each country.

Publishing options

Here is a copy of the email for anyone who is interested.

"Hello Android Developer,

Congratulations on having your application on Android Market. We hope you
have been receiving many downloads of your app and some good feedback as
well. As announced by T-Mobile earlier this month, Android Market will
also launch in the UK on October 30th at 7am GMT. So beginning Wednesday
evening PDT, apps will be shown on the G1 devices in the UK. By default,
any application currently in Market will be shown in both the US and the
UK Markets.

Please be sure to do the following between 8am PDT and 5pm PDT on
Wednesday October 29th if you do not want your app in both the UK and the
US Markets.

Go to, edit your application(s) and
simply uncheck the box for the location you do not want your app to appear

Please look at your EULA again and make sure that it will work for the UK.

And again if you want your app to be in both the US and the UK Markets you
do not need to do anything.


The Android Market team"

Android Clipping

Today is a good day, I finally solved my simple clipping issue. While the issue was simple I had been neglecting it for some unknown reason. Well this afternoon I decided today was the day to face it. Often for sprites you will have an animation strip containing multiple images, however you only want to display a single frame not the whole image. Clipping allows you to specify a particular region on the screen to draw too, anything outside the region will not be shown to the user.

I needed clipping to behave just like J2ME. In J2ME you can continually modify the clip as many times as you like. The code below will draw 2 rectangles on a white background.

public void paint (Graphics g) {
g.setClip(0, 0, canvasWidth, canvasHeight);
g.fillRect(0,0, canvasWidth, canvasHeight);

g.setClip(0, 0, 100, 100);
g.fillRect(0, 0, 100, 100);

g.setClip(100, 100, 50, 50);
g.fillRect(100, 100, 50, 50);

My first attempt in Android many moons ago (actually over a year ago) involved me being naive and not fully reading the docs. I was continually saving the current clip and restoring it everytime I wanted to modify the clip. Here is some sample code.

public void onDraw (Canvas canvas) {
//jmt: save our current clip;
//jmt: clear the screen
canvas.clipRect(0, 0, mCanvasWidth, mCanvasHeight);
canvas.drawRect(0, 0, mCanvasWidth, mCanvasHeight, mPaint);
//jmt restore clip to previous state

//jmt: save our current clip;
//jmt: draw our animation
canvas.clipRect(x, y, x + FRAME_WIDTH, y + FRAME_HEIGHT);
canvas.drawBitmap(mAnimation, x - (mCurretFrame * FRAME_WIDTH) , y, mPaint);
//jmt: restore clip to previous state

Needless to say on more complex games this would soon become an issue. Fast forward to today where I knew there had to be a better method. So I started reading the documentation and suprise suprise (well it wasn't really a surprise) I found a better way of handling clipping. Let me introduce you to Region.OP, this marvel allows me to modify the clip in the same manner as J2ME and thus save a lot of work. The previous code snippet now looks like this

public void onDraw (Canvas canvas) {
//jmt: clear the screen
canvas.clipRect(0, 0, mCanvasWidth, mCanvasHeight, Region.Op.REPLACE);
canvas.drawRect(0, 0, mCanvasWidth, mCanvasHeight, mPaint);

canvas.clipRect(x, y, x + FRAME_WIDTH, y + FRAME_HEIGHT, Region.Op.REPLACE);
canvas.drawBitmap(mAnimation, x - (mCurretFrame * FRAME_WIDTH) , y, mPaint);

Now all my animations are displayed correctly and I have less code.

Monday, October 27, 2008

Market Bug

I am sitting here in frustration. I have a new build of "Amazed" to upload however the Market backend gives the following warning "Upgrading this application will cause its ratings and comments in Android Market to disappear temporarily. We are working on this issue and previous comments and ratings should reappear soon." I really don't want all my comments and download numbers to disappear. Looks like I will just have to wait until the Market is fixed.

Changes from v2.0.1 -> v2.0.2
  • I fixed the level 2 crash bug, previously if you went straight down the screen the application would crash.
  • The screen now stays on, I had set my screen timeout to 10minutes so I never experienced the pain of the screen going off half way through a level, oops.
  • Another new feature is random vibrations, provides quite the challenge when you are navigating through small pathways.
  • I played around with the speed characteristics like people suggested but the game jut doesn't feel the same. Since the screen is so small it became very difficult to make the marble's acceleration and its current speed work well together. I will look into it again another time.

Run, Androidsss are coming........

Have you heard about the mini Android? Apparently these critters have been spotted running around various locations trying to steal G1's, be on the look out!

As if mini-android's weren't enough, check out this giant version standing guard outside a Google building. This green monster stands almost 2 stories tall watching over his faithful servants. The phantom guardian appeared one day last week without any warning.

Sunday, October 26, 2008

48hrs & 10,000 downloads later

wow, G1 users love to download. My first app has been up less than two days and it already hit 10k in downloads.

Average rating is not too bad at 3.5/5. Considering this is a simple demo to show off the accelerometer feature most people have been pretty understanding. I will be working on some updates today and plan to release v2.1.0 on Wednesday.

Saturday, October 25, 2008

Amazed: feedback

Firstly, thank you for all the feedback most of which has been positive. I know the graphics are simple and people like to look at "nice" things but I write code for a living. My graphical ability ends with drawing stick figures, I'm sure a 3yr old with a crayon could do a better job.

Don't forget you can use the "Send email to developer" link to provide feedback. I have read everything sent thus far and will be releasing an update next week.

I apologize to the people who found the crash bug on level 2. This was the first item I fixed, nice find!

First Day

Welcome to my first blog post, ever! Yes I'm sure that's hard to believe in today's computer age but its true. You have most likely been directed here through my open source game "Amazed", available on Android Market.

I initially started out writing a simple tester app for the Accelerometer. After realizing how much fun it was, Amazed was born later that afternoon. Since then I have cleaned up the code and open sourced the game via the apps-for-android project.

I hope to have plenty of interesting information (or random, you can decided for yourself) to post about but I would like to keep the first post short and sweet.......