function mmain(){
tmr += 1;
di = 0;
ud = 0;
for(i=0; i
board_x[i] = 0;
board_ud[i] = 0;
}
for(i=0; i
di += curve[parseInt(car_y[0]+i)%CMAX];
ud += updown[parseInt(car_y[0]+i)%CMAX];
board_x[i] = 400 -BOARD_W[i]*car_x[0]/800 + di/2;
board_ud[i] = ud/30;
}
element = document.getElementById("idselect");
sec_time = element.value;
horizon = 400 + parseInt(ud/3);
sy = horizon;
vertical = vertical - parseInt(car_spd[0]*di/8000);
if(vertical < 0) vertical += 800;
if(vertical >= 800) vertical -= 800;
ctx.fillStyle = "rgb(0, 56, 255)";
ctx.fillRect(0, 0, WIDTH, HEIGHT);
ctx.drawImage(img_bg, vertical-800, horizon-400);
ctx.drawImage(img_bg, vertical, horizon-400);
ctx.drawImage(img_sea, board_x[BOARD-1]-780, sy);
msg_draw();
msg_time(s);
// var start = new Date();
//(描画処理)
for (i=BOARD-1; i >0; i--){
ux = board_x[i];
uy = sy - BOARD_UD[i]*board_ud[i];
uw = BOARD_W[i];
sy = sy + BOARD_H[i]*(600-horizon)/200;
bx = board_x[i-1];
by = sy - BOARD_UD[i-1]*board_ud[i-1];
bw = BOARD_W[i-1];
wkcolor = "rgb( 160, 160, 160)";
if(parseInt(car_y[0]+i)%CMAX === PLCAR_Y + 10){
wkcolor = "rgb(192, 0, 0)";
}
ctx.beginPath();
ctx.moveTo(ux,uy);
ctx.lineTo(ux+uw,uy);
ctx.lineTo(bx+bw,by);
ctx.lineTo(bx,by);
//全て座標を指定
ctx.closePath();
ctx.fillStyle = wkcolor;
ctx.fill();
if(parseInt(car_y[0] +i)%10 <= 4){
ctx.beginPath();
ctx.moveTo(ux,uy);
ctx.lineTo(ux+uw*0.02,uy);
ctx.lineTo(bx+bw*0.02,by);
ctx.lineTo(bx,by);
//全て座標を指定
ctx.closePath();
ctx.fillStyle = YELLOW;
ctx.fill();
ctx.beginPath();
ctx.moveTo(ux+uw*0.98,uy);
ctx.lineTo(ux+uw,uy);
ctx.lineTo(bx+bw,by);
ctx.lineTo(bx+bw*0.98,by);
//全て座標を指定
ctx.closePath();
ctx.fillStyle = YELLOW;
ctx.fill();
}
if(parseInt(car_y[0] +i)%20 <= 10){
ctx.beginPath();
ctx.moveTo(ux+uw*0.24,uy);
ctx.lineTo(ux+uw*0.26,uy);
ctx.lineTo(bx+bw*0.26,by);
ctx.lineTo(bx+bw*0.24,by);
//全て座標を指定
ctx.closePath();
ctx.fillStyle = WHITE;
ctx.fill();
ctx.beginPath();
ctx.moveTo(ux+uw*0.49,uy);
ctx.lineTo(ux+uw*0.51,uy);
ctx.lineTo(bx+bw*0.51,by);
ctx.lineTo(bx+bw*0.49,by);
//全て座標を指定
ctx.closePath();
ctx.fillStyle = WHITE;
ctx.fill();
ctx.beginPath();
ctx.moveTo(ux+uw*0.74,uy);
ctx.lineTo(ux+uw*0.76,uy);
ctx.lineTo(bx+bw*0.76,by);
ctx.lineTo(bx+bw*0.74,by);
//全て座標を指定
ctx.closePath();
ctx.fillStyle = WHITE;
ctx.fill();
}
scale = 1.5*BOARD_W[i]/BOARD_W[0];
obj_l = object_left[parseInt(car_y[0]+i)%CMAX];
if(obj_l === 2) {
draw_obj(img_obj[obj_l], ux-uw*0.05, uy, scale);
}
if(obj_l === 3) {
draw_obj(img_obj[obj_l], ux-uw*0.5, uy, scale);
}
if(obj_l === 9) {
ctx.drawImage(img_sea, ux-uw*0.5-780, uy);
}
obj_r = object_right[parseInt(car_y[0]+i)%CMAX];
if(obj_r === 1) {
draw_obj(img_obj[obj_r], ux+uw*1.3, uy, scale);
}
for(c=1; c
if(parseInt(car_y[c])%CMAX === parseInt(car_y[0]+i)%CMAX){
lr = parseInt(4*(car_x[0]-car_x[c])/800);
if(lr < -3) lr = -3;
if(lr > 3) lr = 3;
draw_obj(img_car[(c%3)*7+3+lr], ux+car_x[c]*BOARD_W[i]/800, uy, 0.05+BOARD_W[i]/BOARD_W[0]);
}
}
if(i === PLCAR_Y){
draw_shadow(ux+car_x[0]*BOARD_W[i]/800, uy, 200*BOARD_W[i]/BOARD_W[0]);
// if(sw_ren === 1){
// if(cnt_draw
// draw_obj(img_sv , svx, svy, 1);
// cnt_draw += 1;
// } else {
// cnt_draw = 0;
// sw_ren = 0;
// }
// }
draw_obj(img_car[3+car_lr[0]+mycar*7], ux+car_x[0]*BOARD_W[i]/800, uy, 0.05+BOARD_W[i]/BOARD_W[0]);
sv_carx = ux+car_x[0]*BOARD_W[i]/800;
sv_cary = uy;
if(sw_ren === 1){
if(cnt_draw
draw_obj(img_sv , sv_carx, sv_cary, 2);
cnt_draw += 1;
} else {
cnt_draw = 0;
sw_ren = 0;
}
}
}
}
wtext = "" + parseInt(car_spd[0]) + "km/h";
draw_text(wtext, 630, 40, "red", fnt_m, moj_m);
draw_text("lap " + laps + "/" + LAPS, 100, 40, WHITE, fnt_m, moj_m);
draw_text("time " + time_str(rec), 100, 80, GREEN, fnt_s, moj_s);
for(i = 0; i
draw_text(laptime[i], 80, 130+40*i, YELLOW, fnt_s, moj_s);
}
// drive_car(keyw, keyw2);
// keyw = 0;
// keyw2 = 0;
// element = document.getElementById("idresult2");
// element.innerHTML = " tmr=" + tmr + " idx=" + idx;
if(idx === 0){
ctx.drawImage(img_title, 120, 120);
draw_text("[A] Start game",300, 320, WHITE, fnt_m, moj_m);
draw_text("[S] Select your car",300, 400, WHITE, fnt_m, moj_m);
move_car(0)
if(keyw2 != 0){
init_car()
idx = 1;
tmr = 0;
laps = 0;
rec = 0;
recbk = 0;
for(i=0; i
laptime[i] = "0'00.00";
}
}
if(keyw3 === 1){
idx = 4;
keyw3 = 0;
}
}
if(idx === 1){
n = 3 - parseInt(tmr/60);
draw_text("" + n,400, 240, YELLOW, fnt_l, moj_l);
if(tmr >= 179){
idx = 2;
tmr = 0;
}
}
if(idx === 2){
if(tmr
draw_text("Go!", 400, 240, RAD, fnt_l, moj_l);
if(wstartsw === 0){
var wstart = new Date();
wstarts = wstart.getTime();
wstartsw = 1;
}
}
rec = rec + 1/60;
drive_car(keyw, keyw2);
move_car(1);
}
if(idx === 3){
if(tmr === 1){
z = 1;
}
if(tmr === 30){
z = 1;
}
draw_text("GOAL!", 400, 240, RAD, fnt_l, moj_l);
car_spd[0] = car_spd[0]*0.96;
car_y[0] = car_y[0] + car_spd[0]/100;
if(wstartsw === 1){
var wend = new Date();
wstarte = wend.getTime();
wstartsw = 0;
}
ms = wstarte - wstarts;
s = ms / 1000;
msg_time(s);
move_car(1);
if(tmr > 60*8){
idx = 0;
}
}
if(idx === 4){
move_car(0);
draw_text("Select your car", 400, 160, WHITE, fnt_m, moj_m);
for(i=0; i
x = 160+240*i;
y = 300;
col = BLACK;
if(i+wn === mycar){
col = "rgb(0, 128, 255)";
}
ctx.fillStyle = col;
ctx.fillRect(x-100, y-80, 200, 160);
draw_text("[" + (i+1) + "]", x-40, y-50, WHITE, fnt_m, moj_m);
ctx.drawImage(img_car[3+(i+wn)*7], x-100, y-20);
}
if(3+wn
draw_text("→", 750, 350, GREEN, fnt_m, moj_m);
}
if(3+wn > 3){
draw_text("←", 5, 350, GREEN, fnt_m, moj_m);
}
draw_text("[Enter] OK!", 300, 430, GREEN, fnt_m, moj_m);
if(keyw4 === 1) mycar = 0+wn;
if(keyw4 === 2) mycar = 1+wn;
if(keyw4 === 3) mycar = 2+wn;
if(keyw3 === 2) { idx = 0; keyw3 = 0;}
}
sframe += 1;
if(sframe === 60) {
// var stop = new Date();
// ms = stop.getTime() - start.getTime();
// s = ms / 1000;
sframe = 0
}
gameover1 += 1
timer1 = setTimeout("mmain()", sec_time);
}
// ゲームオーバーの表示
function msg_draw(){
ctx.font = "20px 'MS Pゴシック'";
ctx.fillStyle = "white";
// ctx.fillText("カーソルキーの上、下、右、左を押してください",200,100);
ctx.fillText("マウスで車体位置を中心に上下左右に動かしてください",200,100);
}
function msg_time(s){
ctx.font = "20px 'MS Pゴシック'";
ctx.fillStyle = "white";
// ctx.fillText("カーソルキーの上、下、右、左を押してください",200,100);
time_s = " time=" + s;
ctx.fillText(time_s, 600, 130);
}
function draw_text(text, x, y, col, fnt, moj){
ctx.font = fnt;
wx = x - text.length*moj/2;
wy = y - moj/2;
ctx.fillStyle = "black";
ctx.fillText(text, x + 2, y + 2);
ctx.fillStyle = col;
ctx.fillText(text, x, y);
}