Professional Documents
Culture Documents
2D Game Programing
2D Game Programing
Yu cu chung
Hnh thc tnh im
Tng im bi tp 70%: bt1: 5%, bt2: 15%, bt3: 20%, bt4: 20%, bt5: 35%, bt6: 5% im bi thi cui k 30%
Mt s lu :
V hng cho sinh vin nm bt k thut cn bn nht ca ngnh lp trnh game, nn mong mun mi sinh vin s lm c tt c cc bi tp nu ra. Nn s i theo hng c nhn 45 tit/mn, 3 tit/bui --> Tun hc 1 bui l thuyt (a s thi gian l thc hnh nh). Bi thi cui k lm trn giy
Yu cu i vi sinh vin:
hon tt 2 mn: Cu trc d liu & gii thut, ha my tnh (chn tng im trung bnh 2 mn t trn xung) Ti a 25 sv / lp Phi c my tnh c nhn (v thc hnh nh l chnh).
9/2/2012 Khoa Khoa hc v K thut My tnh HBK Tp.HCM 2
9/2/2012
M rng
Sinh vin c th dng cc ngn ng lp trnh thc hin bi tp / thc hnh
Java C# VB.Net C++ MFC C++ SDK (mc nh dng trong bi ging ny)
9/2/2012
Bi tp / Thc hnh
9/2/2012
9/2/2012
References - Books
Beginning Game Programming, Second Edition, Jonathan S. Harbour, Thomson Course Technology, 2007 Advanced 2D Game Development, Jonathan S. Harbour, Course Technology, 2009 Introduction to 3D Game Programming with DirectX 9.0, Frank D. Luna, Wordware Publishing, Inc, 2003. Game Programming All in One, Bruno Miguel Teixeira de Sousa, Premier Press, 2002 Beginning C# Game Programming, Thomson Course Technology PTR, 2005 3D Game Engine Design, David H. Eberly, Morgan Kaufmann Publisher
9/2/2012 Khoa Khoa hc v K thut My tnh HBK Tp.HCM 5
Reference - Internet
http://www.gamedev.net/ http://nehe.gamedev.net/ http://www-csstudents.stanford.edu/~amitp/gameprog.html https://sites.google.com/site/sbskit/gamefornewbie http://www.cprogramming.com/tutorial/game_programmi ng http://devmaster.net/posts
9/2/2012
9/2/2012
Content
Windows Programming
Environment Introduction Windows Programming Windows Messaging & Event Handling The Real-Time Game Loop
Advanced Topics
Building a 2D Game Engine 2D Rendering Animation Physics Math
9/2/2012
WINDOWS PROGRAMMING
9/2/2012
9/2/2012
Environment Introduction
9/2/2012
9/2/2012
10
9/2/2012
9/2/2012
11
Compilation process
Taking a source code file, compiles it, and then linking it into an executable.
9/2/2012
12
9/2/2012
DirectX Working
What DirectX does to simplify the hardware interface is countered by an extremely large and complex set of features
9/2/2012 Khoa Khoa hc v K thut My tnh HBK Tp.HCM 13
Multi-Tasking
Non-preemptive multi- Preemptive multitasking tasking
9/2/2012
14
9/2/2012
Multi-Threading
9/2/2012
15
Direct X
The primary components of DirectX 9 DirectX, an alternative to the slow GDI, still relies on the Windows API
9/2/2012 Khoa Khoa hc v K thut My tnh HBK Tp.HCM 16
9/2/2012
Windows Programming
9/2/2012
17
9/2/2012
18
9/2/2012
9/2/2012
19
9/2/2012
20
10
9/2/2012
9/2/2012
21
WinMain and WinProc work hand-in-hand to handle application events (such as painting the screen and responding to mouse clicks).
9/2/2012 Khoa Khoa hc v K thut My tnh HBK Tp.HCM 22
11
9/2/2012
9/2/2012
23
9/2/2012
sensory-deprived, unable to respond to the world. Khoa Khoa hc v K thut My tnh HBK Tp.HCM
24
12
9/2/2012
9/2/2012
25
WindowTest program
Source code at below
9/2/2012
26
13
9/2/2012
Understanding InitInstance
BOOL InitInstance( HINSTANCE hInstance, int nCmdShow )
hInstance is passed by WinMain with the program instance that it receives from Windows. InitInstance will check this with the global instance to see if the new instance needs to be killed (the usual procedure in Windows). When this happens, the main instance of the program is set as the foreground window. To the user, it will seem as if running the program again just brought the original instance forward. nCmdShow is passed to InitInstance by WinMain, which receives the parameter from Windows. The most common values for this parameter include SW_HIDE and SW_SHOW, and are often sent by Windows based on events in the operating system (such as a power down).
9/2/2012 Khoa Khoa hc v K thut My tnh HBK Tp.HCM 27
Understanding MyRegisterClass
ATOM MyRegisterClass(HINSTANCE hInstance) { //create the window class structure WNDCLASSEX wc; wc.cbSize = sizeof(WNDCLASSEX); //fill the struct with info wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = (WNDPROC)WinProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = NULL; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)GetStockObject(WHIT E_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = APPTITLE; wc.hIconSm = NULL; //set up the window with the class info return RegisterClassEx(&wc); }
9/2/2012
28
14
9/2/2012
Understanding WinProc
LRESULT CALLBACK WinProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
hWnd is the window handle. Typically in a game, you will create a new handle to a device context, known as a hDC, using the hWnd as a parameter. Before DirectX came along, this was once crucial in the development of Windows games. message is the message that is being sent to the window callback procedure. The message could be anything, and you might not even need to use it. For this reason, there is a way to pass the message along to the default message handler (discussed in the next section). wParam and lParam are the high and low bit value parameters passed along with certain command messages.
Khoa Khoa hc v K thut My tnh HBK Tp.HCM
9/2/2012
29
Real-Time Game Loop The GameLoop Project Source Code for the GameLoop Program
9/2/2012
30
15
9/2/2012
The newly modified WinMain is much more friendly to a real-time game loop.
9/2/2012
PeekMessage: this function can look at incoming messages without Khoa Khoa hcof v the K thu t My tnh queue necessarily retrieving them out message
HBK Tp.HCM
31
9/2/2012
32
16
9/2/2012
9/2/2012
33
9/2/2012
34
17
9/2/2012
9/2/2012
35
9/2/2012
36
18
9/2/2012
9/2/2012
37
9/2/2012
38
19
9/2/2012
9/2/2012
39
9/2/2012
40
20
9/2/2012
The Direct3D Interfaces Creating the Direct3D Object Taking Direct3D for a Spin Direct3D in Fullscreen Mode
9/2/2012
41
21
9/2/2012
9/2/2012
43
9/2/2012
44
22
9/2/2012
9/2/2012
45
9/2/2012
46
23
9/2/2012
9/2/2012
47
9/2/2012
48
24
9/2/2012
9/2/2012
49
void Game_End(HWND hwnd) { //display close message MessageBox(hwnd, "Program is about to end", "Game_End", MB_OK); //release the Direct3D device if (d3ddev != NULL) d3ddev->Release(); //release the Direct3D object if (d3d != NULL) d3d->Release(); }
50
25
9/2/2012
9/2/2012
51
9/2/2012
52
26
9/2/2012
Example
d3dpp.Windowed = FALSE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8; d3dpp.BackBufferCount = 1; d3dpp.BackBufferWidth = SCREEN_WIDTH; d3dpp.BackBufferHeight = SCREEN_HEIGHT; d3dpp.hDeviceWindow = hwnd;
Khoa Khoa hc v K thut My tnh HBK Tp.HCM
9/2/2012
53
9/2/2012
54
27
9/2/2012
Introduction The Create_Surface Example Loading Bitmaps from Disk The Load_Bitmap Program
9/2/2012
55
Introduction
The monitor displays the linear array of pixels sent to it by the video card
A typical monitor The frame buffer in VRAM contains the image that is rendered on the monitor
9/2/2012 Khoa Khoa hc v K thut My tnh HBK Tp.HCM 56
28
9/2/2012
Surfaces
Both the front and back buffers are created for you when you configure the presentation parameters and call CreateDevice Primary Surfaces
front buffer, which makes sense in that the back buffer is copied to it during each frame
Creating a Surface
LPDIRECT3DSURFACE9 surface = NULL; d3ddev->ColorFill(surface, NULL, D3DCOLOR_XRGB(255,0,0)); HRESULT ColorFill(IDirect3DSurface9 *pSurface, CONST RECT *pRect, D3DCOLOR color);
29
9/2/2012
9/2/2012
The Create_Surface program copies random rectangles from an offscreen surface to the screen
Khoa Khoa hc v K thut My tnh HBK Tp.HCM 60
30
9/2/2012
9/2/2012
61
9/2/2012
62
31
9/2/2012
9/2/2012
63
9/2/2012
64
32
9/2/2012
HRESULT D3DXLoadSurfaceFromFile( LPDIRECT3DSURFACE9 pDestSurface, CONST PALETTEENTRY* pDestPalette, CONST RECT* pDestRect, LPCTSTR pSrcFile, CONST RECT* pSrcRect, DWORD Filter, D3DCOLOR ColorKey, D3DXIMAGE_INFO* pSrcInfo );
9/2/2012
65
9/2/2012
66
33
9/2/2012
9/2/2012
67
9/2/2012
68
34
9/2/2012
9/2/2012
69
9/2/2012
70
35
9/2/2012
9/2/2012
71
9/2/2012
72
36
9/2/2012
9/2/2012
73
9/2/2012
74
37
9/2/2012
9/2/2012
75
9/2/2012
76
38
9/2/2012
9/2/2012
77
9/2/2012
78
39
9/2/2012
Next, in Game_Init, add the line of code to load the background bitmap into this new surface:
back = LoadSurface("background.bmp", D3DCOLOR_XRGB(255,0,255));
Next, down in Game_Run, comment out the ColorFill line and replace it with a call to StretchRect, as shown here:
//d3ddev->ColorFill(backbuffer, NULL, D3DCOLOR_XRGB(0,0,0)); d3ddev->StretchRect(back, NULL, backbuffer, NULL, D3DTEXF_NONE);
Finally, add a line to Game_End to free the memory used by the background surface:
back->Release();
The cat is being animated over a colorful background. Note the lack of transparency.
9/2/2012
79
40
9/2/2012
Others (1)
A bitmapped font used to print text on the screen in a game. A tank sprite with animated treads, courtesy of Ari Feldman
Others (2)
A 32-frame rotation of the tank sprite (not animated), courtesy of Ari Feldman.
9/2/2012
82
41
9/2/2012
Others (3)
//sprite structure typedef struct { int x,y; int width,height; int movex,movey; int curframe,lastframe; int animdelay, animcount; } SPRITE;
9/2/2012
83
9/2/2012
84
42
9/2/2012
Drawing Transparent Sprites Creating a Sprite Handler Object Advanced Sprite Loading the Sprite Image Programming Drawing Transparent Sprites Drawing an Animated Sprite Working with Sprite Sheets The Tiled_Sprite Program Collision Detection Testing for Collisions The CollisionTest Program
9/2/2012 Khoa Khoa hc v K thut My tnh HBK Tp.HCM 85
9/2/2012
86
43
9/2/2012
9/2/2012
87
Drawing a Sprite
HRESULT Draw(LPDIRECT3DTEXTU RE9 pTexture, CONST RECT *pSrcRect, CONST D3DXVECTOR3 *pCenter, CONST D3DXVECTOR3 *pPosition, D3DCOLOR Color); typedef struct D3DXVECTOR3 {FLOAT x; FLOAT y;FLOAT z;} D3DXVECTOR3;
9/2/2012
88
44
9/2/2012
9/2/2012
89
9/2/2012
90
45
9/2/2012
9/2/2012
91
9/2/2012
92
46
9/2/2012
The caveman character has eight running frames and four jumping frames of animation.
9/2/2012
93
left = (curframe % columns) * width; top = (curframe / columns) * height; right = left + width; bottom = top + height;
9/2/2012 Khoa Khoa hc v K thut My tnh HBK Tp.HCM 94
47
9/2/2012
9/2/2012
95
9/2/2012
96
48
9/2/2012
9/2/2012
97
9/2/2012
98
49
9/2/2012
9/2/2012
99
9/2/2012
100
50
9/2/2012
Using DirectSound Initializing DirectSound Creating a Sound Buffer Loading a Wave File Playing a Sound Testing DirectSound Creating the Project Creating the DirectX Audio Support Files Tweaking the Framework Code Adding the Game Files Running the Program
Khoa Khoa hc v K thut My tnh HBK Tp.HCM 101
9/2/2012
DSUtil
CSoundManager The primary DirectSound device. CSound Used to create DirectSound buffers. CWaveFile Helps load a wave file into a CSound buffer.
9/2/2012
102
51
9/2/2012
Initializing DirectSound
CSoundManager *dsound = new CSoundManager(); dsound->Initialize(window_handle, DSSCL_PRIORITY); DirectSound cooperative level
DSSCL_NORMAL: Shares sound device with other programs. DSSCL_PRIORITY: Gains higher priority over sound device (recommended for games). DSSCL_WRITEPRIMARY: Provides access to modify the primary sound buffer.
9/2/2012 Khoa Khoa hc v K thut My tnh HBK Tp.HCM 103
9/2/2012
104
52
9/2/2012
9/2/2012
105
Stop
wave->Stop();
HRESULT Play( DWORD dwPriority = 0, DWORD dwFlags = 0, LONG lVolume = 0, LONG lFrequency = -1, LONG lPan = 0 ); HRESULT Stop();
Khoa Khoa hc v K thut My tnh HBK Tp.HCM 106
9/2/2012
53
9/2/2012
9/2/2012
107
9/2/2012
108
54
9/2/2012
9/2/2012
109
9/2/2012
110
55
9/2/2012
9/2/2012
111
9/2/2012
112
56
9/2/2012
9/2/2012
114
57
9/2/2012
9/2/2012
115
9/2/2012
116
58
9/2/2012
The Keyboard DirectInput Object and Device Initializing the Keyboard Reading Key Presses The Mouse Initializing the Mouse Reading the Mouse Paddle Game The New Framework Code for DirectInput The Paddle Game Source Code Paddle Game Explained
Khoa Khoa hc v K thut My tnh HBK Tp.HCM 117
9/2/2012
The Keyboard
The keyboard is the standard input device for all games The primary DirectInput object is called IDirectInput8;
can reference it directly or using the LPDIRECTINPUT8 pointer data type
9/2/2012
118
59
9/2/2012
9/2/2012
119
9/2/2012
120
60
9/2/2012
61
9/2/2012
9/2/2012
123
9/2/2012
124
62
9/2/2012
Paddle Game
Paddle Game is a near-complete game that demonstrates how to use DirectInput to read the keyboard and mouse
9/2/2012
125
9/2/2012
126
63
9/2/2012
Introduction to Scrolling Introduction to Tile-Based Backgrounds Backgrounds and Scenery Creating Backgrounds from Tiles Tile-Based Scrolling Dynamically Rendered Tiles The Tile Map Creating a Tile Map Using Mappy The DynamicScroll Project
Khoa Khoa hc v K thut My tnh HBK Tp.HCM 127
9/2/2012
Introduction to Scrolling
The scroll window shows a small part of a larger game world
9/2/2012
128
64
9/2/2012
9/2/2012
129
9/2/2012
130
65
9/2/2012
9/2/2012
131
9/2/2012
132
66
9/2/2012
9/2/2012
133
9/2/2012
134
67
9/2/2012
9/2/2012
135
9/2/2012
136
68
9/2/2012
9/2/2012
137
9/2/2012
138
69
9/2/2012
9/2/2012
139
The new map that has been created by Mappy, awaiting your custom tiles
9/2/2012
140
70
9/2/2012
9/2/2012
141
The palette of tiles has been imported from the large space photograph
9/2/2012
142
71
9/2/2012
9/2/2012
143
The Export dialog box is used to export a tile map to a text file.
9/2/2012
144
72
9/2/2012
9/2/2012
145
ADVANCED TOPICS
9/2/2012
146
73
9/2/2012
Compiler Support DirectX SDK Support Why Do We Need an Engine Creating the Engine Project Visual C++ Project Engine Source Code Compiling the Engine Project Testing the Engine The TestEngine Source Code Visual C++ Library Test Project.
Khoa Khoa hc v K thut My tnh HBK Tp.HCM 147
9/2/2012
Compiler Support
Dev-C++ 5.0 (MinGW / CygWin) Borland C++ 6.0 Visual C++ 7.1 (2003) Visual C++ 8.0 (2005) Visual C++ 8.0 (2005 SP1) Visual C++ 9.0 (2008)
9/2/2012
148
74
9/2/2012
9/2/2012
149
75
9/2/2012
9/2/2012
151
9/2/2012
152
76
9/2/2012
Setting the output file for the Visual C++ static library project.
9/2/2012
153
9/2/2012
154
77
9/2/2012
9/2/2012
155
Configuring the Visual C++ projects linker dependencies: 1. ..\..\Engine\lib\Advanced2D.lib 2. d3d9.lib 3. d3dx9.lib 4. dxguid.lib 5. winmm.lib
9/2/2012
156
78
9/2/2012
Adding the engines lib folder to the compilers library search path (optional).
9/2/2012
157
9/2/2012
158
79
9/2/2012
2D Rendering
Basic 2D Rendering Raising Happy Sprites Creating Vectors Testing Vector3 Creating a Reusable Sprite Class Rendering Sprites with Transparency Color Key Transparency Alpha Channel Transparency
Khoa Khoa hc v K thut My tnh HBK Tp.HCM 159
9/2/2012
9/2/2012
160
80
9/2/2012
else { //calculate real framerate p_frameCount_real++; if (p_realTimer.stopwatch(999)) { p_frameRate_real = p_frameCount_real; p_frameCount_real = 0; } //begin rendering this->RenderStart(); //let game do its own 3D game_render3d(); //2D rendering Render2D_Start(); game_render2d(); Render2D_Stop(); //done rendering this->RenderStop(); } }
9/2/2012
161
Creating Vectors
Vector3.h Vector3.cpp
9/2/2012
162
81
9/2/2012
9/2/2012
163
This sprite (being edited in GIMP) will be rendered with color-keyed transparency
9/2/2012
164
82
9/2/2012
9/2/2012
83
9/2/2012
Animation
Animation Demo Sprite Rotation and Scaling Animation with Transforms Particles
9/2/2012
167
Introduction (1)
9/2/2012
168
84
9/2/2012
Introduction (2)
Using the Sprite class developed in the previous chapter, we could create a dragon sprite with code like this:
Sprite *dragon = new Sprite(); dragon->loadImage("dragon.tga"); dragon->setSize(96,96); dragon->setTotalFrames(64);
9/2/2012
169
Introduction (3)
void Sprite::animate() { //update frame based on animdir if (frametimer > 0) { if (timeGetTime() > (DWORD)(framestart + frametimer)) { //reset animation timer framestart = timeGetTime(); curframe += animdir; //keep frame within bounds if (curframe < 0) curframe = totalframes-1; if (curframe > totalframes-1) curframe = 0; } } else { //no animation timer--update at cpu clock speed curframe += animdir; if (curframe < 0) curframe = totalframes-1; if (curframe > totalframes-1) curframe = 0; } }}
9/2/2012
170
85
9/2/2012
Animation Demo
The sprite sheet for an animated explosion
9/2/2012
171
9/2/2012
172
86
9/2/2012
9/2/2012
173
The RotateAnimDemo program draws an animated sprite with rotation and scaling.
174
87
9/2/2012
Particles (1)
Particles are tiny sprites that are rendered with about 50-percent alpha transparency so that they seem to glow. The key to creating a particle systemthat is, an emitter or other special effectis to start with a good source particle image.
9/2/2012
175
Particles (2)
Source particle image
9/2/2012
176
88
9/2/2012
Particles (3)
Particle demonstration with a white background. Particle demonstration with a black background. Khoa Khoa hc v K thut My tnh HBK Tp.HCM
9/2/2012
177
Physics
Collision Detection Automated Collision Detection Bounding Rectangle Collision Test Distance-Based Collision Test
9/2/2012
178
89
9/2/2012
Collision Detection
The two types of collision testing we will utilize are
Bounding rectangle Distance
Bounding rectangle collision detection describes the use of a sprites boundary for collision testing.
these values may be represented as left, top, right, and bottom
9/2/2012
179
four new support functions used internally by the engine to perform collision testing:
9/2/2012
bool collision(Sprite *sprite1, Sprite *sprite2); bool collisionBR(Sprite *sprite1, Sprite *sprite2); bool collisionD(Sprite *sprite1, Sprite *sprite2); void TestForCollisions();
Khoa Khoa hc v K thut My tnh HBK Tp.HCM 180
90
9/2/2012
9/2/2012
182
91
9/2/2012
9/2/2012
184
92
9/2/2012
9/2/2012
185
9/2/2012
186
93
9/2/2012
9/2/2012
187
9/2/2012
188
94
9/2/2012
9/2/2012
189
9/2/2012
190
95
9/2/2012
9/2/2012
191
9/2/2012
192
96
9/2/2012
With collisions turned back on, the framerate improved by the same amount (percentagewise).
9/2/2012
193
9/2/2012
194
97
9/2/2012
9/2/2012
195
Math
Distance between two vectors Length of a vector Dot product Cross product Normalized vector
9/2/2012
196
98
9/2/2012
Math Class
Distance Vector length Dot product Cross product Normalized vector Converting radians to degrees Converting degrees to radians X velocity of an angle Y velocity of an angle Angle to target vector
9/2/2012
197
9/2/2012
198
99
9/2/2012
Math Test
9/2/2012
199
100
9/2/2012
9/2/2012
201
101
9/2/2012
9/2/2012
203
9/2/2012
204
102
9/2/2012
APPENDIXES (VIETNAMESE)
9/2/2012
206
103
9/2/2012
Gii thiu
9/2/2012
207
Cc nn tng chi game Xu hng hin nay Tng quan v pht trin game
Nhn s trong 1 d n game: http://grannycoder.blogspot.com/2009/07/understanding producer, designer, artist, programmer, -game-development.html tester S lc v quy trnh pht trin game Lm th no to ra mt game? http://grannycoder.blogspot.com/2009/07/what-arestages-in-game-development.html http://www.wieringsoftware.nl/coding/
9/2/2012
208
104
9/2/2012
Game l g?
Game cng ch l mt ng dng, v n cng nh bao ng dng khc.
C th bt u vit game t hm main, hoc dng cc engine h tr.
Mt cch nhn khc, game l mt cun phim c tng tc. Nu nh mt b phim cn nhiu th nh kch bn tt, dn dng hay, hu k, kim duyt, qung b, ... th game cng vy. Game cng cn mt ni dung hay (kch bn), coding tt (dn dng, hu k), kim sot cht lng (kim duyt), qung b ... Nu mt phim thnh cng c nh gi qua doanh thu, th game cng vy. Tuy nhin, khi mi bt u, th doanh thu, li nhun, ... cn c gt ra khi t tng ca mnh, c tnh to tp trung vo chuyn mn.
209
ng v kha cnh lp trnh, game n gin l mt vng lp v tn, trong x l cc din bin ca game v s kin tng tc t ngi chi.
Tuy nhin, lm game cho mc ch thng mi, i hi bn nhiu hn th.
9/2/2012 Khoa Khoa hc v K thut My tnh HBK Tp.HCM
C#:
C/C++ cng l mt ngn ng kh c a chung trong lp trnh game ngy nay, vi kh nng thc thi trn khc nhiu platform: Windows, Linux, MacOS, Android, iphone/iPad, Symbian, Brew, Meegoo ...
9/2/2012
210
105
9/2/2012
Video game l g?
Video game l cch gi cc loi my chi game chuyn dng nh Playstation, Xbox, GameCube Cc h my ny cn gi l h my console. Thng th video game thng c chi trn cc my chuyn dng k trn.
9/2/2012
212
106
9/2/2012
Trong cc ngnh nghin cu game vn cha c s ng thun trong vic chp nhn mt nh ngha chnh thc cho cc th loi video game, mt s nh ngha c xem xt nhiu hn nhng ci khc.
Cng nh bt c s phn loi in hnh no khc, mt th loi video game nht nh cn c nhng c trng c th. Phn ln cc game u a ra cc kh khn cn phi vt qua, do vy cc th loi game c th nh ngha bng vic hon tt cc tr ngi thng qua cc cch c bn tng t.
9/2/2012
213
Cc game th loi Beat 'em up (nh bi chng) v hack and slash (cht v chm) tp trung vo kiu chin u mt chi mt trm trong nhng vng khng gian nh, nh bi mt s lng ln qun ch do my tnh iu khin.
9/2/2012 Khoa Khoa hc v K thut My tnh HBK Tp.HCM 214
107
9/2/2012
9/2/2012
216
108
9/2/2012
9/2/2012
217
9/2/2012
218
109
9/2/2012
9/2/2012
219
9/2/2012
220
110
9/2/2012
Lp trnh game 2D
9/2/2012
221
9/2/2012
Text: hin th text vi font True Type Khoa Khoa hc v K thuhttp://en.wikipedia.org/wiki/TrueType t My tnh http://www.libsdl.org/projects/SDL_ttf/ HBK Tp.HCM
111
9/2/2012
Initialization Enter Game Loop Retrieve Player Input Perform AI and Game Logic Render Next Frame Synchronize Display Loop Shutdown State Machine.
Khoa Khoa hc v K thut My tnh HBK Tp.HCM 223
Phn 3: Ly u vo cu th
Trong phn ny, u vo ca ngi chi c x l v / hoc m cho sau ny s dng trong AI v phn lun l.
112
9/2/2012
Phn 6: ng b ha hin th
Nhiu my tnh s tng tc hoc lm chm do mc phc tp ca tr chi. V d, nu c 1.000 i tng ang chy trn mn hnh, CPU s c mt ti cao hn nu c ch c 10 i tng. T l khung hnh ca tr chi s thay i, l khng th chp nhn c. Do , bn phi ng b ha cc tr chi mt s t l khung hnh ti a v c gng gi n bng cch s dng v / hoc cc chc nng thi gian, ch i. Thng thng, tc 30fps c coi l ti u.
9/2/2012
225
Phn 8: Shutdown
Giai on tt my cho bit kt thc ca tr chi, c ngha rng ngi dng thot vng lp c th hoc tr chi chnh v mun quay tr li h iu hnh. Tuy nhin, trc khi thot khi ngi s dng, bn phi pht hnh tt c cc ngun ti nguyn v lm sch h thng, cng ging nh bn cho bt k phn mm khc.
9/2/2012 Khoa Khoa hc v K thut My tnh HBK Tp.HCM 226
113
9/2/2012
9/2/2012
227
9/2/2012
228
114
9/2/2012
9/2/2012
230
115
9/2/2012
Frequency / tn s
L s lng mu chi mi giy, c th hin trong Hertz (Hz) hoc kg-Hertz (kHz, 1 kHz = 1000 Hz). Bn s thit lp ny n 44100 Hz (hoc 44,1 kHz) cho cht lng CD ", hoc khong 8 kHz cht lng in thoi.
Khoa Khoa hc v K thut My tnh HBK Tp.HCM
9/2/2012
231
116
9/2/2012
9/2/2012
233
9/2/2012
234
117
9/2/2012
SDL_gfx
ha nguyn thy (dy chuyn, vng trn, hnh ch nht ...) vi h tr AA, rotozoomer v chc nng h tr bn v khc lin quan n gi ln trong mt da trn Cvo th vin truyn thng trc tip n gin (SDL) nn tng API lp.
9/2/2012 Khoa Khoa hc v K thut My tnh HBK Tp.HCM 236
118
9/2/2012
im cng:
C mn hnh hiu ng khi thng mn (0.5). Hi ngi chi c restart hay khng (menu la chn) lc thua mn chi. (0.5). Code vit d c, khng hard code (0.5).
9/2/2012 Khoa Khoa hc v K thut My tnh HBK Tp.HCM 237
9/2/2012
238
119
9/2/2012
Gia tng tnh ton mi khung hnh, gi s bc thi gian lin tc-khng i v khng c kh nng tng tc:
vx v vy, cc hng s, trc khi tnh ton x += vx, y += vy
9/2/2012 Khoa Khoa hc v K thut My tnh HBK Tp.HCM 239
9/2/2012
240
120
9/2/2012
i vi cc ha tit, t trung tm ca khi lng im nh dy c nht i vi cc tr chi arcade, m hnh lc hp dn trong khung hnh sprite
9/2/2012 Khoa Khoa hc v K thut My tnh HBK Tp.HCM 242
121
9/2/2012
iu g s xy ra sau khi bn p dng mt lc vo mt i tng? iu g s xy ra khi bn bn mt tn la t mt i tng di chuyn? Nhng loi iu khin bn mong i c trn mt con tu khng gian? iu g v mt tr chi bay?
9/2/2012 Khoa Khoa hc v K thut My tnh HBK Tp.HCM 243
9/2/2012
244
122
9/2/2012
t nh t = vi sin()/g Vi sc gi
x += vix + W y += viy
Vi sc gi khng v trng lc
vix += Wrx viy += Wry + g, g chun
9/2/2012 Khoa Khoa hc v K thut My tnh HBK Tp.HCM 246
123
9/2/2012
124
9/2/2012
9/2/2012
250
125
9/2/2012
9/2/2012
251
S dng t-tc tnh ton v tr mi t im va chm Xc nh nhng thay i trong vng quay Khng! y c phi l gi tr n? Ph thuc vo tc ca m phng, ...
9/2/2012 Khoa Khoa hc v K thut My tnh HBK Tp.HCM 252
126
9/2/2012
Xc nh cc i tng khi chng chm vo yc y1 (y1-y2)*(tc-t1) / delta(t) Xc nh cc gc va chm so vi bnh thng va chm
va chm bnh thng l b mt bnh thng ca bc tng trong trng hp ny tnh ton gc ca ng s dng (x1-xh) v (y1-yc)
9/2/2012 Khoa Khoa hc v K thut My tnh HBK Tp.HCM 253
Khng va chm n hi chuyn i ng Nng lng thnh nhit v / hoc bin dng c kh
9/2/2012 Khoa Khoa hc v K thut My tnh HBK Tp.HCM 254
127
9/2/2012
9/2/2012
255
9/2/2012
256
128
9/2/2012
9/2/2012
258
129
9/2/2012
~~~~ HT ~~~~
9/2/2012
260
130