unit USpace;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Stdctrls, ActnList, ExtCtrls, contnrs, jpeg;
type
TForm1 = class(TForm)
PlayerIMG: TImage;
LaserTimer: TTimer;
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure ErzeugeLaser(const Picture: String);
procedure LaserTimerTimer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
LaserList: TObjectList;
implementation
{$R *.dfm}
procedure TForm1.ErzeugeLaser(const Picture: String);
var
ILaser:TImage;
begin
ILaser := TImage.Create( nil );
ILaser.Picture.LoadFromFile(Picture);
ILaser.Width:=8;
ILaser.Height:=16;
ILaser.Left:=PlayerIMG.Left+12;
ILaser.Top:=PlayerIMG.Top-32;
ILaser.Parent:=Self;
ILaser.Tag:=10;
LaserList.Add(ILaser);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
PlayerIMG.Picture.LoadFromFile('.\gfx\Schiff.jpg');
end;
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState
);
begin
case Key of
37: PlayerIMG.Left:=PlayerIMG.Left-10;
39: PlayerIMG.Left:=PlayerIMG.Left+10;
$20: ErzeugeLaser('.\gfx\Laser.jpg');
end;
end;
procedure TForm1.LaserTimerTimer(Sender: TObject);
var
i: Integer;
ILaser: TImage;
begin
i := 0;
while i < LaserList.Count do
begin
ILaser := LaserList.Items[i] as TImage;
if ILaser.Top = 0 then
begin
LaserList.Delete(i);
end
else
begin
ILaser.Top:=ILaser.Top - 5;
Inc(i);
end;
end;
end;
end.