Leistungsstarkes Game Framework
The game framework based on game framework by Woei Kae Chen
Loading...
Searching...
No Matches
gameutil.h
Go to the documentation of this file.
1/*
2 * gamelib.h: 本檔案儲遊戲相關的class的interface
3 * Copyright (C) 2002-2008 Woei-Kae Chen <wkc@csie.ntut.edu.tw>
4 *
5 * This file is part of game, a free game development framework for windows.
6 *
7 * game is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * game is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 * History:
22 * 2002-03-04 V3.1
23 * 1. Add ENABLE_AUDIO flag.
24 * 2004-03-02 V4.0
25 * 1. Add CInteger class.
26 * 2. Add CGameState abstract class and adjust CGame to apply
27 * state pattern for switching game states.
28 * 2004-03-08 V4.1
29 * 1. Add OPEN_AS_FULLSCREEN flag.
30 * 2. The Game Engine now becomes a framework.
31 * 2005-07-28
32 * 1. Add GAME_ASSERT macro to display run time errors gracefully.
33 * 2. Remove CDDarw::CheckSystem(). It is useless.
34 * 2005-09-08
35 * 1. Eliminate CSpecialEffect::Abort. It is useless now.
36 * 2. Add SHOW_GAME_CYCLE_TIME flag.
37 * 3. Add DEFAULT_BG_COLOR flag;
38 * 2005-09-20 V4.2Beta1.
39 * 2005-09-29 V4.2Beta2.
40 * 1. Add MOUSEMOVE Handler for CGame and CGameState.
41 * 2. Add _TRACE preprocessor flag for VC++.net.
42 * 2006-02-08 V4.2
43 * 1. Rename OnInitialUpdate() -> OnInit().
44 * 2. Remove constantness of CAnimation::DELAY_COUNT.
45 * 3. Enhance CAnimation to support SetDelayCount(), Reset(), and IsFinalBitmap().
46 * 4. Remove CAnimation::GetLocation() and CMovingBitmap::GetLocation().
47 * 5. Bitmap coordinate can no longer be set by CMovingBitmap::LoadBitmap().
48 * Defauts to (0,0).
49 * 2006-09-09 V4.3
50 * 1. Rename Move() and Show() as OnMove and OnShow() to emphasize that they are
51 * event driven.
52 * 2. Fix bug: audio is now correctly recovered after a sleep or suspension of windows.
53 * 3. Support ENABLE_GAME_PAUSE.
54 * 2008-02-15 V4.4
55 * 1. Add setup project for Visual studio 2005.
56 * 2. Support bitmap scaling when ShowBitmap(scale) is called.
57 * 3. Add namespace game_framework.
58 * 4. Make the class CGame a singleton so that MFC can access it easily.
59 * 5. Support loading of bitmap from bmp file.
60 * 6. Support ShowInitProgress(percent) to display loading progress.
61 * 2010-03-23 V4.6
62 * 1. Rewrite CAudio with MCI commands to eliminate dependency with DirectMusic.
63*/
64
66// Header for STL (Standard Template Library)
68
69#include <list>
70#include <vector>
71#include <map>
72using namespace std;
73
74namespace game_framework {
75
77 // 這個class提供動態(可以移動)的圖形
78 // 每個Public Interface的用法都要懂,Implementation可以不懂
80
82 public:
84
85 /* The function for loading the bitmap. */
86 void LoadBitmap(int, COLORREF = CLR_INVALID); // 載入圖,指定圖的編號(resource)及透明色
87 void LoadBitmap(char*, COLORREF = CLR_INVALID); // 載入圖,指定圖的檔名及透明色
88 void LoadBitmap(vector<char*>, COLORREF = CLR_INVALID); // 載入圖,指定圖的檔名及透明色
89 void LoadBitmapByString(vector<string>, COLORREF = CLR_INVALID); // 載入圖,指定圖的檔名及透明色
90 void LoadEmptyBitmap(int height, int weight);
91
92 /* Unshow the bitmap. */
93 void UnshowBitmap();
94
95 /* Setter */
96 void SetAnimation(int delay, bool _once);
97 void SetFrameIndexOfBitmap(int frame);
98 void SetTopLeft(int, int); // 將圖的左上角座標移至 (x,y)
99
100 /* Show the bitmap with or without factor. */
101 void ShowBitmap(); // 將圖貼到螢幕
102 void ShowBitmap(double factor); // 將圖貼到螢幕 factor < 1時縮小,>1時放大。注意:需要VGA卡硬體的支援,否則會很慢
103
104 /* Getter */
107 int GetTop();
108 int GetLeft();
109 int GetHeight();
110 int GetWidth();
111 string GetImageFileName();
112 COLORREF GetFilterColor();
113
114 /* Is function */
115 bool IsAnimation();
116 bool IsAnimationDone();
117 bool IsBitmapLoaded();
118 bool IsOnceAnimation();
119 static bool IsOverlap(CMovingBitmap bmp1, CMovingBitmap bmp2);
120
121 /* Toggle function */
122 void ToggleAnimation();
123
124 protected:
126 int frameIndex = 0;
128 int delayCount = 10;
132 bool isAnimation = false;
134 bool isAnimationDone = true;
136 bool isBitmapLoaded = false; // whether a bitmap has been loaded
138 bool isOnce = false;
139 CRect location; // location of the bitmap
140 vector<unsigned> surfaceID;
141 clock_t last_time = clock();
143 string imageFileName = "";
145 COLORREF filterColor = CLR_INVALID;
146
147 private:
148 void InitializeRectByBITMAP(BITMAP bitmap);
149 void ShowBitmapBySetting();
150 };
151
152 class CTextDraw {
153 public:
154 void static Print(CDC *pdc, int x, int y, string str);
155 void static ChangeFontLog(CDC *pdc, int size, string fontName, COLORREF fontColor, int weight = 500);
156 };
157
158}
Definition: gameutil.h:81
void UnshowBitmap()
停止顯示圖片。
Definition: gameutil.cpp:172
bool isAnimation
儲存物件是否為動畫。
Definition: gameutil.h:132
bool IsOnceAnimation()
動畫物件是否為單次動畫物件。
Definition: gameutil.cpp:300
int GetLeft()
取得 CMovingBitmap 物件的左上角的 x 軸座標值。
Definition: gameutil.cpp:53
void SetAnimation(int delay, bool _once)
設置圖片是否為動畫。
Definition: gameutil.cpp:203
string imageFileName
儲存物件讀取的圖片路徑
Definition: gameutil.h:143
bool IsAnimation()
物件是否為動畫物件。
Definition: gameutil.cpp:284
int animationCount
儲存當前動畫的次數。
Definition: gameutil.h:130
vector< unsigned > surfaceID
Definition: gameutil.h:140
COLORREF GetFilterColor()
取得物件過濾顏色。
Definition: gameutil.cpp:364
static bool IsOverlap(CMovingBitmap bmp1, CMovingBitmap bmp2)
兩物件是否交疊。
Definition: gameutil.cpp:374
bool isBitmapLoaded
儲存圖片是否已讀取
Definition: gameutil.h:136
bool isOnce
儲存物件動畫是否為單次動畫
Definition: gameutil.h:138
void ToggleAnimation()
啟動單次動畫。
Definition: gameutil.cpp:274
int GetWidth()
取得當前圖片寬度。
Definition: gameutil.cpp:264
bool IsAnimationDone()
動畫物件是否已執行完動畫。
Definition: gameutil.cpp:292
void SetTopLeft(int, int)
設置圖片至畫布指定座標上。
Definition: gameutil.cpp:185
clock_t last_time
Definition: gameutil.h:141
int GetTop()
取得當前圖片左上角 y 軸的座標值。
Definition: gameutil.cpp:254
CMovingBitmap()
CMovingBitmap 建構子
Definition: gameutil.cpp:32
CRect location
Definition: gameutil.h:139
bool isAnimationDone
儲存物件動畫是否已結束
Definition: gameutil.h:134
void ShowBitmap()
顯示圖片。
Definition: gameutil.cpp:213
string GetImageFileName()
取得物件載入圖片名稱。
Definition: gameutil.cpp:356
void LoadBitmap(int, COLORREF=CLR_INVALID)
讀取圖片資源。
Definition: gameutil.cpp:65
void SetFrameIndexOfBitmap(int frame)
設置當前圖片顯示幀的索引值。
Definition: gameutil.cpp:237
int GetFrameSizeOfBitmap()
回傳物件的幀數。
Definition: gameutil.cpp:316
int GetFrameIndexOfBitmap()
取得當前圖片顯示幀的索引值。
Definition: gameutil.cpp:246
void LoadBitmapByString(vector< string >, COLORREF=CLR_INVALID)
讀取圖片資源。
Definition: gameutil.cpp:131
int frameIndex
當前幀的索引值。
Definition: gameutil.h:126
int delayCount
當前幀切換的延遲。
Definition: gameutil.h:128
COLORREF filterColor
儲存物件過濾的圖片顏色
Definition: gameutil.h:145
bool IsBitmapLoaded()
物件是否已讀取點陣圖。
Definition: gameutil.cpp:308
void LoadEmptyBitmap(int height, int weight)
讀取空白圖片資源。
Definition: gameutil.cpp:145
int GetHeight()
取得 CMovingBitmap 物件的圖片高度。
Definition: gameutil.cpp:42
Definition: gameutil.h:152
static void Print(CDC *pdc, int x, int y, string str)
在畫面上印出文字。
Definition: gameutil.cpp:394
static void ChangeFontLog(CDC *pdc, int size, string fontName, COLORREF fontColor, int weight=500)
設定當前文字的屬性。
Definition: gameutil.cpp:410
Definition: mygame.h:42