The Daily Click ::. Forums ::. Klik Coding Help ::. Enemy generation algorithm
 

Post Reply  Post Oekaki 
 

Posted By Message

Zi-Xiao



Registered
  29/07/2002
Points
  537

VIP Member
3rd September, 2006 at 14:10:43 -

This is probably one of those simple things that gets overlooked far too often. What methods do you guys use to generate enemies in an arena type combat game where each stage features more enemies and harder enemies?

The trick of course is to strike a nice balance between randomness so that things remain unpredictable in a progressively challenging manner.

I personally assign each enemy a difficulty value. Then at the beginning of each level, I take the level number and generate a random value between 0 and the level number. If the result is higher than the difficulty value of the enemy (the level number/enemy difficulty value) instances of the enemy is created.

I find this method easy to use but far from perfect. What methods do you use?

Zi-Xiao

 
n/a

ben mercer

Possibly Insane

Registered
  11/07/2004
Points
  2538
3rd September, 2006 at 14:55:59 -

I use an algorithm in which spawn points are placed all around the map. Each time an enemy is spawned, it will appear at a randomly selected spawn point that is a little way off the screen. I keep a global value for each enemy type that dictates how many are allowed in play at a time. When you kill an enemy another one will appear after a short while somewhere else. It basically starts off with a small number of weak enemies, and as you progress, increasing numbers of increasingly difficult enemies come into play.

I find that this is a stable, yet varied way of spawning enemies. You won't face up against a super minigun mutant within the first 30 seconds of play by some small chance, but when you do start fighting the super minigun mutant you will find the number you face at a time will be steadily increasing. The fact that enemies spawn at a random position off screen means that you will start off with lots of time to breathe between firefights, but eventually you will be fighting a more or less constant flow of enemies.

 
Stuckboy

JC Denton: "I know your UNATCO killphrase: Laputan Machine."
Gunther Hermann: "I - am - not - a - machi --"
JC Denton: "Sticks and stones..."

-Vinny-



Registered
  12/01/2005
Points
  436
3rd September, 2006 at 16:39:05 -

there are various ways of doing this

say you have [b]100[/b] different enemies you could

1) generate a random number between [b]0 and 99[/b] and spawn an enemiy corresponding to that number or

2) divide the number 100 by various [b]factors[/b] of 100 (but not in the actual coding) like [b]100 / 10 = 10[/b] then you could generate 10 random numbers between 0 and 9, then add them all up

these 2 methods of generating values will give different results



 
Vinny

ben mercer

Possibly Insane

Registered
  11/07/2004
Points
  2538
3rd September, 2006 at 18:37:24 -

But what if the first enemy to spawn is the super duper plasma bazooka trooper?

That wouldn't be a very fair arena game, and despite what lots of noobs think, games must be at least a bit fair or otherwise they are frustrating rather than fun.

I was thinking on this since my last post and I had a thought. You need to be able to tell if the player is camping. You could do this by splitting map area into a few zones. Use one global value for each zone, to store a "timer" value. Whilst the player is in the zone, the timer for that zone counts up, until it reaches the "camping limit". Whilst the player is in a different zone, the timer counts down until it reaches zero. When the player has reached the camping limit, no enemies will spawn near the current zone, so the player will have to move on in order to continue scoring points. This will limit the extent to which players can exploit choke points or "bottlenecks" as they are sometimes known.

 
Stuckboy

JC Denton: "I know your UNATCO killphrase: Laputan Machine."
Gunther Hermann: "I - am - not - a - machi --"
JC Denton: "Sticks and stones..."

Zi-Xiao



Registered
  29/07/2002
Points
  537

VIP Member
3rd September, 2006 at 20:46:59 -

Well a method that would eliminate the need for spawn points altogether is to have moving spawn points.

Make them invisible and always bouncing around randomly on the screen. If you want them to stay in/out of an area just make invisible active objects and make the spawn points bounce off them.

Zi-Xiao

 
n/a

-Vinny-



Registered
  12/01/2005
Points
  436
3rd September, 2006 at 22:40:15 -

well for spawn points i guess it would really depend on what you want like whether you want enemies to spawn at doorways to give the impression that they are coming through the doors or you want the enemies to spawn just anywhere on the screen as if the teleported there, it really depends on the goal in mind

@ben: i really like the idea about camping, but i haven't had the time to think about it simply due to the fact that i have only ever released one game everyhting else that i do is just playing around with the editors whilst starting a game and never finishing (let's not get carried away with unfinish projects, we have enough of those, just focus on the main topic)

 
Vinny

Del Duio

Born in a Bowling Alley

Registered
  29/07/2005
Points
  1078

GOTW WINNER CUP 1!GOTW WINNER CUP 2!GOTW WINNER CUP 3!GOTW WINNER CUP 4!Evil klikerHasslevania 2!The OutlawSanta Boot
4th September, 2006 at 00:34:42 -

Ben, when you talk about spawning enemies at a random point on the map, are the spawn points actual objects? If so, are they all the same with a spread value or are they all named differently. (I.E: ForestGENERATOR, MountainsGENERATOR, CaveGENERATOR, etc.) The reason why I ask is the way I'm doing Necropolis Rising now works fine, but I'm starting to get serious slowdown on my 500Mhz computer. What I do is have a larger "line of sight" invisible active picture set to always surround the necro while he moves. Now there are preset, tiny invisible active pictures called "Encounter" that are all over the map- like at least 100 or so. What happens is when the line of sight overlaps an encounter box, that encounter box gets destroyed and a random enemy is created there (depending on the terrain, of course).

But because there are so many tiny enounter points on the map, the whole thing gets bogged down a lot. I was thinking of eliminating the encounter boxes altogether and make it so the enemies will randomly appear on the map section screen you're on now. the problem is that more often than not, the enemies would materialize inside a tree, or a wall, etc. There has to be someway to do it. I was thinking of a Guantlet monster generator deal, but didn't want to rip off the idea when I could be making my own system. Any ideas?

 
--

"Del Duio has received 0 trophies. Click here to see them all."

"To be a true ninja you must first pick the most stealthy of our assorted combat suits. Might I suggest the bright neon orange?"

DXF Games, coming next: Hasslevania 2- This Space for Rent!

Zi-Xiao



Registered
  29/07/2002
Points
  537

VIP Member
4th September, 2006 at 11:25:15 -

Well there's an easy way around that. Just code it so that if a monster is overlapping a tree/mountain/river when it's getting created, destroy it.

The hard way is to store all objects (essentially your entire map) in an array and then simply create monsters where your array thinks theres no objects.

Zi-Xiao

 
n/a

-Vinny-



Registered
  12/01/2005
Points
  436
4th September, 2006 at 12:36:36 -

@del: to decrease the slow down, you can simply destroy and create those encounter points by first sectioning off different parts of the level say on a 1600 x 1200 map with resolution 320 x 240 you could have 640 x 480 sections and when the player leaves one section, the encounter points of that section could be destroyed then you could create encounter points in the new section you've just entered

 
Vinny

ben mercer

Possibly Insane

Registered
  11/07/2004
Points
  2538
4th September, 2006 at 13:11:20 -

@Well a method that would eliminate the need for spawn points altogether is to have moving spawn points.

This creates more problems, like the spawn points getting stuck in rooms, or ending up in all one place.

Del, instead of having loads of spawn points, try spawning your enemies at a random location near the screen area, but test the area with an active object "detector" to make sure the area is not inside an obstacle.

 
Stuckboy

JC Denton: "I know your UNATCO killphrase: Laputan Machine."
Gunther Hermann: "I - am - not - a - machi --"
JC Denton: "Sticks and stones..."

Del Duio

Born in a Bowling Alley

Registered
  29/07/2005
Points
  1078

GOTW WINNER CUP 1!GOTW WINNER CUP 2!GOTW WINNER CUP 3!GOTW WINNER CUP 4!Evil klikerHasslevania 2!The OutlawSanta Boot
4th September, 2006 at 14:16:12 -

Good possible solutions everyone!

The main map is a large frame divided up into 8 x 8 areas of 320 x 200 each. I have some boundary detectors that follow each screen, where if an enemy is on the screen (or off the screen in another area) they can't cross the boundaries at all. This is to keep each screen separate and not have 70 monsters heading your way unknowingly!

I actually really like the moving spawn points, and it'd be really easy to do too. I could further make it so that more could inhabit the screen depending on what game area you were in. (ex. King's Forest would have a lot of knights in it and etc.)

And now that I have some good suggestions, I'll have to try them out!



 
--

"Del Duio has received 0 trophies. Click here to see them all."

"To be a true ninja you must first pick the most stealthy of our assorted combat suits. Might I suggest the bright neon orange?"

DXF Games, coming next: Hasslevania 2- This Space for Rent!

-Vinny-



Registered
  12/01/2005
Points
  436
4th September, 2006 at 17:04:08 -

oh! this just hit me, you could create moving spawn points that don't follow the frame, rather they scroll with the window that way, you don't constantly have to create and destroy objects

an even better way would be to have a counter/alterable value count to certain numbers and at those number you could place spawn points at a random point in the visible window then spawn the enemy

now you won't have your game take up too much resources with loads of actives or constantly moving actives to me the latter sounds like the best solution thus far

 
Vinny
   

Post Reply



 



Advertisement

Worth A Click