📄 playscn.pas
字号:
unit PlayScn;
//游戏主场景
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
DXDraws, DXClass, DirectX, IntroScn, Grobal2, CliUtil, HUtil32,
Actor, HerbActor, AxeMon, SoundUtil, ClEvent, Wil,
StdCtrls, clFunc, magiceff, extctrls;
const
MAPSURFACEWIDTH = 800;
MAPSURFACEHEIGHT = 445;
LONGHEIGHT_IMAGE = 35;
FLASHBASE = 410;
AAX = 16;
SOFFX = 0;
SOFFY = 0;
LMX = 30;
LMY = 26;
SCREENWIDTH = 800;
SCREENHEIGHT = 600;
MAXLIGHT = 5;
LightFiles : array[0..MAXLIGHT] of string = (
'Data\lig0a.dat',
'Data\lig0b.dat',
'Data\lig0c.dat',
'Data\lig0d.dat',
'Data\lig0e.dat',
'Data\lig0f.dat'
);
LightMask0 : array[0..2, 0..2] of shortint = (
(0,1,0),
(1,3,1),
(0,1,0)
);
LightMask1 : array[0..4, 0..4] of shortint = (
(0,1,1,1,0),
(1,1,3,1,1),
(1,3,4,3,1),
(1,1,3,1,1),
(0,1,2,1,0)
);
LightMask2 : array[0..8, 0..8] of shortint = (
(0,0,0,1,1,1,0,0,0),
(0,0,1,2,3,2,1,0,0),
(0,1,2,3,4,3,2,1,0),
(1,2,3,4,4,4,3,2,1),
(1,3,4,4,4,4,4,3,1),
(1,2,3,4,4,4,3,2,1),
(0,1,2,3,4,3,2,1,0),
(0,0,1,2,3,2,1,0,0),
(0,0,0,1,1,1,0,0,0)
);
LightMask3 : array[0..10, 0..10] of shortint = (
(0,0,0,0,1,1,1,0,0,0,0),
(0,0,0,1,2,2,2,1,0,0,0),
(0,0,1,2,3,3,3,2,1,0,0),
(0,1,2,3,4,4,4,3,2,1,0),
(1,2,3,4,4,4,4,4,3,2,1),
(2,3,4,4,4,4,4,4,4,3,2),
(1,2,3,4,4,4,4,4,3,2,1),
(0,1,2,3,4,4,4,3,2,1,0),
(0,0,1,2,3,3,3,2,1,0,0),
(0,0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,4,4,4,4,4,2,1,0,0,0),
(0,0,0,0,1,2,4,4,4,4,4,2,1,0,0,0,0),
(0,0,0,0,0,1,2,4,4,4,2,1,0,0,0,0,0),
(0,0,0,0,0,0,1,2,2,2,1,0,0,0,0,0,0),
(0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0)
{ (0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0),
(0,0,0,0,0,0,0,1,2,2,2,1,0,0,0,0,0,0,0),
(0,0,0,0,0,0,1,2,4,4,4,2,1,0,0,0,0,0,0),
(0,0,0,0,0,1,2,4,4,4,4,4,2,1,0,0,0,0,0),
(0,0,0,0,1,2,4,4,4,4,4,4,4,2,1,0,0,0,0),
(0,0,0,1,2,4,4,4,4,4,4,4,4,4,2,1,0,0,0),
(0,0,1,2,4,4,4,4,4,4,4,4,4,4,4,2,1,0,0),
(0,1,2,4,4,4,4,4,4,4,4,4,4,4,4,4,2,1,0),
(1,2,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,2,1),
(1,2,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,2,1),
(1,2,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,2,1),
(0,1,2,4,4,4,4,4,4,4,4,4,4,4,4,4,2,1,0),
(0,0,1,2,4,4,4,4,4,4,4,4,4,4,4,2,1,0,0),
(0,0,0,1,2,4,4,4,4,4,4,4,4,4,2,1,0,0,0),
(0,0,0,0,1,2,4,4,4,4,4,4,4,2,1,0,0,0,0),
(0,0,0,0,0,1,2,4,4,4,4,4,2,1,0,0,0,0,0),
(0,0,0,0,0,0,1,2,4,4,4,2,1,0,0,0,0,0,0),
(0,0,0,0,0,0,0,1,2,2,2,1,0,0,0,0,0,0,0),
(0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0) }
);
type
PShoftInt = ^ShortInt;
TLightEffect = record
Width: integer;
Height: integer;
PFog: Pbyte;
end;
TLightMapInfo = record
ShiftX: integer;
ShiftY: integer;
light: integer;
bright: integer;
end;
TPlayScene = class (TScene)
private
MapSurface: TDirectDrawSurface;
ObjSurface: TDirectDrawSurface;
FogScreen: array[0..MAPSURFACEHEIGHT, 0..MAPSURFACEWIDTH] of byte;
PFogScreen: PByte;
FogWidth, FogHeight: integer;
Lights: array[0..MAXLIGHT] of TLightEffect;
MoveTime: longword;
MoveStepCount: integer;
AniTime: longword;
AniCount: integer;
DefXX, DefYY: integer;
MainSoundTimer: TTimer;
MsgList: TList;
LightMap: array[0..LMX, 0..LMY] of TLightMapInfo;
procedure DrawTileMap;
procedure LoadFog;
procedure ClearLightMap;
procedure AddLight (x, y, shiftx, shifty, light: integer; nocheck: Boolean);
procedure UpdateBright (x, y, light: integer);
function CheckOverLight (x, y, light: integer): Boolean;
procedure ApplyLightMap;
procedure DrawLightEffect (lx, ly, bright: integer);
procedure EdChatKeyPress (Sender: TObject; var Key: Char);
procedure SoundOnTimer (Sender: TObject);
public
EdChat: TEdit;
ActorList, TempList: TList;
GroundEffectList: TList; //官蹿俊 彬府绰 付过 府胶飘
EffectList: TList; //付过瓤苞 府胶飘
FlyList: TList; //朝酒促聪绰 巴 (带柳档尝, 芒, 拳混)
BlinkTime: Longword;
ViewBlink: Boolean;
constructor Create;
destructor Destroy; override;
procedure Initialize; override;
procedure Finalize; override;
procedure OpenScene; override;
procedure CloseScene; override;
procedure OpeningScene; override;
procedure DrawMiniMap (surface: TDirectDrawSurface);
procedure PlayScene (MSurface: TDirectDrawSurface); override;
function ButchAnimal (x, y: integer): TActor;
function FindActor (id: integer): TActor;
function FindActorXY (x, y: integer): TActor;
function IsValidActor (actor: TActor): Boolean;
function NewActor (chrid: integer; cx, cy, cdir: word; cfeature, cstate: integer): TActor;
procedure ActorDied (actor: TObject); //磷篮 actor绰 盖 困肺
procedure SetActorDrawLevel (actor: TObject; level: integer);
procedure ClearActors;
function DeleteActor (id: integer): TActor;
procedure DelActor (actor: TObject);
procedure SendMsg (ident, chrid, x, y, cdir, feature, state: integer; str: string);
procedure NewMagic (aowner: TActor;
magid, magnumb, cx, cy, tx, ty, targetcode: integer;
mtype: TMagicType;
Recusion: Boolean;
anitime: integer;
var bofly: Boolean);
procedure DelMagic (magid: integer);
function NewFlyObject (aowner: TActor; cx, cy, tx, ty, targetcode: integer; mtype: TMagicType): TMagicEff;
//function NewStaticMagic (aowner: TActor; tx, ty, targetcode, effnum: integer);
procedure ScreenXYfromMCXY (cx, cy: integer; var sx, sy: integer);
procedure CXYfromMouseXY (mx, my: integer; var ccx, ccy: integer);
function GetCharacter (x, y, wantsel: integer; var nowsel: integer; liveonly: Boolean): TActor;
function GetAttackFocusCharacter (x, y, wantsel: integer; var nowsel: integer; liveonly: Boolean): TActor;
function IsSelectMyself (x, y: integer): Boolean;
function GetDropItems (x, y: integer; var inames: string): PTDropItem;
function CanRun (sx, sy, ex, ey: integer): Boolean;
function CanWalk (mx, my: integer): Boolean;
function CrashMan (mx, my: integer): Boolean; //荤恩尝府 般摹绰啊?
function CanFly (mx, my: integer): Boolean;
procedure RefreshScene;
procedure CleanObjects;
end;
implementation
uses
ClMain, FState;
constructor TPlayScene.Create;
begin
MapSurface := nil;
ObjSurface := nil;
MsgList := TList.Create; //消息列表
ActorList := TList.Create; //角色列表
TempList := TList.Create;
GroundEffectList := TList.Create;
EffectList := TList.Create;
FlyList := TList.Create;
BlinkTime := GetTickCount;
ViewBlink := FALSE;
//聊天信息输入框
EdChat := TEdit.Create (FrmMain.Owner);
with EdChat do begin
Parent := FrmMain;
BorderStyle := bsNone;
OnKeyPress := EdChatKeyPress;
Visible := FALSE;
MaxLength := 70;
Ctl3D := FALSE;
Left := 208;
Top := SCREENHEIGHT - 19;
Height := 12;
Width := 387;
Color := clSilver;
end;
MoveTime := GetTickCount;
AniTime := GetTickCount;
AniCount := 0;
MoveStepCount := 0;
MainSoundTimer := TTimer.Create (FrmMain.Owner);
with MainSoundTimer do begin
OnTimer := SoundOnTimer;
Interval := 1;
Enabled := FALSE;
end;
end;
destructor TPlayScene.Destroy;
begin
MsgList.Free;
ActorList.Free;
TempList.Free;
GroundEffectList.Free;
EffectList.Free;
FlyList.Free;
inherited Destroy;
end;
//游戏主场景的背景音乐(长度:43秒)
procedure TPlayScene.SoundOnTimer (Sender: TObject);
begin
PlaySound (s_main_theme);
MainSoundTimer.Interval := 46 * 1000;
end;
//聊天信息输入
procedure TPlayScene.EdChatKeyPress (Sender: TObject; var Key: Char);
begin
if Key = #13 then begin
FrmMain.SendSay (EdChat.Text);
EdChat.Text := '';
EdChat.Visible := FALSE;
Key := #0;
end;
if Key = #27 then begin
EdChat.Text := '';
EdChat.Visible := FALSE;
Key := #0;
end;
end;
//初始化场景
procedure TPlayScene.Initialize;
var
i: integer;
begin
//地图
MapSurface := TDirectDrawSurface.Create (FrmMain.DXDraw1.DDraw);
MapSurface.SystemMemory := TRUE;
MapSurface.SetSize (MAPSURFACEWIDTH+UNITX*4+30, MAPSURFACEHEIGHT+UNITY*4);
//物品
ObjSurface := TDirectDrawSurface.Create (FrmMain.DXDraw1.DDraw);
ObjSurface.SystemMemory := TRUE;
ObjSurface.SetSize (MAPSURFACEWIDTH-SOFFX*2, MAPSURFACEHEIGHT);
//雾
FogWidth := MAPSURFACEWIDTH - SOFFX * 2;
FogHeight := MAPSURFACEHEIGHT;
PFogScreen := @FogScreen;
//PFogScreen := AllocMem (FogWidth * FogHeight);
ZeroMemory (PFogScreen, MAPSURFACEHEIGHT * MAPSURFACEWIDTH);
ViewFog := FALSE;
for i:=0 to MAXLIGHT do
Lights[i].PFog := nil;
LoadFog;
end;
procedure TPlayScene.Finalize;
begin
if MapSurface <> nil then
MapSurface.Free;
if ObjSurface <> nil then
ObjSurface.Free;
MapSurface := nil;
ObjSurface := nil;
end;
//场景开始
procedure TPlayScene.OpenScene;
begin
FrmMain.WProgUse.ClearCache; //肺弊牢 捞固瘤 某矫甫 瘤款促.
FrmDlg.ViewBottomBox (TRUE);
//EdChat.Visible := TRUE;
//EdChat.SetFocus;
SetImeMode (FrmMain.Handle, LocalLanguage);
//MainSoundTimer.Interval := 1000;
//MainSoundTimer.Enabled := TRUE;
MainSoundTimer.Interval := 1000;
MainSoundTimer.Enabled := TRUE;
end;
//关闭场景
procedure TPlayScene.CloseScene;
begin
//MainSoundTimer.Enabled := FALSE;
MainSoundTimer.Enabled := FALSE;
SilenceSound;
EdChat.Visible := FALSE;
FrmDlg.ViewBottomBox (FALSE);
end;
procedure TPlayScene.OpeningScene;
begin
end;
//刷新场景(游戏角色)
procedure TPlayScene.RefreshScene;
var
i: integer;
begin
Map.OldClientRect.Left := -1;
for i:=0 to ActorList.Count-1 do
TActor (ActorList[i]).LoadSurface;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -