顯示具有 Game 標籤的文章。 顯示所有文章
顯示具有 Game 標籤的文章。 顯示所有文章

2011年1月29日 星期六

某個遊戲的 workflow



某個遊戲的 workflow。若以 Model-View-Controller pattern 來看,workflow 談的就是 controller。Controller 可以再細分下去,怎麼說?

傳統上 controller 角色定位有點模糊,但如果將 application 拆成 business logic, tool 及 view 三個 layers,每個 layer 都可以有自己的 controller,這這裡的 workflow 屬於 tool layer。Tool layer 向上與 business objects (ex: physics simulation service) 合作,向下與 view & input controller 合作。這是一個 layer 的概念。

回到 workflow 上,可以看到很多圈圈跟線,這是標準的 UML statechart 語言,乍看很深奧,其實這只是騙人的東西,工具不是重點,重點是「說清楚講明白」。透過這張小圖,清楚知道小遊戲會有哪些 workflow,很多破關遊戲都是類似的 workflow,掌握大趨勢,做的東西自然不會偏差太遠。加油!我可以山寨成功的 XD

How to build Chipmunk Physics 5.3.4?

The source code is located at code.google. In brief, Chipmunk Physics is a fast and lightweight 2D rigid body physics library in C.

How to get source code? Use subversion: svn checkout http://chipmunk-physics.googlecode.com/svn/trunk/ chipmunk-physics-read-only.

How to build? Chipmunk Physics only provide VS2008/2010 solutions. So we need to make our owned VS2005 solution: Make a copy of msvc/vc9 and rename it to msvc/vc8. And then modify one solution and two project files. (In the solution file, change line 2 to "Microsoft Visual Studio Solution File, Format Version 9.00" and line 3 to "# Visual Studio 2005". In two project files, change line 4 to "Version="8.00"")

Finally, open msvc/vc8/chipmunk.sln and compile all projects. Failed! Please do the following steps.
1. Redefine "cpCollisionHandler cpSpaceDefaultHandler." Please change line 45 of cpSpace.h file to "extern cpCollisionHandler cpSpaceDefaultHandler;"
2. Cannot find . It is because that the additional include directories is wrong. Please change "..\glut\include" to "..\..\glut\include"

After passing compiling. I meet another bug: Cannot find glut32.dll. Luckily, I can find glut32.dll in msvc\glut\runtime. Please copy glut32.dll to the working directory of demo.exe.

Now all projects passed sanity tests!

Plan on Physics Simulation Service

Implementation choices:
1. chipmunk-physics
2. box2d

Requirement of physics simulation service: (draft)
1. create a world
2. create a ground body
3. create a dynamic body
4. simulate the world
5. apply a force
6. change the gravity of the world

Plan: Re-factor Testbed project of Box2D to distill the interface of physics simulation service.

Motivation: I was inspired by Martin, Clean Code. I need physics simulation, and I know that using third-party code is a good idea. Don't reinvent the wheel. So I need to explore and learn boundaries of physics simulation. So I have a plan.

Besides, I can use code that does not yet exist. If I have any trouble in implementing the service, I can provide a fake implementation to ensure that other parts can be tested and worked.

2011年1月27日 星期四

How to build Box2D?

Box2D Physics Engine. The source code is located at code.google. In brief, Box2D is an open source C++ engine for simulating rigid bodies in 2D. Box2D is developed by Erin Catto.

How to get source code? The standard way is to use subversion: svn checkout http://box2d.googlecode.com/svn/trunk/ box2d-read-only. There are a lot of binary packages of subversion. I am lazy, so I choose SlikSVN. After installing SlikSVN, I use command "svn checkout" to get the source code in the command prompt.

How to build? I am very lazy, so I use VS2005/2008 as my IDE. In the instruction of Building.txt, I need CMake to generate the solution file. OK, it's fine. I install CMake, and then I continue following the instruction of Building.txt. Yes! Box2D.sln is generated!

Finally, I open Box2D/Build/Box2D.sln and compile all projects. Run HelloWorld & Testbed to verify Box2D is OK! Yes! Box2D is working!