2026-02-28 10:57:08 +00:00
|
|
|
unit creature_m;
|
|
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
|
|
type
|
2026-02-28 16:22:15 +00:00
|
|
|
creatureType = (creatureHamster, creatureGhost, creatureSun,
|
|
|
|
|
creatureSnake, creatureDrop);
|
|
|
|
|
|
|
|
|
|
creaturePtr = ^creature;
|
|
|
|
|
|
2026-02-28 10:57:08 +00:00
|
|
|
creature = record
|
2026-02-28 11:14:58 +00:00
|
|
|
curX, curY, dX, dY, moveSpeed: integer;
|
|
|
|
|
symbol: char;
|
2026-02-28 16:22:15 +00:00
|
|
|
alive: boolean;
|
|
|
|
|
t: creatureType;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
creatureItemPtr = ^creatureItem;
|
|
|
|
|
|
|
|
|
|
creatureItem = record
|
|
|
|
|
cr: creaturePtr;
|
|
|
|
|
next: creatureItemPtr
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
creatureList = record
|
|
|
|
|
len: integer;
|
|
|
|
|
first, last: creatureItemPtr;
|
2026-02-28 10:57:08 +00:00
|
|
|
end;
|
|
|
|
|
|
2026-02-28 16:22:15 +00:00
|
|
|
function RandomLR(l, r: integer): integer;
|
|
|
|
|
procedure AppendCreature(var lst: creatureList; c: creaturePtr);
|
|
|
|
|
procedure DisposeCreatureList(var lst: creatureList);
|
2026-02-28 11:14:58 +00:00
|
|
|
procedure KillCreature(var cr: creature);
|
2026-02-28 10:57:08 +00:00
|
|
|
procedure MakeStep(var cr: creature);
|
2026-02-28 16:22:15 +00:00
|
|
|
procedure InitCreatureList(var lst: creatureList);
|
|
|
|
|
procedure StopCreature(var cr: creature);
|
2026-02-28 10:57:08 +00:00
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
2026-02-28 11:14:58 +00:00
|
|
|
uses arena_graphics_m, arena_m, math_m;
|
2026-02-28 10:57:08 +00:00
|
|
|
|
2026-02-28 16:22:15 +00:00
|
|
|
function RandomLR(l, r: integer): integer;
|
2026-02-28 10:57:08 +00:00
|
|
|
begin
|
2026-02-28 16:22:15 +00:00
|
|
|
RandomLR := l + Random(r - l + 1)
|
2026-02-28 10:57:08 +00:00
|
|
|
end;
|
|
|
|
|
|
2026-02-28 16:22:15 +00:00
|
|
|
procedure AppendCreature(var lst: creatureList; c: creaturePtr);
|
|
|
|
|
var
|
|
|
|
|
item: creatureItemPtr;
|
2026-02-28 10:57:08 +00:00
|
|
|
begin
|
2026-02-28 16:22:15 +00:00
|
|
|
new(item);
|
|
|
|
|
item^.cr := c;
|
|
|
|
|
item^.next := nil;
|
|
|
|
|
if lst.first = nil then
|
|
|
|
|
lst.first := item
|
|
|
|
|
else
|
|
|
|
|
lst.last^.next := item;
|
|
|
|
|
lst.last := item
|
2026-02-28 10:57:08 +00:00
|
|
|
end;
|
|
|
|
|
|
2026-02-28 16:22:15 +00:00
|
|
|
procedure DisposeCreatureList(var lst: creatureList);
|
|
|
|
|
var
|
|
|
|
|
tmp: creatureItemPtr;
|
2026-02-28 10:57:08 +00:00
|
|
|
begin
|
2026-02-28 16:22:15 +00:00
|
|
|
while lst.first <> nil do
|
|
|
|
|
begin
|
|
|
|
|
tmp := lst.first;
|
|
|
|
|
lst.first := lst.first^.next;
|
|
|
|
|
if lst.first = nil then
|
|
|
|
|
lst.last := nil;
|
|
|
|
|
dispose(tmp^.cr);
|
|
|
|
|
dispose(tmp);
|
|
|
|
|
lst.len := lst.len - 1
|
|
|
|
|
end
|
2026-02-28 10:57:08 +00:00
|
|
|
end;
|
|
|
|
|
|
2026-02-28 11:14:58 +00:00
|
|
|
procedure KillCreature(var cr: creature);
|
|
|
|
|
begin
|
|
|
|
|
cr.alive := false;
|
2026-02-28 16:22:15 +00:00
|
|
|
DrawFieldCell(cr.curX, cr.curY, CaptureSymbol)
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure MakeStep(var cr: creature);
|
|
|
|
|
begin
|
|
|
|
|
cr.curX := Clamp(cr.curX + cr.dX, 1, ArenaW);
|
|
|
|
|
cr.curY := Clamp(cr.curY + cr.dY, 1, ArenaH)
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure InitCreatureList(var lst: creatureList);
|
|
|
|
|
begin
|
|
|
|
|
lst.len := 0;
|
|
|
|
|
lst.first := nil;
|
|
|
|
|
lst.last := nil
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure StopCreature(var cr: creature);
|
|
|
|
|
begin
|
|
|
|
|
cr.dX := 0;
|
|
|
|
|
cr.dY := 0
|
2026-02-28 11:14:58 +00:00
|
|
|
end;
|
|
|
|
|
|
2026-02-28 10:57:08 +00:00
|
|
|
end.
|