Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: How to move a list?

  1. #1

    How to move a list?

    Hi everyone, I attach some of the code of my game written in delphi & delphiX. MyMen is a TList and consists of 19 men and they must move as per the TMan.DoMove procedure. How do I call the do move procedure in the playingStateMachine? If I use the SpriteEngine to move my road moves much too fast...

    Maybe AthenaOfDelphi can help?

    PS.: When I try to put the code in a block (code/pascal) some of it is cut off :evil:

    [pascal]procedure TMan.DoMove(MoveCount: Integer);
    begin
    if (fHit) then
    begin
    Movement := 0;
    Y := Y + 1;
    end
    else
    begin
    if (isUp in form1.DXInput1.States) then
    Y := y + 2 else
    if not(isUp in form1.DXInput1.States) then
    Y := Y + 1;
    if y > Form1.DXDraw1.Height - 100 then
    dead;
    if (Movement = 0) Then
    Movement := Random(2);
    if X > 560 Then Movement := 1;
    if X <50>=fRedLightStart) then
    fPlayingState:=_psPlaying
    else
    renderPlay;
    end;
    _psPlaying : begin
    if (RedLight<>nil) then
    begin
    redlight.Move(1);
    if (RedLight.Deaded) then
    begin
    RedLight.free;

    RedLight:=nil;

    end;
    end;

    car.Move(1);
    road.Move(1);

    // Now move the obstacles

    begin
    dxSpriteEngine1.Move(myMen.Count); // .....
    end;

    if (Car.deaded) then
    begin
    Car.free;

    Car:=nil;

    clearMen;

    fGameState:=_gsEnd;
    fEndState:=_esPlaySelected;

    dxspriteEngine1.Items.clear;
    end
    else
    renderPlay;
    end;
    end;
    end;[/pascal]




    MyMen := TList.create; is called in the OnFormCreate procedure.
    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

    How to move a list?

    The idea is to call the TMan.move for each man so you need a list something like this

    1. Create a loop for each item in the list
    2. Call the DoMove for each item
    2a. But TList store TObjects not TMyMan so you need to typecast the Object to a TMyMan first.

    [pascal]
    For I := 0 to MyMen.Count-1 do
    Begin
    TMyMan(MyMen[I]).DoMove(MoveCount);
    End;
    [/pascal]
    William Cairns
    My Games: http://www.cairnsgames.co.za (Currently very inactive)
    MyOnline Games: http://TheGameDeveloper.co.za (Currently very inactive)

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

    How to move a list?

    Hi Wizard,

    William's beaten me to it by about 10 minutes :-)

    With regards to the amount of code in a PASCAL tag... there is a limit on the amount of code you can put into a PASCAL tag in forum posts so they need to be short, sweet and to the point.
    :: AthenaOfDelphi :: My Blog :: My Software ::

  4. #4

    How to move a list?

    Thanks William

    Hi Athena, I thought as much :-)

    I'm almost done with the new version of my game :-) Thanks for your help :-)
    Wake up from the dream and live your life to the full

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

    How to move a list?

    Pleasure

    But remember in DelphiX the Sprites and SpriteEngine do this for you. So by adding your TMyMan objects into the Sprite Engine they should move already.

    From your example it seems you are not using the Sprite Engine (I also never did - could never get the sprites doing what I wanted).
    William Cairns
    My Games: http://www.cairnsgames.co.za (Currently very inactive)
    MyOnline Games: http://TheGameDeveloper.co.za (Currently very inactive)

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

    How to move a list?

    He was using the sprite engine to do the movement originally, but in the code I sent him showing a bit more of an OOP way of doing it, I stopped using the sprite engines move handler directly... I can't remember why exactly... I think it was something to do with only being able to pass in a single value... I needed to pass multiple values.
    :: AthenaOfDelphi :: My Blog :: My Software ::

  7. #7

    How to move a list?

    Guys, I'm either very "dof" or there's something I'm not doing right. ops:

    Code:
         if MyMen.Count > 0 then
                                for loop &#58;= MyMen.Count-1 downto 0 do
                                 Begin
                                    TMan&#40;MyMen&#91;loop&#93;&#41;.DoMove&#40;1&#41;;
                                 end;
    It does'nt work :evil:
    Wake up from the dream and live your life to the full

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

    How to move a list?

    Are you getting compiler errors or does it just not work within the game?
    :: AthenaOfDelphi :: My Blog :: My Software ::

  9. #9

    How to move a list?

    No compiler errors at all, the car and the road moves but the men doesn't even appear...
    Wake up from the dream and live your life to the full

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

    How to move a list?

    Is the code that creates the men the same as the example I sent you? If not, make sure the men are being linked to the sprite engine. Have a look at the example I sent you to check it (I passed a link to the sprite engine in the create method).

    Failing that, send me the code and I'll have a look at it.
    :: AthenaOfDelphi :: My Blog :: My Software ::

Page 1 of 2 12 LastLast

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
  •