DEADSOFTWARE

fc1576069450c8e54e812952e8cee5140f0a57fa
[d2df-sdl.git] / src / game / opengl / r_playermodel.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_playermodel;
18 interface
20 uses g_playermodel; // TPlayerModel
22 procedure r_PlayerModel_Initialize;
23 procedure r_PlayerModel_Finalize;
24 procedure r_PlayerModel_Draw (pm: TPlayerModel; X, Y: Integer; Alpha: Byte = 0);
26 implementation
28 uses
29 SysUtils, Classes, Math,
30 MAPDEF,
31 r_graphics, g_options, r_animations,
32 g_base, g_basic, g_map, g_weapons, g_textures
33 ;
35 const
36 WeapNames: Array [WP_FIRST + 1..WP_LAST] of String = ('csaw', 'hgun', 'sg', 'ssg', 'mgun', 'rkt', 'plz', 'bfg', 'spl', 'flm');
38 var
39 WeaponID: Array [WP_FIRST + 1..WP_LAST, W_POS_NORMAL..W_POS_DOWN, W_ACT_NORMAL..W_ACT_FIRE] of DWORD;
41 procedure r_PlayerModel_Initialize;
42 var
43 a: Integer;
44 begin
45 for a := WP_FIRST + 1 to WP_LAST do
46 begin
47 g_Texture_CreateWAD(WeaponID[a][W_POS_NORMAL][W_ACT_NORMAL], GameWAD+':WEAPONS\'+UpperCase(WeapNames[a]));
48 g_Texture_CreateWAD(WeaponID[a][W_POS_NORMAL][W_ACT_FIRE], GameWAD+':WEAPONS\'+UpperCase(WeapNames[a])+'_FIRE');
49 g_Texture_CreateWAD(WeaponID[a][W_POS_UP][W_ACT_NORMAL], GameWAD+':WEAPONS\'+UpperCase(WeapNames[a])+'_UP');
50 g_Texture_CreateWAD(WeaponID[a][W_POS_UP][W_ACT_FIRE], GameWAD+':WEAPONS\'+UpperCase(WeapNames[a])+'_UP_FIRE');
51 g_Texture_CreateWAD(WeaponID[a][W_POS_DOWN][W_ACT_NORMAL], GameWAD+':WEAPONS\'+UpperCase(WeapNames[a])+'_DN');
52 g_Texture_CreateWAD(WeaponID[a][W_POS_DOWN][W_ACT_FIRE], GameWAD+':WEAPONS\'+UpperCase(WeapNames[a])+'_DN_FIRE');
53 end;
54 end;
56 procedure r_PlayerModel_Finalize;
57 var a, b, c: Integer;
58 begin
59 for a := WP_FIRST + 1 to WP_LAST do
60 for b := W_POS_NORMAL to W_POS_DOWN do
61 for c := W_ACT_NORMAL to W_ACT_FIRE do
62 e_DeleteTexture(WeaponID[a][b][c])
63 end;
65 procedure r_PlayerModel_Draw (pm: TPlayerModel; X, Y: Integer; Alpha: Byte = 0);
66 var
67 Mirror: TMirrorType;
68 pos, act: Byte;
69 p: TDFPoint;
70 begin
71 // Флаги:
72 if pm.Direction = TDirection.D_LEFT then
73 Mirror := TMirrorType.None
74 else
75 Mirror := TMirrorType.Horizontal;
77 if (pm.Flag <> FLAG_NONE) and (pm.FlagAnim <> nil) and (not (pm.CurrentAnimation in [A_DIE1, A_DIE2])) then
78 begin
79 p.X := IfThen(pm.Direction = TDirection.D_LEFT, FLAG_BASEPOINT.X, 64 - FLAG_BASEPOINT.X);
80 p.Y := FLAG_BASEPOINT.Y;
82 r_Animation_DrawEx(pm.FlagAnim, X+IfThen(pm.Direction = TDirection.D_LEFT, pm.FlagPoint.X-1, 2*FLAG_BASEPOINT.X-pm.FlagPoint.X+1)-FLAG_BASEPOINT.X,
83 Y+pm.FlagPoint.Y-FLAG_BASEPOINT.Y+1, Mirror, p,
84 IfThen(pm.Direction = TDirection.D_RIGHT, pm.FlagAngle, -pm.FlagAngle));
85 end;
87 // Оружие:
88 if pm.Direction = TDirection.D_RIGHT then
89 Mirror := TMirrorType.None
90 else
91 Mirror := TMirrorType.Horizontal;
93 if pm.DrawWeapon and (not (pm.CurrentAnimation in [A_DIE1, A_DIE2, A_PAIN])) and (pm.CurrentWeapon in [WP_FIRST + 1..WP_LAST]) then
94 begin
95 if pm.CurrentAnimation in [A_SEEUP, A_ATTACKUP] then
96 pos := W_POS_UP
97 else
98 if pm.CurrentAnimation in [A_SEEDOWN, A_ATTACKDOWN] then
99 pos := W_POS_DOWN
100 else
101 pos := W_POS_NORMAL;
103 if (pm.CurrentAnimation in [A_ATTACK, A_ATTACKUP, A_ATTACKDOWN]) or pm.Fire then
104 act := W_ACT_FIRE
105 else
106 act := W_ACT_NORMAL;
108 if Alpha < 201 then
109 e_Draw(WeaponID[pm.CurrentWeapon][pos][act],
110 X + pm.WeaponPoints[pm.CurrentWeapon, pm.CurrentAnimation, pm.Direction,
111 pm.Anim[TDirection.D_RIGHT][pm.CurrentAnimation].CurrentFrame].X,
112 Y + pm.WeaponPoints[pm.CurrentWeapon, pm.CurrentAnimation, pm.Direction,
113 pm.Anim[TDirection.D_RIGHT][pm.CurrentAnimation].CurrentFrame].Y,
114 0, True, False, Mirror);
115 end;
117 // Модель:
118 if (pm.Direction = TDirection.D_LEFT) and (pm.Anim[TDirection.D_LEFT][pm.CurrentAnimation] <> nil) then
119 begin
120 pm.Anim[TDirection.D_LEFT][pm.CurrentAnimation].Alpha := Alpha;
121 r_Animation_Draw(pm.Anim[TDirection.D_LEFT][pm.CurrentAnimation], X, Y, TMirrorType.None);
122 end
123 else
124 begin
125 pm.Anim[TDirection.D_RIGHT][pm.CurrentAnimation].Alpha := Alpha;
126 r_Animation_Draw(pm.Anim[TDirection.D_RIGHT][pm.CurrentAnimation], X, Y, Mirror);
127 end;
129 // Маска модели:
130 e_Colors := pm.Color;
132 if (pm.Direction = TDirection.D_LEFT) and (pm.MaskAnim[TDirection.D_LEFT][pm.CurrentAnimation] <> nil) then
133 begin
134 pm.MaskAnim[TDirection.D_LEFT][pm.CurrentAnimation].Alpha := Alpha;
135 r_Animation_Draw(pm.MaskAnim[TDirection.D_LEFT][pm.CurrentAnimation], X, Y, TMirrorType.None);
136 end
137 else
138 begin
139 pm.MaskAnim[TDirection.D_RIGHT][pm.CurrentAnimation].Alpha := Alpha;
140 r_Animation_Draw(pm.MaskAnim[TDirection.D_RIGHT][pm.CurrentAnimation], X, Y, Mirror);
141 end;
143 e_Colors.R := 255;
144 e_Colors.G := 255;
145 e_Colors.B := 255;
146 end;
148 end.