File: bullettype.cpp

package info (click to toggle)
wing 0.7-33
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,744 kB
  • sloc: cpp: 2,526; sh: 65; makefile: 16
file content (110 lines) | stat: -rw-r--r-- 3,656 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include "bullettype.h"

//***************************************************************************
BulletTYPE :: BulletTYPE ( )
: myBullets    ( NULL ),
  myNumBullets ( 0 ),
  myBulletImages ( )
{ }
//***************************************************************************
BulletTYPE :: BulletTYPE ( char * fileName )
: myBullets    ( NULL ),
  myNumBullets ( 0 )
{
	myBulletImages.LoadImages ( fileName );
}
//***************************************************************************
BulletTYPE :: ~BulletTYPE ()
{
	BulletNodeTYPE *temp;
	while ( myBullets != NULL )
   {
   	temp = myBullets;
      myBullets = myBullets->next;
      delete temp;
   }
}
//***************************************************************************
bool BulletTYPE :: Fire ( int xcoord, int ycoord, WeaponEnum new_weapon )
{
	return Fire ( xcoord,ycoord, XBulletVelocities [new_weapon], YBulletVelocities [new_weapon],new_weapon);
}
//***************************************************************************
bool BulletTYPE ::  Fire  ( int xcoord, int ycoord, int dx, int dy, WeaponEnum new_weapon )
{
	if ( myNumBullets < MAX_NUM_BULLETS )
   {
   	myNumBullets++;
		BulletNodeTYPE *NewShot = new BulletNodeTYPE;
	   NewShot->xPos = xcoord +35/2;
	   NewShot->yPos = ycoord + 5;
	   NewShot->visible = true;
	   NewShot->dx = dx;
	   NewShot->dy = dy;
      NewShot->weapon = new_weapon;
	 	NewShot->next = myBullets;
	   myBullets = NewShot;
      return true;
   }
   return false;
}
//***************************************************************************
void BulletTYPE :: UpdateAndDisplayShot (BITMAP * buffer)
{
	// we are putting the display with update because they are always called
   // together and we only want to go traverse the list once, speed wins out
   BulletNodeTYPE *current = myBullets;
   BulletNodeTYPE *previous = NULL;
   BulletNodeTYPE *DeleteNode = NULL;

	while ( current != NULL )
   {
    	current->yPos -= current->dy;
    	current->xPos -= current->dx;
      if ( current->yPos <= 0 || current->yPos >= SCREEN_HEIGHT)      // if the bullet goes off-screen delete it
      {
       	DeleteNode = current;
         current = current->next;
         if ( myBullets == DeleteNode )
				myBullets = DeleteNode->next;
         else
            previous->next = DeleteNode->next;
         myNumBullets--;
         delete DeleteNode;
      }
      else
      {
        if ( current->visible )
	        draw_sprite (buffer, myBulletImages.GetImage(current->weapon), current->xPos, current->yPos);
        previous = current;
        current = current->next;
      }
   }
}
//**************************************************************************
void BulletTYPE :: LoadWeapon ( const char * fileName )
{
	myBulletImages.LoadImages ( fileName );
   myBulletMask.resize ( myBulletImages.Length() );
   init_sp_bb ( myBulletMask );

   for ( int i = 0; i < myBulletMask.length(); i++ )
	   mk_spr_mask (myBulletImages.GetImage(i), myBulletMask[i] );

}
//**************************************************************************
BulletNodeTYPE * BulletTYPE :: GetBulletList   (  )
{
	return myBullets;
}
//**************************************************************************
BITMAP  * BulletTYPE :: GetImage ( int index )
{
	return myBulletImages.GetImage ( index );
}
//**************************************************************************
spr_mask * BulletTYPE :: GetMask ( int index )
{
   return (&myBulletMask[index]);
}
//**************************************************************************