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

📄 unit1.pas

📁 Directx游戏制作开发包DGCBETA6
💻 PAS
📖 第 1 页 / 共 3 页
字号:
   end;

   If b > 0 then // adding 1's minute time increment
   begin
      Inc(LapTime[1],b); //increase by number of minutes
      If LapTime[1] > 9 then  //if 1's minute is greater than 9, carry the digit
      begin
         LapTime[1] := LapTime[1] mod 10; //trim the value
         AddToTime(1,0,0,0);              //carry the 1
      end;
   end;

   if c > 0 then // if 10's second time increment
   begin
      Inc(LapTime[2],c);  //increase the 10's seconds value
      If LapTime[2] > 5 then //greater than 59 seconds
      begin
         LapTime[2] := LapTime[2] mod 6; //trim the value
         AddToTime(0,1,0,0);             //add 1 to minutes
      end;
   end;

   if d > 0 then //if 1's second time increment (used in OnTimer!)
   begin
      Inc(LapTime[3],d);  //increase the 1's second value
      If LapTime[3] > 9 then  //greater than 9 seconds?
      begin
         LapTime[3] := LapTime[3] mod 10;  //trim value
         AddToTime(0,0,1,0);               //add 1 to 10's seconds
      end;
   end;
end;

procedure TForm1.AddToScore(a,b,c,d,e,f,g : integer);
begin
   //This procedure works just like the time procedure, just allowing for more
   //digits and doesn't round for 60 seconds/minutes.

   If a > 0 then
   begin
      Inc(Score[0],a);
      If Score[0] > 9 then Score[0] := Score[0] mod 10;
   end;

   If b > 0 then
   begin
      Inc(Score[1],b);
      If Score[1] > 9 then
      begin
         Score[1] := Score[1] mod 10;
         AddToScore(1,0,0,0,0,0,0);
      end;
   end;

   if c > 0 then
   begin
      Inc(Score[2],c);
      If Score[2] > 9 then
      begin
         Score[2] := Score[2] mod 10;
         AddToScore(0,1,0,0,0,0,0);
      end;
   end;

   if d > 0 then
   begin
      Inc(Score[3],d);
      If Score[3] > 9 then
      begin
         Score[3] := Score[3] mod 10;
         AddToScore(0,0,1,0,0,0,0);
      end;
   end;

   if e > 0 then
   begin
      Inc(Score[4],e);
      If Score[4] > 9 then
      begin
         Score[4] := Score[4] mod 10;
         AddToScore(0,0,0,1,0,0,0);
      end;
   end;

   if f > 0 then
   begin
      Inc(Score[5],f);
      If Score[5] > 9 then
      begin
         Score[5] := Score[5] mod 10;
         AddToScore(0,0,0,0,1,0,0);
      end;
   end;

   if g > 0 then
   begin
      Inc(Score[6],g);
      If Score[6] > 9 then
      begin
         Score[6] := Score[6] mod 10;
         AddToScore(0,0,0,0,0,1,0);
      end;
   end;
end;

procedure TForm1.AddToMissiles(a,b: integer);
begin
   //This routine works just like the Time & Score routines, just with 2 digits.
   //These routines are faster than trying to convert an integer amount to a string
   //and pick out each character then convert that character to a value that
   //corrisponds to an Image number.

   If a > 0 then
   begin
      Inc(MissCnt[0],a);
      If MissCnt[0] > 9 then MissCnt[0] := 9;
   end;

   If b > 0 then
   begin
      Inc(MissCnt[1],b);
      If MissCnt[1] > 9 then
      begin
         MissCnt[1] := MissCnt[1] mod 10;
         AddToMissiles(1,0);
      end;
   end;
end;

procedure TForm1.SubtractMissile;
var
  total : integer;
begin
  //This is almost the same as the AddToMissiles procedure, but a couple extra steps.

  total := (MissCnt[0] * 10) + MissCnt[1]; //calculate the real value of missiles
  Dec(Total);                              //decrease this value
  If total <= 0 then                       //if you are out of missiles
  begin
    MissCnt[0] := 0;                       //make the counter '00'
    MissCnt[1] := 0;
  end
  else                                     //else
  begin
    MissCnt[0] := total div 10;            //pick up first digit from value
    MissCnt[1] := total mod 10;            //pick up last digit from value
  end;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
   AddToTime(0,0,0,1);  //add one to the timer (called every 1000ms - 1 second)
end;

procedure TForm1.DGCAudio1Initialize(Sender: TObject);
var
   Loop : Integer;
begin
   //create duplicate pointers to the sound fx so that they can be played for each missile
   //Normally, you can only play a sound once and if you use the RePlay method of DGCAudio,
   //it restarts the sound -- this method allows you to play the same sound buffer multiple
   //times -- this is set up one for each missile allocated.
   For Loop := 0 to MISSILES do
   begin
     DGCAudio1.DirectSound.DuplicateSoundBuffer(DGCAudio1.Sound[0].Buffer, MissileSnd[Loop]);
     DGCAudio1.DirectSound.DuplicateSoundBuffer(DGCAudio1.Sound[2].Buffer, ExplodeSnd[Loop]);
   end;
end;

procedure TForm1.ShowIntro;
var
   MYPos: Integer;   // position of scrolling map
   Dir  : Integer;   // direction of scrolling map
   loop : Integer;   // you guessed it!
   xl   : integer;   // another loop counter -- used for rebuilding the map
   yl   : integer;   // another loop counter -- used for rebuilding the map
   flash: Boolean;   // Show the "S - Start  H - Help" graphic
   pause: integer;   // counter for the flash
   wait : integer;   // how log to hide/show graphic

begin
   If not ShowTitle then exit;

   DGCAudio1.Sound[1].Stop;         //Stop car engine from playing

   MYPos := -9360;                  //Set scrolling map position
   Dir   := 1;                      //set scrolling map direction/speed
   Timer1.Enabled := False;         //turn off game timer

   DGCScreen1.FadePaletteOut(15);   //fade to black

   DGCScreen1.Back.Erase(0);        //DGC now used Tripple buffering for
   DGCScreen1.Flip;                 //better performace on lower-end
   DGCScreen1.Back.Erase(0);        //machines so erase all 3 buffers
   DGCScreen1.Flip;
   DGCScreen1.Back.Erase(0);

   DGCScreen1.FadePaletteIn(1);     //bring palette back

   pause := 0;                      //reset some variables
   flash := True;
   wait  := 10;

   //As long as the ShowTitle variable is set to True then do this loop. This variable
   //is set to false when the user press S or ESC in the OnKeyPress event of Form1
   While ShowTitle do
   begin
     Application.ProcessMessages;  //Do multitasking stuff (messages -- keyboard!)
     DGCScreen1.Back.Erase(0);  //erase background
     DGCScreen1.DrawMap(DGCScreen1.Back,0,0,0,40,MYPos,False); //draw map
     if ShowHelp then  //showing help screen?
        DGCScreen1.Back.Draw(0,0,DGCScreen1.Images[27],True)
     else              //no, then show title
        DGCScreen1.Back.Draw(0,0,DGCScreen1.Images[26],True);

     //Showing the "s-start..." graphic?
     If (Flash) and (not ShowHelp) then DGCScreen1.Back.Draw(105,194,DGCScreen1.Images[28],True);

     Inc (Pause);

     //This will either turn on or off the flashing graphic
     If Pause > wait then
     begin
        Flash := not Flash;
        Pause := 0;
        If flash then Wait := 30 else wait := 10; //It's on longer than it is off!
     end;

     Inc(MYPos,Dir);  //update map position
     if (MYPos < -9360) or (MYPos > 0) then Dir := -Dir; //check map location
     DGCScreen1.Flip; //bring the back buffer to view -- this synchronizes with the
                      //vertical blank of the monitor so no other timing is needed.
   end;
   //When the 'S' or 'ESC' is pressed, the above loop will exit and do the following code:

   //Fade out the palette
   DGCScreen1.FadePaletteOut(15);

   //If it was the escape key that was pressed, then exit (which closes the app)
   If Quit then exit;

   //Otherwise, clear all 3 buffers
   DGCScreen1.Back.Erase(0);
   DGCScreen1.Flip;
   DGCScreen1.Back.Erase(0);
   DGCScreen1.Flip;
   DGCScreen1.Back.Erase(0);

   //reset game variables
   YPos      := -9360;
   PX        := 152;
   Speed     := 0;
   Accel     := 0;
   CarAnim   := 0;
   AnimDir   := 0;
   Shield    := 100;
   Fired     := 0;
   FirePause := 0;
   OkToFire  := True;

   //Clear score
   for loop := 0 to 6 do
       Score[loop] := 0;
   //Clear time
   for loop := 0 to 3 do
       LapTime[loop] := 0;
   //reset missiles
   for loop := 0 to MISSILES do
       Missile[loop].Free := True;
   //rebuild map
   for yl := 0 to 599 do
   begin
      for xl := 0 to 14 do
      begin
         DGCScreen1.SetMapTile(0,xl,yl,MapHold[yl][xl]);
      end;
   end;

   //start with 5 missiles
   MissCnt[0] := 0;
   MissCnt[1] := 5;
   //fade palette in
   DGCScreen1.FadePaletteIn(1);
   GameOver := False;
   //start car engine
   DGCAudio1.Sound[1].PlayLoop;
   //start game timer
   Timer1.Enabled := True;
end;

procedure TForm1.DGCScreen1Initialize(Sender: TObject);
var
   x,y : integer;
begin
   //This will capture the fresh map. While playing the game, pieces of the
   //map will be destroyed -- we need a way of restoring it when a new game
   //starts. We could have re-loaded it from disk but I needed something to
   //show the use of the new functions
   for y := 0 to 599 do
   begin
      for x := 0 to 14 do
      begin
         MapHold[y][x] := DGCScreen1.GetMapTile(0,x,y);
      end;
   end;
end;

end.

⌨️ 快捷键说明

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