unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Windows ,Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls, BGRABitmap, BGRABitmapTypes;
type
{ TForm1 }
TForm1 = class(TForm)
playerPosTimer : TTimer;
shotTimer: TTimer;
procedure FormClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure playerPosTimerTimer(Sender: TObject);
procedure playerPaint(Sender:Tobject);
procedure shotTimerTimer(Sender: TObject);
procedure shotPaint(Sender:TObject);
private
{ private declarations }
public
{ public declarations }
playerShip : TBGRABitmap;
shot : TBGRABitmap;
pPlayer : Point;
pFormer: Point;
shotSpeed : Integer;
pShot : Point;
shooting : Integer;
leftClick : boolean;
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.playerPosTimerTimer(Sender: TObject);
begin
pFormer:= pPlayer;
pPlayer:= Mouse.CursorPos;
pPlayer:= Form1.ScreenToClient(pPlayer);
playerPaint(Sender);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
playerShip := TBGRABitmap.Create('1.png');
pPlayer:= Mouse.CursorPos;
pPlayer:= Form1.ScreenToClient(pPlayer);
shooting:=0;
shotSpeed:=10;
leftClick:= false;
pShot.y:=1;
end;
procedure TForm1.FormClick(Sender: TObject);
begin
leftClick:=true;
end;
procedure TForm1.playerPaint(Sender:Tobject);
begin
Form1.Canvas.FillRect(pFormer.x-round(0.5*playerShip.Width),pFormer.y-round(0.5*playerShip.Height),pformer.x+playerShip.Width-round(0.5*playerShip.Width),pFormer.y+playerShip.Height-round(0.5*playerShip.Height));
playerShip.Draw(Canvas, pPlayer.x-round(0.5*playerShip.Width),pPlayer.y-round(0.5*playerShip.Height),false);
end;
procedure TForm1.shotTimerTimer(Sender: TObject);
begin
if (leftClick = true) and (shooting = 0) then
begin
try shot:= TBGRABitmap.Create('Beam1.png'); except end;
pShot.x:=pPlayer.x- round(0.5*shot.width);
pShot.y:=pPlayer.y- round(0.5*playerShip.Height)-shot.Height;
shot.draw(Canvas,pShot.x,pShot.y,true);
shooting:= shooting+1;
end;
leftClick:=false;
if pShot.y <= 0 then
begin
shot.Free;
shooting:=shooting-1;
end;
if shooting >=1 then
begin
pShot.y:= pShot.y-shotSpeed;
shotPaint(Sender);
end;
end;
procedure TForm1.shotPaint(Sender:TObject);
begin
Form1.canvas.FillRect(pShot.x, pShot.y+shotSpeed, pShot.x+shot.Width, pShot.y+shot.Height+shotSpeed);
shot.draw(Canvas,pShot.x,pShot.y,true);
end;
end.