Hahahahaha I actually thought about this in the beginning, seeing as it is how it is done in one of my Java books that I own and occasionally use as a reference. I guess I just really wanted to see if I could have used a separate file as it seems like my game class will be huge with the controller included inside it. Also having made the change I feel like the code really IS much neater and easier to understand with the usage of the entity class of course.
On a side note: I really hate going back to the move function but to be totally honest I really need clarity. I was playing around with it and I just want to know if you guys can tell me why it isn’t working the way I want it to. Easy example is I want the to travel 100 pixels in 4 seconds. This is the current way that its being done, and odviously the wrong way. It is really making me angry as to why I can not get such a simple concept through my head.
double oldTime = 0;
private void move(int deltaTime) {
double deltaSeconds = deltaTime / 1000.0; // seconds since last update
if (up)
acceleration = (100/4) * deltaSeconds;
if (down)
acceleration = (100/4) * deltaSeconds;
if (right)
carAngle += rotationStep * (vx/topspeed);
if (left)
carAngle -= rotationStep * (vy/topspeed);
vx = Math.min((vx + acceleration) * ( 1 - friction),6);
vx = Math.abs(vx) < 0.09? 0 : vx;
vy = Math.min((vy + acceleration) * ( 1 - friction),6);
vy = Math.abs(vy) < 0.09? 0 : vy;
double ax = Math.sin(Math.toRadians(carAngle));
double ay = -Math.cos(Math.toRadians(carAngle));
x += ax * vx;
y += ay * vy;
}
To my knowledge acceleration = deltavelocity / deltatime. So (100/4) * deltaTime should be the correct formula.