Spawning Enemies Question

Make games! Discuss those games here.

Moderators: Bob the Hamster, marionline, SDHawk

Post Reply
User avatar
Meatballsub
Liquid Metal Slime
Posts: 996
Joined: Mon Oct 15, 2007 6:39 pm
Location: Northwest Georgia
Contact:

Spawning Enemies Question

Post by Meatballsub »

I have a script that spawns an enemy in a random place on the map. It also check walls and recreates an npc if necessary.

It works fine but right now it will only spawn enemies in places that are touching absolutely no walls. I'd like to allow them to spawn anywhere except for when they are completely walled in on all four side, but am unsure how to write that.

Here's my current script. Any suggestions are much appreciated:

Code: Select all

		powerx := random(1,15)
		powery := random (1,9)
		create npc (20,powerx,powery)
		alter NPC (20,NPCstat:move type,npcmovetype:pace)
		alter npc (20,NPCstat:picture,5)
		while (check npc wall (20,north) ,or, check npc wall (20,south) ,or, check npc wall (20,east) ,or, check npc wall (20,west)) do (
			destroy npc (20)
			powerx := random(1,15)
			powery := random (1,9)
			create npc (20,powerx,powery)
			alter NPC (20,NPCstat:move type,npcmovetype:pace)
			alter npc (20,NPCstat:picture,5)
)
Last edited by Meatballsub on Mon Jan 18, 2010 8:05 pm, edited 2 times in total.
User avatar
Mogri
Super Slime
Posts: 4598
Joined: Mon Oct 15, 2007 6:38 pm
Location: Austin, TX
Contact:

Post by Mogri »

If you want any square that does not have all four walls to be legal, all you have to do is this:

Code: Select all

while &#40;read pass block&#40;powerx, powery&#41; <> &#40;north wall + south wall + east wall + west wall&#41;&#41; do &#40;
If you want to verify that the NPC isn't walled in, period, I really suggest using one of the vehicle pass bits to mark unusable tiles.
User avatar
Meatballsub
Liquid Metal Slime
Posts: 996
Joined: Mon Oct 15, 2007 6:39 pm
Location: Northwest Georgia
Contact:

Post by Meatballsub »

Nice, it's working great.

The only other question I have is whether these "spawns" can spawn on top of other npcs or the hero. I haven't seen either occur, but I assume that they can spawn at least on top of the hero. Any way to prevent that, if neccessary?
User avatar
Mogri
Super Slime
Posts: 4598
Joined: Mon Oct 15, 2007 6:38 pm
Location: Austin, TX
Contact:

Post by Mogri »

NPCs: Check npc at spot, easy.

Heroes: Iterate through the heroes and verify that (powerx == herox(who) && powery == heroy(who)) == false for each one.
Post Reply