Thema: Delphi Kollision/Abschuss

Einzelnen Beitrag anzeigen

Koki

Registriert seit: 11. Jan 2006
16 Beiträge
 
Delphi 2005 Personal
 
#14

Re: Kollision/Abschuss

  Alt 19. Mär 2006, 18:33
ich hab schon wieder ein problem bei der kollision die bekomme ich nicht richtig hin

also ich hab erst inherited's vorschlag versucht funktionierte aber nicht, dann hab ich mir nochmal gedanken gemacht und eine weitere procedure ausgedacht und funktioniert auch nicht nun bitte ich euch das mal anzugucken und mir zu helfen aber ich brauch die hilfe schnell denn ich muss das programm bis spätestens übermorgen fertig haben und will noch was verbessern dazu brauche ich aber erst das grundgerüst

Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, Menus, Buttons;

type
  TForm1 = class(TForm)
    background: TImage;
    player: TImage;
    enemy1: TImage;
    MainMenu1: TMainMenu;
    Datei1: TMenuItem;
    Start1: TMenuItem;
    Beenden1: TMenuItem;
    Timer1: TTimer;
    bullet1: TImage;
    planet1: TImage;
    bullet2: TImage;
    bullet3: TImage;
    bullet4: TImage;
    bullet5: TImage;
    Timer2: TTimer;
    planet2: TImage;
    enemy2: TImage;
    enemy3: TImage;
    enemy4: TImage;
    enemy5: TImage;
    explosion1: TImage;
    Timer3: TTimer;
    procedure Timer3Timer(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure Beenden1Click(Sender: TObject);
    procedure Start1Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure Timer2Timer(Sender: TObject);

  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  x,y:integer; {Schiff-X/Y Koordinaten}
  e,f,ee,ff:integer; {Planet-X/Y Koordinaten}
  c,cc,ccc,cccc,ccccc,d,dd,ddd,dddd,ddddd:integer; {Schuss-X/Y Koordinaten}
  a,aa,aaa,aaaa,aaaaa,b,bb,bbb,bbbb,bbbbb:integer; {Feinde-x/y Koordinaten}
  g,h,k:integer; {Explosion-x/y Koordinate}
  ü:integer; {Sonstige Variablen}
  z:boolean;

implementation

{$R *.dfm}

procedure Schuss;
 begin
  c:=x; d:=y;
  cc:=x; dd:=y;
  ccc:=x; ddd:=y;
  cccc:=x; dddd:=y;
  ccccc:=x; ddddd:=y;
  form1.bullet1.picture.loadfromfile('bullet1.bmp');
  form1.bullet2.picture.loadfromfile('bullet1.bmp');
  form1.bullet3.picture.loadfromfile('bullet1.bmp');
  form1.bullet4.picture.loadfromfile('bullet1.bmp');
  form1.bullet5.picture.loadfromfile('bullet1.bmp');
  form1.bullet1.Visible:=false;
  form1.bullet2.Visible:=false;
  form1.bullet3.Visible:=false;
  form1.bullet4.Visible:=false;
  form1.bullet5.Visible:=false;
  form1.bullet1.Left:=c; form1.bullet1.Top:=d;
  form1.bullet2.Left:=cc; form1.bullet2.Top:=dd;
  form1.bullet3.Left:=ccc; form1.bullet3.Top:=ddd;
  form1.bullet4.Left:=cccc; form1.bullet4.Top:=dddd;
  form1.bullet5.Left:=ccccc; form1.bullet5.Top:=ddddd;
 end;

procedure Planet;
 begin
  e:=random(775); f:=random(375);
  form1.planet1.Left:=e; form1.planet1.Top:=f;
  form1.planet1.Picture.LoadFromFile('planet5.bmp');
 end;

procedure Enemy;
 begin
  a:=875; b:=random(700);
  aa:=875; bb:=random(700);
  aaa:=875; bbb:=random(700);
  aaaa:=875; bbbb:=random(700);
  aaaaa:=875; bbbbb:=random(700);
  form1.enemy1.Left:=a; form1.enemy1.Top:=b;
  form1.enemy1.Picture.Loadfromfile('enemy1.bmp');
  form1.enemy2.Picture.LoadFromFile('enemy1.bmp');
  form1.enemy3.Picture.LoadFromFile('enemy1.bmp');
  form1.enemy4.Picture.LoadFromFile('enemy1.bmp');
  form1.enemy5.Picture.LoadFromFile('enemy1.bmp');
 end;

procedure Neu;
 begin
  form1.doublebuffered:=true;
  Enemy; Schuss; Planet;
  x:=0; y:=150;
  form1.background.picture.loadfromfile('space1.bmp');
  form1.player.picture.loadfromfile ('player.bmp');
  form1.player.Left:=x; form1.player.Top:=y;
  z:=true;
 end;

procedure TForm1.Start1Click(Sender: TObject);
 begin
  Neu;
 end;

procedure Kollision;
 begin
  k:=0;
  g:=a; h:=b;
  form1.explosion1.picture.LoadFromFile('explosion1.bmp');
 end;

[b][i]procedure KollisionAb;
 begin
  if (a>c-20) and (b>d-20) or (b>d+20) then form1.enemy1.visible:=false;
  if (a>cc-20) and (b>dd-20) or (b>dd+20) then form1.enemy2.visible:=false;
  if (a>ccc-20) and (b>ddd-20) or (b>ddd+20) then form1.enemy3.visible:=false;
  if (a>cccc-20) and (b>dddd-20) or (b>dddd+20) then form1.enemy4.visible:=false;
  if (a>ccccc-20) and (b>ddddd-20) or (b>ddddd+20) then form1.enemy5.visible:=false;
 end;[/i][/b]

procedure Feuern(ä:integer);
 begin
  c:=x+50; d:=y+23;
  cc:=x+50; dd:=y+23;
  ccc:=x+50; ddd:=y+23;
  cccc:=x+50; dddd:=y+23;
  ccccc:=x+50; ddddd:=y+23;
  if ä=1 then form1.bullet1.visible:=true;
  if ä=2 then form1.bullet2.Visible:=true;
  if ä=3 then form1.bullet3.Visible:=true;
  if ä=4 then form1.bullet4.Visible:=true;
  if ä=5 then form1.bullet5.Visible:=true;
  form1.Timer2.Enabled:=true;
 end;

procedure Tform1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var ö:integer;
begin
  //form1.Caption:=inttostr(key);
  ö:=1;
  if key=113 then Neu;
  if z=true then
   begin
    if ö=5 then ö:=1;
    if key=37 then x:=x-5;
    if key=38 then y:=y-5;
    if key=39 then x:=x+5;
    if key=40 then y:=y+5;
    if key=17 then begin Feuern(ö); ö:=ö+1; end;
   end;
end;

procedure Tform1.Timer1Timer(Sender: TObject);
 begin
  player.Left:=x;
  player.top:=y;
 end;

procedure TForm1.Timer2Timer(Sender: TObject);
 begin
  form1.bullet1.Left:=c; form1.bullet1.Top:=d;
  form1.bullet2.Left:=cc; form1.bullet2.Top:=dd;
  form1.bullet3.Left:=ccc; form1.bullet3.Top:=ddd;
  form1.bullet4.Left:=cccc; form1.bullet4.Top:=dddd;
  form1.bullet5.Left:=ccccc; form1.bullet5.Top:=ddddd;
  if c=1000 then
   begin
    c:=x; form1.bullet1.Visible:=false;
   end
  else c:=c+5;
  if cc=1000 then
   begin
    cc:=x; form1.bullet2.Visible:=false;
   end
  else cc:=cc+5;
  if ccc=1000 then
   begin
    ccc:=x; form1.bullet3.Visible:=false;
   end
  else ccc:=ccc+5;
  if cccc=1000 then
   begin
    cccc:=x; form1.bullet4.Visible:=false;
   end
  else cccc:=cccc+5;
  if ccccc=1000 then
   begin
    ccccc:=x; form1.bullet1.Visible:=false;
   end
  else ccccc:=ccccc+5;
 end;

procedure TForm1.Timer3Timer(Sender: TObject);
 begin
  if k<5 then k:=k+1
  else
   begin
    if k<10 then
     begin
      form1.explosion1.picture.LoadFromFile('explosion2.bmp');
      k:=k+1;
     end
    else form1.explosion1.visible:=false;
   end;
 end;

procedure TForm1.Beenden1Click(Sender: TObject);
begin
  close;
end;

end.
  Mit Zitat antworten Zitat