Пересещает одну картинку поверх другой в любом направлении, при помощи клавиш курсора.
Код:
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
FileUtil, ExtCtrls, Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
{ TForm1 }
TIGROK=record
X,Y,SK:integer;
End;
TForm1 = class(TForm)
PaintBox1: TPaintBox;
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure Timer1Timer(Sender: TObject);
private
public
end;
var
IGROK:TIGROK;
Form1: TForm1;
fon:tbitmap;
Buf:tbitmap;
korab:tbitmap;
lx,rx,vy,ny:Integer;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
IGROK.SK:=2;
IGROK.X:=150;
IGROK.Y:=60;
lx:= 0;
rx:= 0;
vy:= 0;
ny:= 0;
Buf:=tbitmap.Create;
fon:=tbitmap.Create;
korab:=tbitmap.Create;
fon.LoadFromFile('fon.bmp');
korab.LoadFromFile('korab.bmp');
korab.transparent:=true;
Buf.Width:= 600;
Buf.Height:= 400;
end;
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
If Key=37 then lx:= 1;
If Key=39 then rx:= 1;
If Key=38 then vy:= 1;
If Key=40 then ny:= 1;
end;
procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
If Key=37 then lx:= 0;
If Key=39 then rx:= 0;
If Key=38 then vy:= 0;
If Key=40 then ny:= 0;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
If lx =1 then IGROK.X:=IGROK.X-IGROK.SK;
If rx =1 then IGROK.X:=IGROK.X+IGROK.SK;
If vy =1 then IGROK.Y:=IGROK.Y-IGROK.SK;
If ny =1 then IGROK.Y:=IGROK.Y+IGROK.SK;
Buf.Canvas.Draw(0,0,fon);
Buf.Canvas.Draw(IGROK.X,IGROK.Y,korab);
PaintBox1.Canvas.CopyRect( Rect(0, 0, 600, 400), Buf.Canvas, Rect(0,0,600,400));
end;
end.
