It's amazing. Now I simply had to copy over the view handling bits of code to miTanks and BAM!
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>
Hey that looks like Combat on the atari 2600
ReplyDeleteInteresting stuff, abit like minesweeper too
ReplyDeleteThis is neat, I wish I could do it.
ReplyDelete