more HUD API and air indicator
[dd2d.git] / data / scripts / d2dhud.dacs
blobb0214fb2e172970a1d9c9f5baa67940c7a3fd188
1 /* DooM2D: Midnight on the Firing Line
2  * coded by Ketmar // Invisible Vector <ketmar@ketmar.no-ip.org>
3  * Understanding is not required. Only obedience.
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 module d2dhud is "engine" "hud";
20 import apiActor;
21 import apiMap;
22 import apiMove;
23 import apiHud;
24 import stdlib;
26 import d2dplayer; // for some actor fields
29 const KeyFrameBase = 0;
32 // precache sprites
34 public void initializeAnim () {
35   animClearFrames("engine", "hud", "sleep");
36   // keys
37   animAddFrame("engine", "hud", "sleep", ACTOR_DIR_LEFT, "sprites/items/keyra0.vga");
38   animAddFrame("engine", "hud", "sleep", ACTOR_DIR_LEFT, "sprites/items/keyga0.vga");
39   animAddFrame("engine", "hud", "sleep", ACTOR_DIR_LEFT, "sprites/items/keyba0.vga");
44 public void drawHud () {
45   auto pl = getPlayerActor(1);
46   //writeln("pl.classname: ", pl.classname);
47   if (pl.dead || !pl.isPlayer) return;
48   // draw keys
49   // WARNING: keep in sync with INV_ITEM_KEY_xxx
50   //writeln("HUD");
51   int vw = viewportWidth;
52   int vh = viewportHeight;
53   auto inv = pl.invitems;
54   for (int kn = 0; kn < 3; ++kn) {
55     if (inv&(1<<kn)) {
56       string spn;
57       switch (kn) {
58         case 0: spn = "sprites/items/keyra0.vga"; break;
59         case 1: spn = "sprites/items/keyga0.vga"; break;
60         case 2: spn = "sprites/items/keyba0.vga"; break;
61         default: continue; // just in case
62       }
63       //drawSpriteAtNoOfs(spn, 4+kn*(spriteWidth(spn)+1), vh/*-spriteHeight(spn)*/-4);
64       drawSpriteAtNoOfs(spn, 10+kn*(spriteWidth(spn)+1), 20+spriteHeight(spn));
65     }
66   }
67   // draw air
68   int air = pl.air;
69   if ((air&PL_AIR_NOTUW_BIT) == 0) {
70     air &= PL_AIR_MASK;
71     drawRectRGBA(4+0, 32+0, PL_AQUA_AIR/4+4, 12, 255, 127, 0, 100);
72     drawRectRGBA(4+1, 32+1, PL_AQUA_AIR/4+2, 12-2, 0, 0, 0, 255);
73     drawRectRGBA(4+2, 32+2, air/4, 12-4, 0, 0, 255, 255);
74   }
75   /*
76   {
77     string spn = "sprites/items/keyra0.vga";
78     drawSpriteAt(spn, 4, viewportHeight-4);
79   }
80   */
81   /+
82   drawText("Small text", 100, 80, 0, 255, 0);
83   //drawText("Small text", 100, 80, 255, 255, 255, 255);
84   drawTextBig("BiG TeXT", 100, 100);
85   drawTextBig("BiG TeXT no 2", 100, 140, 255, 127, 0, 128);
86   +/