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.
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;
Check out the full blog post by Jim about the Ouya app demo and download the full source code.
The direct link to the source code is here. It is packed up with a bunch of other demos but just open the Ouya demo from the archive to get to the code. You have to register to download the file.