xxxxxxxxxx
146
function Battle(){
background(90,15,5);
imageMode(CORNER);
image(Plain_spr, 0, 0, width, height);
fill(255,125);
rect(0,0,width/1.5,height);
fill(0);
noStroke();
textSize(text_size);
total_text= ""
total_text += encounter.name+' HP['+encounter.hp+'/'+encounter.max_hp+'] LV['+encounter.level+']\n';
//Debug
total_text += "_____________________________________\n"
total_text += player.active_megamon.name+' HP['+player.active_megamon.hp+'/'+player.active_megamon.max_hp+'] LV['+player.active_megamon.level+'] XP['+player.active_megamon.xp+'/'+player.active_megamon.next_level+']\n';
total_text+= "\nMoves:\n";
for(let i =1; i<player.active_megamon.skills.length+1; i++){
total_text+=' ['+i+'] '+ player.active_megamon.skills[i-1].name + ', Damage(' + player.active_megamon.skills[i-1].power+'), Effect('+player.active_megamon.skills[i-1].effect+')\n';
}
total_text+='\nActions:\n';
total_text+=' [B] Ball('+player.megaball+")\n";
total_text+=' [P] Potion('+player.potion+")\n";
total_text+=' [C] Change active Megamon\n';
total_text+=' [R] Run\n';
//Total_text
text(total_text,text_size*1.5,text_size*1.5+text_size/2);
if (player.turn == false){
encounter.turn(player);
player.active_megamon.turn(player);
player.turn = true;
}
}
function battle_action(){
if (player.room == "Battle"){
// Music
if (mute == false){
if (forest_song.isPlaying()) {
forest_song.stop();
}
if (town_song.isPlaying()) {
town_song.stop();
}
if (!battle_song.isPlaying()) {
battle_song.play();
}
}
// Action
if (player.turn ==true){
if (key == 'p'){
if(player.potion>0){
if(player.active_megamon.hp<player.active_megamon.max_hp){
player.potion-=1;
recover_sd.play();
print("You use a potion on "+player.active_megamon.name);
if (player.active_megamon.max_hp - player.active_megamon.hp < potion_heal){
player.active_megamon.hp=player.active_megamon.max_hp;
print("✨ "+player.active_megamon.name+" is now at full hp.")
} else {
player.active_megamon.hp+=10;
print("✨ "+player.active_megamon.name+" get +10 hp.")
}
if(player.active_megamon.debuff[0] != null || player.active_megamon.debuff[1] != null || player.active_megamon.debuff[2] != null || player.active_megamon.debuff[3] != null){
player.active_megamon.debuff[0]=null;
print("✨ Your megamon is no longer affected by any debuff.");
}
} else {
print("✨ Your megamon hp is already full.");
}
} else {
print("Their is no potion in your inventory");
}
}
if (key == 'r'){
player.room='Forest';
let new_x = random(grid_size,width-grid_size);
new_x = (grid_size) * Math.round(new_x/grid_size);
encounter.x = new_x;
let new_y = random(grid_size,height-grid_size);
new_y = (grid_size) * Math.round(new_y/grid_size);
encounter.y = new_y;
append(megamons,encounter);
}
if (key == 'c'){
if(player.megamons.length==0){
print("🚫 "+player.active_megamon.name+" is your only megamon at the moment.");
} else {
change_sd.play();
player.active_index +=1;
if (player.megamons.length > player.active_index){
append(player.megamons,player.active_megamon);
player.active_megamon = player.megamons[player.active_index];
player.megamons.splice(player.active_index, 1);
print("🔄 "+player.active_megamon.name+" is now your active megamon");
//print(player.megamons)
} else {
player.active_index =0;
append(player.megamons,player.active_megamon);
player.active_megamon = player.megamons[player.active_index];
player.megamons.splice(player.active_index, 1);
print("🔄 "+player.active_megamon.name+" is now your active megamon");
//print(player.megamons)
}
}
}
if (key == 'b'){
if (player.megamons.length<6){
if (player.megaball>0){
change_sd.play();
player.megaball -= 1;
if(encounter.level>5 && encounter.hp > 15){
if(encounter.hp<(round(encounter.max_hp/3)+round(encounter.max_hp/encounter.level))/2){
player.console = "✨ "+encounter.name + ' was caught!';
print(player.console);
encounter.owned = true;
append(player.megamons,encounter);
player.active_index += 1;
player.room='Forest';
} else {
player.console = "🐾 "+ encounter.name + ' escaped from the megaball!';
print(player.console);
}
} else {
player.console = encounter.name + ' was caught!';
print(player.console);
encounter.owned = true;
append(player.megamons,encounter);
player.active_index += 1;
player.room='Forest';
}
} else {
print("You have no megaball left?")
}
} else {
print("You can't carry more webemon.");
}
}
// Moves
for(let i=0; i < player.active_megamon.skills.length; i++){
if (int(key)-1 == String(i)){
player.active_megamon.skills[i].use(encounter,player.active_megamon)
player.turn = false;
}
}
}
}
}