Advertisement
cypherine

pokemonbattlescript.js

Jan 19th, 2022
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /////////////////////////////////////////////
  2. // CONTENTS
  3. /////////////////////////////////////////////
  4. // VARIABLES
  5. // UTILITIES
  6.   // RANDOM NUMBER GENERATOR
  7.   // CHARACTER BUILD
  8.   // ATTACK MULTIPLIER
  9.   // SFX PLAYER
  10.   // HP BAR ANIMATION
  11. // RESET
  12. // CHARACTER CHOICE
  13. // HERO ATTACK
  14. // ENEMY ATTACK
  15. // ATTACK SEQUENCE
  16. // MODAL CONTROLS
  17.  
  18.  
  19. /////////////////////////////////////////////
  20. // VARIABLES
  21. /////////////////////////////////////////////
  22. var music = {},
  23.     typeSprite = '',
  24.     types = [],
  25.     gameData = {}
  26.     attackName = '',
  27.     curAttack = {},
  28.     randInt = 0,
  29.     enemyAttack = {},
  30.     characters = [],
  31.     defendProgressInt = null,
  32.     defendProgressComplete = 0,
  33.     progressInt = null,
  34.     progressComplete = 0;
  35.  
  36. function buildVars(){
  37.   // all the music for the game
  38.   // http://downloads.khinsider.com/game-soundtracks/album/pokemon-gameboy-sound-collection
  39.   music = {
  40.     opening: "http://66.90.91.26/ost/pokemon-gameboy-sound-collection/aipycrsoym/101-opening.mp3",
  41.     battle: "http://66.90.91.26/ost/pokemon-gameboy-sound-collection/fllwdebjsg/107-battle-vs-wild-pokemon-.mp3",
  42.     victory: "http://66.90.91.26/ost/pokemon-gameboy-sound-collection/csqodhnibz/108-victory-vs-wild-pokemon-.mp3",
  43.     pikachu: "http://66.90.91.26/ost/pokemon-gameboy-sound-collection/hpjacpzwof/170-pikachu.mp3",
  44.     charmander: "http://66.90.91.26/ost/pokemon-gameboy-sound-collection/wfwdwleyga/149-charmander.mp3",
  45.     squirtle: "http://66.90.91.26/ost/pokemon-gameboy-sound-collection/soagplijvq/152-squirtle.mp3",
  46.     bulbasaur: "http://66.90.91.26/ost/pokemon-gameboy-sound-collection/gvqmhhryki/146-bulbasaur.mp3",
  47.     machop: "http://66.90.91.26/ost/pokemon-gameboy-sound-collection/viaskmobgb/213-machop.mp3"
  48.   }
  49.  
  50.  
  51.  
  52.   typeSprite = 'http://orig15.deviantart.net/24d8/f/2011/057/3/5/ge___energy_type_icons_by_aschefield101-d3agp02.png';
  53.   types = ['bug', 'dark', 'dragon', 'electric', 'fairy', 'fighting', 'fire', 'flying', 'ghost', 'grass', 'ground', 'ice', 'normal', 'poison', 'psychic', 'rock', 'steel', 'water'];
  54.  
  55.  
  56.  
  57.   // the data for the game in play
  58.   gameData = {
  59.     step: 1,
  60.     hero: {},
  61.     enemy: {}
  62.   }
  63.  
  64.  
  65.  
  66.   // attack variables
  67.   attackName = '';
  68.   curAttack = {};
  69.   randInt = 0;
  70.   enemyAttack = {};
  71.   defendProgressInt = null;
  72.   defendProgressComplete = 0;
  73.   progressInt = null;
  74.   progressComplete = 0;
  75.  
  76.  
  77.  
  78.   // available characters
  79.   characters = [
  80.     {
  81.       name: "pikachu",
  82.       type: 'electric',
  83.       weakness: ['fighting'],
  84.       resistance: ['steel'],
  85.       img: {
  86.         default: "http://vignette2.wikia.nocookie.net/all-anime-characters/images/7/7b/Cute_pikachu_with_hat_by_mlpochea-d63xlom.png/revision/latest?cb=20150108111832",
  87.         front: "http://rs1263.pbsrc.com/albums/ii631/Pokemon-Vampire-Knight-lover/pikachu_.gif~c200",
  88.         back: "http://vignette4.wikia.nocookie.net/pokemon/images/5/5b/Pikachu_Back_XY.gif/revision/latest?cb=20141009080948"
  89.       },
  90.       hp: {
  91.         current: 500,
  92.         total: 500
  93.       },
  94.       attacks: [
  95.         {
  96.           name: "thunder jolt",
  97.           hp: randomNum(40,20),
  98.           avail: {
  99.             total: 30,
  100.             remaining: 30
  101.           }
  102.         },
  103.         {
  104.           name: "electro ball",
  105.           hp: randomNum(60,45),
  106.           avail: {
  107.             total: 10,
  108.             remaining: 10
  109.           }
  110.         },
  111.         {
  112.           name: "volt tackle",
  113.           hp: randomNum(75,60),
  114.           avail: {
  115.             total: 5,
  116.             remaining: 5
  117.           }
  118.         },
  119.         {
  120.           name: "thunder crack",
  121.           hp: randomNum(160, 130),
  122.           avail: {
  123.             total: 2,
  124.             remaining: 2
  125.           }
  126.         }
  127.       ]
  128.     },
  129.     {
  130.       name: "charmander",
  131.       type: 'fire',
  132.       weakness: ['water'],
  133.       resistance: ['grass'],
  134.       img: {
  135.         default: "http://img3.wikia.nocookie.net/__cb20150330015216/pokemon/images/f/f5/004Charmander_Pokemon_Mystery_Dungeon_Explorers_of_Sky.png",
  136.         front: "http://rs772.pbsrc.com/albums/yy9/HybridRainbow88/Charmander.gif~c200",
  137.         back: "http://vignette1.wikia.nocookie.net/pokemon/images/2/23/Charmander_Back_XY.gif/revision/latest?cb=20141009063457"
  138.       },
  139.       hp: {
  140.         current: 500,
  141.         total: 500
  142.       },
  143.       attacks: [
  144.         {
  145.           name: "ember",
  146.           hp: randomNum(40,20),
  147.           avail: {
  148.             total: 30,
  149.             remaining: 30
  150.           }
  151.         },
  152.         {
  153.           name: "flamethrower",
  154.           hp: randomNum(60,45),
  155.           avail: {
  156.             total: 10,
  157.             remaining: 10
  158.           }
  159.         },
  160.         {
  161.           name: "burning tail",
  162.           hp: randomNum(75,60),
  163.           avail: {
  164.             total: 5,
  165.             remaining: 5
  166.           }
  167.         },
  168.         {
  169.           name: "fire spin",
  170.           hp: randomNum(160, 130),
  171.           avail: {
  172.             total: 2,
  173.             remaining: 2
  174.           }
  175.         }
  176.       ]
  177.     },
  178.     {
  179.       name: "squirtle",
  180.       type: 'water',
  181.       weakness: ['electric','grass'],
  182.       resistance: ['normal','fire'],
  183.       img: {
  184.         default: "http://vignette3.wikia.nocookie.net/ssbb/images/7/79/Squirtle_Rojo_Fuego_y_Verde_Hoja.png/revision/latest?cb=20130907041944&path-prefix=es",
  185.         front: "https://66.media.tumblr.com/ddd22fe10a485ed56a46d958c058a970/tumblr_n9lnpepqkW1scncwdo1_500.gif",
  186.         back: "http://vignette3.wikia.nocookie.net/pokemon/images/d/d8/Squirtle_XY_Back_Sprite.gif/revision/latest?cb=20141031154426"
  187.       },
  188.       hp: {
  189.         current: 500,
  190.         total: 500
  191.       },
  192.       attacks: [
  193.         {
  194.           name: "bubble",
  195.           hp: randomNum(40,20),
  196.           avail: {
  197.             total: 30,
  198.             remaining: 30
  199.           }
  200.         },
  201.         {
  202.           name: "water gun",
  203.           hp: randomNum(60,45),
  204.           avail: {
  205.             total: 10,
  206.             remaining: 10
  207.           }
  208.         },
  209.         {
  210.           name: "shell attack",
  211.           hp: randomNum(75,60),
  212.           avail: {
  213.             total: 5,
  214.             remaining: 5
  215.           }
  216.         },
  217.         {
  218.           name: "hydro pump",
  219.           hp: randomNum(160, 130),
  220.           avail: {
  221.             total: 2,
  222.             remaining: 2
  223.           }
  224.         }
  225.       ]
  226.     },
  227.     {
  228.       name: "bulbasaur",
  229.       type: 'grass',
  230.       weakness: ['fire'],
  231.       resistance: ['water','psychic'],
  232.       img: {
  233.         default: "http://vignette4.wikia.nocookie.net/pokemon/images/8/81/001Bulbasaur_Pokemon_Mystery_Dungeon_Explorers_of_Sky.png/revision/latest?cb=20150105223818",
  234.         front: "https://media.giphy.com/media/iIWW4BM6nNWTu/giphy.gif",
  235.         back: "http://rs425.pbsrc.com/albums/pp335/Grasaldrea/ShinyBulbasauranimatedback.gif~c200",
  236.         deranged: "http://rs522.pbsrc.com/albums/w348/Richtoon18/b3617568f13aa750c57eacc45d0b2da7.gif~c200",
  237.         sleep: "https://31.media.tumblr.com/4dd7682db26ac687ef81f0dd06794652/tumblr_msesq5uAIk1r93jsro1_500.gif"
  238.       },
  239.       hp: {
  240.         current: 500,
  241.         total: 500
  242.       },
  243.       attacks: [
  244.         {
  245.           name: "tackle",
  246.           hp: randomNum(40,20),
  247.           avail: {
  248.             total: 30,
  249.             remaining: 30
  250.           }
  251.         },
  252.         {
  253.           name: "vine whip",
  254.           hp: randomNum(60,45),
  255.           avail: {
  256.             total: 10,
  257.             remaining: 10
  258.           }
  259.         },
  260.         {
  261.           name: "razor leaf",
  262.           hp: randomNum(75,60),
  263.           avail: {
  264.             total: 5,
  265.             remaining: 5
  266.           }
  267.         },
  268.         {
  269.           name: "solar beam",
  270.           hp: randomNum(160, 130),
  271.           avail: {
  272.             total: 2,
  273.             remaining: 2
  274.           }
  275.         }
  276.       ]
  277.     },
  278.     {
  279.       name: "machop",
  280.       type: 'fighting',
  281.       weakness: ['psychic','electric'],
  282.       resistance: [],
  283.       img: {
  284.         default: "http://clipart.toonarific.com/data/media/11/pokemon066.gif",
  285.         front: "http://graphics.tppcrpg.net/xy/normal/066F.gif",
  286.         back:  "http://pokeunlock.com/wp-content/uploads/2015/01/machop-2.gif"
  287.       },
  288.       hp: {
  289.         current: 500,
  290.         total: 500
  291.       },
  292.       attacks: [
  293.         {
  294.           name: "low kick",
  295.           hp: randomNum(40,20),
  296.           avail: {
  297.             total: 30,
  298.             remaining: 30
  299.           }
  300.         },
  301.         {
  302.           name: "karate chop",
  303.           hp: randomNum(60,45),
  304.           avail: {
  305.             total: 10,
  306.             remaining: 10
  307.           }
  308.         },
  309.         {
  310.           name: "seismic toss",
  311.           hp: randomNum(75,60),
  312.           avail: {
  313.             total: 5,
  314.             remaining: 5
  315.           }
  316.         },
  317.         {
  318.           name: "hundred furious punches",
  319.           hp: randomNum(160, 130),
  320.           avail: {
  321.             total: 2,
  322.             remaining: 2
  323.           }
  324.         }
  325.       ]
  326.     }
  327.   ];
  328. }
  329.  
  330.  
  331.  
  332.  
  333.  
  334. /////////////////////////////////////////////
  335. // UTILITY
  336. /////////////////////////////////////////////
  337. // RANDOM NUMBER GENERATOR
  338. // min is optional
  339. function randomNum(max, min){
  340.   // generate a random number
  341.  
  342.   // min not required
  343.   if(min === undefined || min === '' || min === null){
  344.     // min default value
  345.     min = 0;
  346.   }
  347.  
  348.   // random number, yay
  349.   return Math.floor(Math.random() * (max - min) + min);
  350. }
  351.  
  352.  
  353.  
  354. // CHARACTER BUILD
  355. // build the character UI
  356. function populateChar(container,character){
  357.   // which img
  358.   var facing = 'front';
  359.   if(character === 'hero'){
  360.     // we see the back of our hero
  361.     // a real hero faces danger
  362.     facing = 'back';
  363.   }
  364.  
  365.   // build the character
  366.   container.append('<section class="char"><img src="'+gameData[character].img[facing]+'" alt="'+gameData[character].name+'"><aside class="data"><h2>'+gameData[character].name+'</h2><div><progress max="'+gameData[character].hp.total+'"></progress><p><span>'+gameData[character].hp.current+'</span>/'+gameData[character].hp.total+'</p></div></aside></section>');
  367. }
  368.  
  369.  
  370.  
  371. // ATTACK MULTIPLIER
  372. // modify attack value for weaknesses & strengths
  373. function attackMultiplier(attacker, curAttack){
  374.   var defender = 'enemy';
  375.   if(attacker === 'enemy'){
  376.     defender = 'hero';
  377.   }
  378.  
  379.   if(gameData[defender].weakness.indexOf(gameData[attacker].type) >= 0){
  380.     // weakness exists
  381.     curAttack.hp *= 2;
  382.   }
  383.  
  384.   if(gameData[defender].resistance.indexOf(gameData[attacker].type) >= 0){
  385.     // weakness exists
  386.     curAttack.hp /= 2;
  387.   }
  388.  
  389.   curAttack.hp = Math.floor(curAttack.hp);
  390.   return curAttack.hp;
  391. }
  392.  
  393.  
  394.  
  395. // SFX PLAYER
  396. // stops music and plays sfx
  397. function playSound(name){
  398.   // load sfx src
  399.   $('audio.sfx').attr('src', music[name])
  400.   // pause game music
  401.   $('audio.music')[0].pause();
  402.   // character announce yourself
  403.   $('audio.sfx')[0].play();
  404.  
  405.   // timeout to stop music at given point
  406.   setTimeout(function(){
  407.     // pause the sfx
  408.     $('audio.sfx')[0].pause();
  409.     // start the music again
  410.     $('audio.music')[0].play();
  411.     // reset the sfx
  412.     $('audio.sfx')[0].currentTime = 0;
  413.   },2000);
  414. }
  415.  
  416.  
  417. // HP BAR ANIMATION
  418. // stop and set health bar
  419. function setHP(){
  420.   // stop health animation and set value
  421.   clearInterval(defendProgressInt);
  422.   clearInterval(progressInt);
  423.   $('.stadium .enemy progress').val(gameData.enemy.hp.current);
  424.   $('.stadium .hero progress').val(gameData.hero.hp.current);
  425. }
  426.  
  427.  
  428.  
  429.  
  430.  
  431. /////////////////////////////////////////////
  432. // RESET
  433. /////////////////////////////////////////////
  434. function resetGame(){
  435.   // set default values for game variables
  436.   buildVars();
  437.  
  438.   // clear the stadium
  439.   $('.hero').empty();
  440.   $('.enemy').empty();
  441.  
  442.   // reset
  443.   $('.attack-list li').unbind('click');
  444.   $('.attack-list').empty();
  445.   $('.stadium .enemy').css({'padding':'0'});
  446.   $('.instructions p').text('Choose your hero');
  447.  
  448.   // set & start the opening game music
  449.   $('audio.music').attr('src',music["opening"]);
  450.   $('audio.music')[0].play();
  451.  
  452.   // empty characters
  453.   $('.characters').empty();
  454.   $('.characters').removeClass('hidden');
  455.  
  456.   for(var i in characters){
  457.     // build the character list
  458.     $(".characters").append('<div class="char-container"><img src="'+characters[i].img.default+'" alt="'+characters[i].name+'"><h2>'+characters[i].name+'</h2><span class="type '+characters[i].type+'"></span></div>')
  459.   }
  460.   characterChoice();
  461. }
  462. resetGame();
  463. $('.logo').click(function(){resetGame();});
  464.  
  465.  
  466.  
  467.  
  468.  
  469. /////////////////////////////////////////////
  470. // CHARACTER CHOICE
  471. /////////////////////////////////////////////
  472. function characterChoice(){
  473.   $('.characters .char-container').click(function(){
  474.     // you have chosen a character
  475.  
  476.     // your chosen character name
  477.     var name = $(this).children('h2').text().toLowerCase();
  478.  
  479.     switch(gameData.step){
  480.       // switch for the current step in the game
  481.  
  482.       case 1:
  483.         // step 1: choose your hero
  484.         for(var i in characters){
  485.           if(characters[i].name === name){
  486.             // find and save your chosen hero's data
  487.             gameData.hero = characters[i];
  488.           }
  489.         }
  490.  
  491.         // remove the character from the available list
  492.         var char = $(this).remove();
  493.         // build my hero
  494.         populateChar($('.stadium .hero'), 'hero');
  495.  
  496.         for(var i in gameData.hero.attacks){
  497.           // populate attack list
  498.           $('.attack-list').append('<li><p class="attack-name"><strong>'+gameData.hero.attacks[i].name+'</strong></p><p class="attack-count"><small><span>'+gameData.hero.attacks[i].avail.remaining+'</span>/'+gameData.hero.attacks[i].avail.total+'</small></p></li>');
  499.         }
  500.  
  501.         $('.attack-list').addClass('disabled');
  502.  
  503.         // update instructions
  504.         $('.instructions p').text('Choose your enemy');
  505.         // set health bar value
  506.         $('.stadium .hero progress').val(gameData.hero.hp.current);
  507.  
  508.         // let your hero roar
  509.         playSound(name);
  510.  
  511.         // move on to choosing an enemy
  512.         gameData.step = 2;
  513.         break;
  514.  
  515.       case 2:
  516.         // step 2: choose your enemy
  517.         for(var i in characters){
  518.           if(characters[i].name === name){
  519.             // find and save the enemy data
  520.             gameData.enemy = characters[i];
  521.           }
  522.         }
  523.  
  524.         // remove the enemy from the list
  525.         var char = $(this).remove();
  526.         // build the enemy
  527.         populateChar($('.stadium .enemy'), 'enemy');
  528.         // pad the stadium - give them some breathing room
  529.         $('.stadium .enemy').css({'padding':'25px 0'});
  530.  
  531.         // update instructions
  532.         $('.instructions p').text('Fight!!!');
  533.  
  534.         // hide the hero list
  535.         $('.characters').children().slideUp('500', function(){
  536.           $('.characters').addClass('hidden');
  537.         });
  538.  
  539.         // update enemy health bar value
  540.         $('.stadium .enemy progress').val(gameData.enemy.hp.current);
  541.  
  542.         // the enemy whimpers in fear
  543.         playSound(name);
  544.  
  545.         // update step to attack phase and bind click events
  546.         gameData.step = 3;
  547.         attackList();
  548.         break;
  549.     }
  550.   });
  551. }
  552.  
  553.  
  554.  
  555.  
  556.  
  557. /////////////////////////////////////////////
  558. // HERO ATTACK
  559. /////////////////////////////////////////////
  560. function attackEnemy(that, callback){
  561.   // attack the enemy!!!
  562.  
  563.   // name of your attack
  564.   attackName = that.children('.attack-name').children('strong').text().toLowerCase();
  565.  
  566.   for(var i in gameData.hero.attacks){
  567.     if(gameData.hero.attacks[i].name === attackName){
  568.       // get chosen attack data
  569.       curAttack = gameData.hero.attacks[i];
  570.     }
  571.   }
  572.  
  573.   // if there are attacks left
  574.   if(curAttack.avail.remaining > 0){
  575.     // attack!!!
  576.     $('.attack-list').addClass('disabled');
  577.  
  578.     $('.hero .char img').animate(
  579.       {
  580.         'margin-left': '-30px',
  581.         'margin-top': '10px'
  582.       },
  583.       50,
  584.       'swing'
  585.     );
  586.     $('.hero .char img').animate(
  587.       {
  588.         'margin-left': '30px',
  589.         'margin-top': '-10px'
  590.       },
  591.       50,
  592.       'swing'
  593.     );
  594.     $('.hero .char img').animate(
  595.       {
  596.         'margin-left': '0px',
  597.         'margin-top': '0px'
  598.       },
  599.       50,
  600.       'swing'
  601.     );
  602.  
  603.     // attack enemy
  604.     gameData.enemy.hp.current -= attackMultiplier('hero', curAttack);
  605.  
  606.     if(gameData.enemy.hp.current <= 0){
  607.       // Enemy is dead
  608.  
  609.       clearModal();
  610.     $('.modal-in header').append('<h1>You Enemy is slain</h1><span class="close">x</span>');
  611.     $('.modal-in section').append('<p>Congratulations! Dare you try again?');
  612.     $('.modal-out').slideDown('400');
  613.       modalControls();
  614.  
  615.       gameData.enemy.hp.current = 0;
  616.       // clear the stadium of the dead
  617.       $('.enemy').empty();
  618.       // show the available characters
  619.       $('.characters').removeClass('hidden');
  620.       $('.characters').children().slideDown('500');
  621.  
  622.       gameData.enemy = {};
  623.  
  624.       // choose enemy
  625.       gameData.step = 2;
  626.       // unbind click for reset
  627.       $('.attack-list li').unbind('click');
  628.     }else{
  629.       // enemy is still alive (Attack!!!)
  630.  
  631.       // subtract attack
  632.       curAttack.avail.remaining--;
  633.  
  634.       // interval to animate health bar
  635.       progressInt = setInterval(function(){
  636.         // get current value of health bar
  637.         var val = $('.stadium .enemy progress').val();
  638.         val--;
  639.  
  640.         // update health bar value
  641.         $('.stadium .enemy progress').val(val);
  642.  
  643.         if(val === gameData.enemy.hp.current){
  644.           // if you've hit your target clear interval
  645.           clearInterval(progressInt);
  646.           progressComplete = 1;
  647.         }
  648.       },1);
  649.  
  650.       // update health numbers
  651.       $('.stadium .enemy .data p span').text(gameData.enemy.hp.current);
  652.       that.children('.attack-count').children('small').children('span').text(curAttack.avail.remaining);
  653.  
  654.       // wait a second to recover
  655.       setTimeout(function(){
  656.         // now defend that attack
  657.         defend(that);
  658.       }, 1000);
  659.     }
  660.   }
  661. }
  662.  
  663.  
  664.  
  665.  
  666.  
  667. /////////////////////////////////////////////
  668. // ENEMY ATTACK (DEFEND)
  669. /////////////////////////////////////////////
  670. function defend(that){
  671.   // random attack
  672.   randInt = randomNum(gameData.enemy.attacks.length);
  673.   enemyAttack = gameData.enemy.attacks[randInt];
  674.  
  675.   // enemy attack animation sequence
  676.   $('.enemy .char img').animate(
  677.     {
  678.       'margin-right': '-30px',
  679.       'margin-top': '-10px'
  680.     },
  681.     50,
  682.     'swing'
  683.   );
  684.   $('.enemy .char img').animate(
  685.     {
  686.       'margin-right': '30px',
  687.       'margin-top': '10px'
  688.     },
  689.     50,
  690.     'swing'
  691.   );
  692.   $('.enemy .char img').animate(
  693.     {
  694.       'margin-right': '0px',
  695.       'margin-top': '0px'
  696.     },
  697.     50,
  698.     'swing'
  699.   );
  700.  
  701.   // attack the hero
  702.   gameData.hero.hp.current -= attackMultiplier('enemy', enemyAttack);
  703.  
  704.   if(gameData.hero.hp.current <= 0){
  705.     // ding dong the hero's dead
  706.  
  707.     clearModal();
  708.     $('.modal-in header').append('<h1>Your Hero has died</h1><span class="close">x</span>');
  709.     $('.modal-in section').append('<p>You lose, good day!');
  710.     $('.modal-out').slideDown('400');
  711.     modalControls()
  712.  
  713.     gameData.hero.hp.current = 0;
  714.  
  715.     resetGame();
  716.   }else{
  717.     // the hero lives
  718.  
  719.     // subtract attack from enemy count
  720.     gameData.enemy.attacks[randInt].avail.remaining--;
  721.  
  722.     // health bar animation
  723.     defendProgressInt = setInterval(function(){
  724.       // get current val of health bar
  725.       var val = $('.stadium .hero progress').val();
  726.       val--;
  727.  
  728.       // update health bar value
  729.       $('.stadium .hero progress').val(val);
  730.  
  731.       if(val === gameData.hero.hp.current){
  732.         // stop the interval when target is attained
  733.         clearInterval(defendProgressInt);
  734.         defendProgressComplete = 1;
  735.       }
  736.     },1);
  737.  
  738.     // update health value
  739.     $('.stadium .hero .data p span').text(gameData.hero.hp.current);
  740.  
  741.     setTimeout(function(){
  742.       if(defendProgressComplete && progressComplete){
  743.         $('.attack-list').removeClass('disabled');
  744.       }else{
  745.         setHP();
  746.         $('.attack-list').removeClass('disabled');
  747.       }
  748.     }, 500);
  749.   }
  750. }
  751.  
  752.  
  753.  
  754.  
  755.  
  756. /////////////////////////////////////////////
  757. // ATTACK SEQUENCE
  758. /////////////////////////////////////////////
  759. function attackList(){
  760.   // attack instantiation
  761.   $('.attack-list').removeClass('disabled');
  762.  
  763.   $('.attack-list li').click(function(){
  764.     // attack choice is clicked
  765.     var doAttack = 1;
  766.  
  767.     if(gameData.step === 3){
  768.       // attack step - start attack sequence
  769.       attackEnemy($(this));
  770.     }
  771.   });
  772.  
  773.   setTimeout(function(){
  774.     // characters chosen - set & start the battle music
  775.     $('audio.music').attr('src',music["battle"]);
  776.     $('audio.music')[0].play();
  777.   },1500);
  778. }
  779.  
  780.  
  781.  
  782.  
  783.  
  784. /////////////////////////////////////////////
  785. // MODAL
  786. /////////////////////////////////////////////
  787. function modalControls(){
  788.   $('.modal-out').click(function(){
  789.     $(this).slideUp('400');
  790.   });
  791.   $('.modal-in .close').click(function(e){
  792.     $('.modal-out').slideUp('400');
  793.   });
  794.  
  795.   $('.modal-in').click(function(e){
  796.     e.stopPropagation();
  797.     e.preventDefault();
  798.   });
  799. }
  800.  
  801. function clearModal(){
  802.   $('.modal-in header').empty();
  803.   $('.modal-in section').empty();
  804.   $('.modal-in footer').empty();
  805.   setHP();
  806. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement