Heya Guys!
Well im trying to make a little model of Ballistics to later implement in my game… I have something like this :
package balistica;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
/**
*
*/
class View implements ApplicationListener, InputProcessor {
private SpriteBatch batch;
private Sprite ball;
private Sprite box;
private int boxPosX, boxPosY;
public double ballPosX, ballPosY;
private double angle;
private double frameTime;
@Override
public void create() {
Gdx.input.setInputProcessor(this);
ball = new Sprite(new Texture(Gdx.files.internal("ball.png")));
box = new Sprite(new Texture(Gdx.files.internal("cTest.png")));
batch = new SpriteBatch();
boxPosX = 10;
boxPosY = 10;
ballPosX = 0;
ballPosY = 0;
frameTime = -1;
}
@Override
public void render() {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
if (frameTime >= 0) {
//getSX(double xo, double yo, double vo, double gravity, double angle, double time)
ballPosX = Update.getSX(10,10,50,1, angle, frameTime);
//getSY(double yo, double vo, double gravity, double angle, double time)
ballPosY = Update.getSY(10,50, 1, angle, frameTime);
System.out.println("x;y" + ballPosX + ";" + ballPosY);
frameTime = frameTime + 0.1;
}
batch.begin();
batch.draw(box, boxPosX, boxPosY);
batch.draw(ball, (int) ballPosX, (int) ballPosY);
batch.end();
}
@Override
public void resize(int width, int height) {
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void dispose() {
}
@Override
public boolean keyDown(int keycode) {
return true;
}
@Override
public boolean keyUp(int keycode) {
return true;
}
@Override
public boolean keyTyped(char character) {
return true;
}
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
angle = Update.getAngle(boxPosX, screenX, boxPosY, screenY);
System.out.println("Box = (" + boxPosX + ";" + boxPosY + ")");
System.out.println("Screen = (" + screenX + ";" + screenY + ")");
System.out.println("Angle" + angle);
frameTime = 0;
return true;
}
@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
return true;
}
@Override
public boolean touchDragged(int screenX, int screenY, int pointer) {
return true;
}
@Override
public boolean mouseMoved(int screenX, int screenY) {
return true;
}
@Override
public boolean scrolled(int amount) {
return true;
}
}
package balistica;
public class Update {
public static double getAngle(double xi,double xf, double yi, double yf) {
double atan = Math.atan((yi-yf)/(xi-xf));
return atan;
}
public static double getSX(double xo, double yo, double vo, double gravity, double angle, double time) {
double dx = (xo + vo) * Math.cos(angle) * time;
return dx;
}
public static double getSY(double yo, double vo, double gravity, double angle, double time) {
double dy = (yo + vo) * (Math.sin(angle)) * (time - ((gravity / 2)) * (time * time));
return dy;
}
}
Im not sure its working… Would anyone have a look preety please?