Advertisement
AkbarWicaksono

Script TextDeath HTML

Mar 10th, 2015
541
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.55 KB | None | 0 0
  1. <title>Text Death</title>
  2. <style type='text/css'>
  3. body{background:#000;margin:0;padding:0}
  4. #score_bord{position:absolute;left:0;top:0;z-index:1;padding:5px;color:#666;font-size:14px;font-family:Verdana, Geneva, sans-serif;}
  5. #message{
  6. font-family:Verdana, Geneva, sans-serif;
  7. position:absolute;
  8. right:0;
  9. bottom:0;
  10. z-index:20;
  11. color:#C00;
  12. font-size:11px;
  13. }
  14.  
  15. .pause {
  16. background-color:#000;
  17. left:0;
  18. top:0;
  19. height:100%;
  20. width:100%;
  21. }
  22. canvas{z-index:0;}
  23.  
  24. </style>
  25. <div id="score_bord"></div>
  26. <div id="message"></div>
  27. <canvas id="hell"></canvas>
  28.  
  29. <script type='text/javascript'>//<![CDATA[
  30. /**
  31. * Text Death
  32. *
  33. * ?????????????????????????????
  34. * ??????·???????·????·???· context.shadow·????????????
  35. * ???????????????????????????????????
  36. *
  37. * [enter] Start/Resume
  38. * [space] Pause
  39. */
  40.  
  41. //MooTools $random
  42. function _random(Min, Max){
  43. return Math.floor(Math.random() * (Max - Min + 1) + Min);
  44. }
  45.  
  46. var TypingBlood = function(){
  47. var game = {
  48.  
  49. canvas:null,
  50. context:null,
  51. playing : false,
  52. loop_timer:null, //???????
  53.  
  54. bones:[],//?????????????
  55. powders:[],
  56.  
  57. karma:0, //???
  58.  
  59. bloodPondLineHeight:10,//1????????
  60. bloodPondHeight:0,
  61. bloodPondAlpha:1,
  62. bloodParticles:[],
  63.  
  64. scoreBord:null,
  65. level:1,//???
  66. miss:0,
  67. pass:0,
  68. totalScore:0,
  69. combo:0,
  70.  
  71. ascii : [48,49,50,51,52,53,54,55,56,57,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89],//ASCII CODE
  72.  
  73. //????????
  74. addEvent:function(obj, type, fn){
  75. if(obj.addEventListener)
  76. obj.addEventListener( type, fn, false );
  77. },
  78.  
  79. //????????canvas?ID
  80. load:function(id){
  81.  
  82. this.addEvent(window, 'load', function(event){
  83.  
  84. game.canvas = document.getElementById(id);
  85. game.scoreBord = document.getElementById("score_bord");
  86. game.message = document.getElementById("message");
  87.  
  88. if (game.canvas.getContext){
  89. game.context = game.canvas.getContext('2d');
  90. game.setCanvas();
  91.  
  92. game.setPondSize();
  93. game.title();
  94.  
  95. }
  96.  
  97. });
  98.  
  99. //???????????
  100. this.addEvent(window, 'resize', function(){
  101. game.setCanvas();
  102. if(!game.playing) game.title();
  103. });
  104.  
  105. //pause
  106. this.addEvent(window,'blur', function(e){
  107. game.pause();
  108. });
  109.  
  110. //????????
  111. this.addEvent(document,'keydown', function(e){
  112.  
  113.  
  114. if(e.keyCode==32){
  115. game.pause();
  116. }
  117.  
  118. //??
  119. if(e.keyCode==13){
  120.  
  121. if(!game.loop_timer && game.totalScore === 0){//start
  122. game.play();
  123.  
  124. }else if(!game.playing && game.loop_timer){//gameover
  125. game.level=1;
  126. game.miss=0;
  127. game.pass=0;
  128. game.karma=0;
  129. game.totalScore=0;
  130. game.combo=0;
  131. game.bloodPondAlpha =1;
  132. game.score();
  133. game.setPondSize();
  134.  
  135. clearInterval(game.loop_timer);
  136. game.play();
  137.  
  138. }else if(!game.playing){//pause
  139. game.play();
  140. }
  141.  
  142. }
  143.  
  144. var index = game.searchString(e.keyCode);
  145.  
  146. if(index!==false){
  147. game.bones[index].clear = true;
  148. game.pass++;
  149. game.combo++;
  150. game.karma++;
  151. game.totalScore += 100;
  152. }else{
  153. game.miss++;
  154. game.combo=0;
  155. game.karma-=2;
  156. game.totalScore -= 100;
  157. game.bloodPondHeight+= game.bloodPondLineHeight;//???
  158. }
  159.  
  160. });
  161.  
  162. },
  163.  
  164. //????????
  165. setPondSize:function(){
  166. game.bloodPondLineHeight = Math.floor(game.height/100);
  167. game.bloodPondHeight = Math.floor((game.height/100)-game.bloodPondLineHeight)*100;
  168. },
  169.  
  170. //??????
  171. pause:function(){
  172.  
  173. if(game.playing){
  174. game.message.className = "pause";
  175. game.message.innerHTML = '<p style="color:#fff;position:absolute;top:50%;left:0;width:100%;margin-top:-40px;text-align:center;font-size:20px;">Text Death<br/>- Pause -<br />Tekan Enter Untuk Resume</p>';
  176. }
  177.  
  178. clearInterval(game.loop_timer);
  179. game.playing = false;
  180. game.loop_timer = null;
  181. },
  182.  
  183. //?????????
  184. play:function(){
  185. game.playing = true;
  186. game.message.className = "";
  187. game.message.innerHTML = 'Tekan [Space] Untuk Pause | Tekan [Enter] Untuk Resume.';
  188. game.loop_timer = setInterval(function(){game.loop();}, 1000/60);
  189.  
  190. },
  191.  
  192. //??????(?????????)
  193. title:function(){
  194.  
  195. game.context.save();
  196. game.context.font = "42px 'Arial'";
  197. var str = "Text Death";
  198. tm = game.context.measureText(str);
  199.  
  200. game.context.save();
  201. game.context.fillStyle = "red";
  202. game.context.shadowColor = "#ff0000";
  203. game.context.shadowBlur = 10;
  204. game.context.fillText(str, game.width/2-tm.width/2, game.height/2-80);
  205. game.context.restore();
  206.  
  207. game.context.font = "30px 'Arial'";
  208.  
  209. game.context.fillStyle = "#fff";
  210.  
  211. str = "Klik Enter Untuk Memulai Game";
  212. tm = game.context.measureText(str);
  213. game.context.fillText(str, game.width/2-tm.width/2, game.height/2+20);
  214.  
  215. game.context.font = "11px 'Arial'";
  216.  
  217. str = "©2014";
  218. tm = game.context.measureText(str);
  219. game.context.fillText(str, game.width/2-tm.width/2, game.height/2+60);
  220.  
  221. str = "www.akbar-wicaksono.net";
  222. tm = game.context.measureText(str);
  223. game.context.fillText(str, game.width/2-tm.width/2, game.height/2+75);
  224.  
  225. game.context.restore();
  226. },
  227.  
  228. //Canvas?????
  229. setCanvas:function(){
  230. game.width = window.innerWidth;
  231. game.height = window.innerHeight;
  232. game.canvas.height = game.height;
  233. game.canvas.width = game.width;
  234. game.canvas.style.backgroundColor="#000";
  235. game.canvas.style.position = 'absolute';
  236. game.canvas.style.top ="0px";
  237. game.canvas.style.left="0px";
  238. game.bloodPondLineHeight = Math.round(game.height/100);
  239. },
  240.  
  241. //????????????
  242. createText:function(){
  243. var c = game.ascii[_random(0, game.ascii.length-1)];
  244. var x = Math.floor(_random(35, game.width-35));
  245. var y = (game.level>1)? Math.floor( 0 - 20 * (Math.random()*7) ):0;
  246. var t = {
  247. code : c,
  248. text : String.fromCharCode(c),
  249. x : x,
  250. y : y,
  251. powder:null,
  252. clear:false
  253. };
  254.  
  255. game.bones.push(t);
  256. },
  257.  
  258. /** ????
  259. * @code event.keyCode
  260. */
  261. searchString:function(code){
  262. for (var key in game.bones){
  263. if (game.bones[key].code == code) return key;
  264. }
  265.  
  266. return false;
  267. },
  268.  
  269. /*????????????????
  270. *@a alpha
  271. */
  272. createBloodPond:function(a){
  273. var h = game.height-game.bloodPondHeight;
  274. a = (a<=0)? 0:a;
  275. game.context.save();
  276. var g = game.context.createLinearGradient(0, h, 0, game.width);
  277. g.addColorStop(0,'rgba('+game.bloodPondHeight+', 0, 0, '+a+')');
  278. g.addColorStop(1,'rgba('+game.bloodPondLineHeight+', 0, 0, '+a+')');
  279. game.context.fillStyle = g;
  280.  
  281. game.context.beginPath();
  282. game.context.rect(0, h, game.width, game.height);
  283. game.context.fill();
  284.  
  285. //??
  286. game.context.shadowColor = "#ff0000";
  287. game.context.shadowBlur = 5;
  288. game.context.strokeStyle = 'rgb('+(game.bloodPondHeight+60)+',0,0)';
  289. game.context.beginPath();
  290. game.context.lineTo(0, h);
  291. game.context.lineTo( game.width, h);
  292. game.context.stroke();
  293. game.context.restore();
  294.  
  295. },
  296.  
  297. //????????????
  298. createBloods:function ( x, y ) {
  299. var end = 10 + ( Math.random() * 15 );
  300.  
  301. while( end >= 0 ) {
  302. var p = {
  303. x: x,
  304. y: y,
  305. vx:Math.random() * 0.5,
  306. vy:Math.random() * 1 - 6.7,
  307. r: -4 + Math.random() * 8,
  308. alpha : 1
  309. };
  310.  
  311. game.bloodParticles.push( p );
  312. end--;
  313. }
  314. },
  315.  
  316. //???????????
  317. createPowder:function(x, y){
  318. var q = 20 + ( Math.random() * 15 );
  319. var a = [];
  320.  
  321. while( q >= 0 ) {
  322. var p = {
  323. x: Math.floor(x +( Math.sin(q) * 0.03 )),
  324. y: Math.floor(y + Math.cos(q) * 10 ),
  325. vx:-4 + Math.random() * 8,
  326. vy:-4 + Math.random() * 8,
  327. alpha : 1
  328. };
  329.  
  330. game.powders.push(p);
  331. q--;
  332. }
  333.  
  334. },
  335.  
  336. //???
  337. loop:function(){
  338.  
  339. game.context.save();
  340.  
  341. //??????
  342. if((game.bones.length < 1 * game.level) && game.playing){
  343. game.createText();
  344. }
  345.  
  346. game.context.clearRect(0,0, game.width, game.height);
  347. var borderLine = game.height-game.bloodPondHeight;
  348.  
  349. //???????
  350. for(i=0; i < game.bones.length; i++){
  351. var e = game.bones[i];
  352.  
  353. if(e.y < borderLine){
  354. e.y = e.y + 2;
  355. }else{
  356. e.y = e.y + 0.3;
  357. }
  358.  
  359. game.context.font = "30px 'Arial'";
  360. game.context.fillStyle = "#fff";
  361. game.context.fillText(e.text, e.x, e.y);
  362.  
  363. if(e.clear){//??????????
  364.  
  365. game.bones.splice( i, 1 );//??
  366. game.createPowder(e.x, e.y);
  367.  
  368. if(game.bloodPondHeight!==0) game.bloodPondHeight -= game.bloodPondLineHeight;//???
  369.  
  370. }else if(e.y >= (borderLine+20)) {//??????
  371.  
  372. game.bloodPondHeight+= game.bloodPondLineHeight;//???
  373.  
  374. game.bones.splice( i, 1 );//??
  375. game.miss++;
  376. game.karma-=3;
  377. game.totalScore-=100;
  378. game.createBloods(e.x, borderLine);//?????
  379. }
  380. }
  381.  
  382. if( game.bloodPondHeight >= game.height) {
  383. game.playing = false;
  384. }
  385.  
  386.  
  387. //?????
  388. for( b = 0; b < game.powders.length; b++ ) {
  389. powder = game.powders[b];
  390.  
  391. powder.x += powder.vx;
  392. powder.y += powder.vy;
  393.  
  394. powder.alpha -= 0.02;
  395.  
  396. game.context.save();//fillStyle???????????
  397. game.context.fillStyle = 'rgba(255,255,255,'+Math.max(powder.alpha,0)+')';
  398. game.context.fillRect( powder.x, powder.y, 2, 2);
  399. game.context.restore();
  400.  
  401. if( powder.alpha <= 0 ) {
  402. game.powders.splice( b, 1 );
  403. }
  404. }
  405.  
  406. //???????
  407. for( k = 0; k < game.bloodParticles.length; k++ ) {
  408. p = game.bloodParticles[k];
  409.  
  410. p.vy += 0.5;//????????
  411.  
  412. p.x += p.vx + p.r;
  413. p.y += p.vy ;
  414.  
  415. p.alpha -= 0.01;
  416.  
  417. game.context.save();//????fillStyle????????????
  418. game.context.fillStyle = 'rgba(255,0,0,'+Math.max(p.alpha,0)+')';
  419. game.context.fillRect( p.x, p.y, 3, 3 );
  420. game.context.restore();
  421.  
  422. if( p.alpha <= 0 ) {
  423. game.bloodParticles.splice( k, 1 );
  424. }
  425. }
  426.  
  427. if(!game.playing){
  428. game.bloodPondAlpha -= 0.01;//?????????
  429. game.endroll();
  430. }
  431.  
  432. game.createBloodPond(game.bloodPondAlpha);
  433.  
  434. game.context.restore();
  435.  
  436. game.score();
  437.  
  438. if(game.bloodPondAlpha <= 0) {//??????
  439. clearInterval(game.loop_timer);
  440. }
  441. },
  442.  
  443. //?????????
  444. endroll:function(){
  445. game.context.save();
  446. game.context.font = "42px 'Arial'";
  447. game.context.fillStyle = "#fff";
  448.  
  449. str = "Game Over";
  450. tm = game.context.measureText(str);
  451.  
  452. game.context.fillText(str, game.width/2-tm.width/2, 200);
  453. game.context.font = "24px 'Arial'";
  454.  
  455. str = "Klik Enter Untuk Restart";
  456. tm = game.context.measureText(str);
  457. game.context.fillText(str, window.innerWidth/2-tm.width/2, 250);
  458. game.context.restore();
  459.  
  460. },
  461.  
  462. //????????(???)
  463. score:function(){
  464.  
  465. var c = Math.floor((game.pass+game.combo-game.miss+game.karma)/13.5);
  466.  
  467. if(c>0) game.level = c;
  468.  
  469. var html = "Miss:"+game.miss+" Passed:"+game.pass+" Combo:"+game.combo+" Level:"+game.level+" Score:"+game.totalScore;
  470. game.scoreBord.innerHTML = html;
  471. }
  472.  
  473. };
  474.  
  475. return game;
  476.  
  477. };
  478.  
  479. var typing = new TypingBlood();
  480. typing.load('hell');
  481.  
  482. //]]>
  483. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement