Results 1 to 5 of 5

Thread: Delphi 6, DelphiX Starfighter game

  1. #1

    Delphi 6, DelphiX Starfighter game

    Hi guys and girls, me again :-)

    Can someone give me a suggestion on how to reset the fired count of my player's bullets without using a normal Delphi timer? When I add the line "player.fired := 0" in the DelphiX Timer it works but the bullets leave my player too fast, that's why I did it with the normal timer as it's slower.

    Here's my code for bullet creation, bullet move and the timer's event handler. I also need to display the time in seconds, can this be done with DXTimer?

    [pascal]
    If isButton1 in Form1.DXInput1.States Then
    begin
    if Fired <= 3 then
    begin
    Inc(Fired);
    with TBullet.Create(Form1.DXSpriteEngine1.Engine) do
    begin
    Image := Form1.DXImageList1.Items.Find('Bullet');
    X := MyX + 30;
    Y := MyY;
    Width := Image.Width;
    Height := Image.Height;
    end;
    end;
    end;


    procedure TBullet.DoMove(MoveCount: Integer);
    begin
    Y := Y - 25;
    Collision;
    if (Y < 0) Then
    Dead;
    end;


    procedure TForm1.Timer1Timer(Sender: TObject);
    begin
    //Reset the Fired count so the player can fire 3 bullets again
    Player.Fired := 0;
    //Increase the time
    Inc(Seconds);
    end;[/pascal]

    Thanks very much for your help
    Wake up from the dream and live your life to the full

  2. #2
    Legendary Member cairnswm's Avatar
    Join Date
    Nov 2002
    Location
    Randburg, South Africa
    Posts
    1,537

    Delphi 6, DelphiX Starfighter game

    Store the tick time of the firing action.

    When the player presses fire again - deduct the saved tick time fromt he current tick time - if greater than the delay time that you want then allow the player to fire (and update the stored time) else just skip the fire action.
    William Cairns
    My Games: http://www.cairnsgames.co.za (Currently very inactive)
    MyOnline Games: http://TheGameDeveloper.co.za (Currently very inactive)

  3. #3

    Delphi 6, DelphiX Starfighter game

    Ok, I had a look at the example that ships with delphi x and got it to work:

    Code:
    procedure TPlayer.DoMove&#40;MoveCount&#58; Integer&#41;;
    var
     MyX&#58; Double; 
     MyY &#58; Double;
    begin
      if fMode = 0 then
      begin
    
      If moveLeft and
      &#40;x>5&#41; then
      X &#58;= X - 10;
    
      If moveright and
      &#40;&#40;X+Form1.DXImageList1.Items.Find&#40;'Player'&#41;.Width&#41;<Form1>5&#41; then
      Y &#58;= Y - 10;
    
      if Movedown and
      &#40;y<form1.DXDraw1.Height-65&#41;then
      Y&#58;= Y + 10;
    
      MyX &#58;= X; //Set Temporary variable
      MyY &#58;= y;
    
      If isButton1 in Form1.DXInput1.States Then
        begin
          if &#40;FTamaCount<300>=35&#41; then
          begin
            Inc&#40;FTamaCount&#41;;
    
          with TBullet.Create&#40;Form1.DXSpriteEngine1.Engine&#41; do
            begin
              Image &#58;= Form1.DXImageList1.Items.Find&#40;'Bullet'&#41;; 
              Form1.DXWaveList1.Items.Find&#40;'Fire'&#41;.Play&#40;False&#41;;
              X &#58;= MyX + 30; 
              Y &#58;= MyY; 
              Width &#58;= Image.Width;  
              Height &#58;= Image.Height;
            end;
            FOldTamaTime &#58;= FCounter;
         end;
    end;
    end;
    FCounter &#58;= FCounter + MoveCount;
    end;

    But, I need to display the time in seconds, can it be done with the dxtimer?

    Thanks :-)
    Wake up from the dream and live your life to the full

  4. #4

    Delphi 6, DelphiX Starfighter game

    Quote Originally Posted by Wizard

    But, I need to display the time in seconds, can it be done with the dxtimer?

    Thanks :-)
    Sure, just set the interval at 1000, which is equal to 1 second.

  5. #5

    Delphi 6, DelphiX Starfighter game

    Thanks!!!
    Wake up from the dream and live your life to the full

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •