Ich mache ein Projekt über ein Vogel-Tötungsspiel. Alles funktioniert gut, aber ich möchte, dass mein Vogel den Bildschirm in 35 Sekunden für jeden gegebenen mobilen Bildschirm überquert. Und nach jeder 20 Sekunden seine Zeit auf 31 reduziert. Was wird die mathematische Formel (für die Geschwindigkeit) sein, um den Bildschirm in 35 Sekunden zu überqueren? Zurzeit aktualisiere ich den X-Achsen-Wert in update Methode und erstelle Rechteck für die Vogel-Sprites.Rechenzeit der Simulation in Java
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import java.util.Random;
public class Birds extends GameObject implements View.OnTouchListener{
private Bitmap spritesheet;
private Rect rect;
public boolean firstTym = true;
private Animation animation = new Animation();
private String tag = "";
private int y,touchX,touchY;
public int x=0;
private long startTime;
public Birds(String tag)
{
this.tag = tag;
spritesheet = BitmapFactory.decodeResource(Constants.res, R.drawable.bird_sprites);
dy = 0;
if(Constants.Width > 1300) {
width = 120;
height = 140;
}
else {
width = 80;
height = 72;
}
Bitmap[] image = new Bitmap[5];
for (int i = 0; i < image.length; i++)
{
image[i] = Bitmap.createBitmap(spritesheet, i*width, 0, width, height);
}
animation.setFrames(image);
animation.setDelay(10);
startTime = System.nanoTime();
}
public void update()
{
if(!firstTym) {
// here i am updating speed of bird in x-axis.
//i want bird to cross the screen in 35 seconds
x += Constants.speed;
Log.e("speed = ","" + Constants.speed);
}
else
{
Random r = new Random();
r.nextInt(Constants.Width);
}
if(x > GamePanel.WIDTH){
Constants.missed ++;
x = 0;
}
if(y > GamePanel.HEIGHT)
{
x = 0;
}
}
public void draw(Canvas canvas) {
Random r = new Random();
if (x == 0 || firstTym) {
y = r.nextInt(GamePanel.HEIGHT - 150);
Constants.RAND = r.nextInt(1);
firstTym = false;
}
animation.update();
y += Constants.RAND;
rect = new Rect(x, y, x + 80, 72 + y);
setRect(rect);
setTag(tag);
canvas.drawBitmap(animation.getImage(), null, rect, null);
if (x < 0) {
canvas.drawBitmap(animation.getImage(), null, rect, null);
}
}
public int getX()
{
return x;
}
public int getY()
{
return y;
}
@Override
public boolean onTouch(View v, MotionEvent event) {
touchX = (int)event.getX();
touchY = (int)event.getY();
return true;
}
}
Was wird die mathematische Formel sein, um die Übergangszeit zu berechnen? Diese Aussage ist ein wenig mehrdeutig. Weil du sagst, dass du deinen Vogel beschleunigen willst, um den Bildschirm in 35 Sekunden zu überqueren, für welche Zeit willst du dann rechnen? –
Ich denke, Sie möchten die Geschwindigkeit Ihres Vogels berechnen. Mit welcher Geschwindigkeit sollte es sich in 35 Sekunden bewegen, um einen beliebigen Bildschirm zu überqueren –