SDXFrameWork 0.13 SDXFrameWork

- Main Page
- Related Pages
- Classes

All Classes Namespaces Functions Variables Enumerations Enumerator Pages
IModel.h
1 //Copyright © 2014 SDXFramework
2 //[License]GNU Affero General Public License, version 3
3 //[Contact]http://sourceforge.jp/projects/dxframework/
4 #pragma once
5 #include <Framework/Sprite.h>
6 #include <Framework/Shape.h>
7
8 namespace SDX
9 {
13 class IModel : public IPosition
14 {
15 private:
16 double angle = 0;
17 double shadowSize = 1;
18 protected:
19 bool isRemove = false;
20 public:
21
22 virtual const IShape& GetShape() const = 0;
23 virtual const ISprite& GetSprite() const
24 {
25 static SpNull noSprite;
26 return noSprite;
27 }
28
29 ISprite& GetSprite()
30 {
31 return const_cast<ISprite&>(static_cast<const IModel&>(*this).GetSprite());
32 }
33
34 IShape& GetShape()
35 {
36 return const_cast<IShape&>(static_cast<const IModel&>(*this).GetShape());
37 }
38
39 /*コピペ用
40 const IShape& GetShape() const { return shape; }
41 const ISprite& GetSprite() const { return sprite; }
42 */
43
44 virtual ~IModel() = default;
45
47 bool GetRemoveFlag() const
48 {
49 return isRemove;
50 }
51
53 virtual void Update(){}
54
56 void SetShadowSize(double 影の表示倍率)
57 {
58 shadowSize = 影の表示倍率;
59 }
60
62 virtual void Draw() const
63 {
64 GetSprite().Draw( GetShape() );
65
66 //当たり判定を表示するならコメントアウト解除
67 //iShape.Draw({255,0,0,128} );
68 }
69
71 void DrawShadow(double X座標ずれ, double Y座標ずれ)
72 {
73 if (shadowSize <= 0) return;
74
75 X座標ずれ *= shadowSize;
76 Y座標ずれ *= shadowSize;
77
78 double zoomX = GetSprite().zoomX;
79 double zoomY = GetSprite().zoomY;
80 GetSprite().zoomX *= shadowSize;
81 GetSprite().zoomY *= shadowSize;
82
83 GetSprite().gap.Move(X座標ずれ,Y座標ずれ);
84 GetSprite().Draw(GetShape());
85 GetSprite().gap.Move(-X座標ずれ, -Y座標ずれ);
86
87 GetSprite().zoomX = zoomX;
88 GetSprite().zoomY = zoomY;
89 }
90
92 void SetPos(double X座標, double Y座標) override
93 {
94 GetShape().SetPos(X座標, Y座標);
95 }
96
98 void MultiZoom(double X倍率, double Y倍率) override
99 {
100 zoomX *= X倍率;
101 zoomY *= Y倍率;
102
103 GetShape().MultiZoom(X倍率, Y倍率);
104 GetSprite().MultiZoom(X倍率, Y倍率);
105 }
106
108 void Move(double X移動量, double Y移動量) override
109 {
110 GetShape().Move(X移動量, Y移動量);
111 }
112
114 void Rotate(double 回転角度) override
115 {
116 angle += 回転角度;
117 GetSprite().Rotate(回転角度);
118 GetShape().Rotate(回転角度);
119 }
120
122 double GetAngle() const override
123 {
124 return angle;
125 }
126
128 double GetX() const override
129 {
130 return GetShape().GetX();
131 }
132
134 double GetY() const override
135 {
136 return GetShape().GetY();
137 }
138
140 double GetW() const override
141 {
142 return GetShape().GetW();
143 }
144
146 double GetH() const override
147 {
148 return GetShape().GetH();
149 }
150
152 void SetColor(const Color &描画色)
153 {
154 GetSprite().color = 描画色;
155 }
156
158 double GetZoomX() const
159 {
160 return zoomX;
161 }
162
164 double GetZoomY() const
165 {
166 return zoomY;
167 }
168
170 bool Hit(const IModel *判定を行うModel) const
171 {
172 return GetShape().Hit(&判定を行うModel->GetShape());
173 }
174
176 bool Hit(const IShape *判定を行うShape) const
177 {
178 return GetShape().Hit(判定を行うShape);
179 }
180 };
181 }
SDX::IModel::isRemove
bool isRemove
消滅フラグ
Definition: IModel.h:19
SDX::IPosition::GetW
virtual double GetW() const =0
幅を取得.
SDX::IModel::SetPos
void SetPos(double X座標, double Y座標) override
指定座標に移動.
Definition: IModel.h:92
SDX::IModel::GetH
double GetH() const override
Y座標を取得.
Definition: IModel.h:146
SDX::IPosition::GetH
virtual double GetH() const =0
高さを取得.
SDX::IModel::Draw
virtual void Draw() const
描画する.
Definition: IModel.h:62
SDX::IModel::DrawShadow
void DrawShadow(double X座標ずれ, double Y座標ずれ)
影を描画する.
Definition: IModel.h:71
SDX::ISprite::Rotate
void Rotate(double 回転する角度)
回転させる.
Definition: ISprite.h:84
SDX::IModel::GetAngle
double GetAngle() const override
角度を取得する.
Definition: IModel.h:122
SDX::IShape
衝突判定可能な図形の抽象クラス.
Definition: IShape.h:21
SDX::IModel::GetZoomX
double GetZoomX() const
横方向の拡大率を取得.
Definition: IModel.h:158
SDX::IModel::SetColor
void SetColor(const Color &描画色)
色をまとめて変更する、透明度も含む.
Definition: IModel.h:152
SDX::IShape::Hit
virtual bool Hit(const IShape *iShape) const =0
衝突判定.
SDX::IModel::GetRemoveFlag
bool GetRemoveFlag() const
消滅フラグの取得.
Definition: IModel.h:47
SDX::IPosition::MultiZoom
virtual void MultiZoom(double X倍率, double Y倍率)=0
縦横別で拡大率を掛け算する.
SDX::ISprite::zoomY
double zoomY
描画倍率
Definition: ISprite.h:22
SDX::IModel::Rotate
void Rotate(double 回転角度) override
回転させる.
Definition: IModel.h:114
SDX::ISprite::color
Color color
描画色
Definition: ISprite.h:27
SDX::ISprite
2Dモデルに貼り付けるスプライトを表す抽象クラス.
Definition: ISprite.h:17
SDX::IPosition::Rotate
virtual void Rotate(double 回転する角度)=0
回転する.
SDX::IModel::SetShadowSize
void SetShadowSize(double 影の表示倍率)
影の大きさを設定.
Definition: IModel.h:56
SDX::IPosition::GetY
virtual double GetY() const =0
Y座標を取得.
SDX::Color
色を表すクラス.
Definition: Color.h:11
SDX::IPosition::Move
virtual void Move(double X移動量, double Y移動量)=0
相対座標で移動.
SDX::IModel::MultiZoom
void MultiZoom(double X倍率, double Y倍率) override
縦横別で拡大率を掛ける.
Definition: IModel.h:98
SDX::IModel::Hit
bool Hit(const IModel *判定を行うModel) const
Modelとの衝突判定.
Definition: IModel.h:170
SDX::IModel::Update
virtual void Update()
更新処理を行う.
Definition: IModel.h:53
SDX::ISprite::Draw
virtual void Draw(const IShape &図形) const =0
ISpriteを描画する.
SDX::IModel::GetW
double GetW() const override
X座標を取得.
Definition: IModel.h:140
SDX::SpNull
描画しないNullスプライト.
Definition: Sprite.h:240
SDX::ISprite::gap
Point gap
Shape中心とSpriteとの位置差
Definition: ISprite.h:28
SDX::IModel::Hit
bool Hit(const IShape *判定を行うShape) const
Shapeとの衝突判定.
Definition: IModel.h:176
SDX::IPosition::zoomX
double zoomX
図形の拡大率
Definition: IPosition.h:14
SDX::IModel::Move
void Move(double X移動量, double Y移動量) override
相対座標で移動.
Definition: IModel.h:108
SDX::IModel::GetX
double GetX() const override
X座標を取得.
Definition: IModel.h:128
SDX::IPosition::SetPos
virtual void SetPos(double X座標, double Y座標)=0
指定座標に移動.
SDX::IPosition
位置と方向を持つクラスのインターフェース.
Definition: IPosition.h:11
SDX::IModel
ShapeとSpriteをまとめて、2Dモデルを表すクラス.
Definition: IModel.h:13
SDX::Point::Move
void Move(double X移動量, double Y移動量) override
相対座標で移動.
Definition: Point.h:57
SDX::ISprite::MultiZoom
void MultiZoom(double 倍率)
拡大率を掛け算する.
Definition: ISprite.h:44
SDX::IPosition::GetX
virtual double GetX() const =0
X座標を取得.
SDX::IModel::GetY
double GetY() const override
Y座標を取得.
Definition: IModel.h:134
SDX::ISprite::zoomX
double zoomX
描画倍率
Definition: ISprite.h:21
SDX::IPosition::zoomY
double zoomY
図形の拡大率
Definition: IPosition.h:15
SDX::IModel::GetZoomY
double GetZoomY() const
縦方向の拡大率を取得.
Definition: IModel.h:164