script.js
// attack function (player only ATM)
attack function (player only ATM)
attack function ( player only ATM )
function swingSword(){
        var minion_x = 0; 
        var minion_y = 0; 
        var boss_x = parseInt(boss_details[2]);
        var boss_y = parseInt(boss_details[3]);
        for (var i = 0; i < pos_list.length; i+=2) {
            minion_x = pos_list[i];
            minion_y = pos_list[i+1];
            if(player_x+20===minion_x-20 || player_x+10===minion_x-10 &&
                minion_y-10< player_y >minion_y+10){
                if(i!==0) {
                    health_list[i-1] = health_list[i-1] - player_attack_power;
                    addXP("sword_swing");
                }else if(i === 0){
                    health_list[0] = health_list[0] - player_attack_power;
                    addXP("minion_dead");
                }
                if(health_list[i-1]<=0 || health_list[0]<= 0){
                    if(i!==0) {
                        names_list[i-1] = "DEAD";
                    }else if(i === 0){
                        names_list[0] = "DEAD";
                    }
                    minions_killed++;
                    addXP("minion_dead");
                }
                var rand_drop = Math.floor((Math.random() * player_defence_max) + 1);
                if(rand_drop===2){
                    dropItem(2);
                }
                break;
            }
        }
        if(player_x+20===boss_x-20 || player_x+10===boss_x-10 &&
            boss_y-10< player_y >boss_y+10){
           boss_details[1] = boss_details[1] - player_attack_power;
            if(boss_details[1]<=0 || boss_details[1]<= 0){
                addXP("boss_dead");
                boss_details[0] = "DEAD";
                boss_alive = false;
                draw_doors = false;
                dropItem(2);
                rand = Math.floor((Math.random() * player_defence_current) + 1);
                if(rand === 5){
                    dropBossItem(1);
                }else{
                    dropBossItem(0);
                }
            }
        }
        var rand = Math.floor((Math.random() * player_defence_current) + 1);
        if(rand === 5 || rand === 3){
            strikeBack();
        }
        sword_swings++;
        updatePotions();
        draw();
    }
function swingSword ( ) { var minion_x = 0 ; var minion_y = 0 ; var boss_x = parseInt ( boss_details [ 2 ] ) ; var boss_y = parseInt ( boss_details [ 3 ] ) ; for ( var i = 0 ; i < pos_list . length ; i += 2 ) { minion_x = pos_list [ i ] ; minion_y = pos_list [ i + 1 ] ; if ( player_x + 20 === minion_x - 20 || player_x + 10 === minion_x - 10 && minion_y - 10 < player_y > minion_y + 10 ) { if ( i !== 0 ) { health_list [ i - 1 ] = health_list [ i - 1 ] - player_attack_power ; addXP ( "sword_swing" ) ; } else if ( i === 0 ) { health_list [ 0 ] = health_list [ 0 ] - player_attack_power ; addXP ( "minion_dead" ) ; } if ( health_list [ i - 1 ] <= 0 || health_list [ 0 ] <= 0 ) { if ( i !== 0 ) { names_list [ i - 1 ] = "DEAD" ; } else if ( i === 0 ) { names_list [ 0 ] = "DEAD" ; } minions_killed ++ ; addXP ( "minion_dead" ) ; } var rand_drop = Math . floor ( ( Math . random ( ) * player_defence_max ) + 1 ) ; if ( rand_drop === 2 ) { dropItem ( 2 ) ; } break ; } } if ( player_x + 20 === boss_x - 20 || player_x + 10 === boss_x - 10 && boss_y - 10 < player_y > boss_y + 10 ) { boss_details [ 1 ] = boss_details [ 1 ] - player_attack_power ; if ( boss_details [ 1 ] <= 0 || boss_details [ 1 ] <= 0 ) { addXP ( "boss_dead" ) ; boss_details [ 0 ] = "DEAD" ; boss_alive = false ; draw_doors = false ; dropItem ( 2 ) ; rand = Math . floor ( ( Math . random ( ) * player_defence_current ) + 1 ) ; if ( rand === 5 ) { dropBossItem ( 1 ) ; } else { dropBossItem ( 0 ) ; } } } var rand = Math . floor ( ( Math . random ( ) * player_defence_current ) + 1 ) ; if ( rand === 5 || rand === 3 ) { strikeBack ( ) ; } sword_swings ++ ; updatePotions ( ) ; draw ( ) ; }
attack function (player only ATM)
attack function ( player only ATM )
// check if the player was close to a minion // comparison value // comparison value // pull the boss details too // go through all elements in the pos array (Minion check) // set the values // the minion is to the right of the player // in good sword swinging distance // decrease the health of the minion // update the XP // update the XP // Minion dead (yay) // increment the counter // update the XP // roll the dice on the item drop // Lucky, drop item // Check if swinging at Boss // the boss is to the right of the player // in good sword swinging distance // decrease the health of the boss // Boss dead (yay) // update the XP // rename the boss // adjust variable // open the doors // drop an item // drop a gear upgrade, maybe... // lucky, drop item // unlucky, that happens too // strike the player back, maybe... // unlucky, strike back // update the swing counter // update the potion UI // Finally call draw again, to show the damage