enemies

Started by
5 comments, last by megaman 21 years, 8 months ago
Hi I''m using VB6. How do I program my enemies to appear at random X coords at the top of the screen, then shoot my player but miss sometimes, and also come in at a random time? Any help appreciated. Thanks, -andy (megaman)
Advertisement
Ohhh boy.
How do I program my enemies to appear at random X coords
rand()

then shoot my player but miss sometimes
rand()

and also come in at a random time
rand()

edit: at least in VC, o well

[edited by - angelhart on July 26, 2002 3:58:40 PM]
The short answer is:

Any way you want

The long answer is:

It depends upon how you have structured your code and how you have organized things. There are few hard rules for writing games. The solution to your problem will be specific to the game you''re writing and your coding style. If you can be a little more specific as to how you are already positioning your enemies to begin with, how they fire, what currently determines a hit or miss, etc., then I''m sure someone can offer some ideas. I can almost guarantee your post as is won''t get you the info you''re looking for.

"Like all good things, it starts with a monkey.."
"Like all good things, it starts with a monkey.."
Well, I use the distance equation between two shapes (enemy laser and player ship) when distance = 0 then my boolean variable "hit" = true and the player lose life. If the player hit them, they die and the next enemy in the array needs to arrive.

I already figured out how to make the X coord of appearance random, but it selects a new random X untill it reaches the bottom of the window!!! I need to only get a rand X once and then keep that number untill the enemy is defeated. Hopefully this is more specific. Thanks,


-andy (megaman)
quote:Original post by megaman
Well, I use the distance equation between two shapes (enemy laser and player ship) when distance = 0 then my boolean variable "hit" = true and the player lose life. If the player hit them, they die and the next enemy in the array needs to arrive.



Every time this happens you could get a random number between 0 and, say, 8, and don''t register the hit if it equals 1. That way, the enemy would miss approximately 1 out of every 8 shots(or any other number you wanted).

If you want to make the aim extra bad, you could take the opposite approach and register a hit when the number equals 1. Either way you do it, you have control over how many times on average the enemy hits or misses.


quote:Original post by megaman

I already figured out how to make the X coord of appearance random, but it selects a new random X untill it reaches the bottom of the window!!! I need to only get a rand X once and then keep that number untill the enemy is defeated. Hopefully this is more specific.



The enemy should have its own seperate variables for things like position, health, etc.

When the new enemy is created, you should simply set its variables to whatever(random x position, y at the top of the screen, etc.), and use those variables when you process it..the random function should only be used on the enemy variables when it start/restarts, after that it should not be called..





"Like all good things, it starts with a monkey.."
"Like all good things, it starts with a monkey.."
ive said this once today and i am going to say it again.

1) get brain
2) insert brain into empty brain cavity
3) ensure proper connections
4) use brain

ways to use your brain:
a) make a remote attempt to think critically
b) think real hard like
c) apply what you know, and research what you dont know

ways to research:
a) ask your teacher or a freind
b) look in a book
c) look on MSDN
d) look on google
e) ask people on the internet to explain stuff... [insert evil dialog here]

brain, are you there, brain? brain?

This topic is closed to new replies.

Advertisement