Changeset 127 for pycodeshooter/trunk/index.html
- Timestamp:
- 01/22/12 21:28:03 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pycodeshooter/trunk/index.html
r126 r127 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); 19 18 req.send(null); 20 19 21 // global variables 22 var titleIntervalId = 0; 23 var msg = document.getElementById("message"); 24 var screen = document.getElementById("screen"); 25 var soundCheck = document.getElementById("sound"); 26 var ctx = screen.getContext("2d"); 27 var enemyList = JSON.parse(req.responseText).result; 28 29 // system message clear 20 var enemyList = JSON.parse(req.responseText).result; 21 var msg = document.getElementById("message"); 22 var screen = document.getElementById("screen"); 23 var ctx = screen.getContext("2d"); 24 30 25 setMessage(msg, "<br />"); 26 27 // register enemy images to system 28 var imgs = document.getElementsByTagName("img"); 29 for (var i = 0; i < imgs.length; i++) { 30 if (imgs[i].getAttribute("id").match(/^e_img/)) { 31 addEnemyImage(imgs[i]); 32 } 33 } 31 34 32 35 // register sounds to system … … 45 48 46 49 // sound on/off (default off) 50 var soundCheck = document.getElementById("sound"); 47 51 soundCheck.onclick = function() { 48 52 toggleSound(soundCheck.checked); … … 52 56 53 57 // title screen set 54 var logoimg = document.getElementById("logoimg"); 55 var x = (screen.width - logoimg.width) / 2; 56 var y = -1 - logoimg.height; 57 var titlePos = screen.height / 2 - logoimg.height / 2; 58 59 titleIntervalId = setInterval(function() { 58 var logoimg = document.getElementById("logoimg"); 59 var x = (screen.width - logoimg.width) / 2; 60 var y = -1 - logoimg.height; 61 var titlePos = screen.height / 2 - logoimg.height / 2; 62 var titleIntervalId = setInterval(function() { 60 63 drawScreen(ctx, "source-over", "rgba(8,8,8,0.5)", screen.width, screen.height); 61 64 updateBackground(ctx, screen.width, screen.height, 1, "#AAF", 10); … … 78 81 } 79 82 83 var player = { 84 "name": document.getElementById("name").value, 85 "image": document.getElementById("p_img0"), 86 "size": parseInt(document.getElementById("size").value), 87 "hitsize": parseInt(document.getElementById("hitsize").value), 88 "speed": parseInt(document.getElementById("speed").value), 89 "hitpoint": parseInt(document.getElementById("hitpoint").value), 90 "shotsize": parseInt(document.getElementById("shotsize").value), 91 "shotinterval": parseInt(document.getElementById("shotinterval").value), 92 "shotspeed": parseInt(document.getElementById("shotspeed").value), 93 "shotlevel": parseInt(document.getElementById("shotlevel").value), 94 "numbombs": parseInt(document.getElementById("numbombs").value) 95 }; 96 97 for (var n in player) { 98 if (n == "name" || n == "image") 99 continue; 100 if (!player[n] || player[n] < 1) { 101 setMessage(msg, "Invalid Input Data"); 102 return; 103 } 104 } 105 106 setMessage(msg, "<br />"); 80 107 clearInterval(titleIntervalId); 81 108 titleIntervalId = 0; … … 85 112 86 113 setTimeout(function() { 87 var player = {88 "name": document.getElementById("name").value,89 "image": document.getElementById("p_img0"),90 "size": parseInt(document.getElementById("size").value),91 "hitsize": parseInt(document.getElementById("hitsize").value),92 "speed": parseInt(document.getElementById("speed").value),93 "hitpoint": parseInt(document.getElementById("hitpoint").value),94 "shotsize": parseInt(document.getElementById("shotsize").value),95 "shotinterval": parseInt(document.getElementById("shotinterval").value),96 "shotspeed": parseInt(document.getElementById("shotspeed").value),97 "shotlevel": parseInt(document.getElementById("shotlevel").value),98 "numbombs": parseInt(document.getElementById("numbombs").value)99 };100 101 for (var n in player) {102 if (n == "name")103 continue;104 if (!player[n] || player[n] < 0) {105 setMessage(msg, "Invalid Input Data");106 return;107 }108 }109 110 var imgs = document.getElementsByTagName("img");111 for (var i = 0; i < imgs.length; i++) {112 if (imgs[i].getAttribute("id").match(/^e_img/)) {113 addEnemyImage(imgs[i]);114 }115 }116 117 114 initGame(document.getElementById("screen"), msg, player); 118 115
Note: See TracChangeset
for help on using the changeset viewer.