61 RpgFollow - JcerelusDev/CanvasGameJs GitHub Wiki
What is RpgFollow ?
RpgFollow is used as an ai for enemies to follow player in a top down based game. The player can be chased or followed in 4 directions.
How to use it ?
RpgFollow(a,b,gap)
RpgFollow holds 3 arguments :
1.- the one to be chased
2.- the chaser or hunter
3.- the gap or chaser range
Example with code :
game.update = function(){
enemyChase()
}
function enemyChase(){
RpgFollow(player,enemy,120)
if(Lside){
enemy.row = 5
if(frame % 6 == 0 ){
enemy.col++
if(enemy.col > 5){
enemy.col= 3
}
}
}
else if(Rside){
enemy.row = 6
if(frame % 6 == 0 ){
enemy.col++
if(enemy.col > 5){
enemy.col= 3
}
}
}
else if(Uside){
enemy.row = 7
if(frame % 6 == 0 ){
enemy.col++
if(enemy.col > 5){
enemy.col= 3
}
}
}
else if(Dside ){
enemy.row = 4
if(frame % 6 == 0 ){
enemy.col++
if(enemy.col > 5){
enemy.col= 3
}
}
}
}