Witam. Mam na DXDraw ludzika (Image) i chce zrobić takie coś, że jak klikne gdzieś na formie myszką, to ten ludzik zacznie się w tamtą stronę przesuwać. Jak to zrobić ?
Po linii prostej, czy jak?
Bo jesli po linii prostej to tak:
Masz x, y ludzika,
I masz x y celu.
W:= (Ludzik.x - Cel.x) / (Ludzik.y - Cel.y);
I w zmiennej W pamietasz ta niezwykle cenna wartosc :)
Teraz kazesz ludzikowi pojsc w prawo:
Inc(Ludzik.x)
A potem zawsze sprawdzasz w petli tak:
If W < (Ludzik.x - Cel.x) / (Ludzik.y - Cel.y) then
Inc(Ludzik.x) else
Inc(Ludzik.y);
Albo moze bedzie na odwrot (nie chce mi sie teraz kombinowac) To oczywiscie uproszczony schemat, ale chyba wiadomo o co chodzi :)
Shibby, sprawdź maila !
Poruszanei za pomoca strzalki !
poustawiaj wlasciowsci DXDRAW1.na DXDRAW1:) ... itd.
auto := TAnimation.Create(DxSpriteEngine1.Engine);
auto.x := (screen.Width div 2) + 10 ;
auto.y := screen.Height div 2;
auto.Image := dximagelist1.Items[0];
//musisz dodac itema[0] jakis obrazek zeby bylo co wczytac :)
porusanie za pomoca strzalek ! autka po formie :)
dxdraw1.surface.Fill(0);
dxinput1.Update; .....itd.
if (isleft in dxinput1.states) then
if auto.x > 10 then begin
auto.x := auto.x - speed_auto;
end;
if (isright in dxinput1.states) then
if auto.x < DXForm1.Width - 10 then begin
auto.x := auto.x + speed_auto;
end;
if (isup in dxinput1.states) then
if auto.y > 10 then begin
auto.y := auto.y - speed_auto;
end;
if (isdown in dxinput1.states) then
if auto.y < DXForm1.Height - 10 then begin
auto.y := auto.y + speed_auto;
end;