This repository has been archived on 2024-12-25. You can view files and clone it, but cannot push or open issues or pull requests.
2024-03-10 20:32:51 +03:00

105 lines
2.8 KiB
ObjectPascal
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

uses WPFObjects,Timers;
type
BulletWPF = class(CircleWPF) end;
MonsterWPF = class(SquareWPF) end;
PlayerWPF = class(EllipseWPF) end;
begin
var Player := new PlayerWPF(GraphWindow.Center, 30, 50, RandomColor);
Player.Velocity := 100;
Player.Number := 0;
loop 5 do
begin
var m := new MonsterWPF(750,Random(10,550),30,RandomColor);
m.Velocity := 50;
end;
OnMouseMove := (x,y,mb) -> Player.RotateToPoint(x,y);
OnMouseDown := (x,y,mb) -> begin
var cc := new BulletWPF(Player.CenterTop,5,Colors.Red);
cc.Direction := (x-Player.Center.X,y-Player.Center.Y);
cc.Velocity := 300;
end;
var kl,kr,ku,kd: boolean;
OnDrawFrame := dt -> begin
Window.Title := 'Количество объектов: '+Objects.Count;
// Перемещение игрока
if kr then
Player.Dx := 1
else if kl then
Player.Dx := -1
else Player.Dx := 0;
if ku then
Player.Dy := -1
else if kd then
Player.Dy := 1
else Player.Dy := 0;
for var i:=Objects.Count-1 downto 0 do // все перемещаются в своём направлении со своей скоростью
begin
var o := Objects[i];
if o is MonsterWPF then
o.Direction := (Player.Center.X - o.Center.X,Player.Center.Y-o.Center.Y);
o.MoveTime(dt);
end;
if Player.IntersectionList.Any(o -> o is MonsterWPF) then
begin
// Конец игры
end;
end;
CreateTimerAndStart(100,procedure -> // Таймер убивания монстров и умирания объектов за пределами экрана
begin
for var i:=Objects.Count-1 downto 0 do
begin
var o := Objects[i];
if (o.Center.X < 0) or (o.Center.X > Window.Width) or
(o.Center.Y < 0) or (o.Center.Y > Window.Height) then
if not (o is PlayerWPF) then
o.Destroy;
if o is BulletWPF then
foreach var x in o.IntersectionList do
if x is MonsterWPF then
begin
x.Destroy;
o.Destroy;
Player.Number += 1;
break;
end;
end;
end);
CreateTimerAndStart(1000,procedure -> // Таймер рождения монстров
begin
var x := Random(2)=0 ? 750 : 50;
var m := new MonsterWPF(x,Random(10,550),30,RandomColor);
m.Velocity := 50;
end);
OnKeyDown := k ->
begin
case k of
Key.w,Key.Up: begin ku := true; kd := false; end;
Key.s,Key.Down: begin kd := true; ku := false; end;
Key.a,Key.Left: begin kl := true; kr := false; end;
Key.d,Key.Right: begin kr := true; kl := false end;
end;
end;
OnKeyUp := k ->
begin
case k of
Key.w,Key.Up: ku := false;
Key.s,Key.Down: kd := false;
Key.a,Key.Left: kl := false;
Key.d,Key.Right: kr := false;
end;
end;
end.