Rogue遊戲(一) 遊戲框架搭建

2021-07-06 08:21:57 字數 1159 閱讀 1956

rogue遊戲有著悠久的歷史,為了向經典致敬,我也打算自己編寫乙個類似的遊戲,這次先將遊戲的框架搭建起來。

編寫和執行環境是linux,用到curses.h(終端圖形庫),編譯方法:先編寫makefile,然後make,執行方法:終端下輸入./rogue

makefile:

rogue:rogue.cpp

g++ rogue.cpp -o rogue -lncurses

clean:

rm -rf *.o rogue

rogue.cpp:

#include #include #define empty 0

#define me 1

#define wall 2

static char symbol = ;

static int m_w = 10;

static int m_h = 5;

static int offset_x = 5;

static int offset_y = 5;

static int map[5][10] = ;

void drawmap()

class human

;human::human(int _x, int _y, int _kind)

void human::move(int _dir)

; int dir_y[4] = ;

int old_x = x;

int old_y = y;

x += dir_x[_dir];

y += dir_y[_dir];

if (map[y][x] == wall)

showmove(old_x, old_y, x, y);

move(0, 0);

refresh();

}void human::showmove(int fx, int fy, int tx, int ty)

int main()

} endwin();

return 0;

}

執行效果如下圖,可以上下左右行走,有牆壁碰撞的檢測。

Android遊戲開發 遊戲框架的搭建 3

5.影象模組 graphics 最後乙個模組是影象操作模組,用來繪製影象到螢幕上。不過要想高效能的繪製影象,就不得不了解一些基本的影象程式設計知識。讓我們從繪製2d影象開始,首先要了解的乙個問題是 影象究竟是如何繪製到螢幕的?答案相當複雜,我們不需要知道所有的細節。光柵 畫素和幀緩衝 framebu...

Unity 遊戲框架搭建 2017 一 概述

在 hierarchy 上建立乙個空的gameobject,然後掛上所有與 gameobject 無關的邏輯控制的指令碼。使用gameobject.find 訪問物件資料。缺點 邏輯 散落在各處,不適合大型專案。所有與 gameobject 無關的邏輯都放在乙個單例中。缺點 單一檔案過於龐大。將不同...

飛機大戰 之 遊戲框架的搭建

方法 職責 create sprites self 建立所有精靈和精靈組 方法 職責 event handler self 事件監聽 check collide self 碰撞檢測 子彈銷毀敵機 敵機撞毀英雄 update sprites self 精靈組更新和繪製 game over 遊戲結束 i...