www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/07/31/12:58:18

Message-ID: <33E0C441.5A32@lr.net>
Date: Thu, 31 Jul 1997 12:58:41 -0400
From: Isaac Waldron <waldroni AT lr DOT net>
Reply-To: waldroni AT lr DOT net
Organization: The Computer Nerd
MIME-Version: 1.0
To: stunajoh AT acs DOT eku DOT edu
CC: djgpp AT delorie DOT com
Subject: Re: Accessing Variables
References: <Pine DOT PMDF DOT 3 DOT 95 DOT 970730225431 DOT 630867C-100000 AT ACS DOT EKU DOT EDU>

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019