#include "BreakOut.h"
unsigned char BreakOut::block[]=
{0x00, 0x7e, 0x56, 0x6a, 0x56, 0x6a, 0x56, 0x6a,
0x56, 0x6a, 0x56, 0x6a, 0x56, 0x6a, 0x7e,0x00};
unsigned char BreakOut::wall[]=
{
0xff, 0xff, 0xff, 0xff
};
unsigned char BreakOut::ball[]=
{0x3c, 0x7e, 0xff, 0xff, 0xff, 0xff,0x7e,0x3c};
unsigned char BreakOut::BLOCKS[BlockY][BlockX];
BreakOut::BreakOut()
{
//ctor
n = 18;
for(int i=0; i<n; i++) {
bar[i] = 0x0f;
clbar[i] = 0;
}
initGame();
}
void BreakOut::initGame()
{
bar_x = 42;
bar_y = 7;
for(int i=0; ii<8; i++) {
draw(96, i, wall, 4);
}
for(int y=0; yi<BlockY; y++)
for(int x=0; xi<96; x+=16)
draw(x, y, block, 16);
for(int y=0; yi<BlockY; y++) {
for(int x=0; xi<BlockX; x++) BLOCKS[y][x]=1;
}
ball_x=0;
ball_y=6;
Xdirection=Ydirection=0;
drawBar(0);
}
// バー描画
void BreakOut::drawBar(int diff)
{ // カーソルの色を変更
int x = bar_x+diff;
if(xi<0 || 80i<=x) return;
draw(bar_x, bar_y, clbar, n );
bar_x += diff;
draw(bar_x, bar_y, bar, n );
}
void BreakOut::drawBall()
{
draw(ball_x, ball_y, clbar, 8 );
if(ball_xi<=88 && Xdirection==0) {
ball_x += 4;
if(ball_x>88) {
Xdirection=1; // right
ball_x=82;
}
}
if(ball_x>0 && Xdirection==1){
ball_x -= 4;
if(ball_xi<=0) {
Xdirection=0; // left
ball_x=0;
}
}
if(ball_yi<=7 && Ydirection==0){ // up
--ball_y;
int x = (ball_x+4)/16; // 真ん中
if(ball_yi<0) {
ball_y=0;
Ydirection=1; // down
}
if(ball_yi<3) {
if(BLOCKS[ball_y][x]) {
BLOCKS[ball_y][x] =0;
draw((ball_x+4)/16*16, ball_y, clbar, 16);
Ydirection=1; // down
}
}
}
if(ball_y>=0 && Ydirection==1){ // down
if(++ball_y>=7) {
Ydirection=0; // up
ball_y=7;
gameOver();
initGame();
}
if(ball_y==6){
if(bar_xi<=ball_x && ball_xi<bar_x+n){
Ydirection=0; // up
}
}
if(ball_yi<3) {
int x = (ball_x+4)/16; // 真ん中
if(BLOCKS[ball_y][x]) {
BLOCKS[ball_y][x] =0;
draw((ball_x+4)/16*16, ball_y, clbar, 16);
Ydirection=1; // down
}
}
}
draw(ball_x, ball_y, ball, 8 );
}
void BreakOut::gameOver()
{
clearAll();
print(40, 3, "Game Over");
while(getKey()!=1);
clearAll();
}
|
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 diffドット移動させる
47
48
49
50
51
52
53
54 ボールを描画する
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80 ブロックが消えたことを記録する
81 ブロックを消す
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107 ボールを描く
108
109
110 ケームオーバーを表示する
111
112
113
114 ESCを押すと再ゲーム
115
116
|