Model your world. Try this:
public class GameObject {
public float x,y;
public Bitmap bmp;
}
public class Tank extends GameObject {
// do tank stuff
}
public class Bullet extends GameObject {
// do bullet stuff
}
See where I'm going there? Then in your main game class you just keep
a list of the gameobjects, run through and update them. Check out
this article I wrote when I was doing light racer 3d -
http://www.rbgrn.net/content/215-light-racer-3d-development-journal
Scroll down on that page to the end where all of the book pages are
linked. Read through the first few. I show how games like that are
designed on the inside so you can use that information to do yours.
On Jan 16, 8:37 am, Niksa Lovrinic <[email protected]> wrote:
> Hello everybody,
>
> I've been playing with the LunarLander example and tried to make my own
> thing out of it...
>
> On the right bottom screen, I've got a tank that is not moving and his
> turret that's moving up and down. It's supposed to shoot missiles at
> different angles.
>
> I've got a tank, turret and a bullet and they are a Bitmap image.
>
> private Bitmap tank;
> private Bitmap turret;
> private Bitmap bullet;
>
> Turret only rotates from angle 0 to angle 75, and I did that with the
> update...
>
> I managed to get the turret moving but now I'm finding it hard to shoot
> missiles.
>
> *doDraw method*
> *
> *
> private void doDraw(Canvas canvas) {
>
> canvas.drawBitmap(backgroundImage, 0, 0, null);
>
> canvas.drawBitmap(tank, x_tank, y_tank, new Paint());
>
> //Rotating the turret
> canvas.rotate((float) mHeading, (float) x_turret + mTurretWidth,
> y_turret);
>
> canvas.drawBitmap(turret, x_turret, y_turret, new Paint());
>
> ??? what should I write here for the bullet to be seen shooting out of that
> turret
>
> }
>
> *Update method*
> *
> *
> private void updateGame() {
>
> long now = System.currentTimeMillis();
>
> if (mLastTime > now)
> return;
> double elapsed = (now - mLastTime) / 1000.0;
>
> if (dUp) // UP key
> mHeading += 1 * (PHYS_SLEW_SEC * elapsed);
>
> if (mHeading >= 75) mHeading = 75;
>
> if (dDown) // DOWN key
> mHeading += (-1) * (PHYS_SLEW_SEC * elapsed);
> if (mHeading < 0) mHeading = 0;
>
> i
> f (dSpace){
>
> // Fire bullet SPACE key
> ??? what should I write here for the bullet to be
> seen shooting out of that turret
> ??? When is the method doDraw being called??
>
> }
>
> m
> LastTime = now;
>
> }
>
> Thank you so much guys,
>
> Nick
>
> *
> *
> *
> *
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en