unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, NativeFastCanvas,
Windows, ExtCtrls, StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure ButtonPrevRoomClick(Sender: TObject);
procedure ButtonNextRoomClick(Sender: TObject);
private
FNativeFastCanvas: TNativeFastCanvas;
public
procedure NativeFastCanvas1NativePaint(Sender: TObject; DC: HDC; Pixels: PFastPixel; Ww, Hh: Integer);
end;
var
Form1: TForm1;
robotX : integer = 555;
robotY: integer = 255; // Position actuelle
robotDirection: integer = 1; // 1 = droite, -1 = gauche
robotSpeed: integer = 5; // Vitesse
robotMinX: integer = 312; // Distance limite gauche
robotMaxX: integer = 540; // Distance limite droite
currentRoom: integer = 1;
roomNames: array[1..20] of String = (
'CENTRAL CAVERN','THE COLD ROOM','THE MENAGERIE','ABANDONED URANIUM WORKINGS',
'EUGENES LAIR','PROCESSING PLANT', 'THE VAT', 'MINER WILLY MEETS THE KONG BEAST',
'WACKY AMOEBATRONS','THE ENDORIAN FOREST','ATTACK OF THE MUTANT TELEPHONES',
'RETURN OF THE ALIEN KONG BEAST', 'ORE REFINERY','SKYLAB LANDING BAY',
'THE BANK','THE SIXTEENTH CAVERN','THE WAREHOUSE','AMOEBATRONS REVENGE',
'SOLAR POWER GENERATOR','THE FINAL BARRIER'
);
allRooms: array[1..10] of array[0..15] of string = (
// Room 1
(
'30000000090600006000000000000903',
'30000000000000009000000000000003',
'30000000000000000000000000000003',
'30000000000000000000000000000003',
'30000000000000000000000590050003',
'31111111111111444414444111111113',
'30000000000000000000000000000093',
'31110000000000000000000000000003',
'30000000000000000333050000000003',
'31111000777777777777777777770003',
'30000000000000000000000000000113',
'30000000000000000000000000000003',
'30000000000050000000333444441113',
'30000111111111111111000000000AB3',
'30000000000000000000000000000BB3',
'31111111111111111111111111111113'),
// Room 2
(
'30000000000000000003333333333333',
'30000000900000000000000090000063',
'30000000000000000000000000000003',
'30000000000000000000044410000003',
'30000000000000000000000000000003',
'31111111111111111111000000003003',
'30000000000000000000011113443003',
'31444440000000000000000003903003',
'30000000000000000000000003443003',
'30090000011111110000000003443003',
'30000000000000000004444003443003',
'300CCCC0000000000000000003443003',
'30000000000000111109000003443003',
'30000000444400000000000000000AB3',
'30000000000000000000000000000BB3',
'31111111111111111111111111111113'),
// Room 3
(
'30000090006000090020000900060003',
'30000000000000000060000000000003',
'30000000000000000000000000000003',
'30000000000000000000000000000003',
'30000000000000000000000000000003',
'31111444444444444444444444444443',
'30000000000000000000900000000093',
'31111110000000000000000000011113',
'32000000000000000000000000000003',
'32000077777700000000000000000003',
'32000000000000000000000001111113',
'36000000000000111110000000000AB3',
'30000111111000000000000000000BB3',
'30000000000000000000011111111113',
'30000000000000000000000000000003',
'31111111111111111111111111111113'),
// Room 4
(
'39000006000000333333333333333333',
'30000000000090000000000009000AB3',
'30000000000000000000000000000BB3',
'30000000000000000001111110000003',
'30000000000000000000000000011113',
'31000001000000000100000000000003',
'30000000000011009000011100000093',
'34440000000000000000000000000003',
'30000001100000000000000000111003',
'30000000000000000011100000000003',
'3CCC0000000000000000000000000013',
'30000000000011100000001110000003',
'30000011000000000000000600001113',
'30000000000000000011000000000003',
'30000000000000000000000000000003',
'31111111111111111111111111111113'),
// Room5
(
'30000000000000000000600000000003',
'30000000000000000000000000000093',
'30000000000000000000000000000003',
'30000000000000000000000000000003',
'30000000000000000000000050000003',
'31111111111111000044441111110003',
'30000000009000000000000000000113',
'30000000000000000000050000000903',
'30000000000000000077777777770003',
'30001111111111000000000000000003',
'30000000000000000000000000000003',
'34411111111111000011111110000013',
'30000009390000000000000000000003',
'311000003000003AB300000000000003',
'300005003000003BB333333355000003',
'31111111333333333333333311111113'),
// Room6
(
'30000000000000000000000000000AB3',
'30000000000000000000000000000BB3',
'30000000000000000000000000000003',
'30000000000000000000000000000003',
'30000000000000000000060000000003',
'30000000111000011000011111000003',
'30011000000000093900000000001113',
'30000000000000003000000000000093',
'30000000000000000000000111110003',
'31100000000000000000000000000003',
'39000001111111113111111111000003',
'30000000000009003600000000000003',
'30050000000000003000000000001113',
'30077770000000000000001100000003',
'30000000000000000000000000000003',
'31111111111111111111111111111113'),
// Room7
(
'30000000000000333333333333333333',
'30000000000000000000000000000003',
'30000000000000000000000000000003',
'30000000000000011344444444444493',
'30000000000000000344444444444443',
'30000007777700111344444444446443',
'31110000000000000344944444444443',
'30000000000000000344444444494443',
'31000000000000000344444644444443',
'30000000000000111344444444444443',
'31111111111100000349444444446443',
'30000000000000000344444444444493',
'30000000000000333344444644444443',
'300000000111003AB000000000000003',
'300000000000003BB000000000000003',
'31111111111111333333333333333333'),
// Room 8
(
'30600000006000000300300000000003',
'30000000000000000300300000000003',
'300000000000090EE300000000000113',
'30000000000000000300000000000003',
'30000000000000000300000000000003',
'31110000011111100311000000000003',
'30000000000000900300011110000013',
'30111000000000000300000000010003',
'30900000111000000300000000000003',
'30000000000000000311111000000003',
'31000000000011100300000000011113',
'30000000011000000D00000000000003',
'30001100000000000D00001111100003',
'30000000000CCC3AB311000000000903',
'300000000000003BB300000500000003',
'31111111111111111111111111111113'),
// Room 9
(
'3AB30000000000000000000000000003',
'3BB00000000000090000000000000003',
'30000000000000000000000000000003',
'30000000000000000000000000000003',
'30000000000000000000000000000003',
'31111001110011111111001110011003',
'30000000000000000000000000000003',
'30000000000000000000000000000113',
'300110011100CCCCCCCC000000000003',
'30000000000000000000001110011003',
'31100000000000000000000000000003',
'30000000000000000000000000000003',
'30011001110011111111001110011003',
'30000000000000000000000000000113',
'30000000000000000000000000000003',
'31111111111111111111111111111113'
),
// Room 10
(
'30000000000601113060611111111113',
'30000000000000903000060000000093',
'31111110000000003000090000011113',
'30060000000000003000000000000003',
'30000000000000003111100000000003',
'30000000144444443000000111111113',
'31111000000900003000000000000003',
'30000000000000003111111144400003',
'31111100000000003090000000000003',
'36000000011111113000000000000113',
'31111440000000003111111100000063',
'30000000000000003000000644400003',
'30000000222222222200000000000003',
'311100000000AB000000000000001113',
'300000000000BB000000000000000003',
'22222222222222222222222222222222')
);
implementation
function GetTile(x, y: integer): integer;
var
ch: char;
begin
if (x >= 0) and (x < 32) and (y >= 0) and (y < 32) and
(currentRoom >= 1) and (currentRoom <= 10) then // 7 room
begin
ch := allRooms[currentRoom][y][x + 1];
case ch of
'0': Result := 0;
'1': Result := 1;
'2': Result := 2;
'3': Result := 3;
'4': Result := 4;
'5': Result := 5;
'6': Result := 6;
'7': Result := 7;
'9': Result := 9;
'A': Result := 10; // case A
'C': Result := 12;
else Result := 11; // empty
end;
end else
Result := 0;
end;
procedure UpdateRobot;
begin
// Déplacer le robot
robotX := robotX + (robotDirection * robotSpeed);
if robotX <= robotMinX then
robotDirection := 1 // right walk
else if robotX >= robotMaxX then
robotDirection := -1; // left
end;
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
FNativeFastCanvas := TNativeFastCanvas.Create(Self);
with FNativeFastCanvas do
begin
Parent := Self;
Align := alClient;
BackgroundColor := RGB(0, 0, 32);
OnNativePaint := @NativeFastCanvas1NativePaint;
end;
end;
procedure TForm1.NativeFastCanvas1NativePaint(Sender: TObject; DC: HDC;Pixels: PFastPixel; Ww, Hh: Integer);
var
FastCanvas: TNativeFastCanvas;
x, y, tileIndex, tileX, tileY: integer;
frameIndex: integer;
begin
FastCanvas := TNativeFastCanvas(Sender);
FastCanvas.DC := DC;
FastCanvas.DrawVectorText(300, 560, roomNames[currentRoom], 25, RGB(255, 255, 255));
for y := 0 to 15 do
begin
for x := 0 to 31 do
begin
tileIndex := GetTile(x, y);
case tileIndex of
0..6: begin
// static sprites 32×32
tileX := (tileIndex mod 16) * 32;
tileY := ((currentRoom - 1) * 32) + (tileIndex div 16) * 32;
// if tileIndex > 0 then
Fastcanvas.BlitCopy('blocks.png', tileX, tileY, 32, 32, 60+x*32, 30+y*32, bmCopy);
end;
7: begin // tapis
frameIndex := (GetTickCount div 150) mod 4; // 4 frames anim
tileX := 7*32 + frameIndex * 32;
tileY := ((currentRoom - 1) * 32);
Fastcanvas.BlitCopy('blocks.png', tileX, tileY, 32, 32, 60+x*32, 30+y*32, bmCopy);
end;
12: begin // tapis
frameIndex := (GetTickCount div 150) mod 4; // 4 frames anim
tileX := 7*32 + frameIndex * 32;
tileY := ((currentRoom - 1) * 32);
Fastcanvas.BlitCopy('blocks.png', tileX, tileY, 32, 32, 60+x*32, 30+y*32, bmCopy);
end;
9: begin // keys
frameIndex := (GetTickCount div 200) mod 4;
tileX := 352 + frameIndex * 32;
tileY := ((currentRoom - 1) * 32);
Fastcanvas.BlitCopy('blocks.png', tileX, tileY, 32, 32, 60+x*32, 30+y*32, bmCopy);
end;
10: begin // Case A - door 64×64 occupant 2×2 tiles
frameIndex := (GetTickCount div 500) mod 2;
tileX := ((currentRoom - 1) * 64);
tileY := 1344+(frameIndex * 64);
Fastcanvas.BlitCopy('64x64.png', tileX, tileY, 64, 64, 60+ x*32, 30+y*32, bmCopy);
end;
end;
end;
end;
frameIndex := (robotX div 16) mod 4;
if (currentRoom = 1) then
begin
if robotDirection = 1 then
begin
// right
tileX := 1024 + frameIndex * 72;
tileY := 0;
end
else
begin
// left
tileX := -22 + frameIndex * 72;
tileY := 64;
end;
Fastcanvas.BlitCopy('64x64.png', tileX, tileY, 64, 64, robotX, robotY, bmCopy);
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
UpdateRobot;
FNativeFastCanvas.Invalidate;
end;
procedure TForm1.ButtonPrevRoomClick(Sender: TObject);
begin
if currentRoom > 1 then
begin
currentRoom := currentRoom - 1;
end
else
begin
currentRoom := 10; // To room 10
end;
FNativeFastCanvas.Invalidate; // Redraw
end;
procedure TForm1.ButtonNextRoomClick(Sender: TObject);
begin
if currentRoom < 10 then
begin
currentRoom := currentRoom + 1;
end
else
begin
currentRoom := 1; // To room 1
end;
FNativeFastCanvas.Invalidate; // Redraw
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
if Assigned(FNativeFastCanvas) then FNativeFastCanvas.Free;
end;
end.