Advertisement

Making Enemies shoot bullets

Started by January 28, 2015 03:00 PM
10 comments, last by BeerNutts 10 years ago

Thanks everyone for advice. I'm going to take my time with this. Like someone said I do want it so when I implement collision its not a hassle.

megallion is obviously a beginner, so let's try and keep things simple. Lord there's no need for a 3d vector, in fact, it'd probably be better to keep it in terms of x and y velocities.

Megallion, you'll want a bullet class that contains it's can be constructed with a speed, a direction to fire, a sprite (or series of sprites with timing data if you want to do animations, which would be an animation class probably), an owner (since player bullets hurt enemies, and enemy bullets hurt players), and a damage component.

In your enemy class, you'll want to give it the refire rate to fire it's bullets (or maybe a gun type which holds that data), so, when you add an enemy to the OnScreen list, you'll start calling their update functions. In that update function, besides modifying it's position and other things, you'll check the time since it last fire a bullet. If it's been more than the LastTimeFired + RefireRate, then create a bullet and put it in the bullet list and reset that enemy's LastTimeFired member variable.

That's the basic gist of how to handle firing a bullet from an enemy.

My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

This topic is closed to new replies.

Advertisement