虛函式釋義

2021-04-14 09:21:18 字數 1555 閱讀 3106

最近似乎在手機上a-rpg遊戲很受歡迎,當然,我最近也在幫公司寫一款a-rpg類的遊戲。以前從沒寫過這樣的遊戲,從有到無的寫出來了。也碰到不少問題,包括螢幕滾動時地圖title陣列索引的校驗、整個遊戲框架的搭建、地圖資料的處理、分層的處理、主角技能的處理、碰狀檢測。

這些問題有空我會做為小專題乙個乙個的寫出來,這個話題裡我們來一起討論下a-rpg遊戲裡怪物尋路演算法的確定。

很顯然,在手機這樣的裝置上,a*演算法不適合。因為a*中大量的節點會把手機記憶體爆掉,這個是我直觀的感覺,沒親自去實踐,如果有人能在手機上精確的實現了a*演算法的話,請告訴我一聲。

那麼,在j2me裡該如何處理怪物尋路演算法呢?

我在這個遊戲裡用的是a*演算法的簡化版本,暫時稱其為a* ******演算法。

我們可以建立乙個怪物的類,這個類裡包括不同版本的怪物、相應的、相應的尋路演算法、相應的攻擊技能、相應的碰撞檢測等。如果不建立這個類的話,實在很難想象這個遊戲到後期如何擴充套件。

那麼我們就可以在這個類裡面做如下的判斷:

if(!walking)else if(spritex < therolex&&spritey < theroley)

else if(spritey < theroley&&spritex > therolex)

else if(spritey > theroley&&spritex > therolex)

else if(therolex-spritex > 8+spritewidth&&spritey == theroley)

else if(therolex-spritex <= 8+spritewidth&&spritey == theroley&&therolex-spritex>0)

else if(spritex-therolex > 8+spritewidth&&spritey == theroley)

else if(spritex-therolex <= 8+spritewidth&&spritey == theroley&&spritex>therolex)

else if(spritey-theroley > spriteheight&&spritex == therolex)

else if(spritey-theroley <= spriteheight&&spritex == therolex&&spritey-theroley > 0)

else if(theroley-spritey > height&&spritex == therolex)

else if(theroley-spritey <= height&&spritex == therolex)

在這個尋路演算法中,怪物類會先判斷「權值」,即橫向和豎向到目標地的距離的大小。

然後根據「權值」做出相應的動作。

比如,怪物如果在主角的左下方,那麼它會先逼近主角的正下方,然後從下方逼近主角。

當然,這個演算法可以寫的更精確寫,那要以犧牲效能為代價了。

如何在精確和效能上做出平衡,也是我所要尋找的。

歡迎有類似經驗的同行一起討論。

虛函式釋義

從本月開始msdn webcast將開始乙個名為 windows embedded開發從入門到精通 的系列課程,主要針對的人群是 windows應用開發者 其他嵌入式平台開發者 如linux arm等 和想學習嵌入式開發的人士。這個系列課程將由淺入深,介紹微軟windows embedded產品線 ...

虛函式釋義

型別相容規則舉例 include stdafx.h include using namespace std class b0 基類b0宣告 void main 主函式 輸出結果 b0 display b0 display b0 display press any key to continue 型別...

虛基類釋義

include stdafx.h include include using namespace std class person class teacher virtual public person class student virtual public person class gradua...