Code:
{
****************************************************************
* BASE para um RPG tipo tibia *
* Criado por: Mauricio Barros Scotton[SpykE]. *
* Todos os direitos reservados a SpykeSoft 2006 *
* Por Favor, mantenha os cr?İditos *
****************************************************************
}
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, Menus, DXClass, DXSprite, DXInput, DXDraws,
DXSounds;
type
//TILE pack rec. para os items existentes no mapa (?°rvores e etc...)
TTile = Packed Record
Textura: String;
Bloqueado: Boolean;
end;
//ImageSprite para os items existentes no mapa (ligado a PACK REC.) (?°rvores e etc...)
TLayerItems = class(TImageSprite)
private
FCounter: Double;
FS: Integer;
procedure Hit;
public
procedure DoMove(MoveCount: Integer); override;
end;
TForm1 = class(TForm)
Button1: TButton;
DXDraw: TDXDraw;
DXTimer1: TDXTimer;
DXSpriteEngine: TDXSpriteEngine;
DXInput: TDXInput;
DXImageList1: TDXImageList;
MAPA: TDXImageList;
OBJETOS: TDXImageList;
procedure DXTimer1Timer(Sender: TObject; LagCount: Integer);
procedure FormCreate(Sender: TObject);
procedure DXDrawInitialize(Sender: TObject);
procedure DXDrawMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
private
FMoveMode: Boolean;
MouseX, MouseY : Integer;
public
{ Public declarations }
end;
var
Form1: TForm1;
lcnam:string;
ItmXMax:integer=7;
ItmYMax:integer=8;
posx,posy:double;
mapsizex,mapsizey:integer;
//========================================================================
//====// Declara?ß?µes dos mapas //======
//========================================================================
Mapa_ITEM: Array[0..17, 0..17] of TTile;
//ch?£o
Mapa_CHAO: Array[0..17, 0..17] of INTEGER =(
(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
(0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
(0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
(0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
(0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0),
(0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0),
(0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0),
(0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0),
(0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0),
(0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0),
(0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0),
(0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0),
(0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0),
(0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0),
(0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0),
(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0),
(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0),
(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0) );
implementation
Uses
Unit_basics;
{$R *.dfm}
//========================================================================
//====// Tipos dos objetos utilizados //======
//========================================================================
type
TPlayer = class(TImageSprite)
protected
procedure DoCollision(Sprite: TSprite; var Done: Boolean); override;
procedure DoMove(MoveCount: Integer); override;
end;
//========================================================================
//====// Procedimentos do startamento de sprites ->delphiX //======
//========================================================================
procedure TLayerItems.Hit;
begin
//procedimento para dar hit em um objeto que sofreu a colis?£o
end;
procedure TPlayer.DoCollision(Sprite: TSprite; var Done: Boolean);
begin
if Sprite is TLayerItems then begin
//fazer algo ap??s detectar colis?£o
end;
Done := true;
end;
procedure TLayerItems.DoMove(MoveCount: Integer);
begin
inherited DoMove(MoveCount);
PixelCheck := True;
FCounter := FCounter + (100/1000)*MoveCount;
if not Collisioned then
begin
Inc(FS, MoveCount);
if FS>200 then Dead;
end;
end;
procedure TPlayer.DoMove(MoveCount: Integer);
var
sprite: Tsprite;
NX,NY:integer;
begin
inherited DoMove(MoveCount);
Collision;
if (Form1.DXInput.Joystick.X<>0) or (Form1.DXInput.Joystick.Y<0>=0) and (ny>=0) and (nx<=mapsizex) and (ny<mapsizey>=0) and (ny>=0) and (nx<=mapsizex) and (ny<mapsizey>=0) and (ny>=0) and (nx<=mapsizex) and (ny<mapsizey>=0) and (ny>=0) and (nx<=mapsizex) and (ny<=mapsizey) and (CheckTile(nx,ny) = false) then
X := X + 32;
end;
end;
PixelCheck:=True;
Engine.X := -X+Engine.Width div 2-Width div 2;
Engine.Y := -Y+Engine.Height div 2-Height div 2;
posx:=x;
posy:=y;
end;
//========================================================================
//====// Procedimentos do delphi //======
//========================================================================
procedure TForm1.DXTimer1Timer(Sender: TObject; LagCount: Integer);
begin
if not DXDraw.CanDraw then exit;
DXInput.Update;
if FMoveMode then
LagCount := 1000 div 60;
DXSpriteEngine.Move(LagCount);
DXSpriteEngine.Dead;
DXDraw.Surface.Fill(0);
DXSpriteEngine.Draw;
//coloca o cursor
DXImageList1.Items[0].Draw( DXDraw.Surface, MouseX, MouseY, 0 );
//impres?£o dos textos
DysplayText('FPS: '+inttostr(DXTimer1.FrameRate), BSClear, clWhite, 10, 0, 0);
DysplayText('Sprite: '+inttostr(DXSpriteEngine.Engine.AllCount), BSClear, clWhite, 10, 0, 15);
DysplayText('Draw: '+inttostr(DXSpriteEngine.Engine.DrawCount), BSClear, clWhite, 10, 0, 30);
DysplayText('X:'+floattostr(posx/32)+'['+floattostr(posx)+']'+', Y:'+floattostr(posy/32)+'['+floattostr(posy)+']', BSClear, clWhite, 10, 0, 60);
if FMoveMode then
DysplayText('Time mode: 60 FPS', BSClear, clWhite, 10, 0, 45)
else
DysplayText('Time mode: Real time', BSClear, clWhite, 10, 0, 45);
//flip =D
DXDraw.Flip;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
PlayerSPR: TSprite;
i1,i2:integer;
begin
mapsizex:=17;
mapsizey:=17;
DXDraw.cursor:=crNone;
//LoadOneLayer(123456789,i1,i2,50,true);
lcnam:=extractfilepath(application.ExeName);
//randomiza os objetos
Mapa_ITEM[1,1].Textura:='2';
Mapa_ITEM[1,1].Bloqueado:=true;
Mapa_ITEM[16,1].Textura:='2';
Mapa_ITEM[16,1].Bloqueado:=true;
Mapa_ITEM[1,16].Textura:='2';
Mapa_ITEM[1,16].Bloqueado:=true;
Mapa_ITEM[16,16].Textura:='2';
Mapa_ITEM[16,16].Bloqueado:=true;
{ Mapa_ITEM[1,2].Textura:='pilar1';
Mapa_ITEM[1,2].Bloqueado:=true;
Mapa_ITEM[1,3].Textura:='pilar2';
Mapa_ITEM[1,3].Bloqueado:=true;
Mapa_ITEM[1,4].Textura:='pilar3';
Mapa_ITEM[1,4].Bloqueado:=true;
Mapa_ITEM[2,2].Textura:='pilar1';
Mapa_ITEM[2,2].Bloqueado:=true;
Mapa_ITEM[2,3].Textura:='pilar2';
Mapa_ITEM[2,3].Bloqueado:=true;
Mapa_ITEM[2,4].Textura:='pilar3';
Mapa_ITEM[2,4].Bloqueado:=true; }
{ for i1:=0 to 7 do begin
for i2:=0 to 8 do begin
randomize;
Mapa_ITEM[i1,i2].Textura:=random(2);
if Mapa_ITEM[i1,i2].Textura = 1 then
Mapa_ITEM[i1,i2].Bloqueado:=true;
end;
end; }
//load no ch?£o
for i1:=0 to 17 do begin
for i2:=0 to 17 do begin
LoadOneLayer(inttostr(Mapa_CHAO[i1,i2]),i1,i2,-3,false)
end;
end;
//load nos itens do ch?£o (?°rvores e etc...)
for i1:=0 to 17 do begin
for i2:=0 to 17 do begin
if (Mapa_ITEM[i1,i2].Textura <> '0')and (Mapa_ITEM[i1,i2].Textura <> '') then begin
LoadOneLayer(Mapa_ITEM[i1,i2].Textura,i1,i2,-2,true);
LoadOneLayer('Colisor',i1,i2,-1,true);
end;
end;
end;
//abre o jogador
PlayerSPR:= TPlayer.Create(DXSpriteEngine.Engine);
with TPlayer(PlayerSPR) do
begin
Image := DXImageList1.Items.Find('player_down');
Height:= 48; Width := 32;
Visible:=true;
X := 0;
Y := 0;
Z := 2;
end;
end;
procedure TForm1.DXDrawInitialize(Sender: TObject);
begin
DXTimer1.Enabled := True;
end;
procedure TForm1.DXDrawMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
MouseX := X;
MouseY := Y;
end;
end.
Unit de Fun?ß?µes
Bookmarks