Results 1 to 8 of 8

Thread: DelphiX Question

  1. #1

    DelphiX Question

    H, I attach some of the code on a new game I'm working on. If the ball moves past a certain value of x then I want it to be killed/destroyed/made invisible... how do I do that? I've tried the following in the DoMove Procedure:

    if x < 100 then
    ball.dead

    It works because the ball does not respond to my mouse action past that point but the image remains......how does one get rid of the image?

    Thanks for your help :-)


    Code:
    procedure TBall.DoMove&#40;MoveCount &#58; integer&#41;;
    begin
      if MoveLeft then
      x&#58;= x - 50;
      if MoveRight then
      X&#58;= X + 50;
    end;
    
    procedure TForm1.DXDraw1Initialize&#40;Sender&#58; TObject&#41;;
    begin
      wallpaper &#58;= TDirectDrawsurface.Create&#40;DXDraw1.ddraw&#41;;
      wallpaper.LoadFromGraphic&#40;Form1.DXImagelist1.Items.Items&#91;1&#93;.picture.graphic&#41;;
      Ball &#58;= tball.Create&#40;Form1.DXSpriteEngine1.Engine&#41;;
      Ball.SpriteImg &#58;= TDirectDrawsurface.Create&#40;DXDraw1.ddraw&#41;;
      Ball.SpriteImg.LoadFromGraphic&#40;Form1.DXImagelist1.items.items&#91;0&#93;.picture.graphic&#41;;
      ball.SpriteImg.TransparentColor&#58;=clblack;
      ball.x&#58;=350;
      ball.y&#58;=200;
      dxTimer1.Enabled &#58;= true;
    end;
    
    procedure TForm1.DXTimer1Timer&#40;Sender&#58; TObject; LagCount&#58; Integer&#41;;
    begin
      if not DXDraw1.CanDraw then Exit;
      DXInput1.Update;
      DXSpriteEngine1.Move&#40;1&#41;;
      dxdraw1.Surface.Draw&#40;-10,-10, wallpaper.ClientRect, wallpaper,false&#41;;
      dxdraw1.surface.draw&#40;round&#40;ball.X&#41;,round&#40;ball.Y&#41;,
      ball.SpriteImg.ClientRect, ball.SpriteImg,true&#41;;
      DXDraw1.Flip;
    end;
    Wake up from the dream and live your life to the full

  2. #2

    DelphiX Question

    why are you physically drawing the ball in your timer code? The sprite engine does this for you. Your ball keeps being drawn because you're telling it to.

    you should be calling DXSpriteEngine1.Draw();

  3. #3

    DelphiX Question

    You've probably seen this before, but your code is doing a similar job to one of my tutorials.

    http://www.cerebral-bicycle.co.uk/viewdoc.asp?doc=32

  4. #4

    DelphiX Question

    Hi, you can draw the wallpaper with surface.draw, but the ball is a sprite
    so that you may use DXSpriteEngine1.Draw(); as jasonf said. Then,
    call DXSpriteEngine1.Dead; to kill every dead sprite in the list.
    It does the job automatically.
    Another approach, if you want to use surface.draw (and so you can avoid the use of sprites), is to keep track if your ball is dead with a boolean,
    so easily if not BallisDead then surface.draw(ball...)

    I hope this make sense
    <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>

  5. #5

    DelphiX Question

    Thanks for your replies guys :-)

    JasonF, I actualy saw a version of the code in Traveller's game called Baloons. The reason why I tried it is because I was struggling to get an image displayed over a bitmap.

    FNX, your suggestion of using a boolean works, it now does what I want it to do :-)

    My code:

    [pascal]
    procedure TBall.DoMove(MoveCount : integer);
    begin
    if MoveLeft then
    x:= x - 50;
    if (x = 100) then
    BallIsDead := True;
    end;

    procedure TForm1.DXDraw1Initialize(Sender: TObject);
    begin
    wallpaper := TDirectDrawsurface.Create(DXDraw1.ddraw);
    wallpaper.LoadFromGraphic(Form1.DXImagelist1.Items .Items [1].picture.graphic);
    Ball := tball.Create(Form1.DXSpriteEngine1.Engine);
    Ball.SpriteImg := TDirectDrawsurface.Create(DXDraw1.ddraw);
    Ball.SpriteImg.LoadFromGraphic(Form1.DXImagelist1. items.items[0].picture.graphic);
    ball.SpriteImg.TransparentColor:=clblack;
    ball.x:=350;
    ball.y:=200;
    dxTimer1.Enabled := true;
    end;

    procedure TForm1.DXTimer1Timer(Sender: TObject; LagCount: Integer);
    begin
    if not DXDraw1.CanDraw then Exit;
    DXInput1.Update;
    DXSpriteEngine1.Move(1);
    dxdraw1.Surface.Draw(-10,-10, wallpaper.ClientRect, wallpaper,false);
    if (BallisDead = False) then
    dxdraw1.surface.draw(round(ball.X),round(ball.Y),
    ball.SpriteImg.ClientRect, ball.SpriteImg,true);
    DXDraw1.Flip;
    end;
    [/pascal]

    PS. At the moment my ball moves left and right with the OnMouseDown event. How can I get it to move diagonally ie outside the limits of always up/down or left/right?

    Thanks again :-)

    [/pascal]
    Wake up from the dream and live your life to the full

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

    DelphiX Question

    Quote Originally Posted by Wizard
    [pascal]
    if (BallisDead = False) then
    dxdraw1.surface.draw(round(ball.X),round(ball.Y),
    ball.SpriteImg.ClientRect, ball.SpriteImg,true);
    [/pascal]
    Clearly I've been doing too many QAs this last two weeks....

    BallIsDead is a boolean. You dont need to test booleans = to true/false

    [pascal]
    if NOT BallIsDead then
    dxdraw1.surface.draw(round(ball.X),round(ball.Y),
    ball.SpriteImg.ClientRect, ball.SpriteImg,true);
    [/pascal]

    Would be a better way to write this.
    William Cairns
    My Games: http://www.cairnsgames.co.za (Currently very inactive)
    MyOnline Games: http://TheGameDeveloper.co.za (Currently very inactive)

  7. #7

    DelphiX Question

    cairnswm wrote:

    if NOT BallIsDead then
    dxdraw1.surface.draw(round(ball.X),round(ball.Y),
    ball.SpriteImg.ClientRect, ball.SpriteImg,true);
    Does it make any difference? I've changed it anyway -- :-)

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

  8. #8

    DelphiX Question

    It looks better but I doubt it is compiled any differently
    The views expressed on this programme are bloody good ones. - Fred Dagg

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
  •