How do I program a battle arena system?

0 favourites
  • 10 posts
From the Asset Store
Rat Arena
$100 USD
Try to defeat the enemy rat! Use magic wand, sword and shield.
  • Hi! Im working on a game for my studies and faced a problem, along the way. So...

    What Im trying to accomplish?

    A battle arena system, in which after you enter a certain zone, enemies will appear. Once youd defeat them, a second enemy wave would start. Then after that a third one etc. until all waves have been defeated

    What I tried to make it work?

    First of all, I made two global variables: Arena Wave Counter, which indicates the current wave number and Wave Enemy Counter, which indicates the number of the enemies of each wave. At the end of the corridor, that leads to the battlefield, theres an object, which when the player collides with, is supposed to launch the first wave. Around the zone, there are portals, of which each of them is supposed to spawn an enemy, one at a time, when the wave starts. To indicate when enemies of the current wave are defeated, for the next wave to start, I simply put a value at Wave Enemy Counter just before the wave group activates and that value is as much as I create or spawn enemies for that wave. The way, the value changes is that, whenever an enemys HP reaches zero, it subtracts one from the Wave Enemy Counter. Once it reaches zero, I set a value that represents the next wave, activate the group of that wave, set the number of the next waves enemies and deactivate the group of the wave I just finished. For details, I added these pics of my code.

    What went wrong?

    First of all the enemies are spawning before I touch the corridor fence, secondly for some reason, hundreads of enemies are spawning instead of the few, I told the system to be created. I dont understand at all with what logic these atrocities happened.

    So Id be really grateful for help for fixing this code, or for creating the arena system, with perhaps a completely different way.

  • Basically your logic says if ArenaWaveCounter = 1, keep creating these two enemies constantly. You need to put a trigger once condition under the ArenaWaveCounter.

    Also you've got a typo on Wave 3 there that should be ArenaWaveCounter = 3 but it says 2 so you'll need to change that to make that work properly later on.

    The spawning before you hit the activator could be several things. Something could be triggering ArenaWaveCounter to 1, maybe its 1 by default? It could be that your hero or a version of the hero off screen or something is overlapping an arena activator somewhere in the level.

  • I setted the trigger once actions and it stopped the spawning madness. Thank you! One problem solved, two more to go.

    XD I was too nervous to notice that typo until now.

    I still dont know, why the spawning happens before I hit the switch. Isnt the default value supposed to be the one showing at the beginning of my event sheet (that is 0)?

    I did notice something strange anyway. The debug layout said, that ArenaWaveCounter was already 2(???) and it really was so. The guys of the second wave waited there patiently for my arrival at their line of sight. Also hitting the activator does actually spawn the first waves enemies, but its no use, while the second is already on.

  • Yes the way to resolve an issue like that is to look at it in debug layout and see what ArenaWaveCounter is doing. Yes the default is 0 but something is setting it off. I think I see what it is now, look at event 9. WaveEnemyCounter starts at 0 right? It means that event 9 is true when you start the game. I'd throw in another variable.

  • Now I get it! It didnt even pop to my head that if the value is 0 to begin with, it affects the group instantly especially since I also didnt tell C2 to deactivate all the groups at the start. Thanks a lot!!!

    Now Ill still need to get WaveEnemyCounter to work, because killing enemies wont subtract from it for some reason. Looking for solutions will be easier now that two beasts have felled.

  • Theres still something wrong with this. So once the other issues were fixed, I faced problems with getting WaveEnemyCounter to work. Originally I had set it to the number equal to the number of the enemies, subtract 1 whenever an enemy is killed, and once it would reach to zero Id change the wave (along with its variable, ArenaWaveCounter).

    First everything seemed to be right. As I killed enemies of wave 1, the number went down (there are only 2 enemies in the first wave but still), but once it reached zero, the debug showed that WEC had turned to -1. To fix at least the problem, I decided to turn the enemy counting logic upside down, meaning that instead of setting it to a higher value and subtracting from it till zero, I would set it to zero to begin with and add to it, making the wave transition to happen when WEC is something like 2. But turning the logic upside down, did so as well for the problem I had. Now for some reason when its time for wave shift WEC becomes 1 in debug.

    It means that at the beginning of any counting situation, C2 thinks I killed an enemy, before I actually did anything. I came up with one solution. Because C2 will add that extra number anyway, I kinda fooled it By setting WEC to -1, when its time to change the wave.

    It works for now, but I dont know will I be able to lean on it in the future and will it cause problems perhaps? I still want to understand where that extra number is coming from, if some of you know the answer.

    Another problem I faced, made me question is making a system like this even possible at the end. When I kill 2 enemies at the same time, C2 counts it as only one for WEC. Killing multiple enemies at the same time is very common in this game as its built around combat and being unable to count it right breaks the whole arena system. Can I overcome this somehow?

  • The logic is flawed somewhere around the enemy hp less than or equal to 0, that is likely where the bug is happening. If you kill two at the same time because it's a trigger once event it will probably only add 1 when 2 die. I would change those hp events to 'on enemy destroyed', it'll work a lot more efficiently for you. You could even put all enemy types into a family called 'enemies' and say on family 'enemies' destroyed then you only need one event. There will always be a reason for unexpected values, wouldn't make a habit out of adjusting for bugs like you mentioned with the -1 starting value, can only lead to more issues for you as you get further on with the game.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Did you mean an "on enemy destroyed" boolean instance variable for enemies, that would be set true every time the enemy hp goes 0 and Id replace the 10th, 11th etc events conditions, with ones that say: if that boolean is set and without trigger once conditions with it?

    Because I tried that and without the trigger once conditions, the counting of WEC at one enemy kill starts to be repeated and gets messed up, but when I put the trigger onces back, it counts normally but again doesnt recognise idividuals, when killing multiple enemies at the same time.

  • Not an instance variable, there is a trigger event 'On enemy destroyed' which will action if you are destroying an enemy when hp drops to 0. They will also trigger once only by default. If you use 'On enemy destroyed' you'll find that the picking is a lot more solid and it should work in theory.

  • It seems I fully solved the problem! Along with using On destroyed to make multikilling functional, I also found out that the extra number was a result of C2 being unable to catch up with my events, it was solved by adding a "wait 0.2" action.

    Thanks for all the help Plinkie!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)