lonely_baby2003

New Member

Download miễn phí Ebook Thiết kế và lập trình game căn bản





Các bạn khi trao đổi với nhau vềlập trình game thường trao đổi với nhau vềnhững vấn đề
cụtỉnhưlà vẽbằng DirectX hay OpenGL, làm thếnào đểlấy một sprite hay là vẽsprite đấy
bằng hiệu ứng nhưthếnào thiết nghĩnhững thứ đó quá lặt vặt – dĩnhiên là không nói đến
chuyện thiết kếcác engine 3D lớn rùi – Trong khi lập trình game này, tôi sửdụng bộthư
viện AvenusHelper được tôi thiết kếnhằm giảm tối đa các công việc các bạn cần thực thi chi
tiết với hệthống nhưlà khởi tạo đồhoạ, đọc ảnh và vẽ ảnh bằng những hiệu ứng đơn giản
nhưlà add, sub, mul Ở đây các bạn chỉcần chú ý đến việc làm thếnào game chạy được,
các unit được xửlý nhưthếnào, máy tính chơi ra sao, những sựkiện được xửlý thế
nào mà thôi. Nếu cần quan tâm đến những chi tiết nhưng là làm thếnào đểthực hiện hiệu
ứng alpha blend chẳng hạn chúng ta sẽbàn sau - ởmột tập sách khác.



Để tải bản Đầy Đủ của tài liệu, xin Trả lời bài viết này, Mods sẽ gửi Link download cho bạn sớm nhất qua hòm tin nhắn.
Ai cần download tài liệu gì mà không tìm thấy ở đây, thì đăng yêu cầu down tại đây nhé:
Nhận download tài liệu miễn phí

Tóm tắt nội dung tài liệu:

,1]:=-Abs(Sin(DegToRad(90/8*1)));
Moving[H32,2]:=-Abs(Cos(DegToRad(90/8*1)));
//Debug and condition setting
EndGame:=False;
PauseGame:=False;
ShowFPS:=False;
ShowDebug:=False;
UnitCounting:=0;
FirstUnitSelect:=Low(TUnitCount);
//
{$IfDef FullScreen}
CreateFullScreen(ScrWidth,ScrHeight,BD16Bit,Caption);
{$Else}
CreateWindow(ScrWidth,ScrHeight,Caption);
{$EndIf}
LoadFont(DataPath+'Font.png',16,20,8,16,$0);
SetScreenBPP(32);
//Mini map setting
MiniMapVisible:=True;
MiniMapImage:=CreateImage(MiniMapSizeX,MiniMapSizeY,FormatA1R5G5B5);
MiniMapPosX:=ScrWidth-MiniMapSizeX-10;
Simple ЯTS G∆me Dεsign & CΘding
© CrazyBabe 2003. K-Outertainment™
Trang 24
MiniMapPosY:=10;
//Panel setting
CommandPanelVisible:=True;
PanelImage:=CreateImage(PanelSizeX,PanelSizeY,FormatA1R5G5B5);
PanelPosX:=10;
PanelPosY:=ScrHeight-PanelSizeY-10;
//
SetupWorldImage;
SetupUnitsImage;
LoadSetting;
//Colour setup
White:=RGB2LongWord(255,255,255);
Green:=RGB2LongWord(000,255,000);
Gray:=RGB2LongWord(40,40,40);
BlueGray:=RGB2LongWord(100,100,165);
//Player color setting
PlayerColor[PlayerNature]:=RGB2LongWord(255,255,255);//White
PlayerColor[Player1]:=Color32To15(RGB2LongWord(255,000,000));//Red
PlayerColor[Player2]:=Color32To15(RGB2LongWord(000,255,000));//Green
PlayerColor[Player3]:=Color32To15(RGB2LongWord(000,000,255));//Blue
PlayerColor[Player4]:=Color32To15(RGB2LongWord(255,255,128));//Yellow
//
//Sound setting
//
{$IfDef SoundPlaying}
BackGroundMusic:=CreateSound(DataPath+'Sounds\BackGround.Mp3',False);
MissileLauch:=CreateSound(DataPath+'Sounds\MissileLauch.Wav',False);
MissileExplored:=CreateSound(DataPath+'Sounds\MissileExplored.Wav',False);
{$EndIf}
End;
DESTRUCTOR TGame.Destroy;
Begin
DestroyScreen;
End;
PROCEDURE TGame.ProceedMouseLHolding;
Begin
If MouseCommand=MouseSelection then
Begin
SelectEnd.X:=MouseX;
SelectEnd.Y:=MouseY;
End
Else
Begin
//Click on command panel ?
If CommandPanelVisible then
Begin
End;
//Click on mini map ?
If MiniMapVisible then
Begin
If (MouseX>=MiniMapPosX) and
(MouseX<=MiniMapPosX+MiniMapSizeX) and
(MouseY>=MiniMapPosY) and
(MouseY<=MiniMapPosY+MiniMapSizeY) then
Begin
WorldViewAt((MouseX-MiniMapPosX)*GameWorld.Scale.X,
(MouseY-MiniMapPosY)*GameWorld.Scale.Y);
Exit;
End;
End;
If MouseCommand=NoCmd then
Simple ЯTS G∆me Dεsign & CΘding
© CrazyBabe 2003. K-Outertainment™
Trang 25
Begin
MouseCommand:=MouseSelection;
SelectStart.X:=MouseX;
SelectStart.Y:=MouseY;
SelectEnd.X:=MouseX;
SelectEnd.Y:=MouseY;
End;
End;
End;
PROCEDURE TGame.ProceedMouseRHolding;
Begin
End;
PROCEDURE TGame.ProceedMouseLReleased;
Var UnitNum : TUnitCount;
OnMiniMap : Boolean;
X,Y : Integer;
Begin
OnMiniMap:=False;
X:=0;Y:=0;
If MiniMapVisible then
Begin
If (MouseX>=MiniMapPosX) and
(MouseX<=MiniMapPosX+MiniMapSizeX) and
(MouseY>=MiniMapPosY) and
(MouseY<=MiniMapPosY+MiniMapSizeY) then
Begin
OnMiniMap:=True;
X:=(MouseX-MiniMapPosX)*GameWorld.Scale.X;
Y:=(MouseY-MiniMapPosY)*GameWorld.Scale.Y;
End
End;
Case MouseCommand of
MouseSelection :
Begin
CallMouseSelectionUnit(KeyDown(Key_LShift) or
KeyDown(Key_LControl));
End;
CmdAttack :
Begin
If OnMiniMap then
Begin
HumanSetCommandAttackTo(X,Y);
End
Else
Begin
UnitNum:=GetUnitAtMouse(MouseX,MouseY,False);
If UnitNum=Low(TUnitCount) then
Begin
HumanSetCommandAttackTo(MouseX+GameWorld.ViewPos.X,
MouseY+GameWorld.ViewPos.Y);
End
Else
Begin
HumanSetCommandAttack(UnitNum);
End;
End;
End;
CmdPatrol :
Begin
If OnMiniMap then
Begin
HumanSetCommandPatrol(X,Y);
Simple ЯTS G∆me Dεsign & CΘding
© CrazyBabe 2003. K-Outertainment™
Trang 26
End
Else
Begin
HumanSetCommandPatrol(MouseX+GameWorld.ViewPos.X,
MouseY+GameWorld.ViewPos.Y);
End;
End;
End;
MouseCommand:=NoCmd;
End;
PROCEDURE TGame.ProceedMouseRReleased;
Var UnitNum : TUnitCount;
Begin
If MouseCommand=NoCmd then
Begin
//Click on mini map ?
If MiniMapVisible then
Begin
If (MouseX>=MiniMapPosX) and
(MouseX<=MiniMapPosX+MiniMapSizeX) and
(MouseY>=MiniMapPosY) and
(MouseY<=MiniMapPosY+MiniMapSizeY) then
Begin
HumanSetCommandMove((MouseX-MiniMapPosX)*GameWorld.Scale.X,
(MouseY-MiniMapPosY)*GameWorld.Scale.Y);
Exit;
End;
End;
//Other wise
UnitNum:=GetUnitAtMouse(MouseX,MouseY,False);
If UnitNum=Low(TUnitCount) then
Begin
HumanSetCommandMove(MouseX+GameWorld.ViewPos.X,
MouseY+GameWorld.ViewPos.Y);
End
Else
Begin
If GameUnits[UnitNum].Owner=HumanControl then
Begin
HumanSetCommandMove(MouseX+GameWorld.ViewPos.X,
MouseY+GameWorld.ViewPos.Y);
End
Else
Begin
HumanSetCommandAttack(UnitNum);
End;
End;
End
Else
Begin
//Clear waiting command
MouseCommand:=NoCmd;
End;
End;
PROCEDURE TGame.ProceedPlayerInput;
Begin
//LeftAlt+X ?
If KeyDown(Key_LAlt) and
KeyPress(Key_X) then EndGame:=True;
//Arrow key: Take map view scroll
If KeyDown(Key_Up) then
WorldViewAt(Round(GameWorld.ViewPos.X),
Simple ЯTS G∆me Dεsign & CΘding
© CrazyBabe 2003. K-Outertainment™
Trang 27
Round(GameWorld.ViewPos.Y)-ScrollSpeed);
If KeyDown(Key_Down) then
WorldViewAt(Round(GameWorld.ViewPos.X),
Round(GameWorld.ViewPos.Y)+ScrollSpeed);
If KeyDown(Key_Left) then
WorldViewAt(Round(GameWorld.ViewPos.X)-ScrollSpeed,
Round(GameWorld.ViewPos.Y));
If KeyDown(Key_Right) then
WorldViewAt(Round(GameWorld.ViewPos.X)+ScrollSpeed,
Round(GameWorld.ViewPos.Y));
//Static HotKey
If KeyPress(Key_A) then
MouseCommand:=CmdAttack;
If KeyPress(Key_P) then
MouseCommand:=CmdPatrol;
If KeyPress(Key_S) then
HumanSetCommandStop;
If KeyPress(Key_C) then
HumanSetCommandCreate;
If KeyPress(Key_Space) then
PauseGame:=Not PauseGame;
//Mouse release
If MouseReleasedL then
ProceedMouseLReleased;
If MouseReleasedR then
ProceedMouseRReleased;
//Toggle mini map visible
If KeyPress(Key_Capslock) then
MiniMapVisible:=Not MiniMapVisible;
//Toggle command panel visible
If KeyPress(Key_Tab) then
CommandPanelVisible:=Not CommandPanelVisible;
//Debug control Left Ctrl+P
If KeyDown(Key_LControl) and
KeyPress(Key_P) then ShowFPS:=Not ShowFPS;
If KeyDown(Key_LControl) and
KeyPress(Key_D) then ShowDebug:=Not ShowDebug;
End;
PROCEDURE TGame.ProcessInput;
Begin
If GameTime-LastGameInputTime>InputUpdate then
LastGameInputTime:=GameTime
Else Exit;
GetInputStatus;
If EventMessage=False then EndGame:=True;
If MouseHoldL then ProceedMouseLHolding
Else
If MouseHoldR then ProceedMouseRHolding
Else
ProceedPlayerInput;
End;
PROCEDURE TGame.ProcessUnits;
Var Z : TUnitCount;
Begin
If Not PauseGame then
Begin
If GameTime-LastGameUnitTime>UnitUpdate then
Begin
Inc(GameFrame);
LastGameUnitTime:=GameTime;
End
Else Exit;
Simple ЯTS G∆me Dεsign & CΘding
© CrazyBabe 2003. K-Outertainment™
Trang 28
For Z:=Low(TUnitCount) to
High(TUnitCount) do
With GameUnits[Z] do
If HitPoint>0 then
Begin
Case Typer of
FirePlanet :
Begin
TransparentLevel:=TransparentLevel+TransparentSpeed;
If TransparentLevel<64 then
Begin
TransparentLevel:=64;
TransparentSpeed:=-TransparentSpeed;
End;
If TransparentLevel>255 then
Begin
TransparentLevel:=255;
TransparentSpeed:=-TransparentSpeed;
End;
End
Else
ProcessNormalUnit(Z);
End;
End;
End;
End;
PROCEDURE TGame.ProcessEvents;
Begin
//Update mini map
If GameTime-LastGameMiniMapTime>MiniMapUpdate then
Begin
LastGameMiniMapTime:=GameTime;
WorldMiniMapUpdate;
End;
//Update money
If GameTime-LastGameMoneyTime>MoneyTime then
Begin
LastGameMoneyTime:=GameTime;
AddMoneyForAllPlayer;
End;
IsFrameToFindTarget:=GameFrame mod FrameRateForFindTarget=0;
GameTime:=MMSystem.TimeGetTime;
End;
PROCEDURE TGame.Play;
Begin
LoadWorld('Demo.World');
RestartCount;
{$IfDef SoundPlaying}
SoundPlay(BackGroundMusic);
{$EndIf}
Repeat
ProcessInput;
ProcessUnits;
ProcessEvents;
RenderScene;
Until EndGame;
End;
PROCEDURE TGame.HumanSetCommandStop;
Var Z : TUnitCount;
Begin
For Z:=Low(TUnitCount) to
Simple ЯTS G∆me Dεsign & CΘding
© CrazyBabe 2003. K-Outertainment™
Trang 29
High(TUnitCount) do
//Unit is owner
If (GameUnits[Z].Owner=HumanControl) and
//Unit alive
(GameUnits[Z].HitPoint>0) and ...
 

Các chủ đề có liên quan khác

Top