unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Windows ,Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls, BGRABitmap, BGRABitmapTypes;
type
TPlayer = class
playerPosTimer : TTimer;
shotTimer: TTimer;
constructor create();
procedure playerPosTimerTimer(Sender: TObject);
procedure playerPaint(p:Point;pOld:Point);
procedure shotTimerTimer(Sender: TObject);
procedure shotPaint(shot:TBGRABitmap; p:Point);
private
public
playerShip : TBGRABitmap;
shot1, shot2, shot3 : TBGRABitmap;
pPlayer : Point;
pFormer: Point;
shotSpeed : Integer;
pShot1, pShot2, pShot3 : Point;
leftClick, x : boolean;
end;
{ TForm1 }
TForm1 = class(TForm)
procedure FormClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
Player1 : TPlayer;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
Player1:=TPlayer.create;
end;
procedure TForm1.FormClick(Sender: TObject);
begin
Player1.leftClick:=true;
end;
constructor TPlayer.Create();
begin
playerShip := TBGRABitmap.Create('1.png');
pPlayer:= Mouse.CursorPos;
pPlayer:= Form1.ScreenToClient(pPlayer);
shotSpeed:=10;
leftClick:= false;
pShot1.y:=1; pShot2.y:=1; pShot3.y:=1;
playerPosTimer := TTimer.Create(nil);
shotTimer := TTimer.create(nil);
playerPosTimer.Interval := 25;
shotTimer.Interval := 25;
playerPosTimer.OnTimer := @playerPosTimerTimer;
shotTimer.onTimer := @shotTimerTimer;
playerPosTimer.Enabled := true;
shotTimer.Enabled := true;
end;
procedure TPlayer.playerPosTimerTimer(Sender: TObject);
begin
pFormer:= pPlayer;
pPlayer:= Mouse.CursorPos;
pPlayer:= Form1.ScreenToClient(pPlayer);
playerPaint(PPlayer,pFormer);
end;
procedure TPlayer.playerPaint(p:Point;pOld:Point);
begin
Form1.Canvas.FillRect(pOld.x-round(0.5*playerShip.Width),pOld.y-round(0.5*playerShip.Height),pOld.x+playerShip.Width-round(0.5*playerShip.Width),pOld.y+playerShip.Height-round(0.5*playerShip.Height));
playerShip.Draw(Form1.Canvas, p.x-round(0.5*playerShip.Width),p.y-round(0.5*playerShip.Height),false);
end;
procedure TPlayer.shotTimerTimer(Sender: TObject);
begin
if (leftClick = true) and not assigned(shot1) then
begin
shot1:= TBGRABitmap.Create('Beam1.png');
pShot1.x:=pPlayer.x- round(0.5*shot1.width);
pShot1.y:=pPlayer.y- round(0.5*playerShip.Height)-shot1.Height;
shotPaint(shot1,pShot1);
leftClick:=false;
end;
if (leftClick = true) and not assigned(shot2) and assigned(shot1) then
begin
shot2:= TBGRABitmap.Create('Beam1.png');
pShot2.x:=pPlayer.x- round(0.5*shot2.width);
pShot2.y:=pPlayer.y- round(0.5*playerShip.Height)-shot2.Height;
shotPaint(shot2,pShot2);
leftClick:=false;
end;
if (leftClick = true) and not assigned(shot3) and assigned(shot2) and assigned(shot1)then
begin
shot3:= TBGRABitmap.Create('Beam1.png');
pShot3.x:=pPlayer.x- round(0.5*shot3.width);
pShot3.y:=pPlayer.y- round(0.5*playerShip.Height)-shot3.Height;
shotPaint(shot3,pShot3);
leftClick:=false;
end;
if assigned(shot1) or assigned(shot2) or assigned(shot3) then
begin
if pShot1.y<=0 then
begin
Form1.canvas.FillRect(pShot1.x, pShot1.y, pShot1.x+shot1.Width, pShot1.y+shot1.Height);
shot1.free;
pShot1.y:=1;
end
else if assigned(shot1) then
begin
pShot1.y:= pShot1.y-shotSpeed;
shotPaint(shot1,pShot1);
end;
if (pShot2.y <= 0) then
begin
Form1.canvas.FillRect(pShot2.x, pShot2.y, pShot2.x+shot2.Width, pShot2.y+shot2.Height);
shot2.free;
pShot2.y:=1;
end
else if assigned(shot2) then
begin
pShot2.y:= pShot2.y-shotSpeed;
shotPaint(shot2,pShot2);
end;
if (pShot3.y <= 0) then
begin
Form1.canvas.FillRect(pShot3.x, pShot3.y, pShot3.x+shot3.Width, pShot3.y+shot3.Height);
shot3.free;
pShot3.y:=1;
end
else if assigned(shot3) then
begin
pShot3.y:= pShot3.y-shotSpeed;
shotPaint(shot3,pShot3);
end;
end;
end;
procedure TPlayer.shotPaint(shot:TBGRABitmap; p:Point);
begin
Form1.canvas.FillRect(p.x, p.y+shotSpeed, p.x+shot.Width, p.y+shot.Height+shotSpeed);
shot.draw(Form1.Canvas,p.x,p.y,true);
end;
end.