Dismiss Notice

REGISTRATION IS AFTER ADMIN ACTIVATION

DONATIONS WITH PAYPAL CLICK TO BUTTON

1 MONTH VIP - 5$; 3 MONTHS VIP - 10$; 6 MONTHS VIP - 20$; 1 YEAR VIP - 30$; 2 YEARS VIP - 50$; GOLD USER FOR LIFE VIP - 150$

DONATIONS WITH Bitcoin Address:3NRs3CK3fhXifrNYxHEZKpETDd9vNLMsMD

Dismiss Notice
The registration is approved by the Administrator. It takes about 1 day to approve your registration
Dismiss Notice
For open hidden message no need write thanks, thank etc. Enough is click to like button on right side of thread.

Point Based Collision Detection For Delphi XE5

Discussion in 'Delphi Android And IOS' started by AdminDF, Mar 20, 2014.

  1. AdminDF
    Online

    AdminDFAdminDF is a Verified Member DelphiFan Administrator Staff Member DF Staff

    [​IMG]

    Jim McKeeth from Embarcadero has a demo up where he built an app for the Ouya game console using Delphi XE5 Firemonkey. The Ouya runs Android but it has a controller so you have to check for keystrokes (the buttons from the controller) instead of mouse movements or implement a mouse cursor controlled by the controller. The Ouya demo contains two main pieces of code where the first is the key down event and the second is a point based collision detection function. If you want rectangle based collision detection check out this other post. The point based collision detection function just checks the distance between two points and if they are close enough it does it’s action. You could use the point based collection detection in any of your apps as it is not specific to Android or the Ouya console so it should also work on IOS, Windows, and OSX. Here is a sample of the keydown code:

    Code:
    procedure TForm5.FormKeyDown(Sender: TObject; var Key: Word; var KeyChar: Char;
    Shift: TShiftState);
    begin
    case Key of
    37: MoveLeft;
    38: MoveUp;
    39: MoveRight;
    40: MoveDown;
    end;
    
    label1.Text := ‘Key: ‘ + Key.ToString;
    end;

    And here is a sample of the point based collision detection. You could easily convert this function into a re-usable function where you pass in the two objects as variables and the distance that you want to check and then return true of false.

    Code:
    procedure TForm5.HitCheck;
    var
    shipPt, targetPt: TPointF;
    distance: Integer;
    begin
    shipPt := ship.Position.Point;
    targetPt := target.Position.Point;
    distance := round(shipPt.Distance(targetPt));
    
    label2.Text := ‘Dist: ‘ + round(distance).ToString;
    
    if distance < fMove then
    begin
    targetX.StartValue := target.Position.X;
    targetY.StartValue := target.Position.Y;
    targetX.StopValue := Random(round(playArea.width));
    targetY.StopValue := Random(round(playArea.height));
    targetX.Start;
    targetY.Start;
    label2.Text := ‘Hit!’;
    fScore := fScore + 1;
    lblScore.Text := ‘Score: ‘ + fScore.ToString;
    end;
    end;
     

Share This Page

Laws
Our website, law, laws, copyright and aims to be respectful of individual rights. Our site, as defined in the law of 5651 serves as a provider of space. According to the law, contrary to the law of site management has no obligation to monitor content. Therefore, our site has adopted the principle of fit and remove. Works are subject to copyright laws and is shared in a manner that violated their legal rights, or professional associations, rights holders who, adsdelphi@gmail.com I can reach us at e-mail address. Complaints considered to be infringing on the examination of the content will be removed from our site.
Donate Help To Us and Be VIP
DONATIONS WITH PAYPAL CLICK TO BUTTON
6 MONTHS VIP - 20$; 1 YEAR VIP - 30$; 2 YEARS VIP - 50$; GOLD USER FOR LIFE VIP - 150$
Social Block