1
2 #include "Maelstrom_Globals.h"
3 #include "object.h"
4
5
6 /* The screen object class */
7
Object(int X,int Y,int Xvec,int Yvec,Blit * blit,int PhaseTime)8 Object::Object(int X, int Y, int Xvec, int Yvec, Blit *blit, int PhaseTime)
9 {
10 Points = DEFAULT_POINTS;
11
12 Set_Blit(blit);
13 if ( (phasetime=PhaseTime) != NO_PHASE_CHANGE )
14 phase = FastRandom(myblit->numFrames);
15 else
16 phase = 0;
17 nextphase = 0;
18
19 playground.left = (gScrnRect.left<<SPRITE_PRECISION);
20 playground.right = (gScrnRect.right<<SPRITE_PRECISION);
21 playground.top = (gScrnRect.top<<SPRITE_PRECISION);
22 playground.bottom = (gScrnRect.bottom<<SPRITE_PRECISION);
23
24 SetPos(X, Y);
25 xvec = Xvec;
26 yvec = Yvec;
27
28 solid = 1;
29 shootable = 1;
30 HitPoints = DEFAULT_HITS;
31 Exploding = 0;
32 Set_TTL(-1);
33 onscreen = 0;
34 ++gNumSprites;
35 }
36
~Object()37 Object::~Object()
38 {
39 //error("Object destructor called!\n");
40 --gNumSprites;
41 }
42
43 /* What happens when we have been shot up or crashed into */
44 /* Returns 1 if we die here, instead of go into explosion */
45 int
Explode(void)46 Object::Explode(void)
47 {
48 if ( Exploding )
49 return(0);
50 Exploding = 1;
51 solid = 0;
52 shootable = 0;
53 phase = 0;
54 nextphase = 0;
55 phasetime = 2;
56 xvec = yvec = 0;
57 Set_Blit(gExplosion);
58 Set_TTL(myblit->numFrames*phasetime);
59 ExplodeSound();
60 return(0);
61 }
62
63 /* Movement */
64 /* This function returns 0, or -1 if the sprite died */
65 int
Move(int Frozen)66 Object::Move(int Frozen) // This is called every timestep.
67 {
68 if ( ! Frozen )
69 SetPos(x+xvec, y+yvec);
70
71 /* Phase, but don't draw our new position */
72 Phase();
73
74 /* Does this object have a lifetime? */
75 if ( TTL && (--TTL == 0) ) { // This sprite died...
76 return(BeenTimedOut());
77 }
78 return(0);
79 }
80 void
BlitSprite(void)81 Object::BlitSprite(void)
82 {
83 screen->QueueBlit(x>>SPRITE_PRECISION, y>>SPRITE_PRECISION,
84 myblit->sprite[phase]);
85 onscreen = 1;
86 }
87 void
UnBlitSprite(void)88 Object::UnBlitSprite(void)
89 {
90 /* Only unblit if we were onscreen */
91 if ( ! onscreen )
92 return;
93
94 if ( myblit->isSmall ) {
95 screen->Clear(x>>SPRITE_PRECISION, y>>SPRITE_PRECISION, 16, 16,
96 DOCLIP);
97 } else {
98 screen->Clear(x>>SPRITE_PRECISION, y>>SPRITE_PRECISION, 32, 32,
99 DOCLIP);
100 }
101 onscreen = 0;
102 }
103
104 /* Sound functions */
105 void
HitSound(void)106 Object::HitSound(void)
107 {
108 sound->PlaySound(gSteelHit, 3);
109 }
110 void
ExplodeSound(void)111 Object::ExplodeSound(void)
112 {
113 sound->PlaySound(gExplosionSound, 3);
114 }
115
116 /* The objects!! */
117 Object *gSprites[MAX_SPRITES];
118