Enemy Spawning

For questions about using Classic.

Post » Tue Apr 13, 2010 9:44 pm

I'm creating a game and I've run into a problem. In my game, there is supposed to be a maximum of five enemies all at once. However, that is not the case. I have the computer spawn a sprite that is either an enemy pistol-man or an enemy shotgun determined by a random (1 or 2) global variable. Then, depending on which number is chosen, the computer spawns the enemy sprite when one sprite is killed. The problem is that the computer will actually spawn more than one sprite(I think, either that or randomly creating sprites which it shouldn't since I have it set up as a condition connected to another condition). Any ideas on why this is happening? Thanks in advance.

P.S. Not sure how to post a .cap. Will do so if told how to. Thanks

Edit: Here's the cap
http://www.box.net/shared/pxlm0v85xi
It's only my second game, so the events are a little all over the place. :D

Edit 2: Just remembered that I don't mention the controls in the game. They are:
Arrow-directions
Left Click- shoot
Right Click- run
Control- switch weapon
B
2
G
2
Posts: 48
Reputation: 746

Post » Tue Apr 13, 2010 9:55 pm

Sounds like a simple mistake in your events. You can upload a .cap to a site like box.net and post the link here.
B
2
S
2
G
2
Posts: 372
Reputation: 1,794

Post » Wed Apr 14, 2010 1:11 am

Hi. There is a simple error in your testing of the global variable:

+ orange_pistol_enemy2: Value 'Hit Count' Less or equal 0
-> orange_pistol_enemy2: Destroy
-> System: Set global variable 'enemy_choice' to random(2)
-> player: Add 1 to 'Score'
...
+ System: global('enemy_choice') Equal to 1
-> System: Create object orange_pistol_enemy2 on layer 1 at (random(3000), random(3000))
+ System: global('enemy_choice') Lower or equal 1
-> System: Create object green_shotgun_enemy on layer 1 at (random (3000), random(3000))
-> green_shotgun_enemy: Set speed to 200

Random(2) will result in either zero or one. If it's zero, you'll get a shotgun enemy. if it's one, you'll get both enemies, because both are true on one.

So, Lower or equal 1 should be Equal to 0, or possibly Lower than 1. In this case, I'd favor direct equality testing with Equal to 0.
B
3
S
2
G
2
Posts: 187
Reputation: 1,449

Post » Wed Apr 14, 2010 1:49 am

Thanks Mr. Wolf and Silent Cacophony. I learned two new things today. :) How to post a .cap and that random two will pick 0 or 1. Thanks a lot. :)
B
2
G
2
Posts: 48
Reputation: 746


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 4 guests