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/inventory.cpp at master · EXL/NXEngine Expand file tree/ Copy pathinventory.cppMore file actions 353 lines (286 loc) · 6.97 KB / Copy pathinventory.cppFile metadata and controls353 lines (286 loc) · 6.97 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 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 // the in-game inventory screen #include "nx.h" #include "inventory.h" #include "inventory.fdh" #define ARMS_X 10 #define ARMS_Y 8 #define ITEMS_X 10 #define ITEMS_Y 60 static stInventory inv; // can't enter Inven if // * script is running // * fade is in progress // * player is dead // param is passed as 1 when returning from Map System. bool inventory_init(int param) { memset(&inv, 0, sizeof(inv)); inv.curselector = &inv.armssel; inv.armssel.cursel = RefreshInventoryScreen(); inv.curselector->lastsel = -9999; // run the script first time // returning from map system? if (param == 1) { inv.curselector = &inv.itemsel; // highlight Map System for(int i=0;i<inv.itemsel.nitems;i++) { if (inv.itemsel.items[i] == 2) { inv.curselector->cursel = i; // textbox NOT up until they move the selector inv.curselector->lastsel = i; break; } } } return 0; } void inventory_tick(void) { // run the selectors RunSelector(inv.curselector); // draw DrawScene(); DrawInventory(); textbox.Draw(); } /* void c------------------------------() {} */ // reload which items & guns are available. // reset the cursor for the current selector. // return the slot corresponding to the current weapon. int RefreshInventoryScreen(void) { int i; int curwpn = 0; if (game.mode != GM_INVENTORY) return 0; inv.w = 244; inv.h = 152; inv.x = (SCREEN_WIDTH / 2) - (inv.w / 2); #ifndef _480X272 // 480x272 widescreen fix inv.y = 8; #else inv.y = 30; #endif // find current weapon and count # items for armssel selector inv.armssel.items[0] = 0; // show "no weapon" in case of no weapon inv.armssel.nitems = 0; for(i=1;i<WPN_COUNT;i++) { if (!player->weapons[i].hasWeapon) continue; if (player->curWeapon == i) curwpn = inv.armssel.nitems; inv.armssel.items[inv.armssel.nitems++] = i; } inv.armssel.spacing_x = 40; inv.armssel.spacing_y = 0; inv.armssel.sprite = SPR_SELECTOR_ARMS; inv.armssel.sound = SND_SWITCH_WEAPON; inv.armssel.scriptbase = 1000; inv.armssel.rowlen = inv.armssel.nitems; // setup itemsel... inv.itemsel.nitems = player->ninventory; inv.itemsel.items[0] = 0; // show "no item" in case of no items for(i=0;i<player->ninventory;i++) inv.itemsel.items[i] = player->inventory[i]; inv.itemsel.spacing_x = sprites[SPR_ITEMIMAGE].w; inv.itemsel.spacing_y = sprites[SPR_ITEMIMAGE].h + 2; inv.itemsel.sprite = SPR_SELECTOR_ITEMS; inv.itemsel.sound = SND_MENU_MOVE; inv.itemsel.rowlen = 6; inv.itemsel.scriptbase = 5000; inv.curselector->cursel = 0; // after an item has been used don't bring up the script of whatever item // the selector is moved to inv.curselector->lastsel = inv.curselector->cursel; return curwpn; } void UnlockInventoryInput(void) { if (inv.lockinput) inv.lockinput = false; } /* void c------------------------------() {} */ static void DrawInventory(void) { int x, y, w, i, c; // draw the box TextBox::DrawFrame(inv.x, inv.y, inv.w, inv.h); // - draw the weapons ---- x = inv.x + ARMS_X; y = inv.y + ARMS_Y; draw_sprite(x, y, SPR_TEXT_ARMS, 0, 0); y += sprites[SPR_TEXT_ARMS].h; DrawSelector(&inv.armssel, x, y); // draw the arms for(w=1;w<WPN_COUNT;w++) { if (!player->weapons[w].hasWeapon) continue; draw_sprite(x+1, y+1, SPR_ARMSICONS, w, 0); DrawWeaponLevel(x+1, y+16, w); DrawWeaponAmmo(x+1, y+16+8, w); x += inv.armssel.spacing_x; } // - draw the items ---- x = inv.x + ITEMS_X; y = inv.y + ITEMS_Y; draw_sprite(x, y, SPR_TEXT_ITEMS, 0, 0); y += sprites[SPR_TEXT_ITEMS].h; DrawSelector(&inv.itemsel, x, y); c = 0; for(i=0;i<inv.itemsel.nitems;i++) { draw_sprite(x, y, SPR_ITEMIMAGE, inv.itemsel.items[i], 0); x += inv.itemsel.spacing_x; if (++c >= inv.itemsel.rowlen) { x = inv.x + ITEMS_X; y += inv.itemsel.spacing_y; c = 0; } } } static void RunSelector(stSelector *selector) { int nrows; int currow, curcol; char toggle = 0; if (inv.lockinput) { if (GetCurrentScript()==-1) inv.lockinput = 0; else return; } if (selector->nitems) { nrows = (selector->nitems - 1) / selector->rowlen; currow = (selector->cursel / selector->rowlen); curcol = (selector->cursel % selector->rowlen); } else { nrows = currow = curcol = 0; } if (justpushed(LEFTKEY)) { sound(selector->sound); // at beginning of row? if (curcol == 0) { // wrap to end of row if (currow < nrows) selector->cursel += (selector->rowlen - 1); else if (selector->nitems > 0) selector->cursel = selector->nitems - 1; } else selector->cursel--; } if (justpushed(RIGHTKEY)) { sound(selector->sound); // at end of row? if (curcol==selector->rowlen-1 || selector->cursel+1 >= selector->nitems) { // wrap to beginning of row selector->cursel = (currow * selector->rowlen); } else selector->cursel++; } if (justpushed(DOWNKEY)) { // on last row? if (currow >= nrows) toggle = 1; else { selector->cursel += selector->rowlen; // don't go past last item if (selector->cursel >= selector->nitems) selector->cursel = (selector->nitems - 1); sound(selector->sound); } } if (justpushed(UPKEY)) { // on top row? if (currow == 0) toggle = 1; else { selector->cursel -= selector->rowlen; sound(selector->sound); } } // switch to other selector if (toggle) { if (selector == &inv.itemsel) { selector = &inv.armssel; } else { selector = &inv.itemsel; } inv.curselector = selector; sound(selector->sound); selector->lastsel = -9999; } // bring up scripts if (selector->cursel != selector->lastsel) { selector->lastsel = selector->cursel; StartScript(selector->items[selector->cursel] + selector->scriptbase, SP_ARMSITEM); } if (selector == &inv.armssel) // selecting a weapon { if (buttonjustpushed()) { // select the new weapon weapon_slide(LEFT, selector->items[selector->cursel]); ExitInventory(); } } else // selecting an item { if (justpushed(JUMPKEY)) { // bring up "more info" or "equip" script for this item StartScript(selector->items[selector->cursel] + selector->scriptbase + 1000, SP_ARMSITEM); inv.lockinput = 1; } if (justpushed(INVENTORYKEY) || justpushed(FIREKEY)) ExitInventory(); } } static void ExitInventory(void) { StopScripts(); game.setmode(GM_NORMAL); memset(inputs, 0, sizeof(inputs)); } static void DrawSelector(stSelector *selector, int x, int y) { int selx, sely; int xsel, ysel; if (selector == inv.curselector) { // flash the box if (++selector->animtimer > 1) { selector->animtimer = 0; selector->flashstate ^= 1; } } else { // permanently dim selector->flashstate = 1; selector->animtimer = 99; // light up immediately upon becoming active } if (selector->rowlen) { xsel = (selector->cursel % selector->rowlen); ysel = (selector->cursel / selector->rowlen); } else xsel = ysel = 0; selx = x + (xsel * selector->spacing_x); sely = y + (ysel * selector->spacing_y); draw_sprite(selx, sely, selector->sprite, selector->flashstate, 0); } |
| 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. |