DXフレームワーク　リファレンス・マニュアル 0.01 DXフレームワークのリファレンスです。詳細は公式wiki

- メインページ
- 関連ページ
- クラス
- ファイル

- ファイル一覧

Scene.h
1 #pragma once
2 #include "DXFrameWork.h"
3 #include "IScene.h"
4 #include "Layer.h"
5 #include "Unit.h"
6 #include "Shot.h"
7
8 namespace DXStg
9 {
10 class Scene : public IScene
11 {
12 private:
13 std::list<Layer*> layers;
14
15 Layer backEfects;
16 Layer midEfects;
17 Layer frontEfects;
18
19 Layer allys;
20 Layer skyEnemys;
21 Layer earthEnemys;
22 Layer items;
23
24 Layer allyShots;
25 Layer enemyShots;
26
27 Layer blocks;
28
29 std::vector<IModule*> events;
30
31 static Scene* sceneNow;
32
33 void ExeEvent()
34 {
35 for (auto it : events)
36 {
37 it->Exe();
38 }
39 }
40
41 void Remove()
42 {
43 for(auto it : layers )
44 {
45 it->ExeRemove( &area );
46 }
47 }
48
49 void Clear()
50 {
51 timer = 0;
52 for( auto it : layers )
53 {
54 it->Clear();
55 }
56 }
57
58 void Hit()
59 {
60 //ブロック
61 blocks.Hit( allys );
62 blocks.Hit( skyEnemys );
63 blocks.Hit( allyShots );
64 blocks.Hit( enemyShots );
65
66 //敵,敵弾,自機,自機弾
67 allys.Hit( skyEnemys );
68 allys.Hit( enemyShots );
69 skyEnemys.Hit( allyShots );
70 earthEnemys.Hit( allyShots );
71
72 //アイテム
73 items.Hit( player );
74 }
75
76 public:
77 int timer = 0;
78 bool isEnd = false;
79
80 std::unique_ptr<Camera> camera;
81
82 double scrSpeedX = 0;
83 double scrSpeedY = 0;
84
85 Rect area = Rect(300 , 300 , 640 , 700);
86 Rect moveArea = Rect(300 , 300 , 600 , 600);
87
88 Unit *player = nullptr;
89
90 Scene():
91 camera( new Camera( 400 , 300 , 1) )
92 {
93 SetNow();
94 layers.push_back(&backEfects);
95 layers.push_back(&earthEnemys);
96 layers.push_back(&midEfects);
97 layers.push_back(&blocks);
98 layers.push_back(&allys);
99 layers.push_back(&skyEnemys);
100 layers.push_back(&allyShots);
101 layers.push_back(&enemyShots);
102 layers.push_back(&items);
103 layers.push_back(&frontEfects);
104 }
105
106 virtual ~Scene(){}
107
108 void SetNow()
109 {
110 sceneNow = this;
111 Camera::SetNow(this->camera.get());
112 }
113
114 static Scene* Now()
115 {
116 return sceneNow;
117 }
118
119 void Update()
120 {
121 SetNow();
122 Camera::SetNow( camera.get() );
123 timer++;
124
125 Time::StartWatch();
126 ExeEvent();
127
128 Time::DrawWatch( 10 , 60 , "Main");
129
130 Time::StartWatch();
131 for( auto it : layers )
132 {
133 it->Update();
134 }
135 Time::DrawWatch( 10 , 90 , "Update");
136
137 camera->Update();
138
139 Time::StartWatch();
140 Hit();
141 Time::DrawWatch( 10 , 120 , "Hit");
142
143 Time::StartWatch();
144 Remove();
145 Time::DrawWatch( 10 , 150 , "Remove");
146 }
147
148 void Draw()
149 {
150 SetNow();
151 backEfects.Draw();
152 earthEnemys.Draw();
153
154 Screen::SetBright( 0 , 0 , 0 );
155 Screen::SetBlendMode( BlendMode::Alpha , 128 );
156 allys.DrawShadow( 50 , 50 );
157 skyEnemys.DrawShadow( 50 , 50 );
158 Screen::SetBlendMode( BlendMode::NoBlend , 0 );
159 Screen::SetBright( 255 , 255 , 255 );
160
161 midEfects.Draw();
162 blocks.Draw();
163 allys.Draw();
164 skyEnemys.Draw();
165 allyShots.Draw();
166 enemyShots.Draw();
167 items.Draw();
168 frontEfects.Draw();
169 }
170
171 void ExeInit()
172 {
173 SetNow();
174 Init();
175 Clear();
176 }
177
178 void ExeFinal()
179 {
180 SetNow();
181 Final();
182 Clear();
183 }
184
185 virtual void Init()
186 {
187 }
188
189 virtual void Final()
190 {
191 }
192
193 static void AddPlayer(Unit* player)
194 {
195 Now()->player = player;
196 Now()->Add(player);
197 }
198
199 static Unit* GetPlayer()
200 {
201 return Now()->player;
202 }
203
204 static void Add(Unit *unit, int suspendTime = 0)
205 {
206 switch( unit->belong)
207 {
208 case Belong::Ally:Now()->allys.Add( unit , suspendTime );break;
209 case Belong::EnemyF:Now()->skyEnemys.Add(unit, suspendTime); break;
210 case Belong::EnemyG:Now()->earthEnemys.Add(unit, suspendTime); break;
211 case Belong::Block:Now()->blocks.Add(unit, suspendTime); break;
212 case Belong::Item:Now()->items.Add(unit, suspendTime); break;
213 }
214 }
215
216 static void Add(Shot *shot, int suspendTime = 0)
217 {
218 if( shot->belong == Belong::Ally )
219 {
220 Now()->allyShots.Add(shot, suspendTime);
221 }
222 else
223 {
224 Now()->enemyShots.Add(shot, suspendTime);
225 }
226 }
227
228 static void Add(Object *obj, int suspendTime = 0)
229 {
230 Now()->midEfects.Add(obj, suspendTime);
231 }
232
233 static void AddFront(Object *object, int suspendTime = 0)
234 {
235 Now()->frontEfects.Add(object, suspendTime);
236 }
237
238 static void AddBack(Object *object, int suspendTime = 0)
239 {
240 Now()->backEfects.Add(object, suspendTime);
241 }
242
243 static void AddEvent(IModule *module)
244 {
245 Now()->events.emplace_back(module);
246 }
247
248 static void AddEvent(std::function<void()> fmodule)
249 {
250 Now()->events.emplace_back(new FuncModule(fmodule));
251 }
252
253 static Object* GetNearEnemy(Object* object)
254 {
255 if( Now()->skyEnemys.GetCount() == 0 )
256 {
257 return Now()->earthEnemys.GetNearest(object);
258 }
259 return Now()->skyEnemys.GetNearest(object);
260 }
261
262 bool IsEnd()
263 {
264 return isEnd;
265 }
266 };
267 }
DXStg::Shot
Definition: Shot.h:6
DXFW::Layer
Definition: Layer.h:6
DXFW::Camera::SetNow
static void SetNow(Camera *アクティブカメラ)
summary&gt;カメラの焦点を設定
Definition: Camera.h:73
DXFW::Camera
2D用のカメラクラス
Definition: Camera.h:27
DXStg::Scene
Definition: Scene.h:10
DXFW::IScene
説明
Definition: IScene.h:5
DXFW::IModule
Definition: Module.h:7
DXFW::FuncModule
Definition: Module.h:41
DXFW::Screen::SetBright
static bool SetBright(int r, int g, int b)
summary&gt;透過色を設定
Definition: Screen.h:150
DXFW::Time::StartWatch
static void StartWatch()
Definition: Timer.h:91
DXStg::Unit
Definition: Unit.h:8
DXFW::Rect
説明
Definition: Figure.h:768
DXFW::Object
説明
Definition: Object.h:18