Changeset 110 for pycodeshooter/trunk
- Timestamp:
- 01/18/12 14:04:55 (13 years ago)
- Location:
- pycodeshooter/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
pycodeshooter/trunk/index.html
r109 r110 13 13 <script type="text/javascript" charset="UTF-8" src="shooter/system.js"></script> 14 14 <script type="text/javascript"> 15 var titleIntervalId = 0;16 17 function startGame() {18 var msg = document.getElementById("message");19 var player = {20 "name": document.getElementById("name").value,21 "image": document.getElementById("p_img0"),22 "size": parseInt(document.getElementById("size").value),23 "hitsize": parseInt(document.getElementById("hitsize").value),24 "speed": parseInt(document.getElementById("speed").value),25 "hitpoint": parseInt(document.getElementById("hitpoint").value),26 "shotsize": parseInt(document.getElementById("shotsize").value),27 "shotinterval": parseInt(document.getElementById("shotinterval").value),28 "shotspeed": parseInt(document.getElementById("shotspeed").value),29 "shotlevel": parseInt(document.getElementById("shotlevel").value),30 "numbombs": parseInt(document.getElementById("numbombs").value)31 };32 33 for (var n in player) {34 if (n == "name")35 continue;36 if (!player[n] || player[n] < 0) {37 setMessage(msg, "Invalid Input Data");38 return;39 }40 }41 42 document.onkeydown = function (ev) { setKeyDown(ev.keyCode); };43 document.onkeyup = function (ev) { setKeyUp(ev.keyCode); };44 document.onkeypress = function (ev) { setKeyPress(ev.charCode); };45 46 initGame(document.getElementById("screen"), msg, player);47 }48 49 function initControlPanel(list) {50 var cp = document.getElementById("controlpanel");51 var sel = "<select id=\"enemySelection\">";52 53 for (var id in list) {54 sel += "<option value=\"" + id + "\"" + ">" + list[id].name + "</option>";55 }56 57 cp.innerHTML = sel + "</select>";58 59 document.getElementById("enemySelection").onchange = function (ev) {60 if (titleIntervalId) {61 clearInterval(titleIntervalId);62 titleIntervalId = 0;63 64 var imgs = document.getElementsByTagName("img");65 for (var i = 0; i < imgs.length; i++) {66 if (imgs[i].getAttribute("id").match(/^e_img/)) {67 addEnemyImage(imgs[i]);68 }69 }70 71 startGame();72 }73 74 addEnemy(list[this[this.selectedIndex].value]);75 };76 }77 78 15 window.onload = function () { 79 var screen = document.getElementById("screen"); 80 var ctx = screen.getContext("2d"); 81 var logoimg = document.getElementById("logoimg"); 82 16 // load enemies 17 var req = new XMLHttpRequest(); 18 req.open("GET", document.getElementById("api").value, false); 19 req.send(null); 20 21 // global variables 22 var titleIntervalId = 0; 23 var msg = document.getElementById("message"); 24 var screen = document.getElementById("screen"); 25 var ctx = screen.getContext("2d"); 26 var enemyList = JSON.parse(req.responseText).result; 27 28 setMessage(msg, "<br />"); 29 30 // title screen set 31 var logoimg = document.getElementById("logoimg"); 83 32 var x = (screen.width - logoimg.width) / 2; 84 33 var y = -1 - logoimg.height; … … 92 41 if (++y > titlePos) 93 42 y = titlePos; 43 44 drawString( 45 ctx, "source-over", 46 "Click screen to start game", 47 15, 20, "#ACF", "9pt monospace", "left" 48 ); 94 49 }, 20); 95 50 96 var req = new XMLHttpRequest(); 97 req.open("GET", document.getElementById("api").value, false); 98 req.send(null); 99 100 initControlPanel(JSON.parse(req.responseText).result); 51 // start game 52 screen.onclick = function() { 53 if (!titleIntervalId) { 54 return; 55 } 56 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; 80 } 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]); 87 } 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 }, 5000); 103 }; 101 104 }; 102 105 </script> … … 118 121 <form> 119 122 <h3><span class="sanchor">â </span> ææŠãã!</h3> 120 <p id="controlpanel">Now loading...</p>121 123 <p> 122 124 åå: <input type="text" value="Player" size="8" id="name" /> … … 133 135 <input type="hidden" value="5" id="shotinterval" /> 134 136 <input type="hidden" value="3" id="shotlevel" /> 137 <input type="hidden" value="3" id="numenemies" /> 135 138 <input type="hidden" value="/etc/pycodebattler/?mode=json" id="api" /> 136 139 <img src="images/logo.png" style="visibility: hidden;" id="logoimg" /> … … 193 196 194 197 <p>ã·ã¹ãã ã¡ãã»ãŒãž</p> 195 <span id="message" style="font-size: small;"> <br /></span>198 <span id="message" style="font-size: small;">Now loading...</span> 196 199 197 200 <p>泚æ</p> -
pycodeshooter/trunk/shooter/system.js
r109 r110 195 195 } 196 196 197 function numEnemies() { 198 return System.enemies.length; 199 } 200 197 201 function addEnemyImage(image) { 198 202 System.enemyImages.push(image); … … 256 260 System.screen.width, 257 261 System.screen.height, 258 enemyData.hitpoint,262 Math.floor(enemyData.hitpoint / 75) + 1, 259 263 Math.log(enemyData.agility + 0.1) * 3, 260 264 0,
Note: See TracChangeset
for help on using the changeset viewer.