SDXFrameWork  0.04
SDXFrameWork
 全て クラス ネームスペース 関数 変数 ページ
SpriteDerived.h
1 #pragma once
2 #include <Framework/Sprite.h>
3 
4 namespace SDX
5 {
7 class SpImage : public Sprite
9 {
10 private:
11  const Image *image;
12 
13 public:
14  SpImage(const Image *image ):
15  image(image)
16  {}
17 
18  void Draw( double x , double y , bool isCamera)
19  {
20  if( isCamera )
21  {
22  image->DrawRotateAxis( (int)Camera::Now()->TransX(x + gapX) ,
23  (int)Camera::Now()->TransY(y + gapY) ,
24  (int)(axisX * Camera::Now()->GetZoom() ) + image->GetWidth() / 2,
25  (int)(axisY * Camera::Now()->GetZoom() ) + image->GetHeight() / 2,
26  zoomX * Camera::Now()->GetZoom() ,
27  zoomY * Camera::Now()->GetZoom() ,
28  angle , isTurn);
29  }else{
30  image->DrawRotateAxis( (int)(x + gapX) ,
31  (int)(y + gapY),
32  (int)axisX + image->GetHeight() / 2,
33  (int)axisY + image->GetHeight() / 2,
34  zoomX ,
35  zoomY ,
36  angle , isTurn);
37  }
38  }
39 };
40 
42 class SpAnime : public Sprite
44 {
45 private:
46  const Anime *anime;
47  Anime::Player counter;
48  double aniSpeed;
49 
50 public:
51 
52  SpAnime(const Anime *anime , double aniSpeed = 1) :
53  anime( anime ),
54  counter( anime ),
55  aniSpeed( aniSpeed )
56  {}
57 
58  void AnimeUpdate()
59  {
60  counter.UpDate( aniSpeed );
61  };
62 
63  void Draw( double x , double y ,bool isCamera)
64  {
65  if( isCamera )
66  {
67  counter.GetFrame()->DrawRotateAxis(
68  (int)Camera::Now()->TransX(x + gapX) ,
69  (int)Camera::Now()->TransY(y + gapY) ,
70  (int)(axisX * Camera::Now()->GetZoom()) + anime->GetWidth() / 2,
71  (int)(axisY * Camera::Now()->GetZoom()) + anime->GetHeight() / 2,
72  zoomX * Camera::Now()->GetZoom() ,
73  zoomY * Camera::Now()->GetZoom(),
74  angle ,
75  isTurn);
76  }
77  else
78  {
79  counter.GetFrame()->DrawRotateAxis(
80  (int)(x +gapX),
81  (int)(y +gapY),
82  (int)axisX + anime->GetWidth() / 2,
83  (int)axisY + anime->GetHeight() / 2,
84  zoomX ,
85  zoomY ,
86  angle , isTurn);
87  }
88  }
89 };
90 
92 class SpFont : public Sprite
94 {
95 private:
96  const IFont *font;
97  std::string str;
98  Color rgb;
99 
100 public:
101  SpFont(const IFont *font , Color rgb , const char *str ):
102  font(font),
103  rgb(rgb),
104  str(str)
105  {}
106 
107  void Draw( double x , double y ,bool isCamera)
108  {
109  if( isCamera )
110  {
111  font->DrawExtend( (int)Camera::Now()->TransX(x) , (int)Camera::Now()->TransY(y) , zoomX * Camera::Now()->GetZoom() , zoomY * Camera::Now()->GetZoom() , rgb , str.c_str() );
112  }
113  else
114  {
115  font->DrawExtend((int)x, (int)y, zoomX, zoomY, rgb, str.c_str());
116  }
117  }
118 };
119 
121 class SpFrame : public Sprite
123 {
124 private:
125  const IFrame *bmpFrame;
126  double width;
127  double height;
128 
129 public:
130  SpFrame(const IFrame *bmpFrame , double width , double height ):
131  bmpFrame(bmpFrame),
132  width(width),
133  height(height)
134  {}
135 
136  void Draw( double x , double y ,bool isCamera)
137  {
138  if( isCamera )
139  {
140  bmpFrame->Draw( (int)Camera::Now()->TransX(x) ,
141  (int)Camera::Now()->TransY(y) ,
142  (int)(width * zoomX * Camera::Now()->GetZoom()) ,
143  (int)(height * zoomY * Camera::Now()->GetZoom()));
144  }
145  else
146  {
147  bmpFrame->Draw( (int)x ,
148  (int)y ,
149  (int)(width * zoomX) ,
150  (int)(height * zoomY) );
151  }
152  }
153 };
154 
155 
157 class SpMap : public Sprite
159 {
160 private:
161  ImagePack &chip;
162  int width;
163  int height;
164  int rotate;
165  std::vector< std::vector<int> > data;
166 public:
167 
168  SpMap( ImagePack& マップチップ , const char* ファイル名 , int 幅 , int 高さ , int 角度):
169  width(幅),
170  height(高さ),
171  rotate(角度),
172  chip(マップチップ)
173  {
174  File csvFile( ファイル名 , FileMode::Read );
175 
176  data.resize( 幅 );
177 
178  for(int i=0 ; i<幅 ;++i)
179  {
180  data[i].resize( 高さ );
181  }
182 
183  std::vector<std::string> lineBuf;
184 
185  for(int i = 0 ; i < 高さ ; ++i )
186  {
187  csvFile.GetLineCSV( lineBuf );
188  for( int j = 0 ; j < 幅 ; j++)
189  {
190  data[j][i] = atoi( lineBuf[j].c_str() );
191  }
192  lineBuf.clear();
193  }
194  }
195 
196  void Draw( double X座標 , double Y座標 ,bool カメラ有りフラグ)
197  {
198  const int chipW = chip.GetWidth();
199  const int chipH = chip.GetHeight();
200 
201  if( カメラ有りフラグ )
202  {
203  const int baseY = int(Camera::Now()->TransY( Y座標 ));
204  const int baseX = int(Camera::Now()->TransX( X座標 ));
205 
206  int posXA;
207  int posYA;
208  int posXB;
209  int posYB;
210 
211  for(int i=0 ; i<width ; ++i )
212  {
213  posXA = int( baseX + chipW * i * Camera::Now()->GetZoom() );
214  posXB = int( baseX + chipW * (i+1) * Camera::Now()->GetZoom() );
215 
216  for(int j=0 ; j<height ; ++j )
217  {
218  posYA = int( baseY + chipH * j * Camera::Now()->GetZoom() );
219  posYB = int( baseY + chipH * (j+1) * Camera::Now()->GetZoom() );
220  const int no = data[i][j];
221  if( no == 0 ) continue;
222  chip[no]->DrawExtend( posXA , posYA , posXB , posYB );
223  }
224  }
225  }else{
226  for(int i=0 ; i<width ; ++i )
227  {
228  for(int j=0 ; j<height ; ++j )
229  {
230  const int no = data[i][j];
231  if( no == 0 ) continue;
232  chip[no]->Draw( int(X座標 + i*chipW) , int(Y座標 + j*chipH) );
233  }
234  }
235  }
236  }
237 
238 };
239 }
void Draw(double x, double y, bool isCamera)
Spriteを描画する.
Definition: SpriteDerived.h:136
void Draw(double x, double y, bool isCamera)
Spriteを描画する.
Definition: SpriteDerived.h:63
int GetWidth() const
最大幅を取得.
Definition: ImagePack.h:108
bool UpDate(double 経過フレーム=1)
カウンタの更新.
Definition: Anime.h:49
void AnimeUpdate()
説明.
Definition: SpriteDerived.h:58
static Camera * Now()
アクティブなカメラを取得.
Definition: Camera.h:54
double GetZoom()
拡大率を取得.
Definition: Camera.h:126
void Draw(double x, double y, bool isCamera)
Spriteを描画する.
Definition: SpriteDerived.h:107
int GetHeight() const
高さを取得.
Definition: Image.h:385
int GetWidth() const
幅を取得.
Definition: Image.h:375
void Draw(double x, double y, bool isCamera)
Spriteを描画する.
Definition: SpriteDerived.h:18
int GetHeight() const
最大高さを取得.
Definition: ImagePack.h:114
virtual bool DrawExtend(int X座標, int Y座標, double X軸拡大率, double Y軸拡大率, Color 色, const char *描画文字列,...) const =0
拡大率を指定して文字を描画.
bool DrawRotateAxis(int X座標, int Y座標, int X軸, int Y軸, double 拡大率, double 角度, bool 反転フラグ=false) const
回転軸、角度、拡大率を指定して描画.
Definition: Image.h:276
Image * GetFrame()
現在のコマ番号を取得.
Definition: Anime.h:85
void Draw(double X座標, double Y座標, bool カメラ有りフラグ)
Spriteを描画する.
Definition: SpriteDerived.h:196