3 #include "floattext.fdh"
5 FloatText
*FloatText::first
= NULL
;
6 FloatText
*FloatText::last
= NULL
;
9 void c------------------------------() {}
12 FloatText::FloatText(int sprite
)
23 this->sprite
= sprite
;
26 ObjectDestroyed
= false;
29 FloatText::~FloatText()
31 if (this->next
) this->next
->prev
= this->prev
;
32 if (this->prev
) this->prev
->next
= this->next
;
34 if (this == first
) first
= first
->next
;
35 if (this == last
) last
= last
->prev
;
38 void FloatText::Reset()
40 this->state
= FT_IDLE
;
41 this->shownAmount
= 0;
45 void c------------------------------() {}
48 // adds the spec'd amount of damage/energy to the object's point display
49 void FloatText::AddQty(int amt
)
51 //stat("FloatText::AddQty(%d)", amt);
54 // first add the damage to the total
55 if (this->state
== FT_IDLE
)
57 this->state
= FT_RISE
;
59 this->shownAmount
= amt
;
60 this->yoff
= FT_Y_START
;
65 this->shownAmount
+= amt
;
67 // if we're scrolling away jerk back down
68 if (this->state
== FT_SCROLL_AWAY
)
70 this->state
= FT_HOLD
;
71 this->yoff
= FT_Y_HOLD
;
74 // reset the timer which counts how long we stay in hold state
75 if (this->state
!= FT_RISE
)
79 if (this->shownAmount
> 9999)
80 this->shownAmount
= 9999; // overrun protection for buffer
83 // updates the position of a floattext in respect to it's object
84 void FloatText::UpdatePos(Object
*assoc_object
)
86 // get the center pixel of the object we're associated with
87 this->objX
= (assoc_object
->x
>> CSF
) + (sprites
[assoc_object
->sprite
].w
/ 2);
88 this->objY
= (assoc_object
->y
>> CSF
) + (sprites
[assoc_object
->sprite
].h
/ 2);
90 // adjust for possible draw point
91 SIFDir
*dir
= &sprites
[assoc_object
->sprite
].frame
[assoc_object
->frame
].dir
[assoc_object
->dir
];
92 this->objX
-= dir
->drawpoint
.x
;
93 this->objY
-= dir
->drawpoint
.y
;
97 // moves and draws the given float text if need be
98 void FloatText::Draw()
100 FloatText
*ft
= this;
105 // rise to top point, moving once every other frame
111 if (--ft
->yoff
<= FT_Y_HOLD
)
120 // hold at top for a moment
123 if (++ft
->timer
>= 42)
124 ft
->state
= FT_SCROLL_AWAY
;
128 // scroll away quickly and disappear
131 if (--ft
->yoff
<= FT_Y_RISEAWAY
)
142 // set the SDL clipping region to just above the hold point
143 // so it looks like it "rolls" away.
144 if (ft
->state
== FT_SCROLL_AWAY
)
146 // this formula is confusing until you realize that FT_Y_HOLD is a negative number
147 int y
= ((ft
->objY
- (map
.displayed_yscroll
>> CSF
)) + FT_Y_HOLD
);
148 int h
= (SCREEN_HEIGHT
- y
);
150 set_clip_rect(0, y
, SCREEN_WIDTH
, h
);
153 // render the damage amount into a string
154 char text
[6] = { 10 };
155 sprintf(&text
[1], "%d", ft
->shownAmount
);
156 for(i
=1;text
[i
];i
++) text
[i
] -= '0';
159 x
= ft
->objX
- (textlen
* (8 / 2)); // center the string on the object
160 y
= ft
->objY
+ ft
->yoff
;
161 // adjust to object's onscreen position
162 x
-= (map
.displayed_xscroll
>> CSF
);
163 y
-= (map
.displayed_yscroll
>> CSF
);
165 // draw the text char by char
166 for(i
=0;i
<textlen
;i
++)
168 draw_sprite(x
, y
, ft
->sprite
, text
[i
], 0);
172 if (ft
->state
== FT_SCROLL_AWAY
)
176 bool FloatText::IsScrollingAway()
178 return (this->state
== FT_SCROLL_AWAY
);
182 void c------------------------------() {}
185 void FloatText::DrawAll(void)
187 FloatText
*ft
= first
;
195 if (ft
->state
!= FT_IDLE
)
201 if (ft
->ObjectDestroyed
)
210 // do NOT call this to remove all enemy's floattext from the map.
211 // for one thing, it could leave dangling invalid pointers.
212 // for another, it deletes the player->XPText, etc.
213 // instead, call ResetAll and let them clean themselves up.
214 void FloatText::DeleteAll(void)
220 void FloatText::ResetAll(void)
222 FloatText
*ft
= first
;