GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — NXEngine/floattext.cpp at master · EXL/NXEngine Expand file tree/ Copy pathfloattext.cppMore file actions 232 lines (190 loc) · 4.34 KB / Copy pathfloattext.cppFile metadata and controls232 lines (190 loc) · 4.34 KB 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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 #include "nx.h" #include "floattext.fdh" FloatText *FloatText::first = NULL; FloatText *FloatText::last = NULL; /* void c------------------------------() {} */ FloatText::FloatText(int sprite) { prev = NULL; next = first; if (first) first->prev = this; else last = this; first = this; this->sprite = sprite; Reset(); ObjectDestroyed = false; } FloatText::~FloatText() { if (this->next) this->next->prev = this->prev; if (this->prev) this->prev->next = this->next; if (this == first) first = first->next; if (this == last) last = last->prev; } void FloatText::Reset() { this->state = FT_IDLE; this->shownAmount = 0; } /* void c------------------------------() {} */ // adds the spec'd amount of damage/energy to the object's point display void FloatText::AddQty(int amt) { //stat("FloatText::AddQty(%d)", amt); if (amt == 0) return; // first add the damage to the total if (this->state == FT_IDLE) { this->state = FT_RISE; this->shownAmount = amt; this->yoff = FT_Y_START; this->timer = 0; } else { this->shownAmount += amt; // if we're scrolling away jerk back down if (this->state == FT_SCROLL_AWAY) { this->state = FT_HOLD; this->yoff = FT_Y_HOLD; } // reset the timer which counts how long we stay in hold state if (this->state != FT_RISE) this->timer = 0; } if (this->shownAmount > 9999) this->shownAmount = 9999; // overrun protection for buffer } // updates the position of a floattext in respect to it's object void FloatText::UpdatePos(Object *assoc_object) { // get the center pixel of the object we're associated with this->objX = (assoc_object->x >> CSF) + (sprites[assoc_object->sprite].w / 2); this->objY = (assoc_object->y >> CSF) + (sprites[assoc_object->sprite].h / 2); // adjust for possible draw point SIFDir *dir = &sprites[assoc_object->sprite].frame[assoc_object->frame].dir[assoc_object->dir]; this->objX -= dir->drawpoint.x; this->objY -= dir->drawpoint.y; } // moves and draws the given float text if need be void FloatText::Draw() { FloatText *ft = this; int x, y, i; switch(ft->state) { // rise to top point, moving once every other frame case FT_RISE: { ft->timer ^= 1; if (ft->timer) { if (--ft->yoff <= FT_Y_HOLD) { ft->state = FT_HOLD; ft->timer = 0; } } } break; // hold at top for a moment case FT_HOLD: { if (++ft->timer >= 42) ft->state = FT_SCROLL_AWAY; } break; // scroll away quickly and disappear case FT_SCROLL_AWAY: { if (--ft->yoff <= FT_Y_RISEAWAY) { ft->state = FT_IDLE; ft->shownAmount = 0; ft->timer = 0; return; } } break; } // set the SDL clipping region to just above the hold point // so it looks like it "rolls" away. if (ft->state == FT_SCROLL_AWAY) { // this formula is confusing until you realize that FT_Y_HOLD is a negative number int y = ((ft->objY - (map.displayed_yscroll >> CSF)) + FT_Y_HOLD); int h = (SCREEN_HEIGHT - y); set_clip_rect(0, y, SCREEN_WIDTH, h); } // render the damage amount into a string char text[6] = { 10 }; sprintf(&text[1], "%d", ft->shownAmount); for(i=1;text[i];i++) text[i] -= '0'; int textlen = i; x = ft->objX - (textlen * (8 / 2)); // center the string on the object y = ft->objY + ft->yoff; // adjust to object's onscreen position x -= (map.displayed_xscroll >> CSF); y -= (map.displayed_yscroll >> CSF); // draw the text char by char for(i=0;i<textlen;i++) { draw_sprite(x, y, ft->sprite, text[i], 0); x += 8; } if (ft->state == FT_SCROLL_AWAY) clear_clip_rect(); } bool FloatText::IsScrollingAway() { return (this->state == FT_SCROLL_AWAY); } /* void c------------------------------() {} */ void FloatText::DrawAll(void) { FloatText *ft = first; FloatText *nextft; int count = 0; while(ft) { nextft = ft->next; if (ft->state != FT_IDLE) { ft->Draw(); } else { if (ft->ObjectDestroyed) delete ft; } ft = nextft; count++; } } // do NOT call this to remove all enemy's floattext from the map. // for one thing, it could leave dangling invalid pointers. // for another, it deletes the player->XPText, etc. // instead, call ResetAll and let them clean themselves up. void FloatText::DeleteAll(void) { while(first) delete first; } void FloatText::ResetAll(void) { FloatText *ft = first; while(ft) { ft->Reset(); ft = ft->next; } } |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |