⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sample5.dpr

📁 3D GameStudio 的Delphi开发包
💻 DPR
字号:
program sample5;

//////////////////////////////////////////////////////////////////////
//
// Delphi sample for using the A6_5x Engine (acknex.dll) done by
// Michal Messerschmidt aka LazyDog of Lazy Dog Software
// (www.LazyDogSoftware.com)
//
// SDK Version 6.50.6
//
// tested on Delphi 5,6,7 & 2005
//////////////////////////////////////////////////////////////////////

{$R 'icon.res' 'icon.rc'}  // this allows defining your own .ico file
                           // without the overhead of using the forms unit
                           // to get to the application.icon.  simply change
                           // the icon.rc file to point to your icon

uses A6Engine, Engine_Library, SysUtils, Dialogs;

var FPSText : PText;
    Panel1 : PPanel;
    View2 : PView;

procedure MakeSecondView;
begin
  View2 := view_create(_VAR(1));    // create a new view with layer of 1

  View2.pos_x := _VAR(550);         // position the view
  View2.pos_y := _VAR(250);         // in the engine window

  View2.size_x := _VAR(200);        // set the size of
  View2.size_y := _VAR(200);        // the view in pixels

  // set the view to match what the camera sees
  vec_set(PVector(@View2.x),PVector(@ev.camera.x));

  FlagOn(View2.flags,_VISIBLE);     // make view visible, defined in A6Engine Unit
end;

procedure MakePanels;
begin
  //don't forget the ";" at the end of the command string !!!!
  Panel1 := pan_create('bmap = targ1.pcx;pos_x = 0;pos_y = 0;flags=visible;digits=0,0,"fps",*,0,null;digits = 20,0,3,*,16,time_fac;',_VAR(1));
end;

procedure FillFPSString;

var Temp : String;
begin
  Temp := 'Current FPS: '+ IntToStr(_INT(fps));
  str_cpy(FPSText.Astring^,PChar(Temp));
end;

procedure CreateText;

const TheStrings : Array[0..14] of string = ('Hold Ctrl while pressing one of',
                                             'the following to alter Second View',
                                             ' ',
                                             'A moves camera to the left',
                                             'D moves camera to the right',
                                             'W moves camera forward',
                                             'S moves camera backwards',
                                             ' ',
                                             'Left arrow rotates camera left',
                                             'Right arrow rotates camera right',
                                             'up arrow rotates camera up',
                                             'down arrow rotates camera down',
                                             ' ',
                                             'Hitting Enter toggles Second View ON/OFF',
                                             'Hit Esc to Quit the Program');

var TheText : PText;
    TheFont : PFont_;
begin
  TheFont := font_create('font1_red.pcx'); // create a font

  TheText := txt_create(_VAR(15),_VAR(1)); // create a text with 15 strings
                                           // setting the layer = 1


  TheText.font := TheFont;                 // assign the font
  TheText.pos_x := _VAR(400);              // set the x position
  TheText.pos_y := _VAR(50);               // set the y position
  TheText.flags := _VISIBLE or CENTER_X;   // set it visible, centered on x

  Txt_Fill(TheText,TheStrings);            // fill the text object from array
                                           // txt_fill defined in Engine_Library


  FPSText := txt_create(_VAR(1),_VAR(1));
  FPSText.font := TheFont;
  FPSText.pos_x := _VAR(400);
  FPSText.pos_y := _VAR(300);
  FPSText.flags := _VISIBLE or CENTER_X;

  FillFPSString;
end;

procedure ToggleView;
begin
  FlagToggle(View2.flags,_VISIBLE);        // FlagToggle is defined A6Engine Unit
end;

procedure UpdateSecondView;

var vMove : TVector;	// movement vector
begin
  if ev.key_ctrl^ = 0 then Exit;            // ctrl key NOT pressed, exit

  Dec(view2.pan, (3 * ev.key_force.x));	    // left/right cursor keys
  Inc(view2.tilt,(3 * ev.key_force.y));	    // up/down cursor keys

  vMove.x := 6 * (ev.key_w^ - ev.key_s^);   // move forward
  vMove.y := 6 * (ev.key_a^ - ev.key_d^);   // move sideward
  vMove.z := 0;

  vec_rotate(@vMove,PAngle(@view2.pan));  //
  vec_add(PVector(@view2.x),@vMove);     //
end;

procedure MoveMouse;
begin
  if ev.mouse_map = Nil then Exit;

  if _INT(ev.freeze_mode^) > 1 then Exit;  // all functions suspended

  if ev.mouse_valid^ = 0 then              // makes cursor disappear when
    ev.mouse_mode^ := 0                    // no longer over the engine window
  else
    ev.mouse_mode^ := _VAR(1);

  if ev.mouse_mode^ > 0 then               // move it over the screen
  begin
    ev.mouse_pos.x := ev.mouse_cursor.x;
    ev.mouse_pos.y := ev.mouse_cursor.y;
  end;
end;

procedure MoveCamera;

var vMove : TVector;	// movement vector
    x : tangle;
    y : tvector;
begin
  if _INT(ev.freeze_mode^) > 1 then Exit;       // all functions suspended

  if ev.key_ctrl^ = _VAR(1) then Exit;          // ctrl key pressed, exit

  Dec(ev.camera.pan, (3 * ev.key_force.x));	// left/right cursor keys
  Inc(ev.camera.tilt,(3 * ev.key_force.y));	// up/down cursor keys

  {.$DEFINE EASYTOFOLLOW}
  {.$DEFINE SIMPLIER}
  {$DEFINE FASTEST}

  {$IFDEF EASYTOFOLLOW}
  x.pan  := ev.camera.pan;
  x.tilt := ev.camera.tilt;
  x.roll := ev.camera.roll;
  y.x    := ev.camera.x;
  y.y    := ev.camera.y;
  y.z    := ev.camera.z;

  vMove.x := 6 * (ev.key_w^ - ev.key_s^);   // move forward
  vMove.y := 6 * (ev.key_a^ - ev.key_d^);   // move sideward
  vMove.z := 0;

  vec_rotate(@vMove,@x);
  vec_add(@y,@vMove);

  ev.camera.x := y.x;
  ev.camera.y := y.y;
  ev.camera.z := y.z;
  {$ENDIF}

  {$IFDEF SIMPLIER}
  x := GetAng(ev.camera^);
  y := GetVec(ev.camera^);

  vMove.x := 6 * (ev.key_w^ - ev.key_s^);   // move forward
  vMove.y := 6 * (ev.key_a^ - ev.key_d^);   // move sideward
  vMove.z := 0;

  vec_rotate(@vMove,@x);
  vec_add(@y,@vMove);

  SetVec(ev.camera^,y);
//    vec_set(PVector(@ev^.camera.x),@y);
  {$ENDIF}

  {$IFDEF FASTEST}
  vMove.x := 6 * (ev.key_w^ - ev.key_s^);   // move forward
  vMove.y := 6 * (ev.key_a^ - ev.key_d^);   // move sideward
  vMove.z := 0;

  vec_rotate(@vMove,PAngle(@ev.camera.pan));  //
  vec_add(PVector(@ev.camera.x),@vMove);     //
  {$ENDIF}
end;

procedure Quit;
begin
  sys_exit('');     // quit running and shut down the engine
end;

procedure Main;
begin
  if FindDirectX < 9 then
  begin
    ShowMessage('DirectX 9 is required to run this program');
    Exit;
  end;

  ev := engine_open('');         // commands like -diag can be used here

  if ev = Nil then Exit;

  add_folder('files');           // point to subdirectory that holds level files

  ev.on_close^ := @Quit;         // [X] close icon clicked quits program
  ev.on_esc^   := @Quit;         // ESC key quits program

  ev.mouse_mode^    := _VAR(1);  // windows cursor is visible
  ev.mouse_pointer^ := _VAR(1);  // default cursor is hand

  ev.video_screen^ := _VAR(2);   // default to window mode
  ev.video_mode^   := _VAR(7);   // default to 800x600
  ev.video_depth^  := _VAR(32);  // default to 32 bit depth

  ev.on_enter^ := @ToggleView;

  ev.fps_min^ := _VAR(16);
  ev.fps_max^ := _VAR(60);

  level_load('paths.wmb');       // this is loaded from the files subdirectory

  engine_frame;                  // need to wait 2 frames after a level_load
  engine_frame;                  // before creating entities

  CreateText;                    // don't call until engine is running
  MakePanels;
  MakeSecondView;

  // here is the engine main loop
  while engine_frame <> 0 do
  begin
    MoveCamera;
    MoveMouse;
    UpdateSecondView;
    FillFPSString;
  end;

  engine_close();
end;

begin
  Main;
end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -