Showing posts with label xml. Show all posts
Showing posts with label xml. Show all posts

Thursday, 10 March 2011

miTanks, Part 11

FINALLY!!! After 5 days searching the net and testing heaps of different custom views, I've drawn a circle. That's right. 5 days of work and all I've done is draw a circle. This must sound rediculous but this is the biggest break though. Look! Here it is:



It's amazing. Now I simply had to copy over the view handling bits of code to miTanks and BAM!



We get an ugly, badly drawn game of tanks. It's nice. So now I'm working on tweeking the look so that it, well, works. For those of you using the code snippets I'm putting on here, the main bits are:

In the main class:

public class miTanks extends Activity {

private GameView gv;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GameView gv = new GameView(this);
setContentView(gv);
}

In the GameView:

public class GameView extends View{

private final Paint PAINT;
private static final Bitmap[] TANK_IMAGES = new Bitmap[8];
private static final int[] TANK_COLOURS = new int[8];
private final GradientDrawable BACKGROUND_GRADIENT;
private static GameView INSTANCE;

/**
 * Initialises the GameView.
 * @param context
 */
public GameView(Context context) {
super(context);
setFocusable(true);
setFocusableInTouchMode(true);
...
/**
 * Draws the game onto the canvas.
 */
protected void onDraw(Canvas canvas){
drawBackground(canvas);
drawGround(canvas);
drawTanks(canvas);
}

In the main.xml:

<?xml version="1.0" encoding="utf-8" ?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent">
 <com.miTanks.game.GameView
  android:id="@+id/View01"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:maxHeight="40dip" />
 </LinearLayout>

Friday, 31 December 2010

miTanks, Part 2

Something I've missed:
Android apps are written in Java plus some xml for view layouts etc.

I have started drawing up a rough class diagram for the game and started to think about how to implement destructible terrain. As we want a clean fall animation for the ground when a piece is broken below, I am currently thinking about having the entire game screen as a 3d boolean array. Animations with this will be incredably easy. Hopefully this won't be too much to process every turn.

Some minor code has been written to help visualise the working of the tank class. As this is early on in the process it is likely to be rearranged quite regularly, due to the nature of eXtreme Programming.

I will try to have the game run on both the Android and a computer. This will help for initial game development as testing on the Android Virtual Device is time consuming. Also when the game is complete I will release a run-able jar file so everyone on here can play the game.

Most likely won't be doing small releases as we go, due to the size of the app. When it is actually playable it will almost be finished. Just bug fixes, extra weapons and smoothing out code after the app works.

Here are some initial concept shots by Foo.
Initial Concept Screenshot
Second Concept Screenshot


Sky

Tree

Concept Tank 1