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

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

- ファイル一覧

Model.h
1 #pragma once
2 #include"Sprite.h"
3 #include"Figure.h"
4 #include"Camera.h"
5 #include"Sprite派生.h"
6 #include<memory>
7
8 namespace DXFW
9 {
25 class Model
26 {
27 private:
28 double zoomX;
29 double zoomY;
30 double angle;
31 double shadowSize;
32 bool isCamera;
33 public:
34 std::vector<std::shared_ptr<Sprite>> sprites;
35 std::unique_ptr<Figure> figure;
36
37 Model( Figure *figure , Sprite *sprite ):
38 zoomX(1),
39 zoomY(1),
40 angle(0),
41 isCamera(true),
42 shadowSize(1),
43 figure(figure)
44 {
45 if( sprite )sprites.emplace_back(sprite);
46 }
47
48 virtual void Draw() const
49 {
50 for( auto it : sprites )
51 {
52 if( !it->isVisible ) continue;
53 if( !it->isAllway && it->isActive ) continue;
54
55 if( it->GetAlpha() >= 255 )
56 {
57 it->Draw( GetX() , GetY() , isCamera && Camera::Now() );
58 }
59 else if( it->GetAlpha() > 0 )
60 {
61 Screen::SetBlendMode( BlendMode::Alpha , it->GetAlpha() );
62 it->Draw( GetX() , GetY() , isCamera && Camera::Now() );
63 Screen::SetBlendMode( BlendMode::NoBlend , 0 );
64 }
65 }
66 }
67
68 void DrawShadow( double X座標ずれ , double Y座標ずれ )
69 {
70 if( shadowSize <= 0 ) return;
71
72 X座標ずれ *= shadowSize;
73 Y座標ずれ *= shadowSize;
74
75 for( auto it : sprites )
76 {
77 if( !it->isVisible ) continue;
78 if( !it->isAllway && it->isActive ) continue;
79
80 if( it->GetAlpha() >= 255 )
81 {
82 double zoomX = it->zoomX;
83 double zoomY = it->zoomY;
84 it->zoomX *= shadowSize;
85 it->zoomY *= shadowSize;
86 it->Draw( GetX() + X座標ずれ , GetY() + Y座標ずれ , isCamera && Camera::Now() );
87 it->zoomX = zoomX;
88 it->zoomY = zoomY;
89 }
90 }
91
92 }
93
94 void AnimeUpdate()
95 {
96 for(auto it: sprites )
97 {
98 it->AnimeUpdate();
99 }
100 }
101
102 void Move(double x , double y)
103 {
104 figure->Move( x , y );
105 }
106
107 void MovePolar(double distance , double angle)
108 {
109 figure->Move( distance * cos(angle) , distance * sin(angle) );
110 }
111
112 void SetPos(double x , double y)
113 {
114 figure->SetPos( x , y );
115 }
116
117 void SetZoom(double rate )
118 {
119 zoomX *= rate;
120 zoomY = rate;
121 }
122
123 void SetZoom(double rateX , double rateY)
124 {
125 figure->MultiZoom( rateX / zoomX , rateY / zoomY );
126
127 for( auto it : sprites )
128 {
129 //it->SetZoom( rateX , rateY );
130 }
131
132 zoomX = rateX;
133 zoomY = rateY;
134 }
135
136 void MultiZoom(double rate )
137 {
138 zoomX *= rate;
139 zoomY *= rate;
140 }
141
142 void MultiZoom(double rateX , double rateY)
143 {
144 zoomX *= rateX;
145 zoomY *= rateY;
146 }
147
148 void Rotate( double angle )
149 {
150 this->angle += angle;
151
152 for( auto it : sprites )
153 {
154 it->Rotate( angle );
155 }
156 }
157
158 double GetAngle()
159 {
160 return angle;
161 }
162
163 void SetAngle( double angle )
164 {
165 for( auto it : sprites )
166 {
167 it->Rotate( angle - this->angle );
168 }
169 this->angle = angle;
170 }
171
172 void SetActive(int index)
173 {
174 for(unsigned int i=0; i<sprites.size() ;i++)
175 {
176 sprites[i]->isActive = ( i == index );
177 }
178 }
179
180 double GetZoomX()
181 {
182 return this->zoomX;
183 }
184
185 double GetZoomY()
186 {
187 return this->zoomY;
188 }
189
190 double GetX() const
191 {
192 return figure->GetX();
193 }
194
195 double GetY() const
196 {
197 return figure->GetY();
198 }
199
200 bool Hit( Model *model)
201 {
202 return figure->Hit( model->figure.get() );
203 }
204
205 bool Hit( Figure *figure)
206 {
207 return figure->Hit( figure );
208 }
209
210 bool Hit( Mouse &mouse , Camera *camera = nullptr)
211 {
212 Point pt;
213
214 if( camera )
215 {
216 pt.x = camera->TranX( Input::mouse.x + camera->GetCenterX() );
217 pt.y = camera->TranY( Input::mouse.y + camera->GetCenterY() );
218 }else{
219 pt.x = mouse.x;
220 pt.y = mouse.y;
221
222 }
223
224 return figure->Hit( &pt );
225 }
226
227 double GetDirect(Model* model)
228 {
229 return atan2( figure->GetY() - this->GetY(), figure->GetX() - this->GetX() );
230 }
231 double GetDirect(Figure* figure)
232 {
233 return atan2( figure->GetY() - this->GetY(), figure->GetX() - this->GetX() );
234 }
235
236 double GetDistance(Figure* figure)
237 {
238 const double xd = this->GetX() - figure->GetX();
239 const double yd = this->GetY() - figure->GetY();
240
241 return sqrt( xd * xd + yd * yd );
242 }
243 double GetDistance(Model* figure)
244 {
245 const double xd = this->GetX() - figure->GetX();
246 const double yd = this->GetY() - figure->GetY();
247
248 return sqrt( xd * xd + yd * yd );
249 }
250 };
251 }
DXFW::Figure::Move
virtual void Move(double x, double y)=0
説明
DXFW::Model
クラス説明
Definition: Model.h:25
DXFW::Camera
2D用のカメラクラス
Definition: Camera.h:27
DXFW::Sprite
クラス説明
Definition: Sprite.h:28
DXFW::Mouse
マウス入力
Definition: Input.h:405
DXFW::Figure::Hit
virtual bool Hit(const Figure *figure) const =0
説明
DXFW::Figure::SetPos
virtual void SetPos(double x, double y)=0
説明
DXFW::Figure::MultiZoom
virtual void MultiZoom(double rate)=0
説明
DXFW::Camera::Now
static Camera * Now()
Definition: Camera.h:66
DXFW::Figure::GetX
virtual double GetX() const =0
説明
DXFW::Point
クラス説明
Definition: Figure.h:317
DXFW::Figure
説明
Definition: Figure.h:29