DEADSOFTWARE

c55e143ed92fba001467dbe7a596109d97028ce9
[d2df-sdl.git] / src / game / opengl / r_monsters.pas
1 (* Copyright (C) Doom 2D: Forever Developers
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 *)
15 {$INCLUDE ../../shared/a_modes.inc}
16 unit r_monsters;
18 interface
20 procedure r_Monsters_Draw;
21 procedure r_Monsters_DrawHealth;
23 implementation
25 uses
26 SysUtils, Classes, Math,
27 r_graphics, g_options, r_animations,
28 MAPDEF,
29 g_base, g_basic, g_game, g_phys,
30 g_monsters
31 ;
33 procedure r_Monsters_Draw (constref monster: TMonster);
34 var m: TMirrorType; dx, dy, c, fX, fY: Integer; o: TObj;
35 begin
36 with monster do
37 begin
38 //e_CharFont_Print(gMenuSmallFont, Obj.X + Obj.Rect.X, Obj.Y + Obj.Rect.Y, 'TYPE: ' + IntToStr(MonsterType));
39 //e_CharFont_Print(gMenuSmallFont, Obj.X + Obj.Rect.X, Obj.Y + Obj.Rect.Y + 16, 'STATE: ' + IntToStr(MonsterState));
41 Obj.lerp(gLerpFactor, fX, fY);
43 // Если колдун стреляет, то рисуем огонь:
44 if MonsterType = MONSTER_VILE then
45 if MonsterState = MONSTATE_SHOOT then
46 if GetPos(MonsterTargetUID, @o) then
47 r_Animation_Draw(VileFireAnim, o.X + o.Rect.X + (o.Rect.Width div 2) - 32, o.Y + o.Rect.Y + o.Rect.Height - 128, TMirrorType.None);
49 // Не в области рисования не ресуем:
50 //FIXME!
51 if (g_dbg_scale = 1.0) then
52 begin
53 if not g_Collide(Obj.X + Obj.Rect.X, Obj.Y + Obj.Rect.Y, Obj.Rect.Width, Obj.Rect.Height, sX - 128, sY - 128, sWidth + 256, sHeight + 256) then
54 Exit;
55 end;
57 // Эти монстры, умирая, не оставляют трупов:
58 if MonsterState = MONSTATE_DEAD then
59 case MonsterType of
60 MONSTER_BARREL, MONSTER_SOUL, MONSTER_PAIN: Exit;
61 end;
63 // Есть что рисовать при текущем поведении:
64 if DirAnim[MonsterAnim, GameDirection] <> nil then
65 begin
66 // Если нет левой анимации или она совпадает с правой => отражаем правую:
67 if (GameDirection = TDirection.D_LEFT) and ((not MONSTER_ANIMTABLE[MonsterType].LeftAnim) or (DirAnim[MonsterAnim, TDirection.D_LEFT].FramesID = DirAnim[MonsterAnim, TDirection.D_RIGHT].FramesID)) and (MonsterType <> MONSTER_BARREL) then
68 m := TMirrorType.Horizontal
69 else
70 m := TMirrorType.None;
72 // Левая анимация => меняем смещение относительно центра:
73 if (GameDirection = TDirection.D_LEFT) and (MonsterType <> MONSTER_BARREL) then
74 begin
75 dx := MONSTER_ANIMTABLE[MonsterType].AnimDeltaLeft[MonsterAnim].X;
76 dy := MONSTER_ANIMTABLE[MonsterType].AnimDeltaLeft[MonsterAnim].Y;
78 if m = TMirrorType.Horizontal then
79 begin
80 // Нет отдельной левой анимации
81 // Расстояние от края текстуры до края визуального положения объекта на текстуре:
82 c := (MONSTERTABLE[MonsterType].Rect.X - dx) + MONSTERTABLE[MonsterType].Rect.Width;
83 // Расстояние от края хит бокса до края визуального положения объекта на текстуре:
84 dx := DirAnim[MonsterAnim, GameDirection].Width - c - MONSTERTABLE[MonsterType].Rect.X;
85 // Т.к. двигать текстуру нужно будет в противоположном направлении:
86 dx := -dx;
87 // Это значит: dX := -frameWidth - animDeltaX + hitX + hitWidth + hitX
88 end
89 end
90 else // Правая анимация
91 begin
92 dx := MONSTER_ANIMTABLE[MonsterType].AnimDeltaRight[MonsterAnim].X;
93 dy := MONSTER_ANIMTABLE[MonsterType].AnimDeltaRight[MonsterAnim].Y;
94 end;
96 r_Animation_Draw(DirAnim[MonsterAnim, GameDirection], fX + dx, fY + dy, m);
97 end;
99 if g_debug_Frames then
100 begin
101 e_DrawQuad(Obj.X + Obj.Rect.X, Obj.Y + Obj.Rect.Y, Obj.X + Obj.Rect.X + Obj.Rect.Width - 1, Obj.Y + Obj.Rect.Y + Obj.Rect.Height - 1, 0, 255, 0);
102 end
103 end
104 end;
106 procedure r_Monsters_Draw;
107 var a: Integer;
108 begin
109 if gMonsters <> nil then
110 for a := 0 to High(gMonsters) do
111 if (gMonsters[a] <> nil) then r_Monsters_Draw(gMonsters[a]);
112 end;
114 procedure r_Monsters_DrawHealth;
115 var a: Integer; fW, fH: Byte;
116 begin
117 if gMonsters = nil then Exit;
118 e_TextureFontGetSize(gStdFont, fW, fH);
119 for a := 0 to High(gMonsters) do
120 begin
121 if gMonsters[a] <> nil then
122 begin
123 e_TextureFontPrint(gMonsters[a].Obj.X + gMonsters[a].Obj.Rect.X,
124 gMonsters[a].Obj.Y + gMonsters[a].Obj.Rect.Y + gMonsters[a].Obj.Rect.Height - fH,
125 IntToStr(gMonsters[a].MonsterHealth), gStdFont);
126 end
127 end
128 end;
130 end.