Skocz do zawartości


Zdjęcie

[delphi]Gierka w Delphi - problem z punktami


  • Zamknięty Temat jest zamknięty
1 odpowiedź w tym temacie

#1 Wojcisz

Wojcisz

    Nowy

  • 3 postów

Napisano 16 03 2008 - 14:02

Witam, mam mały problem. Piszę na infę gierkę w delphi, a mianowicie Pilsnera (butelki spadają i trzeba je łapać). Tylko mam problem z deklaracją kolizji butelki ze skrzynką i naliczania punktów.

Pierwszą butelkę zlicza jako 50 punktów zamiast 100, potem już normalnie. Kto ma pomysl czemu tak jest?

Tu kod z timera, który zlicza pkt-y i sprawdza czy nie doszło do kolizji.
procedure TForm1.TimerekTimer(Sender: TObject);
var
i,j:integer;
begin
for i:=1 to a do
			  begin
				 obrazy[i].Top:=obrazy[i].Top+10;
				 if i >= 2 then for j := (i-1) to i do
				 if (obrazy[j].top+obrazy[j].Height>=389) and
				 (obrazy[j].top+obrazy[j].Height<=395) and
				 (obrazy[j].left+15>=image1.left) and
				 (obrazy[j].Left+15<=image1.Left+image1.Width) then
					begin
					  obrazy[j].Visible:=False;
					  pkt:=pkt+50;
					end;
				 end;
Label1.Caption:='Punkty: '+IntToStr(pkt);

A tu kod całego progsa:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, jpeg, ExtCtrls, StdCtrls, ShellAPI;
var
a,pkt:integer;
type
  TForm1 = class(TForm)
	Panel1: TPanel;
	Image1: TImage;
	Label1: TLabel;
	Timer1: TTimer;
	i4: TImage;
	Timerek: TTimer;
	procedure Panel1MouseMove(Sender: TObject; Shift: TShiftState; X,
	  Y: Integer);
	procedure FormCreate(Sender: TObject);
	procedure Timer1Timer(Sender: TObject);
	procedure TimerekTimer(Sender: TObject);

  private
	 {private declarations}
	 obrazy:array [1..100] of TImage;
  public
	{ Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}


procedure TForm1.Panel1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
Image1.Left:=x-52;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
pkt:=0;
ShowCursor(False);
Form1.DoubleBuffered := true;
a:=0;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
inc(a);
obrazy[a]:= TImage.Create(Self);
 with obrazy[a] do
   begin
	 parent:=Panel1;
	 left:=random(473);
	 top:=0;
	 Picture.LoadFromFile('asd.jpg');
	 Visible:=True;
	 Width:=30;
	 height:=90;
   end;
end;

procedure TForm1.TimerekTimer(Sender: TObject);
var
i,j:integer;
begin
for i:=1 to a do
			  begin
				 obrazy[i].Top:=obrazy[i].Top+10;
				 if i >= 2 then for j := (i-1) to i do
				 if (obrazy[j].top+obrazy[j].Height>=389) and
				 (obrazy[j].top+obrazy[j].Height<=395) and
				 (obrazy[j].left+15>=image1.left) and
				 (obrazy[j].Left+15<=image1.Left+image1.Width) then
					begin
					  obrazy[j].Visible:=False;
					  pkt:=pkt+50;
					end;
				 end;
Label1.Caption:='Punkty: '+IntToStr(pkt);
end;
end.

Kto zna jakiś prostszy algorytm na sprawdzanie kolizji? Bo ten wydaje mi sie strasznie łopatologiczny. Jest w delphi coś na styl flashowego hittesta??

  • 0

#2 Sowiasty

Sowiasty

    Początkujący

  • 22 postów

Napisano 23 03 2008 - 20:23

Co do tych 50 punktow, to moze na poczatku dodaj do zmiennej pkt 50, a pozniej IMHO powinno byc ok.
Pozdro :P

  • 0

Zobacz więcej tematów z tagiem: Delphi



Użytkownicy przeglądający ten temat: 0

0 użytkowników, 0 gości, 0 anonimowych