Hey all!
Im in pretty deep with the Pokemon clone, have added a bunch of new sprites to the map etc...
I am wondering, if i wanted to call different enemy monsters at random to fight, would I use a similar call function like the math.random used for selecting the monsters attacks at random?
My initial thought would be to create a secondary monster/sprite class, group all monsters that I want to be in the pool to be randomly chosen and then implement?
In my mind something similar to "const randomEnemy = monster.enemy[Math.floor(Math.random() * monster.enemy.length)]"(for which this would choose 1 defined monster at random for the battle)
Im thinking that I could make a new const in the monsters.js, maybe call 1 "hero" for emby and the other "monsters" and define them in that section.
Then call them in the "renderedSprites = [draggle, emby]" section of the code. I am guessing it would be something similar to renderedSprites = [hero, monsters]
followed by the
"const randomEnemy = monster.enemy[Math.floor(Math.random() * monster.enemy.length)]"
Hope this makes sense and any help or input is greatly appreciated.
Cheers!
Mike
I think you're on the right track. My initial thought process would be to assign a grouping of monsters to each battle zone. Based on which battle zone you're in, a monster from the battle zone's array would be chosen on random using the code you've written above:
const randomEnemy = monster.enemy[Math.floor(Math.random() * monster.enemy.length)]Plug the randomEnemy const into the battle initialization function, and I believe you should be good to go with that.
Want to participate?
Create a free Chris Courses account to begin