| onClipEvent (load) {
//değişkenleri belirlememiz lazım
x = 0;
y = 0;
hız = 0;
}
onClipEvent (enterFrame) {
// aracın ileri gitmesi ileri tuşunu çalıştırıyoz
if (Key.isDown(Key.UP)) {
hız += 1;
}
// aracın geri gitmesi geri tuşunu çalıştırıyoz
if (Key.isDown(Key.DOWN)) {
hız -= 1;
}
// hız 20 olduğunda aracımız yavaşlıyo
if (Math.abs(hız)>20) {
hız *= .7;
}
// aracın yön değiştirmesi sağ ve sol tuşlarını çalıştırıyoz
if (Key.isDown(Key.LEFT)) {
_rotation -= 15;
}
if (Key.isDown(Key.RIGHT)) {
_rotation += 15;
}
// işte asıl mesele burda yukarda hızı ayarladık şimdi de hız değişkenine göre aracın yerini
//ayarlıyoz
hız *= .98;
x = Math.sin(_rotation*(Math.PI/180))*hız;
y = Math.cos(_rotation*(Math.PI/180))*hız*-1;
if (!_root.bariyer.hitTest(_x+x, _y+y, true)) {
_x += x;
_y += y;
} else {
hız *= -.6;
}
} |
|
 |
|