📄 playscn.pas
字号:
Visible:=FALSE;
//OnKeyPress:=EdNewIdKeyPress;
//OnEnter:=EdNewOnEnter;
Tag := 12;
end;
EdChgNewPwd := TEdit.Create (FrmMain.Owner);
with EdChgNewPwd do begin
Parent:=FrmMain;
Height:=16;
Width:=137;
Left:=nx+239;
Top:=ny+176;
BorderStyle:=bsNone;
Color:=clBlack;
Font.Color:=clWhite;
MaxLength:=10;
PasswordChar:='*';
Visible:=FALSE;
//OnKeyPress:=EdNewIdKeyPress;
//OnEnter:=EdNewOnEnter;
Tag:=12;
end;
EdChgRePwd := TEdit.Create (FrmMain.Owner);
with EdChgRePwd do begin
Parent := FrmMain;
Height := 16;
Width := 137;
Left := nx+239;
Top := ny+208;
BorderStyle := bsNone;
Color := clBlack;
Font.Color := clWhite;
MaxLength := 10;
PasswordChar := '*';
Visible := FALSE;
//OnKeyPress := EdNewIdKeyPress;
//OnEnter := EdNewOnEnter;
Tag := 12;
end;
}
end;
destructor TPlayScene.Destroy;
begin
m_MsgList.Free;
m_ActorList.Free;
m_TempList.Free;
m_GroundEffectList.Free;
m_EffectList.Free;
m_FlyList.Free;
inherited Destroy;
end;
//游戏主场景的背景音乐(长度:43秒)
procedure TPlayScene.SoundOnTimer (Sender: TObject);
begin
PlaySound (s_main_theme);
m_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
//地图
m_MapSurface := TDirectDrawSurface.Create (frmMain.DxDraw.DDraw);
m_MapSurface.SystemMemory := TRUE;
m_MapSurface.SetSize (MAPSURFACEWIDTH+UNITX*4+30, MAPSURFACEHEIGHT+UNITY*4);
//物品
m_ObjSurface := TDirectDrawSurface.Create (frmMain.DxDraw.DDraw);
m_ObjSurface.SystemMemory := TRUE;
m_ObjSurface.SetSize (MAPSURFACEWIDTH-SOFFX*2, MAPSURFACEHEIGHT);
//雾
m_nFogWidth := MAPSURFACEWIDTH - SOFFX * 2;
m_nFogHeight := MAPSURFACEHEIGHT;
m_PFogScreen := @m_FogScreen;
//PFogScreen := AllocMem (FogWidth * FogHeight);
ZeroMemory (m_PFogScreen, MAPSURFACEHEIGHT * MAPSURFACEWIDTH);
g_boViewFog := FALSE;
for i:=0 to MAXLIGHT do
m_Lights[i].PFog := nil;
LoadFog;
end;
procedure TPlayScene.Finalize;
begin
if m_MapSurface <> nil then
m_MapSurface.Free;
if m_ObjSurface <> nil then
m_ObjSurface.Free;
m_MapSurface := nil;
m_ObjSurface := nil;
end;
//场景开始
procedure TPlayScene.OpenScene;
begin
g_WMainImages.ClearCache; //肺弊牢 捞固瘤 某矫甫 瘤款促.
FrmDlg.ViewBottomBox (TRUE);
//EdChat.Visible := TRUE;
//EdChat.SetFocus;
SetImeMode (FrmMain.Handle, LocalLanguage);
//MainSoundTimer.Interval := 1000;
//MainSoundTimer.Enabled := TRUE;
end;
//关闭场景
procedure TPlayScene.CloseScene;
begin
//MainSoundTimer.Enabled := FALSE;
SilenceSound;
EdChat.Visible := FALSE;
FrmDlg.ViewBottomBox (FALSE);
end;
procedure TPlayScene.OpeningScene;
begin
end;
//刷新场景(游戏角色)
procedure TPlayScene.RefreshScene;
var
i: integer;
begin
Map.m_OldClientRect.Left := -1;
for i:=0 to m_ActorList.Count-1 do
TActor (m_ActorList[i]).LoadSurface;
end;
procedure TPlayScene.CleanObjects;
var
i: integer;
begin
//删除所有非当前玩家角色
for i := m_ActorList.Count-1 downto 0 do begin
if TActor(m_ActorList[i]) <> g_MySelf then begin
TActor(m_ActorList[i]).Free;
m_ActorList.Delete (i);
end;
end;
m_MsgList.Clear;
g_TargetCret := nil;
g_FocusCret := nil;
g_MagicTarget := nil;
//清除魔法效果
for i:=0 to m_GroundEffectList.Count-1 do
TMagicEff (m_GroundEffectList[i]).Free;
m_GroundEffectList.Clear;
for i:=0 to m_EffectList.Count-1 do
TMagicEff (m_EffectList[i]).Free;
m_EffectList.Clear;
end;
{---------------------- Draw Map -----------------------}
//画地图
procedure TPlayScene.DrawTileMap;
var
i,j, nY,nX,nImgNumber:integer;
DSurface: TDirectDrawSurface;
begin
with Map do
if (m_ClientRect.Left = m_OldClientRect.Left) and (m_ClientRect.Top = m_OldClientRect.Top) then exit;
Map.m_OldClientRect := Map.m_ClientRect;
m_MapSurface.Fill(0);
//地图背景 画地面
if not g_boDrawTileMap then exit;
with Map.m_ClientRect do begin
nY := -UNITY * 2;
for j:=(Top - Map.m_nBlockTop - 1) to (Bottom - Map.m_nBlockTop + 1) do begin
nX := AAX + 14 -UNITX;
for i:=(Left - Map.m_nBlockLeft -2) to (Right - Map.m_nBlockLeft + 1) do begin
if (i >= 0) and (i < LOGICALMAPUNIT * 3) and (j >= 0) and (j < LOGICALMAPUNIT *3) then begin
nImgNumber := (Map.m_MArr[i, j].wBkImg and $7FFF);
if nImgNumber > 0 then begin
if (i mod 2 = 0) and (j mod 2 = 0) then begin
nImgNumber := nImgNumber - 1;
DSurface := g_WTilesImages.Images[nImgNumber];
if Dsurface <> nil then begin
//Jacky 显示地图内容
// DrawLine(DSurface);
m_MapSurface.Draw (nX, nY, DSurface.ClientRect, DSurface, FALSE);
end;
end;
end;
end;
Inc (nX, UNITX);
end;
Inc (nY, UNITY);
end;
end;
//地图中间层
with Map.m_ClientRect do begin
nY := -UNITY;
for j:=(Top - Map.m_nBlockTop-1) to (Bottom - Map.m_nBlockTop+1) do begin
nX := AAX + 14 -UNITX;
for i:=(Left - Map.m_nBlockLeft-2) to (Right - Map.m_nBlockLeft+1) do begin
if (i >= 0) and (i < LOGICALMAPUNIT * 3) and (j >= 0) and (j < LOGICALMAPUNIT * 3) then begin
nImgNumber := Map.m_MArr[i, j].wMidImg;
if nImgNumber > 0 then begin
nImgNumber := nImgNumber - 1;
DSurface := g_WSmTilesImages.Images[nImgNumber];
if Dsurface <> nil then
m_MapSurface.Draw (nX, nY, DSurface.ClientRect, DSurface, TRUE);
end;
end;
Inc (nX, UNITX);
end;
Inc (nY, UNITY);
end;
end;
end;
{----------------------- 器弊, 扼捞飘 贸府 -----------------------}
procedure TPlayScene.LoadFog; //扼捞飘 单捞鸥 佬扁
var
i, fhandle, w, h, prevsize: integer;
cheat: Boolean;
begin
prevsize := 0; //炼累 眉农
cheat := FALSE;
for i:=0 to MAXLIGHT do begin
if FileExists (LightFiles[i]) then begin
fhandle := FileOpen (LightFiles[i], fmOpenRead or fmShareDenyNone);
FileRead (fhandle, w, sizeof(integer));
FileRead (fhandle, h, sizeof(integer));
m_Lights[i].Width := w;
m_Lights[i].Height := h;
m_Lights[i].PFog := AllocMem (w * h + 8);
if prevsize < w * h then begin
FileRead (fhandle, m_Lights[i].PFog^, w*h);
end else
cheat := TRUE;
prevsize := w * h;
FileClose (fhandle);
end;
end;
if cheat then
for i:=0 to MAXLIGHT do begin
if m_Lights[i].PFog <> nil then
FillChar (m_Lights[i].PFog^, m_Lights[i].Width*m_Lights[i].Height+8, #0);
end;
end;
procedure TPlayScene.ClearDropItem;
var
I:Integer;
DropItem:pTDropItem;
begin
for I := g_DropedItemList.Count - 1 downto 0 do begin
DropItem:=g_DropedItemList.Items[I];
if DropItem = nil then begin
g_DropedItemList.Delete(I);
Continue;
end;
if (abs(DropItem.x - g_MySelf.m_nCurrX) > 30) and (abs(DropItem.y - g_MySelf.m_nCurrY) > 30) then begin
{$IF DEBUG = 1}
DScreen.AddChatBoardString (format('DropItem:%s X:%d Y:%d',[DropItem.Name,DropItem.X,DropItem.Y]),clWhite, clRed);
{$IFEND}
Dispose(DropItem);
g_DropedItemList.Delete(I);
end;
end;
end;
procedure TPlayScene.ClearLightMap;
var
i, j: integer;
begin
FillChar (m_LightMap, (LMX+1)*(LMY+1)*SizeOf(TLightMapInfo), 0);
for i:=0 to LMX do
for j:=0 to LMY do
m_LightMap[i, j].Light := -1;
end;
procedure TPlayScene.UpdateBright (x, y, light: integer);
var
i, j, r, lx, ly: integer;
pmask: ^ShortInt;
begin
pmask:=nil;//jacky
r := -1;
case light of
0: begin r := 2; pmask := @LightMask0; end;
1: begin r := 4; pmask := @LightMask1; end;
2: begin r := 8; pmask := @LightMask2; end;
3: begin r := 10; pmask := @LightMask3; end;
4: begin r := 14; pmask := @LightMask4; end;
5: begin r := 16; pmask := @LightMask5; end;
end;
for i:=0 to r do
for j:=0 to r do begin
lx := x-(r div 2)+i;
ly := y-(r div 2)+j;
if (lx in [0..LMX]) and (ly in [0..LMY]) then
m_LightMap[lx, ly].bright := m_LightMap[lx, ly].bright + PShoftInt(integer(pmask) + (i*(r+1) + j) * sizeof(shortint))^;
end;
end;
function TPlayScene.CheckOverLight (x, y, light: integer): Boolean;
var
i, j, r, mlight, lx, ly, count, check: integer;
pmask: ^ShortInt;
begin
pmask:=nil;//jacky
check:=0;//jacky
r := -1;
case light of
0: begin r := 2; pmask := @LightMask0; check := 0; end;
1: begin r := 4; pmask := @LightMask1; check := 4; end;
2: begin r := 8; pmask := @LightMask2; check := 8; end;
3: begin r := 10; pmask := @LightMask3; check := 18; end;
4: begin r := 14; pmask := @LightMask4; check := 30; end;
5: begin r := 16; pmask := @LightMask5; check := 40; end;
end;
count := 0;
for i:=0 to r do
for j:=0 to r do begin
lx := x-(r div 2)+i;
ly := y-(r div 2)+j;
if (lx in [0..LMX]) and (ly in [0..LMY]) then begin
mlight := PShoftInt(integer(pmask) + (i*(r+1) + j) * sizeof(shortint))^;
if m_LightMap[lx, ly].bright < mlight then begin
inc (count, mlight - m_LightMap[lx, ly].bright);
if count >= check then begin
Result := FALSE;
exit;
end;
end;
end;
end;
Result := TRUE;
end;
procedure TPlayScene.AddLight (x, y, shiftx, shifty, light: integer; nocheck: Boolean);
var
lx, ly: integer;
begin
lx := x - g_MySelf.m_nRx + LMX div 2;
ly := y - g_MySelf.m_nRy + LMY div 2;
if (lx >= 1) and (lx < LMX) and (ly >= 1) and (ly < LMY) then begin
if m_LightMap[lx, ly].light < light then begin
if not CheckOverLight(lx, ly, light) or nocheck then begin // > LightMap[lx, ly].light then begin
UpdateBright (lx, ly, light);
m_LightMap[lx, ly].light := light;
m_LightMap[lx, ly].Shiftx := shiftx;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -