Mail Archives: djgpp/2001/04/17/04:59:35
Rafael Frongillo wrote:
>
One tip: try and make your code more readable.
For one thing, try to avoid tabs as indentation, it can make
code virtually unreadable in some editors (where tab = 8 spaces).
> guy::guy(int n, int xx, int yy) {
> num = n; x = xx; y = yy; w = 40, h = 51;
> speed=2, maxspeed=6, canjump = weapon = 1, hp=100;
> checkpic = check1; temp = stand;
> for (int i=0; i<WEPNUM+1; i++) ammo[i] = 0;
> for (int i=0; i<MAXMSL; i++) msls[i] = MSL();
> }
Anyway, here is your problem: lifting isn't initialized (though
you clearly stated it was).
Also, data members should be in the initializer list as much as
possible, and that the initializer list should follow the order
of the member declarations:
guy::guy(int n, int xx, int yy)
: speed(2), maxspeed(6), picn(0), jumpn(0), stopjump(0), running(0),
jumping(0), falling(0), loading(0), canjump(1), grabbing(0),
weapon(1), d(0), dead(0), mslnum(0), hp(100), lifting(0),
num(n), x(xx), y(yy), px(0), py(0), Kj(0), Kf(0), Ku(0), Kd(0),
Kd(0), Kr(0), Kl(0), w(40), h(51), checkpic(check1), temp(stand)
{
// consider 'memset (ammo, 0, sizeof (ammo));' for this
for (int i = 0; i < (WEPNUM + 1); ++i)
ammo[i] = 0;
// Consider using vector<MSL> for this; you wouldn't need
// an upper limit (MAXMSL), and this initialisation would be done
// automagically
for (int i = 0; i < MAXMSL; ++i)
msls[i] = MSL();
}
You may also want to consider using bool instead of ints for those
values that represent on/off or true/false flags (canjump seems to
be one of those), or using vector<bool> to store them (while you
then lose the ability to address them by name directly, you do
get more efficient storage (1 bit per boolean)).
--
Tim Van Holder - Falcon Software N.V.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
This message was posted using plain text. I do not endorse any
products or services that may be hyperlinked to this message.
- Raw text -