Mail Archives: djgpp/1997/07/31/12:58:18
stunajoh AT ACS DOT EKU DOT EDU wrote:
>
> On Wed, 30 Jul 1997, Isaac Waldron wrote:
>
> > Does anyone know if it is possible to create a variable in a function,
> > and then access it outside of that function. For instance, I have
> > classes Ship and Shot, can I use code like this:
> >
> It seems to me that what you want could be accomplished having a pointer
> to a shot in ship, and in the Fire() function have it create a new shot
> gun (on the heap) if it hasn't been created yet (sort of like in your
> ship::update(), but use the new operator instead. ). However, unless you
> call this pointer a static, you
> will need to reference it by gun::pFirst->Update() (I'm pretty sure that
> it has to be this way. I do know that this at least works.). In
> the
> default(non-static), you will have a pointer and an instance of Shot for
> each instance of Ship. However, if this pointer is static, there will be
> only one instance for the entire class Ship, no matter how many instance
> variables( at least the way you plan to set it up ). Maybe I missed the
> point entirely on what you were asking, and
> maybe this doesn't apply to you. Just trying to help. Also, remember to
> delete your instance(s) of Shot, probably in the destructor of Ship.
>
> >[code snipped]
> >
> > Basically, I need to know if a variable constructed in a function can be
> > made to not be destructed at the end of that function, and have it
> > visible globally? If not, does anyone know how to make a linked list of
> > objects so I can have more than one object of any one type on screen at
> > one time?
> >
> > thanks in advance,
> > --
> > -Begin Signature-
> > Isaac Waldron <waldroni AT lr DOT net> N1YZI
> > http://www.geocities.com/SiliconValley/Lakes/5703/home.html
> > -End Signature-
> >
I'm sorry, that last mail wasn't clear at all. What I want to do is be
able to have many objects on screen at once, and be able to have them
move around all at once. I basically need to multi-thread. In my
previous games, if you shot at something, the whole shot would get
handled before anything was able to move. I want the enemies to have a
chance at getting out of the way before the shot hit them.
code for old games:
void Fire()
{
int x;
for (x = 0; x < 320; x++)
{
PutPixel(x, y (of ship), <a color>);
if (x = <enemies_x>)
{
delete enemy;
score++;
return;
};
};
using this code, nothing on screen could move until the shot either hit
the enemy or the end of the screen. This was VERY unfair.
Thanks again,
--
-Begin Signature-
Isaac Waldron <waldroni AT lr DOT net> N1YZI
http://www.geocities.com/SiliconValley/Lakes/5703/home.html
-End Signature-
- Raw text -