前提・実現したいこと
課題で参考資料のpdfを基に、HTMLファイルとfunction.jsファイルを改変しダッシュゲームを作成する。
ローカルへfunctions.jsファイルを作成し読み込むよう改変する。
ローカルで動作するか確認する。
発生している問題・エラーメッセージ
以下がhtmlのpdfとfunction.jsのpdfの文で、どこをどう直せばいいかわからないです。 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>ダッシュゲーム</title> </head> <body> <canvas id="c1" width="480px" height="320px"></canvas> <script src="functions.js"></script> <script type="text/javascript"> var files_name ="hero.png,bg.png,floor.png"; img_url = "http://wuah.sakura.ne.jp.lesson/" var btn_click = 0; var score = 0; var movespeed = 10; var speed_adjust = 2; var max_speed = 32; var move_px = 0; var position_now = 0; var tmp_ground = 0; var speedup_span = 0; var ground_line; var ground_data = "260,260,260,260,260,260,260,260,260,260,0,0,0,240,240,240,240,240,0,0,0,280,280,280,0,0,0,0,0,260,260,260,260,260,260,260,0,0,220,220,220,220,220,220,220,0,0,0,0,0,260,260,260,260,260,0,0,260,260,260,260,260,0,0,260,260,260,260,260,0,0"; var player_x = 32; var player_width = 32; var player_height = 32; var player_anime = 0; var player_anime_span = 0; var jump_state = 0; var jump_max = 36; var jump_minus = 2; var jump_now = jump_max; var gravity = 6; var player_line = 260; function start(){ ground_line = ground_data.split(','); } function btnClickStart(event){ if(jump_state == 0){ btn_click = 1; } } function btnClickOut(){ btn_click = 0; } function update(ctx){ if(btn_click == 1){ jump_now -= jump_minus; if(jump_now > 0){ player_line -= jump_now; }else{ btn_click = 0; jump_now = jump_max; } }else{ jump_now = jump_max; } jump_state = 1; tmp_ground = 380; for(var x=1; x<3; x++){ if((position_now + x)>= ground_line.length){ var tmp_position = (position_now + x)- ground_line.length; }else{ var tmp_position = (x + position_now); } if(ground_line[tmp_position]!=0){ if(move_px !=(32 -((x - 1)*))){ if(player_line == ground_line[tmp_psition]){ jump_state = 0; }else{ tmp_ground = ground_line[tmp_position]; } } } } if(jump_state == 1){ player_line += gravity; if(player_line > tmp_ground){ player_line = tmp_ground jump_state = 0; }else if(player_line >= 320){ gameover_fhg = 1; } } ctx.drawimage(img_obj["bg.png"],0,0,480,320,0,0,480,320); writeText(ctx,16"white",5,5,'SCORE;'+ score); for(var x=0; x<16; x++){ if((position_now +x)>= ground_line.length){ var tmp_position = (position_now + x) - ground_line.length; }else{ var tmp_position = (x + position_now); } if(ground_line[tmp_position]!=0){ ctx.drawImage(img_obj["floor.png"],0,0,16,48,((x*32)- move_px),(ground_line[tmp_position]-16),32,96); } } move_px = move_px + move_speed; if(move_px>32){ move_px -= 32; position_now += 1; if(position_now >= ground_line.length){ position_now -= ground_line.length; } score++; speedup_span++; } if(move_speed < max_speed){ if(speedup_span > 100){ move_speed += speed_adjust; speedup_span = 0; } }else{ move_speed = max_speed; } ctx.drawIamge(img_obj["hero.png"],(player_anime*32),64,32,32,player_x(player_line -player_height),32,32); player_anime_span++; if(player_anime_span == 6){ player_anime_span = 0; player_anime = 0; }else if(player_anime_span == 4){ player_anime = 2; }else if(player_anime_span == 2){ player_anime = 1; } } </script> </body> </html> ここから下はfunctions.jsファイルの文 var img_loaded = 0; var img_obj = []; var btn_X = 0; var btn_Y = 0; function $(id){ return document.getElementById(id); } window.onload = function (){ imageParse(files_name); document.addEventListener("mousedown",btnPush); document.addEventListener('mouseup', btnOut, false); start(); renderer(); } function imageParse(files){ var file_array = files.split(","); for(var i = 0; i < file_array.length; i++){ img_obj[file_array[i]] = new Image(); img_obj[file_array[i]].src = img_url + file_array[i]; img_obj[file_array[i]].onload = function (){ img_loaded++; } } } function btnPush(e){ var divide = $("c1").getBoundingClientRect(); btn_X = (e.clientX - divide.left); btn_Y = (e.clientY - divide.top); btnClickStart(); } function btnOut(e){ btnClickOut(); } function renderer(){ if(Object.keys(img_obj).length == img_loaded){ var ctx = $("c1").getContext("2d"); ctx.fillStyle = "#000000"; ctx.fillRect(0,0,480,320); update(ctx); } var t = setTimeout(renderer,16); } function hitTest(x1,y1,r1,x2,y2,r2){ var lineC = ((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)); var lineAB = (r2 + r1) * (r2 + r1); if(lineAB >= lineC){ return 1; }else{ return 0; } } function writeText(ctx,size,color,x,y,text){ ctx.font = size + "px 'MSPゴシック'"; ctx.fillStyle = color; ctx.fillText(text, x, (y + size)); }
該当のソースコード
javascript
試したこと
先生への質問。
補足情報(FW/ツールのバージョンなど)
ATOMでかいています。