var canvas;
var ctx;
WIDTH = 800;
HEIGHT = 600;
var username = ["ipad","iphone","android"]; //端末の名前
WHITE = "rgb(255, 255, 255)";
YELLOW = "rgb(255, 224, 0)";
BLACK = "rgb( 0, 0, 0)";
RAD = "rgb(255, 0, 0)";
GREEN = "rgb( 0, 255, 0)";
var mycar = 0;
//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];
var DATA_LR = [0, 0, 0, 0, 0, 2, 4, 1,-2,-1, 0, 0,-2, 2, 0, 0, 1, 0, 2, 4, 2, 4, 2, 0, 0, 0,-2,-2,-4,-4,-2,-1, 0, 0, 0, 0, 0, 0, 0, 0];
var 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, 0];
var CLEN = DATA_LR.length;
su_lr = 0;
su_ud = 0;
var VLU0 = "MM 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40\n";
var VLU1 = "DATA_LR, 0, 0, 0, 0, 0, 2, 4, 1,-2,-1, 0, 0,-2, 2, 0, 0, 1, 0, 2, 4, 2, 4, 2, 0, 0, 0,-2,-2,-4,-4,-2,-1, 0, 0, 0, 0, 0, 0, 0, 0,DE\n";
var VLU2 = "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, 0,DE\n";
var VLU3 = "CAR,10\n";
var VLU4 = "EE\n";
BOARD = 120;
var CMAX = BOARD*CLEN;
ZAHYO_XY = [
"00,300,280,800,320,a",
"00,300,360,800,410,s",
"04,300,390,800,440,r",
"04,060,220,260,380,1",
"04,300,220,500,380,2",
"04,540,220,740,380,3",
"04,005,300,045,350,L",
"04,750,300,795,350,R",
];
ZAHYOMAX = 8;
img_bg = new Image();
img_bg.src = "bg.png";
img_sea = new Image();
img_sea.src = "image_pr/sea.png";
img_shotogo = new Image();
img_shotogo.src = "shotogo.png";
img_title = new Image();
img_title.src = "title02.png";
img_sv = new Image();
img_sv.src = "shotogo1.png";
//var audio = new Audio("sound_pr/02 無言坂.mp3");
MYCARMAX = 4;
var wn = 0;
var gameover1 = 0;
var curve = [];
var updown = [];
var object_left = [];
var object_right = [];
var BOARD_W = [];
var BOARD_H = [];
var BOARD_UD = [];
var board_x = [];
var board_ud = [];
var img_obj = [];
var img_car = [];
//var car_y = 0;
var keyw = 0;
var keyw2 = 0;
var keyw3 = 0;
var keyw4 = 0;
var keyp = 0;
var vertical = 0;
var di = 0;
var sy = 0;
var CAR = 10;
var car_x = [];
var car_y = [];
var car_lr = [];
var car_spd = [];
var PLCAR_Y = 10;
var coursecode = []; //ロボットデータテーブル
var bwr = 41,bhr = 5; //ロボットデータテーブル(サイズ、横、縦)
var idy = 0; // 連携用インデックスy
var cdatasu = 0;
var coursearea = " "; //テキストエリアからの読込用
var coursetext = []; //テキストエリアの第一次分割エリア(行)
var courseitem = []; //テキストエリアの第二次分割エリア(項目)
LAPS = 3;
laptime = [];
var sv_y = 0;
var sv_carx = 0;
var sv_cary = 0;
var sec_time = 20;
var sframe = 0;
var s = 0;
var wstarts = 0;
var wstarte = 0;
var wstartsw = 0;
var idx = 0;
var tmr = 0;
var laps = 0;
var rec = 0;
var recbk = 0;
var sw_ren = 0;
var sw_ren1 = 0;
var cnt_draw = 0;
var svx = 0;
var svy = 0;
var svsc = 1;
var fnt_s = "40px 'MS Pゴシック'";
var fnt_m = "50px 'MS Pゴシック'";
var fnt_l = "120px 'MS Pゴシック'";
var moj_s = 40;
var moj_m = 50;
var moj_l = 120;
var errflg = 0;
function init(){
canvas = document.getElementById('world');
canvas.width = WIDTH;
canvas.height = HEIGHT;
ctx = canvas.getContext('2d');
ctx.font = "48px 'MS Pゴシック'";
user = window.navigator.userAgent.toLowerCase();
for(i=0; i
if(user.indexOf(username[i]) > 0)break;
}
if(i
document.addEventListener("touchmove", touchmove);
}else{
document.addEventListener("mousemove", mousemove);
}
if(i
document.addEventListener("touchstart", touchstart);
}else{
document.addEventListener("mousedown", mousedown);
}
document.addEventListener("keydown", keydown);
document.addEventListener("keyup", keyupop);
for(i=0; i <=CMAX; i++){
curve[i] = 0;
updown[i] = 0;
object_left[i] = 0;
object_right[i] = 0;
}
for(i=0; i
laptime[i] = "0'00.00";
}
element = document.getElementById("idselect");
sec_time = element.value;
document.myFORM.myTEXT.value = VLU0 + VLU1 + VLU2 + VLU3 + VLU4;
for(i=0; i
img_obj[i] = new Image();
}
img_obj[1].src = "board.png";
img_obj[2].src = "yashi.png";
img_obj[3].src = "yacht.png";
for(i=0; i
img_car[i] = new Image();
}
img_car[0].src = "car00.png";
img_car[1].src = "car01.png";
img_car[2].src = "car02.png";
img_car[3].src = "car03.png";
img_car[4].src = "car04.png";
img_car[5].src = "car05.png";
img_car[6].src = "car06.png";
img_car[7].src = "image_pr/car10.png";
img_car[8].src = "image_pr/car11.png";
img_car[9].src = "image_pr/car12.png";
img_car[10].src = "image_pr/car13.png";
img_car[11].src = "image_pr/car14.png";
img_car[12].src = "image_pr/car15.png";
img_car[13].src = "image_pr/car16.png";
img_car[14].src = "image_pr/car20.png";
img_car[15].src = "image_pr/car21.png";
img_car[16].src = "image_pr/car22.png";
img_car[17].src = "image_pr/car23.png";
img_car[18].src = "image_pr/car24.png";
img_car[19].src = "image_pr/car25.png";
img_car[20].src = "image_pr/car26.png";
img_car[21].src = "car30.png";
img_car[22].src = "car31.png";
img_car[23].src = "car32.png";
img_car[24].src = "car33.png";
img_car[25].src = "car34.png";
img_car[26].src = "car35.png";
img_car[27].src = "car36.png";
main();
}
function init_car(){
// if(sec_time === 20){
// CAR = 10;
// } else {
// if(sec_time === 10){
// CAR = 20;
// } else {
// CAR = 30;
// }
// }
for(i=0; i
car_x[i] = 0;
car_y[i] = 0;
car_lr[i] = 0;
car_spd[i] = 0;
}
for(i=1; i
car_x[i] = Math.floor(Math.random()*700)+50;
car_y[i] = Math.floor(Math.random()*(CMAX-400))+200;
car_lr[i] = 0;
car_spd[i] = Math.floor(Math.random()*100)+100;
}
car_x[0] = 400;
car_y[0] = 0;
car_lr[0] = 0;
car_spd[0] = 0;
}
function touchmove(e){
if (e.targetTouches.length == 1){
touch = e.targetTouches[0];
touchpice(touch.pageX ,touch.pageY);
}
}
function touchstart(e){
if (e.targetTouches.length == 1){
touch = e.targetTouches[0];
touchkey(touch.pageX ,touch.pageY);
}
}
//pcのマウスクリックイベントで起動する関数
function mousemove(e){
touchpice(e.x ,e.y);
}
function mousedown(e){
touchkey(e.x ,e.y);
}
//引数で指定した位置にある駒の移動処理(※変更前です)
function touchpice(tx,ty){
mx = tx;
my = ty;
element = document.getElementById("idselect");
sec_time = element.value;
if(ty
if(tx
if(tx > sv_carx + 80) keyw = 2;
if(ty - 50 > sv_y) keyw2 = 6;
if(ty > sv_cary - 30) keyw2 = 6;
if(idx != 2) keyw2 =0;
sv_y = ty;
// element = document.getElementById("idresult2");
// element.innerHTML = " x=" + tx + " y=" + ty;
}
// A,S,R
function touchkey(tx,ty){
mx = tx;
my = ty;
element = document.getElementById("idselect");
sec_time = element.value;
hmoj = "0";
for(i = 0; i
tidx = parseInt(ZAHYO_XY[i].substr(0,2));
tx1 = parseInt(ZAHYO_XY[i].substr(3,3));
ty1 = parseInt(ZAHYO_XY[i].substr(7,3));
tx2 = parseInt(ZAHYO_XY[i].substr(11,3));
ty2 = parseInt(ZAHYO_XY[i].substr(15,3));
tmoj = ZAHYO_XY[i].substr(19,1);
if(idx === tidx){
if((tx >= tx1) && (tx <= tx2) && (ty >= ty1) && (ty <= ty2)){
hmoj = tmoj;
break;
}
}
}
if(hmoj === "a") keyw2 = 5;
if(hmoj === "s") keyw3 = 1;
if(hmoj === "r") keyw3 = 2;
if(hmoj === "1") keyw4 = 1;
if(hmoj === "2") keyw4 = 2;
if(hmoj === "3") keyw4 = 3;
if(hmoj === "L") wn -= 1;
if(hmoj === "R") wn += 1;
if(wn + 3 > MYCARMAX) wn = MYCARMAX - 3;
if(wn < 0) wn = 0;
// element = document.getElementById("idresult2");
// element.innerHTML = " x=" + tx + " y=" + ty + " hmoj=" + hmoj + " idx= " + idx;
}
//コースデーターの取得
function get_cdata(){
errflg = 0;
clearTimeout(timer1);
coursearea = document.myFORM.myTEXT.value;
//ロボットエリアのデーターを改行(¥n)で分ける。
//行ごとにテーブルに入る。
coursetext = coursearea.split("\n");
//bhの数だけテーブル(配列)にする。(ちなみにhはハイ(高さ)です)
for(y=0; y
if(coursetext[y].substr(0,2) === "EE") break;
//bwの数だけテーブル(配列)にする。(ちなみにwはワイド(幅)です)
//行を項目に分ける。(¥t)タブで分ける。
if((coursetext[y].substr(0,2) != "DD") && (coursetext[y].substr(0,2) != "MM")){
cdatasu = cdatasu + 1;
courseitem = coursetext[y].split(",");
if(courseitem[0] === "DATA_LR") set_lr();
else if(courseitem[0] === "DATA_UD") set_ud();
else if(courseitem[0] === "CAR") set_car();
}
}
for(i=0; i
car_x[i] = 0;
car_y[i] = 0;
car_lr[i] = 0;
car_spd[i] = 0;
}
if(su_lr != su_ud) errflg = 1; else { CLEN = su_lr; CMAX = BOARD*CLEN; }
// element = document.getElementById("idresult2");
// element.innerHTML = "DATA_LR=" + DATA_LR + " su_lr =" + su_lr + " su_ud=" + su_ud;
if(errflg === 0){
idx = 0;
keyw2 = 0;
main();
// make_course();
// init_car();
}
}
function set_lr(){
for(x=1; x
//配列(テーブル)に収納する。
if(courseitem[x].substr(0,2) === "DE") break;
if(courseitem[x].substr(0,1) === "-") s1 = -1; else s1 = 1;
DATA_LR[x-1] = s1 * parseInt(courseitem[x].substr(1,1));
}
su_lr = x - 1;
}
function set_ud(){
for(x=1; x
//配列(テーブル)に収納する。
if(courseitem[x].substr(0,2) === "DE") break;
if(courseitem[x].substr(0,1) === "-") s1 = -1; else s1 = 1;
DATA_UD[x-1] = s1 * parseInt(courseitem[x].substr(1,1));
}
su_ud = x - 1;
}
function set_car(){
CAR = 1 * parseInt(courseitem[1]);
}
function make_course(){
for(i=0; i
lr1 = DATA_LR[i];
lr2 = DATA_LR[(i+1)%CLEN];
ud1 = DATA_UD[i];
ud2 = DATA_UD[(i+1)%CLEN];
for(j=0; j
pos = j+BOARD*i;
curve[pos] = lr1*(BOARD-j)/BOARD + lr2*j/BOARD;
updown[pos] = ud1*(BOARD-j)/BOARD + ud2*j/BOARD;
if(j === 60) object_right[pos] = 1;
if(i%8 < 7){
if(j%12 === 0) object_left[pos] = 2;
} else {
if(j%20 === 0) object_left[pos] = 3;
}
if(j%12 === 6) object_left[pos] = 9;
}
}
}
function draw_shadow(x, y, siz){
ctx.globalAlpha= 0.3;
ctx.beginPath();
ctx.scale(1, 1/3);
ctx.fillStyle = "black";
ctx.arc(x, (y-siz/6)*3, siz/2, 0, Math.PI*2, false);
ctx.fill();
ctx.setTransform(1,0,0,1,0,0);
ctx.globalAlpha=1;
}
function drive_car(key, key2){
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]
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(key2 === 5){
car_spd[0] += 3;
} else if(key2 === 6){
// car_spd[0] -= 10;
car_spd[0] -= 4;
} else {
// car_spd[0] -= 0.25;
car_spd[0] -= 0.05;
}
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;
laptime[laps] = time_str(rec - recbk);
recbk = rec;
laps +=1
if(laps == LAPS){
idx = 3;
tmr = 0;
}
}
}
//キーが押された時の処理
function keydown(e){
element = document.getElementById("idselect");
sec_time = element.value;
k = e.keyCode;
if(k==37) { keyw = 1; keyw2 = 5;}
// if(k==38) { keyw2 = 5; keyw = 3; sec_time = 20;}
if(k==38) { keyw2 = 5; keyw = 3;}
if(k==39) { keyw = 2; keyw2 = 5;}
if(k==40) keyw2 = 6;
if(k==65) keyw2 = 5;
if(k==90) keyw2 = 6;
if(k==83) keyw3 = 1; //s
if(k==13) keyw3 = 2; //enter
if(k===49 || k===35) keyw4 = 1; //1
if(k===50 || k===40) keyw4 = 2; //2
if(k===51 || k===34) keyw4 = 3; //3
keyp = 1;
if(idx === 4){
if(k ===39){
wn +=1;
if(wn+3 > MYCARMAX) wn = MYCARMAX - 3;
}
if(k ===37){
wn -=1;
if(wn < 0) wn = 0;
}
}
}
function keyupop(e){
if(keyp = 1){ keyw = 0;; keyw2 = 0; keyp = 0;}
}
function draw_obj(img, x, y, sc){
// img_sv.src = img.src;
// if(sw_ren1 === 1){
svx = x;
svy = y;
svsc = sc;
sw_ren1 = 0;
// }
w = img.width*sc;
h = img.height*sc;
ctx.drawImage(img, x - w/2, y - h, w, h);
}
function time_str(val){
sec = parseInt(val);
ms = parseInt((val- sec)*100);
mi = parseInt(sec/60);
return(""+ mi + "'" + ( '00' + sec%60 ).slice(-2) + "." + ( '00' + ms ).slice(-2));
}
function move_car(cs){
for(i = cs; i
if(car_spd[i]
car_spd[i] += 3;
}
if(i === tmr%120){
car_lr[i] += Math.floor(Math.random() * 3) -1;
if(car_lr[i] < -3) car_lr[i] = -3;
if(car_lr[i] > 3) car_lr[i] = 3;
}
car_x[i] = car_x[i] + car_lr[i]*car_spd[i]/100;
if(car_x[i]
car_x[i] = 50;
car_lr[i] = parseInt(car_lr[i]*0.9)
}
if(car_x[i] > 750){
car_x[i] = 750;
car_lr[i] = parseInt(car_lr[i]*0.9)
}
car_y[i] += car_spd[i]/100;
if(car_y[i] > CMAX-1){
car_y[i] -= CMAX;
}
if(idx === 2){
cx = car_x[i] - car_x[0];
cy = car_y[i] - (car_y[0]+PLCAR_Y)%CMAX;
if( (-100 <= cx) && (cx <= 100) && (-10 <= cy) && (cy <= 10) ){
sw_ren = 1;
sw_ren1 = 1;
draw_obj(img_shotogo, car_x[i] - cx/2, car_y[i] - cy/2, 5);
car_x[0] -= cx/4;
car_x[i] += cx/4;
car_spdsv = car_spd[0];
car_spd[0] = car_spd[i]*0.3;
car_spd[i] = car_spdsv*0.3;
// audio.play();
}
}
}
}
function main(){
minit();
//クロックの処理
mmain();
}
function minit(){
//**イメージ・テーブル作成**
for(i=0; i <=BOARD; i++){
BOARD_W[i] = 0;
BOARD_H[i] = 0;
BOARD_UD[i] = 0;
}
for(i=0; i
BOARD_W[i] = 10+(BOARD-i)*(BOARD-i)/12;
BOARD_H[i] = 3.4*(BOARD-i)/BOARD;
BOARD_UD[i] = 2*Math.sin(i*1.5*(Math.PI/180));
}
make_course();
init_car();
vertical = 0;
}