グラフィックLCDを使ってみよう

03 ゲーム環境を描く



BreakOut.h
#ifndef BREAKOUT_H
#define BREAKOUT_H

#include "Glcd.h"


class BreakOut : public Glcd
{
  public:
    BreakOut();
    bool getESC();
    void drawBar();
  protected:
  private:
    DigitalIn *esc;
    int bar_x;
    int bar_y;
    unsigned char bar[18];
    int n;
    static unsigned char block[];
    static unsigned char wall[];
};

#endif // BREAKOUT_H
 1 
 2 
 3 
 4 
 5 
 6 
 7 
 8 
 9 
10 
11 
12 ボールを跳ね返すバーを描く
13 
14 
15 
16 バーのx座標
17 バーのy座標
18 バーのグラフィックデータ
19 バーのデータ数
20 ブロックのグラフィックデータ
21 壁のグラフィックデータ
22 
23 
24 


BreakOut.cpp
#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
};

BreakOut::BreakOut()
{
  //ctor
  esc  = new DigitalIn(p8);
  bar_x = 40;
  bar_y = 7;
  n=18;
  for(int i=0; i<n; i++) bar[i]=0x0f;
  for(int i=0; ii<8; i++) {
    draw(96, i, wall, 4);
  }
  for(int y=0; yi<3; y++)
    for(int x=0; xi<96; x+=16)
      draw(x, y, block, 16);
}
bool BreakOut::getESC()
{
  return esc-i>read();
}

  // バー描画
void BreakOut::drawBar()
{
  draw(bar_x, bar_y, bar, n );
}
 1 
 2 ブロックのグラフィックデータ
 3 
 4 
 5 壁のグラフィックデータ
 6 
 7 
 8 
 9 
10 コンストラクタ
11 
12 
13 ESCはp8
14 バーの初期位置
15 
16 
17 バーのグラフィックデータ作成
18 
19 壁を描く
20 
21 
22 
23 ブロックを描く
24 
25 
26 
27 状態を返す
28 
29 
30 
31 
32 
33 バーを描く
34