Results 1 to 4 of 4

Thread: Counting down with delphix's timer..

  1. #1

    Counting down with delphix's timer..

    Hi all, I have the following procedure in my game which is called in the DXTimer event. The car should stop when the gas runs out... Problem is that when the app runs the car immediately stops and the game-end procedure follows...

    Maybe the DXtimer is too fast? Help please :-)

    Code:
    procedure TForm1.RemainingGas;
    var GasLevil, FullTank : integer;
    begin
      FullTank := 100;
      for GasLevil := FullTank downto 0 do
      begin
      if &#40;GasLevil <= 0&#41; then
      car.Moved &#58;= false;
      end;
    end;
    Wake up from the dream and live your life to the full

  2. #2
    PGD Community Manager AthenaOfDelphi's Avatar
    Join Date
    Dec 2004
    Location
    South Wales, UK
    Posts
    1,245
    Blog Entries
    2

    Counting down with delphix's timer..

    Does car.moved:=false tell the rest of the game that the car is out of gas?

    If so, your car will stop on the first run through this procedure because the for loop will execute and set car.moved to false on the last run through its loop.

    How many cars are there?

    I would put the cars gas level in the car object. And then in your 'remainingGas' routine do something like this...

    [pascal]
    car.moved:=(car.gas>0);
    [/pascal]

    Assuming as well that you want to decrease the fuel, in that routine, then this is more appropriate:-

    [pascal]
    car.gas:=car.gas-1;
    car.moved:=(car.gas>0);
    [/pascal]

    Unfortunately its a bit difficult without seeing all the code to comment any further. But even that second block of code is likely to result in early termination as it would take less than 2 seconds to use 100 units of gas (assuming a timer frequency equivalent to 60fps).

    To get around that you can either use real numbers and subtract a fraction every cycle or you can use integers and give the car say 1000 units of gas and only subtract 1.

    Hope this helps... if not, then I could do with seeing more of the code.
    :: AthenaOfDelphi :: My Blog :: My Software ::

  3. #3

    Counting down with delphix's timer..

    Hi, what Athena said is correct, if you do a for loop the car's fuel will run
    out in just one step.

    The DXTimer itself is your for loop

    Also, i can't understand why using a boolean also (.Moved) as you
    can just test the remaining gas into the "TCarSprite.DoMove" having
    if (car.gas>0) then do all your car move routine

    Gambare!
    <center>
    <br />Federico &quot;FNX&quot; Nisoli
    <br />Lead Programmer - FNX Games
    <br />http://www.fnxgames.com
    <br /><img src="http://www.fnxgames.com/imgs/banners/fnxban.gif">
    <br /></center>

  4. #4

    Counting down with delphix's timer..

    Thanks for your help :-)

    It now works as I want it to :-)

    Global variable : gas as integer, gas := 1000 in my startmain procedure and the following:

    Code:
    procedure TForm1.RemainingGas;
    begin
      Gas &#58;= Gas -1;
      car.Moved &#58;= &#40;gas>0&#41;;
    end;
    The for loop is so attractive but I understand that the timer is the for loop :-)

    Thanks again, you guys/girls are brilliant!
    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
  •