Mar 16, 2024


So, today's goal was to finally work on a random encounter system.  This actually turned out to be much easier than I thought it would be.  I'm assuming this is because of GB Studio itself.  I'd imagine this probably would've been a huge PITA back in the day (as was all gb dev probably).  

I had previously worked on the battleUI scene.  This scene would have a switch statement that basically loads a sprite based on a numeric value.  So if I want an area to have 3 possible enemies spawn in it, when that scene loads, I set the 'nextEnemyType' variable to randomly populate as 1, 2, or 3.  I have corresponding enemy sprites named 1.png, 2.png, and 3.png.  That preps the scene for the next enemy you encounter on it.

The next step is essentially figuring out WHEN to enter a battle.  To do this, I needed 2 variables.  I created a variable for counting the number of steps since my last encounter and a variable with a random number.  So my thinking was that I want players to go a maximum of 15 "steps" between battles.  So $stepCounter will increment on each step and be reset to 0 after each encounter or scene change.  $randomEncounter will receive a number between 1 and 15 with each step and will also be reset to 0 after each encounter or scene change.

Each "step" is considered a press of any direction on the dpad.  I use step in quotes because even if you tap it once to change directions, it counts that as a step.  To fix, I want to populate the player's xy coordinates before calling the script vs the player's xy coordinate when it triggers on dpad press; however, I was not seeing a reference to player position when editing the script.  I know I can do it, but am just not feeling it right now.  






Files

tower-of-meowgic.zip Play in browser
Mar 16, 2024
Tower-of-Meowgic.gb 128 kB
Mar 16, 2024

Get Tower of Meowgic

Comments

Log in with itch.io to leave a comment.

(+1)

Great tutorial! Worked really well for me. Thank you.

I know you commented over on reddit thanking me(I think it was you!), but i just saw this comment here.  I'm just glad that while I learn things here that others can benefit as well.  There's probably better and more efficient ways to do the things I've done, but I'm glad to know my way works for others!

(+1)

Yes, it was me. I have been struggling to find efficient ways to do the same thing and spent too much time playing with triggers. This ended up working perfectly for me. Now, if there ever comes a time where I feel like it can be adjusted or improved on, I will be sure to share it here.