creating Enemy Bots

Started by
0 comments, last by matrisking 10 years, 12 months ago

I am a software developer but have recently learning to develop game, I know how to move a char in an applet animate it and even create bots

(basic stuff) but i fail to understand how to bring in bots randomly (like cars appearing in a racing game). All beginners tutorials I look into are about animation or keyboard/mouse interface. What and where should I look into...

Advertisement

It's tough to say without knowing a little bit more about how things are structured, but my first thought would be to do something like this:

Set a variable that represents the odds a bot should appear in a given game frame, let's say it should be 0.1%, so:

BOT_SPAWN_CHANCE = 1

Then, somewhere in your main game loop, just run pick a random number between 0 and 999, let's call it "r", and spawn a bot if r is less than the spawn chance:

if ( r < BOT_SPAWN_CHANCE )

spawn_bot()

This is a pretty basic way of doing it but maybe it will work for you.

This topic is closed to new replies.

Advertisement