/
Stage.cpp
55 lines (45 loc) · 995 Bytes
/
Stage.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// ================================
// ステージ
// ================================
// ステージヘッダ
#include "Stage.h"
Stage::Stage(){
// シード値を設定
SeedDefaultRNG(std::random_device()());
// ブロックの乱数初期化
BlockReset();
}
Stage::~Stage(){
}
// 更新&プレイヤーのX座標を取得
void Stage::Update(int x){
// スクロール用変数の計算
offsetX = x - WINDOW_WIDTH / 4;
}
// 描画
void Stage::Draw(){
// 床
Rect(0 - offsetX, 500, MAP_SIZE, 300).draw(Palette::Green);
// ブロック描画
BlockDraw();
}
// ================================ 境界 ================================
// ブロックの乱数初期化
void Stage::BlockReset(){
for (auto & a : randX){
a = Random(300, MAP_SIZE - 100);
}
for (auto & a : randY){
a = Random(0, 450);
}
}
// ブロック描画関数
void Stage::BlockDraw(){
for (int i = 0; i < BLOCK_NUM; ++i){
block[i] = Rect(randX[i] - offsetX, randY[i] , 50, 50).draw(Palette::Brown);
}
}
// ブロックを返す関数
Rect Stage::getBlock(int v){
return block[v];
}