Jul 16

Unter den neuen Widgets die ich für die Vodafone Widget Runtime programmiert habe ist u.a. “Galaxy Lander”. Ein Spiel, das wahrscheinlich viele schon auf programmierbaren Taschenrechnern gespielt haben. Mehr Funktionaliät als damals gibt es auch nicht, nur etwas schönere Grafiken :-)

In 3 Levels kann der Spieler Versuchen seine Landefähre auf dem Mond, dem Mars oder dem Jupiter zu landen. Natürlich ist der Jupiter das schwerste Level, aber es ist möglich heile anzukommen! Mit der “Hoch”-Taste des Handys kann der Spieler die Raketen zünden und damit den Fall abbremsen, aber Achtung: Man hat keinen unendlichen Kerosinvorrat!
Viel Spaß macht auch der umgekehrte Spielmodus: “Wer macht den tiefsten Krater?”. Probiert’s mal aus!

Also viel Spaß beim Spielen, hier mal der Link auf die deutsche Version:
Galaxy Lander downloaden

Jun 24

This is part 2 of my Android mobile game series. I want to develop a game just like my Widget game for the Vodafone Widget Runtime: Space Janitor.

So, in the last part we created some parts of the UI the user sees when he starts the game.

Today we want to create a small part of the real “Game View”!
First, lets change the standard layout of the Android App. The layout file can be found in res/layout/main.xml.
The standard is a simple LinearLayout with a TextView, that currently just displays “Hello…” when you start the game.
Let’s remove this part and change it to:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
 
    <GameView
    	android:id="@+id/game"
    	android:layout_width="fill_parent"
    	android:layout_height="fill_parent" />
 
    <RelativeLayout
	android:layout_width="fill_parent"
	android:layout_height="fill_parent">
	<TextView
		android:id="@+id/text"
		android:text="@string/space_janitor_info_text"
		android:visibility="visible"
		android:layout_height="wrap_content"
		android:layout_width="wrap_content"
		android:layout_centerInParent="true"
		android:gravity="center_horizontal"
		android:textColor="#88ffffff"
		android:textSize="24sp" />
    </RelativeLayout>
</FrameLayout>

First, we define a Game View that we can use later on to hold the game graphics. Second we defined a RelativeLayout that holds a TextView, we need this to display some infos later on.

Now let’s extend the code to use this views.

Create a new class called GameView in your App. The GameView extends SurfaceView and has to implement the SufaceHolder.Callback interface. Add the yet unimplemented methods and a constructor to fulfill the interface’s requirements.

public class GameView extends SurfaceView implements SurfaceHolder.Callback {
 
	public GameView(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
	}
 
	public void surfaceChanged(SurfaceHolder holder, int format, int width,
			int height) {
		// TODO Auto-generated method stub
 
	}
 
	public void surfaceCreated(SurfaceHolder holder) {
		// TODO Auto-generated method stub
 
	}
 
	public void surfaceDestroyed(SurfaceHolder holder) {
		// TODO Auto-generated method stub
 
	}
}

The SurfaceView is designated to hold the game graphics. Via the SurfaceHolder.Callback we are informed about dimension changes, i.e. when the user switches to landscape mode.

In the Main View we now have to code a connection to the Game View, we’ll do this via an instance variable of GameView. Add a variable of the type “GameView” to your Activity.

public class SpaceJanitor extends Activity {
	private static final int MENU_START = 1;
	private GameView myGameView;
        ...
}

In our “onCreate”-method we have to initialize this variable and we would like to give the GameView the ability to display some info in the TextView we recently defined in our layout file, like “Game Over”, etc. So:

public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
 
   requestWindowFeature(Window.FEATURE_NO_TITLE);
   setContentView(R.layout.main);
   myGameView = (GameView) findViewById(R.id.game);
   myGameView.setTextView = (TextView) findViewById(R.id.text);
}

This implies that we have to add a method “setTextView” in the GameView class to save a reference on this TextView locally.

public void setTextView(TextView findViewById) {
		// TODO Auto-generated method stub	
	}

In the next part we will add a thread to handle graphic updates, user actions, etc. etc.

Jun 01

Game development tutorial on Android – Part 1

First I have to say that I am using Eclipse and the Android plugin to program, because it really minifies the work needed. If your using another IDE you have to change some of the steps according to your IDE’s workflow, but the code stays the same.

I decided that my game should have a welcome screen and an options menu to start the game (or later when playing to pause or stop the game). That is easily done with Android.
First lets create a new project in Android, name it what you like, I chose “Space Janitor” (I assume that you already now how to create new Android project, otherwise refer to one of the many tutorials).

Weiterlesen »

Jun 01

I am currently learning more on Android development and for me the best way to learn something new is to try it out by myself. It’s the same when I learn new ways of programming: reading books and tutorials is fine, but when I try to build my own apps I learn even more.

So I decided to write a simple game for the Android platform, not that there aren’t already enough games in the Android Market, more because in the last weeks I mostly concentrated on developing games for the Vodafone mobile widget runtime. I made a game called “Space Janitor”, which I now want to port to the Android platform. I would like to extend the game at some points, i.e. making use of the device accelerometer sensors to move the spaceship to the left or to the right, or vibrating the mobile when being hit by an asteroid. That would be real fun.

Another good way to learn is to try to explain the things one learned to others. That was a great way to learn during my university time, because the professors always wanted to have something explained :-) So if one already explained the learned things to others, it was no problem to explain it again to the professor. I now decided to keep track of my development by writing some blog posts about how to develop the game, thus explaing it to others. But I would also very much appreciate your comments on how to improve the quality and the speed of my code as I would call myself just a novice in Android programming. Maybe you’ve also got some more tipps for game improvement, game handling, gameplay, etc.

I will somewhat unregularly post new entries in my blog, so keep in touch.