@rvk
vxx := (ball[i].left - 25) - (ball[i + 1].left - 25);
i did that to get the center point but i just realised that it's wrong
it should be
vxx := (ball[i].left + 25) - (ball[i + 1].left + 25);
also how should i do this?
Try to change the point where they connect according to the direction the main ball is going. And even if they are connected the follow-balls should still move if they are not connected to the point at 0 (for down direction), 90 (for left), 180 (for up) or 270 (for right) degrees.
which formula should i change?
@user137
hi i tried to do this
edit2: You actually had the following covered up well. Only issue you had is caused by integer rounding. You need to use floating point values for worm position, so you need a second array. Round the position into integer and copy to shape's left and top values at the end of the loop.
but i got errors
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
LCLType;
type
{ TForm1 }
TForm1 = class(TForm)
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
procedure Timer1Timer(Sender: TObject);
private
ball: array of tshape;
xpos: array of real;
ypos: array of real;
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
direction: integer;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
var
i: integer;
begin
randomize;
setlength(xpos, 3);
for i := 0 to 3-1 do
begin
xpos:= ball[i].Width + random(Width - ball[i].Width);
end;
setlength(ypos, 3);
for i := 0 to 3-1 do
begin
ypos:= ball[i].Height + random(Height - ball[i].Height);
end;
setlength(ball, 3);
for i := 0 to 3 - 1 do
begin
ball[i] := Tshape.Create(self);
ball[i].parent := self;
ball[i].shape := stcircle;
ball[i].Width := 30;
ball[i].Height := 30;
ball[i].top := ypos[i];
ball[i].left := xpos[i];
ball[i].brush.color := clwhite;
ball[i].pen.color := clwhite;
end;
ball[0].brush.color := clred;
end;
Compile Project, Target: project1.exe: Exit code 1, Errors: 6
unit1.pas(48,57) Error: Incompatible types: got "Double" expected "TForm1.{Dynamic} Array Of Real"
unit1.pas(54,62) Error: Incompatible types: got "Double" expected "TForm1.{Dynamic} Array Of Real"
unit1.pas(66,27) Error: Incompatible type for arg no. 1: Got "Double", expected "LongInt"
unit1.pas(67,28) Error: Incompatible type for arg no. 1: Got "Double", expected "LongInt"
unit1.pas(122,49) Error: Incompatible type for arg no. 1: Got "Double", expected "LongInt"
unit1.pas(123,47) Error: Incompatible type for arg no. 1: Got "Double", expected "LongInt"