Dandi GTA, czyli szwankujące je?żd?żenie

Dandi GTA, czyli szwankujące je?żd?żenie
D8
  • Rejestracja: dni
  • Ostatnio: dni
  • Postów: 41
0

Siema!
Robię grę a'la GTA, i nie wiem co zrobiłem źle.
Oto kod na poruszanie się ludka, i wsiadanie/wysiadanie do/z samochodów:

Kopiuj
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
case key of
VK_Left: Guy.Left := Guy.Left -5;
VK_Right: Guy.Left := Guy.Left +5;
VK_Up: Guy.Top := Guy.Top -5;
VK_Down: Guy.Top := Guy.Top +5;
13:
if Guy.Visible = true then
begin
 if Car1.Visible = false then
begin
Car1.Visible := true;
Guy.Picture := Guy_Texture.Picture;
Car1.Left := Guy.Left;
Car1.Top  := Guy.Top;
end else
 if Guy.Top < Car1.Top then
 if Guy.Left < Car1.Left then
if Car1.Visible = true then
begin
Guy.Left := Car1.Left;
Guy.Top  := Car1.Top;
Car1.Visible := false;
Guy.Picture := Car1_Texture.Picture;
end else


if Car2.Visible = false then
begin
Car2.Visible := true;
Guy.Picture := Guy_Texture.Picture;
Car2.Left := Guy.Left;
Car2.Top  := Guy.Top;
end else
 if Guy.Top < Car2.Top then
 if Guy.Left < Car2.Left then
if Car2.Visible = true then
begin
Guy.Left := Car2.Left;
Guy.Top  := Car2.Top;
Car2.Visible := false;
Guy.Picture := Car2_Texture.Picture;
end else


if Car3.Visible = false then
begin
Car3.Visible := true;
Guy.Picture := Guy_Texture.Picture;
Car3.Left := Guy.Left;
Car3.Top  := Guy.Top;
end else
 if Guy.Top < Car3.Top then
 if Guy.Left < Car3.Left then
if Car3.Visible = true then
begin
Guy.Left := Car3.Left;
Guy.Top  := Car3.Top;
Car3.Visible := false;
Guy.Picture := Car3_Texture.Picture;
end else
if Car.Visible = false then
begin
Car.Visible := true;
Guy.Picture := Guy_Texture.Picture;
Car.Left := Guy.Left;
Car.Top  := Guy.Top;
end else
 if Guy.Top < Car.Top then
 if Guy.Left < Car.Left then
if Car.Visible = true then
begin
Guy.Left := Car.Left;
Guy.Top  := Car.Top;
Car.Visible := false;
Guy.Picture := Car_Texture.Picture;
end;
end;
end;
end;

Kiedy włączam grę, wszystko jest ok, ludek chodzi, ale kiedy chcę wsiąść do jakiegoś samochodu, Od razu jest problem:
do 2 samochodów nie da się wsiąść, jeden jeśli jest wyżej od drugiego, to ludek zamiast wejść w niego, wchodzi w ten drugi itp.

Mam nadzieję, że ktoś rozszyfruje, o co tu chodzi, bo mam straszną ochotę na zagranie w już działającą wersję programu "Dandi GTA" (Oczywiście jest to nazwa wstępna) :P

Dzięks za wszystko, i mam nadzieję, że kogoś ten temat zainteresuje.

P.S. Nie mówcie mi nic o DelphiX, bo już mi to bokiem wychodzi :p

ŁF
  • Rejestracja: dni
  • Ostatnio: dni
0

o mamo, stosuj wcięcia, bo nie sposób się połapać gdzie idzie który if...
ponadto:

Kopiuj
var
  b: boolean
...
if b = true then
...

to to samo co

Kopiuj
if b then

nie prościej?

D8
  • Rejestracja: dni
  • Ostatnio: dni
  • Postów: 41
0

Nie bardzo kapuję, o co chodzi z tymi "wcięciami"...
Mógłbyś mnie oświecić?
w każdym razie dzięki za podpowiedź, że nie trzeba dawać

Kopiuj
if b = true 

tylko wystarczy if b

Kopiuj
.
CK
  • Rejestracja: dni
  • Ostatnio: dni
  • Postów: 2692
0

Ekhem, widzę, żę robisz grę w Delphi używając VCL :|

z Bogiem

minimalne wymagania to pewnie 1200 GHZ :-8

Rudy
  • Rejestracja: dni
  • Ostatnio: dni
0

<font color="green">minimalne wymagania to pewnie 1200 GHZ</span>

bez przesady. Wcale nie trzeba pisać w Api (chociaż polecam) !

D8
  • Rejestracja: dni
  • Ostatnio: dni
  • Postów: 41
0

Ekhem, koledzy,
<font color="red">sorka, ale to chyba nie komentarzysko</span> :p

omikron87
  • Rejestracja: dni
  • Ostatnio: dni
0

Łukasz Fronczyk ma rację! Stosuj wcięcia, bo nikt nie przeczyta twojego kodu, a jak nie wiesz jak stosowac wcięcia to popatrz sobie do DelphiKurs'u (lekcja 16 punkt 3: Styl pisania).

Poza tym:

Kopiuj
if Guy.Top < Car1.Top then
if Guy.Left < Car1.Left then
if Car1.Visible = true then

to to samo co:

Kopiuj
if (Guy.Top < Car1.Top) and (Guy.Left < Car1.Left) and (Car1.Visible = true) then
WA
  • Rejestracja: dni
  • Ostatnio: dni
  • Postów: 501
0
Kopiuj
begin
  case key of
  VK_Left: Guy.Left := Guy.Left -5;
  VK_Right: Guy.Left := Guy.Left +5;
  VK_Up: Guy.Top := Guy.Top -5;
  VK_Down: Guy.Top := Guy.Top +5;
  13:
    if Guy.Visible then
      begin
      if not Car1.Visible then
        begin
          Car1.Visible := true;
          Guy.Picture := Guy_Texture.Picture;
          Car1.Left := Guy.Left;
          Car1.Top  := Guy.Top;
        end
      else
        if (Guy.Top < Car1.Top) AND (Guy.Left < Car1.Left) AND (Car1.Visible) then
          begin
            Guy.Left := Car1.Left;
            Guy.Top  := Car1.Top;
            Car1.Visible := false;
            Guy.Picture := Car1_Texture.Picture;
          end
        else
        if not Car2.Visible then
          begin
            Car2.Visible := true;
            Guy.Picture := Guy_Texture.Picture;
            Car2.Left := Guy.Left;
            Car2.Top  := Guy.Top;
          end
        else
        if (Guy.Top < Car2.Top) And (Guy.Left < Car2.Left) and (Car2.Visible) then
          begin
            Guy.Left := Car2.Left;
            Guy.Top  := Car2.Top;
            Car2.Visible := false;
            Guy.Picture := Car2_Texture.Picture;
          end
        else
        if not Car3.Visible then
          begin
            Car3.Visible := true;
            Guy.Picture := Guy_Texture.Picture;
            Car3.Left := Guy.Left;
            Car3.Top  := Guy.Top;
          end
        else
        if (Guy.Top < Car3.Top) AND (Guy.Left < Car3.Left) AND (Car3.Visible) then
          begin
            Guy.Left := Car3.Left;
            Guy.Top  := Car3.Top;
            Car3.Visible := false;
            Guy.Picture := Car3_Texture.Picture;
          end
        else
        if not Car.Visible then
          begin
          Car.Visible := true;
          Guy.Picture := Guy_Texture.Picture;
          Car.Left := Guy.Left;
          Car.Top  := Guy.Top;
        end
        else
          if (Guy.Top < Car.Top) and (Guy.Left < Car.Left) and (Car.Visible) then
            begin
              Guy.Left := Car.Left;
              Guy.Top  := Car.Top;
              Car.Visible := false;
              Guy.Picture := Car_Texture.Picture;
            end;
      end;
end;
end;

Poprawilem kod, jak prosiles (mile mi miejsce w autorach :p)

ŁF
  • Rejestracja: dni
  • Ostatnio: dni
0

Ej, a po co Ci label l3??? korzystasz z etykiet i skoków goto??? o matko!!!!!! ;-(

D8
  • Rejestracja: dni
  • Ostatnio: dni
  • Postów: 41
0

Dzięki, działa bez zarzutów :-)
no to tamten problem już rozwiązany - pora na następny:

oto kod na poruszanie się ludka, i przy tym zmienianie mu obrazka:

Kopiuj
 case key of
  VK_Left: begin
  Guy.Left := Guy.Left -5;
  if (Guy.Picture = Guy_Texture.Picture) or (Guy.Picture = Left.Picture) or (Guy.Picture = Right.Picture) or (Guy.Picture = Up.Picture) or (Guy.Picture = Down.Picture) then
    begin
  Guy_Texture.Picture := Left.Picture;
  Guy.Picture := Guy_Texture.Picture;
    end;
    end;
  VK_Right: begin
  Guy.Left := Guy.Left +5;
  if (Guy.Picture = Guy_Texture.Picture) or (Guy.Picture = Left.Picture) or (Guy.Picture = Right.Picture) or (Guy.Picture = Up.Picture) or (Guy.Picture = Down.Picture) then
    begin
  Guy_Texture.Picture := Right.Picture;
  Guy.Picture := Guy_Texture.Picture;
    end;
    end;

    VK_Up: Begin
  Guy.Top := Guy.Top -5;
  if (Guy.Picture = Guy_Texture.Picture) or (Guy.Picture = Left.Picture) or (Guy.Picture = Right.Picture) or (Guy.Picture = Up.Picture) or (Guy.Picture = Down.Picture) then
    begin
  Guy_Texture.Picture := Up.Picture;
  Guy.Picture := Guy_Texture.Picture;
    end;
    end;

    VK_Down: Begin
  Guy.Top := Guy.Top +5;
  if (Guy.Picture = Guy_Texture.Picture) or (Guy.Picture = Left.Picture) or (Guy.Picture = Right.Picture) or (Guy.Picture = Up.Picture) or (Guy.Picture = Down.Picture) then
    begin
  Guy_Texture.Picture := Down.Picture;
  Guy.Picture := Guy_Texture.Picture;
    end;
    end;

Ale obrazek pozostaje ten sam (!)...
Co zrobić??

ŁF
  • Rejestracja: dni
  • Ostatnio: dni
0

czy Ty w ogóle wiesz, co to jest debuger?

nie oczekuj od innych ludzi, że będą ciągle poprawiać Twój kod!

Zarejestruj się i dołącz do największej społeczności programistów w Polsce.

Otrzymaj wsparcie, dziel się wiedzą i rozwijaj swoje umiejętności z najlepszymi.