Thanks alot for the help, but unfortunately i did not help me.
"double vx = 0, vy = 0;
there's your problem. those v's stand for "velocity" I imagine, change those variables to something other than 0 and it should work, because:
Code:
// Förflyttar bilen
bilx = bilx + vx;
bily = bily + vy;
won't work unless vx and/or vy is not 0"
Yes, v stands for veliocity, and vx for the veliocity in the x-axis. vy stands for the veliocity in the y-axis. But I may have to clarify a little:
public void keyPressed(KeyEvent e) {
int key = e.getKeyChar();
if (key == KeyEvent.VK_LEFT) left = true;
if (key == KeyEvent.VK_RIGHT) right = true;
if (key == KeyEvent.VK_UP) up = true;
if (key == KeyEvent.VK_DOWN) down = true;
}
public void keyReleased(KeyEvent e) {
int key = e.getKeyChar();
if (key == KeyEvent.VK_LEFT) left = false;
if (key == KeyEvent.VK_RIGHT) right = false;
if (key == KeyEvent.VK_UP) up = false;
if (key == KeyEvent.VK_DOWN) down = false;
}
The thing is that I have defined keyReleased and keyPressed myself, to make them set boolean values to true/false depending on if any of the arrow-keys is pressed or released.
public void run()
{
while( true) {
// Ändrar hastigheten beroende på användarens knapptryckningar
if( left) vx = vx - 0.05;
if( right) vx = vx + 0.05;
// Kollar så att bilen stannar när den träffar väggen
if( bilx + RADIE > appletSize.width || bilx - RADIE < 0) vx = 0;
if( bily + RADIE > appletSize.height || bily - RADIE < 0) vy = 0;
// Förflyttar bilen
bilx = bilx + vx;
bily = bily + vy;
repaint();
try { Thread.sleep( 10); } catch( InterruptedException ie) {}
}
}
Then these boolean values would be used to make the dot's veliocity to increase:
if( left) vx = vx - 0.05;
if( right) vx = vx + 0.05;
(Note that I haven't written the code for the up and down keys yet)
Finally the dot is moved and the picture repainted:
bilx = bilx + vx;
bily = bily + vy;
repaint();
My problem is that the dot wont move event though I press the arrow-keys like a maniac. Any help is appreciated.
\\Gewran
