Advertisement

firing rockets

Started by November 26, 2002 04:25 PM
2 comments, last by fatherjohn666 22 years, 2 months ago
how would you fire a rocket? eg: how could you call an instance of the class and not have to wait for the rocket to traverse its distance. Like still be able to fire more rockets etc,move around currently my project pauses momentarily while the rocket (which i cant see yet?? another issue for me ) traverses to its destiny vector But I want to shoot many rockets at the same time I worked out how to make it travel where im facing but how do I make it independant. I probably know how to, just need to be memory jogged I only want the class to control one rocket. I want to be able to fire a rocket, look at something else, fire it again and the new one''s data members would not have any effect on the other one which may or may not still be moving/exploding etc. I have been suggested stl''s. Anyone got some ideas for me? I have a rocket class which controls one rocket. I can visualise something with stl''s but would love some guidance. ~~~~~~~~~~~~~~~~~~~~~~~~~ http://on.to/oni
~~~~~~~~~~~~~~~~~~~~~~~~~http://on.to/oni
make a rocket/bullet very similar or the same as your basic object class. every moving thing in your game should at least have it''s own position/velocity/acceleration vectors. when you "fire" a gun/rocket you just call your game engines addBullet or addObject methods. then have those methods push a new object onto the dynamic objects stack/vector.

all alive/active objects get their position/velocity/acceleration updated every frame.

it seems like you have some basic architectural problem with your game if you have to pause the game to move the rocket to it''s destination befor eyou can move anything else.

the important thing is to have a vector of objects (or some similar data structure) in your engine class (or as an engine global var if your coding procedural style). all dynamic (aka moving) objects in your game should contained by that vector and removed when they die/explode. every time you want to add a new object/bullet to the game you call an engine function which adds the object to your engine''s vector. that way the engine is aware of it.

then your main game loop will look vaguely something like:


  //OO versionwhile (1) {  if (engine.isEndOfGame())     break;  float dT = getTimeSinceLastLoop();  AISystem.update(dT);  PlayerControlSystem.update(dT);  engine.update(dT);  engine.draw(dT);}//procedural versionwhile (1) {  if (GameEngine::isEndOfGame())     break;  float dT = getTimeSinceLastLoop();  AISystem::update(dT);  PlayerControlSystem::update(dT);  GameEngine::update(dT);  GameEngine::draw(dT);}  


typically the engine.update() method will execute all your physics of motion equations or whatever method you have settled upon to update the positions of your game objects.

i hope i''ve helped more than i''ve confused

-me
Advertisement
quote:

while (1) {
if (GameEngine::isEndOfGame())
break;



Also known as
while (!GameEngine::isEndOfGame()) {




[edited by - alvaro on November 26, 2002 5:46:51 PM]
quote:
Original post by alvaro
Also known as
while (!GameEngine::isEndOfGame()) {



heh, nice catch. i was going back and editing the pseudo algorithm with very little thought....

[runs to get more coffee before brain _compeletely_ dies]

-me

This topic is closed to new replies.

Advertisement