参考までに、良ければ本買ってください。もとはpythonです。
DATA_LR = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 2, 1, 0, 2, 4, 2, 4, 2, 0, 0, 0,-2,-2,-4,-4,-2,-1, 0, 0, 0, 0, 0, 0, 0];
DATA_UD = [0, 0, 1, 2, 3, 2, 1, 0,-2,-4,-2, 0, 0, 0, 0, 0,-1,-2,-3,-4,-3,-2,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-3, 3, 0,-6, 6, 0];
CAR = 30;
var car_x = [];
var car_y = [];
var car_lr = [];
var car_spd = [];
var PLCAR_Y = 10;
//キーが押された時の処理
function keydown(e){
k = e.keyCode;
if(k==37) keyw = 1;
if(k==38) keyw = 5;
if(k==39) keyw = 2;
if(k==40) keyw = 6;
if(k==65) keyw = 5;
if(k==90) keyw = 6;
}
function draw_shadow(x, y, siz){
ctx.globalAlpha= 0.5;
ctx.beginPath();
ctx.scale(1, 0.25);
ctx.fillStyle = "black";
ctx.arc(x, (y-siz/4)*4, siz/2, 0, Math.PI*2, false);
ctx.fill();
ctx.setTransform(1,0,0,1,0,0);
ctx.globalAlpha=1;
}
function drive_car(key){
if(key === 1){
if(car_lr[0] > -3) car_lr[0] -= 1;
car_x[0] = car_x[0] + (car_lr[0]-3) * car_spd[0]/100 -5;
} else if(key === 2){
if(car_lr[0] < -3) car_lr[0] += 1;
car_x[0] = car_x[0] + (car_lr[0]+3) * car_spd[0]/100 +5;
} else {
car_lr[0] = parseInt(car_lr[0]*0.9);
}
if(key === 5){
car_spd[0] += 3;
} else if(key === 6){
car_spd[0] -= 10;
} else {
car_spd[0] -= 0.25;
}
if(car_spd[0] < 0) car_spd[0] = 0;
if(car_spd[0] > 320) car_spd[0] = 320;
car_x[0] -= car_spd[0]*curve[parseInt(car_y[0]+ PLCAR_Y)%CMAX]/50;
if(car_x[0] < 0){
car_x[0] = 0;
car_spd[0] *= 0.9;
}
if(car_x[0] > 800){
car_x[0] = 800;
car_spd[0] *= 0.9;
}
car_y[0] = car_y[0] + car_spd[0]/100;
if(car_y[0] > CMAX-1) car_y[0] -= CMAX;
}
if(i === PLCAR_Y){
draw_shadow(ux+car_x[0]*BOARD_W[i]/800, uy, 200*BOARD_W[i]/BOARD_W[0])
draw_obj(img_car[3+car_lr[0]], ux+car_x[0]*BOARD_W[i]/800, uy, 0.05+BOARD_W[i]/BOARD_W[0]);
}
drive_car(keyw);
keyw = 0;
setTimeout("mmain()",100);