Главная » 2011 » Май » 16 » Своя RPG\TBS на GLScene. Часть 2. Описываем класс персонажа.
19:17
Своя RPG\TBS на GLScene. Часть 2. Описываем класс персонажа.

И так в этой части статьи мы рассмотрим пример создания класса персонажа.
Вообще т.к. это пример создания простой игры то можно было делать и без класса ,но  я посчитал что гораздо интересне внедрить универсальный класс нежели описывать 2х игроков.
И так нам нужен класс наследник от TGLSprite. Почему именно наследник? Просто по сути для этой игры достаточно персонажа с набором свойств и процедур, а так как у нас персонаже представлены в виде спрайтов, то использовать мы будем спрайты. Кстати для тех кто хочет 3д модели вместо спрайтов, вы сможете переделать класс под модель без особых усилий.
type
 TPlayer= class(TGLSprite)
  private
    fEndH:boolean;
    fHealth:integer;
    fMana:integer;
    fPlayerType:string;
    fCast:boolean;

 public
    property EndHod: boolean read fEndH write fEndH;
    property Health:integer read fHealth write fHealth;
    property Mana:integer read fMana write fMana;
    property PlayerType:string read fPlayerType write fPlayerType;
    property Cast:boolean read fCast write fCast;
   
    procedure Attack(power:integer;target:TPlayer);
    procedure Mage(DcObject:TGLDummyCube;PlayerIndex:integer);
    procedure Paladin(DcObject:TGLDummyCube;PlayerIndex:integer);

    constructor CreatePlayer(PlayerName:string;MainPath:string;typePlayer:string; const PX,PZ,PIndex,PHealth,PMana:integer);

 end;

Мы описали наш класс и создали ему набор свойств и процедур. Что и для чего думаю понятно из названия.

Внимание ещё раз напомню что это пример для новичков, т.е. многие решения как минимум не логичны, в реальных играх так делать нельзя, но как пример создания нормально!


И так теперь опишем конструктор.

constructor TPlayer1.CreatePlayer(PlayerName:string;MainPath:string;typePlayer:string; const PX,PZ,PIndex,PHealth,PMana:integer);
begin
  CreateAsChild(Form1.DCUnits);
  Visible:=true;
  Name:=PlayerName;
  PlayerType:=typePlayer;
  Health:=PHealth;
  Mana:=PMana;
  Position.X:=PX;
  Position.Y:=1;
  Position.Z:=PZ;
  Scale.X:=1.2;
  Scale.Y:=1.2;
  Scale.Z:=1.2;
  Material.Texture.Image.LoadFromFile(ExtractFilePath(Application.ExeName)+'core/'+MainPath);
  Material.Texture.Disabled:=false;
  Material.Texture.MinFilter:=miLinear;
  Material.Texture.ImageAlpha := tiaSuperBlackTransparent;
  Material.Texture.TextureMode := tmReplace;
  Material.BlendingMode:= bmTransparency;
  EndHod:=false;

Ниже один из пунктов каторые НЕЛЬЗЯ применять в больших проектах, годиться лишь он как пример.
Смысл в том что если у нас тип игрока Маг или Паладин то и создадим набор магий либо для Паладина либо для Мага.
    if typePlayer='Mage' then   Mage(DCGUI,PIndex);
    if typePlayer='Paladin' then  Paladin(DCGUI,PIndex);

end;

Тут простейшая процедура атаки.
procedure TPlayer1.Attack(power:integer;target:TPlayer1);
begin
   Target.Health:=Target.Health-power;
end;

Эта процедура создает набор магий для Мага. Все очень просто создаём ряд спрайтов и расставляем их по местам.

procedure TPlayer1.Mage(DCObject:TGLDummyCube;PlayerIndex:integer);
begin

 with DCObject.AddNewChild(TGLDummyCube)  do begin
     Name:='DCPlayer'+FloatToStr(PlayerIndex);
     Visible:=false;
 end;


 with  TGLHUDSprite((DCObject.FindChild('DCPlayer'+FloatToStr(PlayerIndex),true)).AddNewChild(TGLHUDSprite)) do begin
   name := 'Thor_p'+FloatToStr(PlayerIndex);
   Position.X:=190;
   Position.Y:=Form1.Height-50;
   Width:=40;
   Height:=40;
   //Scale.Y:=5;
   //Scale.Z:=2;
   Material.Texture.Image.LoadFromFile(ExtractFilePath(Application.ExeName)+'core/spell_00.bmp');
   Material.Texture.Disabled:=false;
   Visible:=true;
 end;

 with  TGLHUDSprite((DCObject.FindChild('DCPlayer'+FloatToStr(PlayerIndex),true)).AddNewChild(TGLHUDSprite)) do begin
   name := 'Volcano_p'+FloatToStr(PlayerIndex);
   Position.X:=240;
   Position.Y:=Form1.Height-50;
   Width:=40;
   Height:=40;
   //Scale.Y:=5;
   //Scale.Z:=2;
   Material.Texture.Image.LoadFromFile(ExtractFilePath(Application.ExeName)+'core/spell_01.bmp');
   Material.Texture.Disabled:=false;
   Visible:=true;
 end;

 with  TGLHUDSprite((DCObject.FindChild('DCPlayer'+FloatToStr(PlayerIndex),true)).AddNewChild(TGLHUDSprite)) do begin
   name := 'Flesh_p'+FloatToStr(PlayerIndex);
   Position.X:=290;
   Position.Y:=Form1.Height-50;
   Width:=40;
   Height:=40;
   //Scale.Y:=5;
   //Scale.Z:=2;
   Material.Texture.Image.LoadFromFile(ExtractFilePath(Application.ExeName)+'core/spell_02.bmp');
   Material.Texture.Disabled:=false;
   Visible:=true;
 end;

 with  TGLHUDSprite((DCObject.FindChild('DCPlayer'+FloatToStr(PlayerIndex),true)).AddNewChild(TGLHUDSprite)) do begin
   name := 'HellTornado_p'+FloatToStr(PlayerIndex);
   Position.X:=340;
   Position.Y:=Form1.Height-50;
   Width:=40;
   Height:=40;
   //Scale.Y:=5;
   //Scale.Z:=2;
   Material.Texture.Image.LoadFromFile(ExtractFilePath(Application.ExeName)+'core/spell_03.bmp');
   Material.Texture.Disabled:=false;
   Visible:=true;
 end;




end;


Аналогично делаем для паладина.

//Paladin
procedure TPlayer1.Paladin(DCObject:TGLDummyCube;PlayerIndex:integer);
begin
 with DCObject.AddNewChild(TGLDummyCube)  do begin
     Name:='DCPlayer'+FloatToStr(PlayerIndex);
     Visible:=false;
 end;

 with  TGLHUDSprite((DCObject.FindChild('DCPlayer'+FloatToStr(PlayerIndex),true)).AddNewChild(TGLHUDSprite)) do begin
   name := 'Hammer_p'+FloatToStr(PlayerIndex);
   Position.X:=190;
   Position.Y:=Form1.Height-50;
   Width:=40;
   Height:=40;
   //Scale.Y:=5;
   //Scale.Z:=2;
   Material.Texture.Image.LoadFromFile(ExtractFilePath(Application.ExeName)+'core/spell_04.bmp');
   Material.Texture.Disabled:=false;
   Visible:=true;
 end;

 with  TGLHUDSprite((DCObject.FindChild('DCPlayer'+FloatToStr(PlayerIndex),true)).AddNewChild(TGLHUDSprite)) do begin
   name := 'Shield_p'+FloatToStr(PlayerIndex);
   Position.X:=240;
   Position.Y:=Form1.Height-50;
   Width:=40;
   Height:=40;
   //Scale.Y:=5;
   //Scale.Z:=2;
   Material.Texture.Image.LoadFromFile(ExtractFilePath(Application.ExeName)+'core/spell_05.bmp');
   Material.Texture.Disabled:=false;
   Visible:=true;
 end;

 with  TGLHUDSprite((DCObject.FindChild('DCPlayer'+FloatToStr(PlayerIndex),true)).AddNewChild(TGLHUDSprite)) do begin
   name := 'Burning_p'+FloatToStr(PlayerIndex);
   Position.X:=290;
   Position.Y:=Form1.Height-50;
   Width:=40;
   Height:=40;
   //Scale.Y:=5;
   //Scale.Z:=2;
   Material.Texture.Image.LoadFromFile(ExtractFilePath(Application.ExeName)+'core/spell_06.bmp');
   Material.Texture.Disabled:=false;
   Visible:=true;
 end;

 with  TGLHUDSprite((DCObject.FindChild('DCPlayer'+FloatToStr(PlayerIndex),true)).AddNewChild(TGLHUDSprite)) do begin
   name := 'Spirit_p'+FloatToStr(PlayerIndex);
   Position.X:=340;
   Position.Y:=Form1.Height-50;
   Width:=40;
   Height:=40;
   //Scale.Y:=5;
   //Scale.Z:=2;
   Material.Texture.Image.LoadFromFile(ExtractFilePath(Application.ExeName)+'core/spell_07.bmp');
   Material.Texture.Disabled:=false;
   Visible:=true;
 end;



end;


Категория: Статьи | Просмотров: 596 | Добавил: De:Light | Теги: TBS, класс, GLScene, game, RPG, CLASS, DELPHI | Рейтинг: 0.0/0
Всего комментариев: 0
Добавлять комментарии могут только зарегистрированные пользователи.
[ Регистрация | Вход ]
Вы вошли как: Гость
13:32
Вы вошли как: Гость
Календарь
«  Май 2011  »
ПнВтСрЧтПтСбВс
      1
2345678
9101112131415
16171819202122
23242526272829
3031
Категории
Новости [11]
Статьи [23]
GLscene,Web Design,IT,etc...
Счетчик

Онлайн всего: 1
Гостей: 1
Пользователей: 0