mirror 散播福音的祭司
註冊時間: 2007-07-27 文章: 174
828.60 果凍幣
|
發表於: 2009-9-12, PM 5:26 星期六 文章主題: Dark GDK與碰撞 |
|
|
其實我一開始打算用模型本身的碰撞檢測去做
不過發現問題一堆,反而自己建立一個BOX去做檢測就好很多
目前的做法是一個模型就生一個BOX給他用
然後再給它隱藏起來...
我是打算弄個小型RPG所以下去摸了一下..
程式碼如下..
代碼: |
// Dark GDK - The Game Creators - www.thegamecreators.com
// whenever using Dark GDK you must ensure you include the header file
#include "DarkGDK.h"
void Move()
{
if(dbObjectCollision(3,4))
{
dbPositionObject(3,
dbObjectPositionX(1),
dbObjectPositionY(1),
dbObjectPositionZ(1));
}else{
dbPositionObject(1,
dbObjectPositionX(3),
dbObjectPositionY(3),
dbObjectPositionZ(3));
}
}
// the main entry point for the application is this function
void DarkGDK ( void )
{
// turn on sync rate and set maximum rate to 60 fps
dbSyncOn ( );
dbSyncRate ( 60 );
// 等待模型讀取的訊息
dbPrint ( "Please wait loading model..." );
dbSync ( );
dbSync ( );
// 載入模型(後面的數字代表這個模型的ID)
dbLoadObject ( "001.X", 1 );
// 複製一個一樣的模型出來
dbCloneObject(2, 1);
// 移動位置
dbPositionObject(2,100,0,100);
// 建立高低起伏不定的地表
dbMakeMatrix(5,1000,1000,50,50);
dbRandomizeMatrix(5, 5);
//dbSetMatrixWireframeOn(5);
dbUpdateMatrix(5);
// 建立一個方塊盒給obj1用(碰撞判定)
dbMakeObjectBox (3,50,50,50);
dbHideObject(3);
// 建立一個方塊盒給obj2用(碰撞判定)
dbMakeObjectBox (4,50,50,100);
dbPositionObject(4,100,0,100);
/*dbShowObjectBounds(3,1);
dbShowObjectBounds(4,1); */
// 文字部分不支援中文..QoQ
dbSetTextFont("Arial");
dbSetTextSize(20);
// 攝影機位置
//dbMakeCamera(1);
dbPositionCamera ( 0, 150, -200 );
// 播放ID為1的模型動畫,從第10格播放到第20格
dbLoopObject ( 1 );
// 設定ID為1的模型,播放速度為40
dbSetObjectSpeed ( 1, 10000 );
// our main loop
while ( LoopGDK ( ) )
{
{
dbJoystickHatAngle (0);
if(dbJoystickDown() || dbDownKey())
{
dbRotateObject(1, 0, 0, 0);
dbRotateObject(3, 0, 0, 0);
dbMoveObject(3, -4);
Move();
}
if(dbJoystickUp() || dbUpKey())
{
dbRotateObject(1, 0, 180, 0);
dbRotateObject(3, 0, 180, 0);
dbMoveObject(3, -4);
Move();
}
if(dbJoystickRight() || dbRightKey())
{
dbRotateObject(1, 0, 270, 0);
dbRotateObject(3, 0, 270, 0);
dbMoveObject(3, -4);
Move();
}
if(dbJoystickLeft() || dbLeftKey())
{
dbRotateObject(1, 0, 90, 0);
dbRotateObject(3, 0, 90, 0);
dbMoveObject(3, -4);
Move();
}
}
// ======================
// 下面的程式碼只是用來顯示資訊用,不用理它沒關係..
char xc[20], yc[20], zc[20];
sprintf(xc,"x:%f\n",dbObjectPositionX (1));
sprintf(yc,"y:%f\n",dbObjectPositionY (1));
sprintf(zc,"z:%f\n",dbObjectPositionZ (1));
dbText(0, 0, xc);
dbText(0, 20, yc);
dbText(0, 40, zc);
char xcc[20], ycc[20], zcc[20], rcc[20];
//dbPositionObject(3, 0, 0, 0);
sprintf(rcc,"r:%f\n",dbObjectCollisionRadius (1));
sprintf(xcc,"xc:%f\n",dbObjectCollisionCenterX (1));
sprintf(ycc,"yc:%f\n",dbObjectCollisionCenterY (1));
sprintf(zcc,"zc:%f\n",dbObjectCollisionCenterZ (1));
dbText(0, 70, rcc);
dbText(0, 90, xcc);
dbText(0, 110, ycc);
dbText(0, 130, zcc);
char chit[20];
sprintf(chit, "chit:%d\n",dbObjectCollision (3,4));
dbText(0, 150, chit);
// update the screen
// 更新畫面
dbSync ( );
}
// return back to windows
return;
}
|
描述: |
|
附件大小: |
25.76 KB |
觀看次數: |
共 8372 次 |
|
|
|