Я должен сделать танк, который стоит на месте, но двигает башню и стреляет ракетами.
Поскольку это мое первое приложение для Android, и я не занимался разработкой игр, я столкнулся с несколькими проблемами...
Теперь я сделал танк и движущуюся башню после того, как прочитал руководство по Android для примера кода LunarLander. Итак, этот код основан на коде LunarLander.
Но у меня проблемы с запуском ракеты, когда нажата кнопка ПРОБЕЛ.
private void doDraw(Canvas canvas) {
canvas.drawBitmap(backgroundImage, 0, 0, null);
// draws the tank
canvas.drawBitmap(tank, x_tank, y_tank, new Paint());
// draws and rotates the tank turret
canvas.rotate((float) mHeading, (float) x_turret + mTurretWidth, y_turret);
canvas.drawBitmap(turret, x_turret, y_turret, new Paint());
// draws the grenade that is a regular circle from ShapeDrawable class
bullet.setBounds(x_bullet, y_bullet, x_bullet + width, y_bullet + height);
bullet.draw(canvas);
}
ОБНОВИТЬ метод ИГРЫ
private void updateGame() throws InterruptedException {
long now = System.currentTimeMillis();
if (mLastTime > now)
return;
double elapsed = (now - mLastTime) / 1000.0;
mLastTime = now;
// dUP and dDown, rotates the turret from 0 to 75 degrees.
if (dUp)
mHeading += 1 * (PHYS_SLEW_SEC * elapsed);
if (mHeading >= 75) mHeading = 75;
if (dDown)
mHeading += (-1) * (PHYS_SLEW_SEC * elapsed);
if (mHeading < 0) mHeading = 0;
if (dSpace){
// missile Logic, a straight trajectorie for now
x_bullet -= 1;
y_bullet -= 1;
}
}
метод run, запускающий игру...
public void run() {
while (mRun) {
Canvas c = null;
try {
c = mSurfaceHolder.lockCanvas(null);
synchronized (mSurfaceHolder) {
if (mMode == STATE_RUNNING)
updateGame();
doDraw(c);
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
// do this in a finally so that if an exception is thrown
// during the above, we don't leave the Surface in an
// inconsistent state
if (c != null) {
mSurfaceHolder.unlockCanvasAndPost(c);
}
}
}
}
Итак, вопрос: как сделать так, чтобы пуля стреляла одним нажатием клавиши ПРОБЕЛ от турели до конца экрана?
Не могли бы вы помочь мне здесь, я, кажется, здесь в темноте...
Спасибо,
Никса
(dSpace)
не работает? Или пули не видно? Или траектория неверная? - person Beta   schedule 19.01.2011x_bullet
иy_bullet
? И какие значения эти переменные имеют изначально, и какие значения они должны иметь, когда пуля находится у края экрана? - person Beta   schedule 19.01.2011