D'angband  0.0.0
Deeangband
 全て クラス ファイル 関数 変数 型定義 列挙型 列挙型の値 フレンド マクロ定義
クラス GameSurfaceSDL

ゲームのメインインターフェイスクラス(SDL実装) [詳細]

#include <GameSurfaceSDL.h>

GameSurfaceSDLに対する継承グラフ
GameSurfaceSDLのコラボレーション図

Public メソッド

void Redraw (void)
 ゲーム画面を再描画する [詳細]
 
void ViewCreatureStatus (Creature *creaturePtr)
 指定されたクリーチャーのステータスを表示する [詳細]
 
void SetFloor (Floor *floorPtr)
 表示するフロアを切り替える [詳細]
 
 GameSurfaceSDL (void)
 コンストラクタ [詳細]
 
 ‾GameSurfaceSDL (void)
 デストラクタ [詳細]
 
GAME_COMMAND GetCommand (void)
 プレイヤーからコマンドを取得する [詳細]
 
void FocusFloor (int x, int y)
 フロア表示のフォーカスを変更する。 [詳細]
 
void FocusFloor (Coordinates coord)
 フロア表示のフォーカスを変更する。 [詳細]
 
- Public メソッド inherited from GameSurface
 GameSurface (void)
 
virtual ‾GameSurface (void)
 

Private メソッド

void pushAnyKey (void)
 
void initInterfaces (void)
 
void drawCreatureStatus (Creature *creaturePtr)
 
void drawFloor (Floor *floorPtr, int x, int y, int w, int h)
 フロアの状況を描画する [詳細]
 

Private 変数

CreatureviewCreaturePtr
 
FloorviewFloorPtr
 
SDL_Renderer * renderer
 
SDL_RWops * rwop
 
std::string error
 
SDL_Window * window
 
TTF_Font * font
 
SDL_Surface * titleSurface
 
SDL_Color color
 
SDL_Rect src
 
SDL_Rect title
 
Coordinates focusPoint
 

説明

ゲームのメインインターフェイスクラス(SDL実装)

GameSurfaceSDL.h27 行で定義されています。

コンストラクタとデストラクタ

GameSurfaceSDL::GameSurfaceSDL ( void  )

コンストラクタ

GameSurfaceSDL.cpp36 行で定義されています。

37 {
38  if(SDL_Init(SDL_INIT_VIDEO) < 0) return;
39  window = SDL_CreateWindow(GAME_TITLE, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_RESIZABLE);
40  SDL_GetWindowSurface(window);
41  if(!window) return;
42 
43  if(TTF_Init() == -1) return;
44  if(IMG_Init(IMG_INIT_PNG) != IMG_INIT_PNG) return;
45 
47 
48  viewCreaturePtr = NULL;
49  viewFloorPtr = NULL;
50 
51  return;
52 }
#define WINDOW_HEIGHT
Definition: Deeangband.h:7
#define WINDOW_WIDTH
Definition: Deeangband.h:6
Floor * viewFloorPtr
#define GAME_TITLE
Definition: Deeangband.h:5
void initInterfaces(void)
Creature * viewCreaturePtr
SDL_Window * window

関数の呼び出しグラフ:

関数

void GameSurfaceSDL::drawCreatureStatus ( Creature creaturePtr)
private

GameSurfaceSDL.cpp127 行で定義されています。

128 {
129  int id;
130  SDL_Surface *windowSurface = SDL_GetWindowSurface(window);
131 
132  enum CREATURE_STATUS_VIEW_POSITION
133  {
134  POS_NAME,
135  POS_LEVEL,
136  POS_HP,
137  POS_MP,
138  POS_AC,
139  POS_EV,
140  POS_VO,
141  POS_STR,
142  POS_INT,
143  POS_WIS,
144  POS_DEX,
145  POS_CON,
146  POS_CHA,
147  POS_SOUL,
148  POS_GOOD,
149  POS_EVIL,
150  POS_ORDER,
151  POS_CHAOS,
152  POS_BALANCE,
153  POS_HEIGHT,
154  POS_WEIGHT,
155  POS_BODY_SIZE,
156  POS_MAX
157  };
158 
159  SDL_Rect CreatureStatusViewPosition[POS_MAX] =
160  {
161  {10, 10, 0, 0},
162  {10, 30, 0, 0},
163  {10, 50, 0, 0},
164  {10, 70, 0, 0},
165  {10, 90, 0, 0},
166  {10, 110, 0, 0},
167  {10, 130, 0, 0},
168  {200, 30, 0, 0},
169  {200, 50, 0, 0},
170  {200, 70, 0, 0},
171  {200, 90, 0, 0},
172  {200, 110, 0, 0},
173  {200, 130, 0, 0},
174  {200, 150, 0, 0},
175  {200, 170, 0, 0},
176  {200, 190, 0, 0},
177  {200, 210, 0, 0},
178  {200, 230, 0, 0},
179  {200, 250, 0, 0},
180  {10, 150, 0, 0},
181  {10, 170, 0, 0},
182  {10, 190, 0, 0},
183  };
184 
185  SDL_Rect CreatureStatusViewRect[POS_MAX];
186 
187  const int STATUS_BUFSIZE = 100;
188  char statusBuf[POS_MAX][STATUS_BUFSIZE];
189  SDL_Surface *statusSurface[POS_MAX];
190 
191  SDL_Rect masterRect = {10, 10, 490, 450};
192 
193  sprintf_s(statusBuf[POS_NAME], STATUS_BUFSIZE, "名前:%s", creaturePtr->GetName().c_str());
194  sprintf_s(statusBuf[POS_LEVEL], STATUS_BUFSIZE, "LV:%3d", creaturePtr->GetLevel());
195  sprintf_s(statusBuf[POS_HP], STATUS_BUFSIZE, "HP:%5d/%5d", creaturePtr->GetCurHP(), creaturePtr->GetMaxHP());
196  sprintf_s(statusBuf[POS_MP], STATUS_BUFSIZE, "MP:%5d/%5d", creaturePtr->GetCurMP(), creaturePtr->GetMaxMP());
197  sprintf_s(statusBuf[POS_AC], STATUS_BUFSIZE, "AC:%4d", creaturePtr->GetArmorSaving());
198  sprintf_s(statusBuf[POS_EV], STATUS_BUFSIZE, "EV:%4d", creaturePtr->GetEvasionSaving());
199  sprintf_s(statusBuf[POS_VO], STATUS_BUFSIZE, "VO:%4d", creaturePtr->GetVolitionSaving());
200  sprintf_s(statusBuf[POS_GOOD], STATUS_BUFSIZE, " 善 :%4d", creaturePtr->GetDiscipilneRank(DISCIPLINE_TYPE_GOOD));
201  sprintf_s(statusBuf[POS_EVIL], STATUS_BUFSIZE, " 悪 :%4d", creaturePtr->GetDiscipilneRank(DISCIPLINE_TYPE_EVIL));
202  sprintf_s(statusBuf[POS_ORDER], STATUS_BUFSIZE, "秩序:%4d", creaturePtr->GetDiscipilneRank(DISCIPLINE_TYPE_ORDER));
203  sprintf_s(statusBuf[POS_CHAOS], STATUS_BUFSIZE, "混沌:%4d", creaturePtr->GetDiscipilneRank(DISCIPLINE_TYPE_CHAOS));
204  sprintf_s(statusBuf[POS_BALANCE], STATUS_BUFSIZE, "天秤:%4d", creaturePtr->GetDiscipilneRank(DISCIPLINE_TYPE_BALANCE));
205  sprintf_s(statusBuf[POS_STR], STATUS_BUFSIZE, "腕力:%4d", creaturePtr->GetCurrentStatus(CS_STR));
206  sprintf_s(statusBuf[POS_INT], STATUS_BUFSIZE, "知力:%4d", creaturePtr->GetCurrentStatus(CS_INT));
207  sprintf_s(statusBuf[POS_WIS], STATUS_BUFSIZE, "賢さ:%4d", creaturePtr->GetCurrentStatus(CS_WIS));
208  sprintf_s(statusBuf[POS_DEX], STATUS_BUFSIZE, "器用:%4d", creaturePtr->GetCurrentStatus(CS_DEX));
209  sprintf_s(statusBuf[POS_CON], STATUS_BUFSIZE, "耐久:%4d", creaturePtr->GetCurrentStatus(CS_CON));
210  sprintf_s(statusBuf[POS_CHA], STATUS_BUFSIZE, "魅力:%4d", creaturePtr->GetCurrentStatus(CS_CHA));
211  sprintf_s(statusBuf[POS_SOUL], STATUS_BUFSIZE, "ソウル:%4d", creaturePtr->GetCurrentSoul());
212  sprintf_s(statusBuf[POS_HEIGHT], STATUS_BUFSIZE, "身長:%6dcm", creaturePtr->GetHeight());
213  sprintf_s(statusBuf[POS_WEIGHT], STATUS_BUFSIZE, "体重:%6dkg", creaturePtr->GetWeight());
214  sprintf_s(statusBuf[POS_BODY_SIZE], STATUS_BUFSIZE, "体格:%3d", creaturePtr->GetSize());
215 
216  for(id = 0; id < POS_MAX; id++)
217  {
218  statusSurface[id] = TTF_RenderUTF8_Blended(font, toUTF8(statusBuf[id]).c_str(), color);
219  CreatureStatusViewRect[id].x = 0;
220  CreatureStatusViewRect[id].y = 0;
221  CreatureStatusViewRect[id].w = statusSurface[id]->w;
222  CreatureStatusViewRect[id].h = statusSurface[id]->h;
223  CreatureStatusViewPosition[id].x += masterRect.x;
224  CreatureStatusViewPosition[id].y += masterRect.y;
225  }
226 
227  SDL_FillRect(windowSurface, &masterRect, SDL_MapRGBA(windowSurface->format, 0, 0, 0, 120));
228 
229  for(id = 0; id < POS_MAX; id++)
230  {
231  SDL_BlitSurface(statusSurface[id], &CreatureStatusViewRect[id], windowSurface, &CreatureStatusViewPosition[id]);
232  }
233 
234  for(id = 0; id < POS_MAX; id++)
235  {
236  SDL_FreeSurface(statusSurface[id]);
237  }
238  return;
239 }
AC GetArmorSaving(void)
クリーチャーの現装甲セービング値を返す
Definition: Creature.cpp:265
修養属性:混沌
Definition: Discipline.h:22
MP GetMaxMP(void)
クリーチャーの現最大MPを返す
Definition: Creature.cpp:255
int GetDiscipilneRank(DISCIPLINE_TYPE typ)
クリーチャーの現在修養ランクを返す
Definition: Creature.cpp:310
HEIGHT GetHeight(void)
クリーチャーの身長を返す
Definition: Creature.cpp:315
HP GetMaxHP(void)
クリーチャーの現最大HPを返す
Definition: Creature.cpp:240
修養属性:善
Definition: Discipline.h:19
EV GetEvasionSaving(void)
クリーチャーの現回避セービング値を返す
Definition: Creature.cpp:270
HP GetCurHP(void)
クリーチャーの現HPを返す
Definition: Creature.cpp:235
SDL_Color color
TTF_Font * font
SOUL GetCurrentSoul(void)
クリーチャーの現ソウル値を返す
Definition: Creature.cpp:280
BASE_STATUS GetCurrentStatus(CREATURE_STATUS stat)
クリーチャーの現基礎能力値を返す
Definition: Creature.cpp:290
VO GetVolitionSaving(void)
クリーチャーの現意思セービング値を返す
Definition: Creature.cpp:275
std::string toUTF8(LPCSTR str)
修養属性:天秤
Definition: Discipline.h:23
LEVEL GetLevel(void)
クリーチャーの現レベルを返す
Definition: Creature.cpp:223
SDL_Window * window
修養属性:秩序
Definition: Discipline.h:21
修養属性:悪
Definition: Discipline.h:20
MP GetCurMP(void)
クリーチャーの現MPを返す
Definition: Creature.cpp:250
NAME GetName(void)
クリーチャーの名前を返す
Definition: Creature.cpp:218
BODY_SIZE GetSize(void)
クリーチャーの体格値を返す
Definition: Creature.cpp:325
WEIGHT GetWeight(void)
クリーチャーの体重を返す
Definition: Creature.cpp:320

関数の呼び出しグラフ:

呼出しグラフ:

void GameSurfaceSDL::drawFloor ( Floor floorPtr,
int  x,
int  y,
int  w,
int  h 
)
private

フロアの状況を描画する

引数
floorPtr表示したいフロアの構造体参照ポインタ
x左上起点のX座標
y左上起点のY座標
w表示のマス幅
h表示のマス高さ
戻り値
なし

GameSurfaceSDL.cpp276 行で定義されています。

277 {
278  SDL_Surface *windowSurface = SDL_GetWindowSurface(window);
279  SDL_Rect symbolRect = {0, 0, 30, 30};
280  SDL_Surface *symbolSurface;
281  char symBuf[5];
282 
283  int px, py;
284  for(py = y; py < y + h; py++)
285  {
286  for(px = x; px < x + w; px++)
287  {
288  if(px < floorPtr->GetWidth() && py < floorPtr->GetHeight())
289  {
290  TAG tag = floorPtr->GetSquare(px, py)->getFeatureTag();
291  Color symColor = floorPtr->GetGameWorld()->GetFeature(tag)->GetSymColor();
292  Color backColor = floorPtr->GetGameWorld()->GetFeature(tag)->GetBackColor();
293  SDL_Color sdlSymCol = {(Uint8)symColor.r, (Uint8)symColor.g, (Uint8)symColor.b, (Uint8)symColor.a};
294  SDL_Rect blitRect = {240 + px * 24, py * 24 , 24, 24};
295  SDL_FillRect(windowSurface, &blitRect, SDL_MapRGBA(windowSurface->format, (Uint8)backColor.r, (Uint8)backColor.g, (Uint8)backColor.b, (Uint8)backColor.a));
296  sprintf_s(symBuf, 5, "%c", floorPtr->GetGameWorld()->GetFeature(tag)->GetSymbol());
297 
298  symbolSurface = TTF_RenderUTF8_Blended(font, toUTF8(symBuf).c_str(), sdlSymCol);
299  blitRect.x += (24 - symbolSurface->w) / 2;
300  blitRect.y += (24 - symbolSurface->h) / 2;
301  SDL_BlitSurface(symbolSurface, &symbolRect, windowSurface, &blitRect);
302  SDL_FreeSurface(symbolSurface);
303  }
304  }
305  }
306  return;
307 }
int b
Definition: Color.h:24
std::string TAG
ゲーム要素文字列ID
Definition: Deeangband.h:106
色定義クラス
Definition: Color.h:18
ID GetSymbol(void)
地形記号を返す
Definition: Feature.cpp:48
Color GetBackColor(void)
背景カラーを返す
Definition: Feature.cpp:58
TTF_Font * font
TAG getFeatureTag(void)
対応する地形のタグを返す。
Definition: Square.cpp:44
std::string toUTF8(LPCSTR str)
Color GetSymColor(void)
シンボルカラーを返す
Definition: Feature.cpp:53
int r
Definition: Color.h:22
SDL_Window * window
Square * GetSquare(MAP_LENGTH x, MAP_LENGTH y)
フロアの該当座標のマスを返す。
Definition: Floor.cpp:48
int g
Definition: Color.h:23
int a
アルファチャンネル
Definition: Color.h:25
GameWorld * GetGameWorld()
所属元のGameWorldインスタンスを返す
Definition: GameElement.cpp:50
Feature * GetFeature(TAG tag)
GameWorld中に存在する地形を返す
Definition: GameWorld.cpp:116

関数の呼び出しグラフ:

呼出しグラフ:

void GameSurfaceSDL::FocusFloor ( int  x,
int  y 
)
virtual

フロア表示のフォーカスを変更する。

引数
x基準X座標
y基準Y座標
戻り値
なし

GameSurfaceを再定義しています。

GameSurfaceSDL.cpp309 行で定義されています。

310 {
311  this->focusPoint.Set(x, y);
312 }
Coordinates focusPoint
void Set(int x, int y)
Definition: Coordinates.cpp:38

関数の呼び出しグラフ:

void GameSurfaceSDL::FocusFloor ( Coordinates  coord)
virtual

フロア表示のフォーカスを変更する。

引数
coord基準座標
戻り値
なし

GameSurfaceを再定義しています。

GameSurfaceSDL.cpp314 行で定義されています。

315 {
316  this->focusPoint.Set(coord.GetX(), coord.GetY());
317 }
int GetY(void)
Definition: Coordinates.cpp:33
Coordinates focusPoint
int GetX(void)
Definition: Coordinates.cpp:28
void Set(int x, int y)
Definition: Coordinates.cpp:38

関数の呼び出しグラフ:

GAME_COMMAND GameSurfaceSDL::GetCommand ( void  )
virtual

プレイヤーからコマンドを取得する

戻り値
ゲームコマンドID

GameSurfaceを再定義しています。

GameSurfaceSDL.cpp241 行で定義されています。

242 {
243  SDL_Event event;
244  SDL_Keycode key;
245 
246  while (SDL_PollEvent(&event))
247  {
248  switch(event.type)
249  {
250 
251  case SDL_KEYDOWN:
252  {
253  key=event.key.keysym.sym;
254 
255  switch(key)
256  {
257  case SDLK_ESCAPE:
258  return GAME_COMMAND_EXIT;
259  case SDLK_c:
261  }
262 
263  }
264  break;
265 
266  case SDL_QUIT:
267  return GAME_COMMAND_EXIT;
268  break;
269 
270  }
271  }
272 
273  return GAME_COMMAND_REDRAW;
274 }
void GameSurfaceSDL::initInterfaces ( void  )
private

GameSurfaceSDL.cpp71 行で定義されています。

72 {
73  font = TTF_OpenFont("ttf¥¥ipam.ttf", 18);
74  src.x = 0;
75  src.y = 0;
76  src.w = 300;
77  src.h = 200;
78  title.x = 0;
79  title.y = 0;
80  title.w = 512;
81  title.h = 512;
82  color.r = 255;
83  color.g = 223;
84  color.b = 200;
85  color.a = 255;
86 
87  if(!font) exit(1);
88 
89  rwop = SDL_RWFromFile("img¥¥Title.png", "rb");
90  error = IMG_GetError();
91  titleSurface = IMG_LoadPNG_RW(rwop);
92 
93  renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTVSYNC);
94 }
SDL_Surface * titleSurface
SDL_Color color
TTF_Font * font
SDL_Renderer * renderer
std::string error
SDL_Window * window
SDL_RWops * rwop

呼出しグラフ:

void GameSurfaceSDL::pushAnyKey ( void  )
private

GameSurfaceSDL.cpp62 行で定義されています。

63 {
64  SDL_Event event;
65  do
66  {
67  SDL_PollEvent(&event);
68  } while(event.type != SDL_KEYDOWN);
69 }

呼出しグラフ:

void GameSurfaceSDL::Redraw ( void  )
virtual

ゲーム画面を再描画する

戻り値
なし

GameSurfaceを再定義しています。

GameSurfaceSDL.cpp96 行で定義されています。

97 {
98  SDL_Surface *windowSurface = SDL_GetWindowSurface(window);
99  SDL_Rect rect = {0, 0, 0, 0};
100 
101  SDL_GetWindowSize(window, &rect.w, &rect.h);
102  SDL_SetRenderDrawColor(renderer, 100, 100, 0, 255);
103  SDL_FillRect(windowSurface, &rect, SDL_MapRGBA(windowSurface->format, 50, 20, 10, 255));
104  SDL_BlitSurface(titleSurface, &title, windowSurface, &title);
105 
106  if(viewFloorPtr) drawFloor(viewFloorPtr, 0, 0, 20, 20);
108 
109  SDL_UpdateWindowSurface(window);
110 
111  return;
112 }
void drawCreatureStatus(Creature *creaturePtr)
SDL_Surface * titleSurface
void drawFloor(Floor *floorPtr, int x, int y, int w, int h)
フロアの状況を描画する
Floor * viewFloorPtr
Creature * viewCreaturePtr
SDL_Renderer * renderer
SDL_Window * window

関数の呼び出しグラフ:

呼出しグラフ:

void GameSurfaceSDL::SetFloor ( Floor floorPtr)
virtual

表示するフロアを切り替える

引数
floorPtr表示したいフロアの参照ポインタ
戻り値
なし

GameSurfaceを再定義しています。

GameSurfaceSDL.cpp122 行で定義されています。

123 {
124  viewFloorPtr = floorPtr;
125 }
Floor * viewFloorPtr
void GameSurfaceSDL::ViewCreatureStatus ( Creature creaturePtr)
virtual

指定されたクリーチャーのステータスを表示する

引数
creaturePtr表示したいクリーチャーの参照ポインタ
戻り値
なし

GameSurfaceを再定義しています。

GameSurfaceSDL.cpp114 行で定義されています。

115 {
116  viewCreaturePtr = creaturePtr;
117  Redraw();
118  pushAnyKey();
119  viewCreaturePtr = NULL;
120 }
void pushAnyKey(void)
void Redraw(void)
ゲーム画面を再描画する
Creature * viewCreaturePtr

関数の呼び出しグラフ:

GameSurfaceSDL::‾GameSurfaceSDL ( void  )

デストラクタ

GameSurfaceSDL.cpp54 行で定義されています。

55 {
56  IMG_Quit();
57  TTF_Quit();
58  SDL_Quit();
59  return;
60 }

変数

SDL_Color GameSurfaceSDL::color
private

GameSurfaceSDL.h39 行で定義されています。

std::string GameSurfaceSDL::error
private

GameSurfaceSDL.h35 行で定義されています。

Coordinates GameSurfaceSDL::focusPoint
private

GameSurfaceSDL.h42 行で定義されています。

TTF_Font* GameSurfaceSDL::font
private

GameSurfaceSDL.h37 行で定義されています。

SDL_Renderer* GameSurfaceSDL::renderer
private

GameSurfaceSDL.h33 行で定義されています。

SDL_RWops* GameSurfaceSDL::rwop
private

GameSurfaceSDL.h34 行で定義されています。

SDL_Rect GameSurfaceSDL::src
private

GameSurfaceSDL.h40 行で定義されています。

SDL_Rect GameSurfaceSDL::title
private

GameSurfaceSDL.h41 行で定義されています。

SDL_Surface* GameSurfaceSDL::titleSurface
private

GameSurfaceSDL.h38 行で定義されています。

Creature* GameSurfaceSDL::viewCreaturePtr
private

GameSurfaceSDL.h30 行で定義されています。

Floor* GameSurfaceSDL::viewFloorPtr
private

GameSurfaceSDL.h31 行で定義されています。

SDL_Window* GameSurfaceSDL::window
private

GameSurfaceSDL.h36 行で定義されています。


このクラスの説明は次のファイルから生成されました: