Changeset 119 for pycodeshooter/trunk
- Timestamp:
- 01/22/12 03:41:27 (13 years ago)
- Location:
- pycodeshooter/trunk
- Files:
-
- 9 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
pycodeshooter/trunk/index.html
r118 r119 14 14 <script type="text/javascript"> 15 15 window.onload = function () { 16 // load enemies17 16 var req = new XMLHttpRequest(); 18 17 req.open("GET", document.getElementById("api").value, false); … … 23 22 var msg = document.getElementById("message"); 24 23 var screen = document.getElementById("screen"); 24 var soundCheck = document.getElementById("sound"); 25 25 var ctx = screen.getContext("2d"); 26 26 var enemyList = JSON.parse(req.responseText).result; 27 27 28 registerSound("bgm_title", document.getElementById("bgm_title")); 29 registerSound("bgm_stage1", document.getElementById("bgm_stage1")); 30 registerSound("se_start", document.getElementById("se_start")); 31 registerSound("se_encounter", document.getElementById("se_encounter")); 32 registerSound("se_damage_enemy", document.getElementById("se_damage_enemy")); 33 registerSound("se_damage_player", document.getElementById("se_damage_player")); 34 registerSound("se_bomb", document.getElementById("se_bomb")); 35 registerSound("se_destroy", document.getElementById("se_destroy")); 28 36 setMessage(msg, "<br />"); 29 37 38 // sound on/off 39 soundCheck.onclick = function() { 40 toggleSound(soundCheck.checked); 41 }; 42 soundCheck.click(); 43 30 44 // title screen set 45 var titlebgm = document.getElementById("bgm_title"); 31 46 var logoimg = document.getElementById("logoimg"); 32 47 var x = (screen.width - logoimg.width) / 2; … … 49 64 }, 20); 50 65 66 playSound("bgm_title"); 67 51 68 // start game 52 69 screen.onclick = function() { … … 55 72 } 56 73 57 clearInterval(titleIntervalId); 58 titleIntervalId = 0; 59 60 var player = { 61 "name": document.getElementById("name").value, 62 "image": document.getElementById("p_img0"), 63 "size": parseInt(document.getElementById("size").value), 64 "hitsize": parseInt(document.getElementById("hitsize").value), 65 "speed": parseInt(document.getElementById("speed").value), 66 "hitpoint": parseInt(document.getElementById("hitpoint").value), 67 "shotsize": parseInt(document.getElementById("shotsize").value), 68 "shotinterval": parseInt(document.getElementById("shotinterval").value), 69 "shotspeed": parseInt(document.getElementById("shotspeed").value), 70 "shotlevel": parseInt(document.getElementById("shotlevel").value), 71 "numbombs": parseInt(document.getElementById("numbombs").value) 72 }; 73 74 for (var n in player) { 75 if (n == "name") 76 continue; 77 if (!player[n] || player[n] < 0) { 78 setMessage(msg, "Invalid Input Data"); 79 return; 74 titlebgm.pause(); 75 playSound("se_start"); 76 77 setTimeout(function() { 78 clearInterval(titleIntervalId); 79 titleIntervalId = 0; 80 81 var player = { 82 "name": document.getElementById("name").value, 83 "image": document.getElementById("p_img0"), 84 "size": parseInt(document.getElementById("size").value), 85 "hitsize": parseInt(document.getElementById("hitsize").value), 86 "speed": parseInt(document.getElementById("speed").value), 87 "hitpoint": parseInt(document.getElementById("hitpoint").value), 88 "shotsize": parseInt(document.getElementById("shotsize").value), 89 "shotinterval": parseInt(document.getElementById("shotinterval").value), 90 "shotspeed": parseInt(document.getElementById("shotspeed").value), 91 "shotlevel": parseInt(document.getElementById("shotlevel").value), 92 "numbombs": parseInt(document.getElementById("numbombs").value) 93 }; 94 95 for (var n in player) { 96 if (n == "name") 97 continue; 98 if (!player[n] || player[n] < 0) { 99 setMessage(msg, "Invalid Input Data"); 100 return; 101 } 80 102 } 81 } 82 83 var imgs = document.getElementsByTagName("img");84 for (var i = 0; i < imgs.length; i++) {85 if (imgs[i].getAttribute("id").match(/^e_img/)) {86 addEnemyImage(imgs[i]);103 104 var imgs = document.getElementsByTagName("img"); 105 for (var i = 0; i < imgs.length; i++) { 106 if (imgs[i].getAttribute("id").match(/^e_img/)) { 107 addEnemyImage(imgs[i]); 108 } 87 109 } 88 } 89 90 document.onkeydown = function (ev) { setKeyDown(ev.keyCode); }; 91 document.onkeyup = function (ev) { setKeyUp(ev.keyCode); }; 92 document.onkeypress = function (ev) { setKeyPress(ev.charCode); }; 93 94 initGame(document.getElementById("screen"), msg, player); 95 96 var enemyIntervalId = setInterval(function() { 97 if (numEnemies() < parseInt(document.getElementById("numenemies").value)) { 98 var ids = Object.keys(enemyList); 99 var id = ids[Math.floor(Math.random() * ids.length)]; 100 addEnemy(enemyList[id]); 101 } 102 }, 1500); 110 111 document.onkeydown = function (ev) { setKeyDown(ev.keyCode); }; 112 document.onkeyup = function (ev) { setKeyUp(ev.keyCode); }; 113 document.onkeypress = function (ev) { setKeyPress(ev.charCode); }; 114 115 playSound("bgm_stage1"); 116 initGame(document.getElementById("screen"), msg, player); 117 118 var enemyIntervalId = setInterval(function() { 119 if (numEnemies() < parseInt(document.getElementById("numenemies").value)) { 120 var ids = Object.keys(enemyList); 121 var id = ids[Math.floor(Math.random() * ids.length)]; 122 playSound("se_encounter"); 123 addEnemy(enemyList[id]); 124 } 125 }, 1500); 126 }, 1400); 103 127 }; 104 128 }; … … 126 150 æ§: <input type="text" value="5" size="3" id="hitpoint" /> 127 151 ãã æ°: <input type="text" value="2" size="3" id="numbombs" /> 152 é³æ¥œ: <input type="checkbox" checked="checked" id="sound" /> 128 153 <br /> 129 154 <canvas id="screen" width="320" height="480"></canvas> … … 138 163 <input type="hidden" value="/etc/pycodebattler/?mode=json" id="api" /> 139 164 <img src="images/logo.png" style="visibility: hidden;" id="logoimg" /> 165 166 <audio src="sounds/bgm_sht_a01.mp3", id="bgm_title" loop="true" preload="auto" /> 167 <audio src="sounds/bgm_sht_a02.mp3", id="bgm_stage1" loop="true" preload="auto" /> 168 <audio src="sounds/se_coinin_1.mp3", id="se_start" preload="auto" /> 169 <audio src="sounds/se_denshion_1.mp3", id="se_encounter" preload="auto" /> 170 <audio src="sounds/se_pyuun.mp3", id="se_damage_player" preload="auto" /> 171 <audio src="sounds/se_click_2.mp3", id="se_damage_enemy" preload="auto" /> 172 <audio src="sounds/se_zusyunzusyun.mp3", id="se_bomb" preload="auto" /> 173 <audio src="sounds/se_zugan.mp3", id="se_destroy" preload="auto" /> 140 174 141 175 <img src="images/ma1s.gif" style="visibility: hidden;" id="p_img0" /> … … 210 244 <li>ãã¯ãŒã¢ããã¢ã€ãã </li> 211 245 <li>åäœãåã</li> 212 <li>é³ã鳎ãã</li>213 246 </ul> 214 247 … … 221 254 <ul style="font-size: small;"> 222 255 <li><a href="http://www.civillink.net/">ããªãŒçŽ æã®æ¥å€¢æ¥äºº</a></li> 256 <li><a href="http://www.skipmore.com/sound/">ãŠãŠã©ã8bitãµãŠã³ãå·¥æ¿</a></li> 223 257 </ul> 224 258 </div> -
pycodeshooter/trunk/shooter/system.js
r117 r119 21 21 "height": 0 22 22 }, 23 "sound": {}, 23 24 "message": null, 24 25 "enemyImages": new Array(), … … 186 187 187 188 if (enemy.isDead()) { 189 playSound("se_destroy"); 190 188 191 addDeathPieces( 189 192 enemy.x, enemy.y, … … 202 205 203 206 trooper.draw(System.screen.ctx); 207 } 208 209 function toggleSound(val) { 210 for (var name in System.sound) 211 System.sound[name].muted = !val; 212 } 213 214 function registerSound(name, audio) { 215 System.sound[name] = audio; 216 } 217 218 function playSound(name) { 219 if (System.sound[name]) 220 System.sound[name].play(); 204 221 } 205 222 … … 287 304 brrgs 288 305 ); 306 enemy.registerCallback("damaged", function() {playSound("se_damage_enemy")}); 289 307 290 308 System.enemies.push(enemy); … … 415 433 ); 416 434 417 System.players.push(new Trooper(435 var trooper = new Trooper( 418 436 playerData.name, 419 437 new ActionList([new ManualAction(new ManualShot())]), … … 455 473 playerData.shotlevel + 2, 456 474 -0.5)] 457 )); 475 ); 476 trooper.registerCallback("addBomb", function() {playSound("se_bomb")}); 477 trooper.registerCallback("damaged", function() {playSound("se_damage_player")}); 478 479 System.players.push(trooper); 458 480 459 481 for (var i = 0; i < System.players.length; i++) { -
pycodeshooter/trunk/shooter/trooper.js
r114 r119 75 75 76 76 this.bullets = new Array(); 77 this.callbacks = {}; 77 78 this.bomb = null; 78 79 this.name = name; … … 172 173 173 174 // update my life 174 if (hit && this.life > 0) 175 if (hit && this.life > 0) { 175 176 this.life--; 177 178 if (this.callbacks["damaged"]) 179 this.callbacks["damaged"](this); 180 } 176 181 } 177 182 }; … … 215 220 this.bullets.push( 216 221 new bulletType(size, color, frame, this.w, this.h, this.x + x, this.y + y, dir, speed)); 222 223 if (this.callbacks["addBullet"]) 224 this.callbacks["addBullet"](this); 217 225 }; 218 226 … … 242 250 this.size * 2, 10, this.bombColors); 243 251 this.numBombs--; 244 } 252 253 if (this.callbacks["addBomb"]) 254 this.callbacks["addBomb"](this); 255 } 256 }; 257 258 this.registerCallback = function(name, callback) { 259 this.callbacks[name] = callback; 245 260 }; 246 261 }
Note: See TracChangeset
for help on using the changeset viewer.