So I want to start working on a 2D platforming game, and I won't be in physics till next year, so I found the equations in an old physics book I had to help be find the x and y positions along with their velocities. The problem is, they seem to accelerate too fast in that the rendering is too slow. It's not the programs fault, its my fault in that I don't know how to slow down the acceleration so that it looks smoother. Here is the code for the ball class that i'm using (i know the code is an absolute mess! i was just messing around trying to get the equations right.... I would NEVER write my code like this if I was working on a serious project so please don't remind me that it looks bad)
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JComponent;
public class Ball extends JComponent{
public double xpos;
double oX;
double oY;
double ypos;
double xvel;
double yvel;
long time;
double oxvel;
double oyvel;
long angle = 45;
long startTime = System.currentTimeMillis();
public Ball(int p1, int p2, long t){
xpos = p1;
oxvel = 50;
oX = p1;
ypos = p2;
time = t;
oyvel = -50;
}
public void update(){
xvel = (oxvel*Math.cos(45));
yvel = (oyvel*Math.sin(45)) + (9.8*time);
if(!(xpos + xvel + 10 > getWidth())&&!(xpos + xvel < 0))
xpos +=xvel;
if(!(ypos + yvel + 10 > getHeight())&&!(ypos + yvel <= 0))
ypos+=yvel;
time++;
}
public void paint(Graphics g){
Graphics2D g2d = (Graphics2D) g;
g2d.setColor(Color.RED);
g2d.fillOval((int)xpos, (int)ypos, 15, 15);
}
}