Results 1 to 2 of 2

Thread: What is wrong with my collision detection?

  1. #1

    What is wrong with my collision detection?

    This is my program and i don't know what is wrong with my collision detection...PLEEEEEZEEE HELP ME!!!


    [pascal]unit Unit1;

    interface

    uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, DXSprite, DXDraws, DXClass, DXInput;

    type
    TForm1 = class(TForm)
    DXDraw: TDXDraw;
    DXSpriteEngine1: TDXSpriteEngine;
    DXImageList: TDXImageList;
    DXSpriteEngine: TDXSpriteEngine;
    DXInput: TDXInput;
    DXTimer: TDXTimer;
    procedure DXTimerTimer(Sender: TObject; LagCount: Integer);
    procedure DXDrawInitialize(Sender: TObject);
    private
    { Private declarations }
    public
    { Public declarations }
    end;
    type tplayer=class(timagesprite)
    public
    procedure DoMove(MoveCount: Integer); override;
    procedure DoCollision(Sprite: TSprite; var Done: Boolean); override;
    end;
    tnature=class(timagesprite)
    incx,incy:integer;
    public
    procedure DoMove(MoveCount: Integer); override;
    end;

    var
    Form1: TForm1;

    implementation

    {$R *.dfm}
    procedure tplayer.DoMove(MoveCount: Integer);
    var img_bulet:integer;
    musicfilechar;
    begin
    inherited;
    if isUp in Form1.DXInput.States then
    begin
    Y := Y - (250/1000)*MoveCount;
    img_bulet:=form1.DXImageList.Items.IndexOf('plane_ throttle');
    image :=form1.DXImageList.Items[img_bulet];
    end
    else
    begin
    img_bulet:=form1.DXImageList.Items.IndexOf('plane' );
    image :=form1.DXImageList.Items[img_bulet];

    end;
    if isDown in Form1.DXInput.States then
    Y := Y + (250/1000)*MoveCount;

    if isLeft in Form1.DXInput.States then
    X := X - (250/1000)*MoveCount;

    if isRight in Form1.DXInput.States then
    X := X + (250/1000)*MoveCount;
    if isbutton1 in Form1.DXInput.States then
    begin
    end;

    if X<=26 then X := 26;
    if X>640-26 then X := 640-26;
    if Y<=26 then Y := 26;
    if Y>=480-26 then Y := 480-26;
    PixelCheck := True;
    Collision;
    end;
    procedure TPlayer.DoCollision(Sprite: TSprite; var Done: Boolean);
    begin
    //Check if the sprite hit was the ghost
    if Sprite is Tnature then
    begin
    form1.Close;
    end;

    end;
    procedure tnature.DoMove(MoveCount: Integer);
    begin
    x:=x+1;
    y:=y+1;
    if x>=640 then x:=-10;
    if y>=500 then y:=-10;
    collision;
    end;

    procedure TForm1.DXTimerTimer(Sender: TObject; LagCount: Integer);
    begin
    if not dxdraw.CanDraw then exit;
    dxdraw.Surface.Fill(0);
    dxspriteengine.Move(1000 div 80);
    dxspriteengine.Dead;
    dxspriteengine.Draw;
    dxdraw.Flip;
    end;

    procedure TForm1.DXDrawInitialize(Sender: TObject);
    begin
    dximagelist.Items.LoadFromFile('d:\projects\Plane fighter\graphics.dxg');
    with tplayer.Create(dxspriteengine.Engine) do
    begin
    image:=form1.DXImageList.Items.Find('plane');
    x:=100;
    y:=100;
    end;
    with tnature.Create(dxspriteengine.Engine) do
    begin
    image:=form1.DXImageList.Items.Find('meteorit');
    x:=-10;
    y:=-10;
    end;

    end;

    end.[/pascal]

    EDIT by Useless Hacker: Added pascal tags

  2. #2

    What is wrong with my collision detection?

    What's that Collision procedure in OnMove (last line in OnMove)? Did you just not include that procedure or should it be DoCollision. Other than that I don't know - maybe you should be calling Collision if any of the if statements above it are true rather than calling it for every OnMove.
    Peter

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
  •