acceleration til min bil!
Hej Folkens!Jeg er igang med at lave et simpelt spil i flash og har lavet et script der skal få en bil til at køre ved hjælp af piletasterne.
scriptet ser således ud:
// -------- car move script
stop();
car.carHor = 0;
car.carVer = 5;
car.frame = 1;
car.speed = 1;
function myCarMove() {
car.onEnterFrame = function(){
if (Key.isDown(Key.LEFT)) {
if (car.frame >= 1 && car.frame <= 5){
car.frame += 1;
car.carHor += car.speed;
car.carVer -= car.speed;
car.gotoAndStop(car.frame);
}
else if (car.frame >= 6 && car.frame <= 10){
car.frame += 1;
car.carHor -= car.speed;
car.carVer -= car.speed;
car.gotoAndStop(car.frame);
}
else if (car.frame >= 11 && car.frame <= 15){
car.frame += 1;
car.carHor -= car.speed;
car.carVer += car.speed;
car.gotoAndStop(car.frame);
}
else if (car.frame >= 16 && car.frame < 20){
car.frame += 1;
car.carHor += car.speed;
car.carVer += car.speed;
car.gotoAndStop(car.frame);
}
else if (car.frame = 20){
car.frame = 1;
car.carHor += car.speed;
car.carVer += car.speed;
car.gotoAndStop(car.frame);
}
}
if (Key.isDown(Key.RIGHT)) {
if (car.frame >= 2 && car.frame <= 6){
car.frame -= 1;
car.carHor -= car.speed;
car.carVer += car.speed;
car.gotoAndStop(car.frame);
}
else if (car.frame >= 7 && car.frame <= 11){
car.frame -= 1;
car.carHor += car.speed;
car.carVer += car.speed;
car.gotoAndStop(car.frame);
}
else if (car.frame >= 12 && car.frame <= 16){
car.frame -= 1;
car.carHor += car.speed;
car.carVer -= car.speed;
car.gotoAndStop(car.frame);
}
else if (car.frame >= 17 && car.frame <= 20){
car.frame -= 1;
car.carHor -= car.speed;
car.carVer -= car.speed;
car.gotoAndStop(car.frame);
}
else if (car.frame = 1){
car.frame = 20;
car.carHor -= car.speed;
car.carVer -= car.speed;
car.gotoAndStop(car.frame);
}
trace("--------------------");
trace("LEFT " + car.carHor);
trace("UP " + car.carVer);
trace("FRAME " + car.frame);
}
if (Key.isDown(Key.UP)) {
car._y -= car.carVer;
car._x -= car.carHor;
}
}
}
var myListener = new Object();
myListener.onKeyDown = myCarMove;
Key.addListener( myListener );
//-------------hittest script
onEnterFrame = function(){
if (_root.car.hitTest(_root.block1) || _root.car.hitTest(_root.block2) || _root.car.hitTest(_root.block3) || _root.car.hitTest(_root.block4) || _root.car.hitTest(_root.block5) || _root.car.hitTest(_root.block6) || _root.car.hitTest(_root.block7)){
trace("hit");
car._x += car.carHor * 3;
car._y += car.carVer * 3;
_global.Behaviors.Sound.bounce.start(0,1);
}
}
______________________________________________________
______________________________________________________
Du kan se et eksempel på www.palermosurf.dk/bil/bil.html
mit problem er at jeg gerne vil have tilføjet acceleration til min bil men ikke har matematisk sans nok til at se hvordan jeg skal kringle den ind i mit script.
På forhånd tak for alt hjælp !