Mail Archives: djgpp/1998/01/24/02:02:39
In this message, I'll add '>' to the beginning of any line containing
source code from my game.
Ok, this is in TC++ for Windows, not DJGPP, but I use DJGPP as
well (for DOS games), and I thought you guys would probably be able
to help me. My problem is, I'm making a 4-player Windows RPG game,
and my Character structure is:
> struct Character
> {
> int player; // 1,2,3, or 4
> BOOL create; // TRUE if character has been created
> BOOL alive; // TRUE if character is alive
...[snipped]...
> int stamina; // stamina(health)
> char shield; // wooden, copper, steel, or none
> char armour; // leather, ringmail,chainmail, or none
> };
Soon afterwards in the game, I globally declare the players, and
some other global variables, including:
> struct Character Player1,Player2,Player3,Player4,*ptrPLAYER;
> int TempDefence=0;
> int TempDamage=0;
> int PlayerTurn=1;
I have a function which creates the characters, and it includes the
code:
> Player1.alive=TRUE;
> Player2.alive=TRUE;
> Player3.alive=TRUE;
> Player4.alive=TRUE;
Later on in the game, I have a function, for when the players fight a
monster:
> void MonsterAttacks()
> {
> // find player with least stamina(health)
> if(Player1.stamina>Player2.stamina && Player2.alive)
> {
> *ptrPLAYER=Player2;
> }
> else if(Player1.alive)
> {
> *ptrPLAYER=Player1;
> }
> else if(Player2.alive)
> {
> *ptrPLAYER=Player2;
> }
> else if(Player3.alive)
> {
> *ptrPLAYER=Player3;
> }
> else
> {
> *ptrPLAYER=Player4;
> }
> if(Player3.stamina<ptrPLAYER->stamina && Player3.alive)
> {
> *ptrPLAYER=Player3;
> }
> if(Player4.stamina<ptrPLAYER->stamina && Player4.alive)
> {
> *ptrPLAYER=Player4;
> }
> TempDefence+=ptrPLAYER->defence+ptrPLAYER->armour+ptrPLAYER->shield;
> TempDamage=CurrentMonster.damage-TempDefence;
>
> if(ptrPLAYER->player==2) // instead of these next few lines, I wrote ptrPLAYER->stamina-=TempDamage;, but
> {
> Player2.stamina-=TempDamage; // the players stamina didnt change at all, so I had to change the code to this ...
> }
> else if(ptrPLAYER->player==1)
> {
> Player1.stamina-=TempDamage;
> }
> else if(ptrPLAYER->player==3)
> {
> Player3.stamina-=TempDamage;
> }
> else if(ptrPLAYER->player==4)
> {
> Player4.stamina-=TempDamage;
> }
> TempDamage=TempDefence=0;
> if(ptrPLAYER->stamina<1)
> {
> MessageBox(GetFocus(),"One of the players has died!","Bad
> Luck",MB_OK|MB_ICONEXCLAMATION); ptrPLAYER->alive=FALSE;
> }
> return;
But the problem is... whenever I run the game, it stuffs up!
If I comment out any lines that have anything to do with the players
being alive or not (eg replacing Player1.alive==TRUE; with
// Player1.alive==TRUE;), the game works fine!
If you can help me, please do! And I apologize for sending a message
that doesnt really have anything to do with DJGPP to this mailing
list, but I thought that one of you might be able to help me.
Thanx for your time,
Richard
- Raw text -