2ちゃんねる スマホ用 ■掲示板に戻る■ 全部 1- 最新50    

■ このスレッドは過去ログ倉庫に格納されています

Cでブロック崩しを作りたい

1 :名前は開発中のものです。:03/12/08 00:21 ID:YP9pjvLE.net
おしえてください

11 :10:03/12/16 12:29 ID:AbmLxMwB.net
表示位置を指定するには ansi.sys ってのが必要なんだそうだ
http://www.gaia.h.kyoto-u.ac.jp/users/izui/technotes/escape.html
上記サイトの情報を元にまとめてみた
// ansi.sys用の画面操作
#define BLACK 0
#define RED 1
#define GREEN 2
#define YELLOW 3
#define BLUE 4
#define MAGENTA 5
#define CYAN 6
#define WHITE 7
#define clearScreen() printf("\x1b[0m\x1b[2J")
#define setColor(f, b) printf("\x1b[0;1;3%d;4%dm", f, b)
#define setColorDark(f, b) printf("\x1b[0;3%d;4%dm", f, b)
#define setCursorPos(x, y) printf("\x1b[%d;%dH", y+1, x+1)
#define displayCursor(disp) printf("\x1b[>5%c", disp ? 'l':'h')


12 :名前は開発中のものです。:03/12/16 12:48 ID:X4Q7cl+/.net
16ビットアプリで作るのか。
いや、止めやしないが。

13 :名前は開発中のものです。:03/12/16 12:49 ID:Dm2m+BAd.net
いやまておまいら。
「C」が言語のことだとは限らんぞ。
つまり、>>1が作りたいのは、こう↓だ。


CCCCCCCCCCCCCCCCCCCCCCCCC ←ブロック
CCCCCCCCCCCCCCCCCCCCCCCCC
CCCCCCCCCCCCCC  CCCCCCC


     C    ←ボール
    /

  CCCCC     ←バー

14 :10:03/12/16 13:03 ID:AbmLxMwB.net
速度の調整方法がわからない。やっつけで組んでみたがガタガタになる。
とりあえず後回しにしてロジックから組もう…
#define FPS 60
void wait()
{
  static long waitTime = 0;
  long count1, count2;
  int second;
  if(waitTime == 0)
  {
    second = time(NULL);
    while(second == time(NULL));
    second = time(NULL);
    for(waitTime = 0; second == time(NULL); waitTime++)
    {
      for(count2 = 0; count2 < 0x10000; count2++);
    }
    waitTime /= FPS;
  }
  for(count1 = 0; count1 < waitTime; count1++)
  {
    second = time(NULL);
    for(count2 = 0; count2 < 0x10000; count2++);
  }
}

15 :10:03/12/16 13:13 ID:AbmLxMwB.net
キーバッファを確認してあれば読み取り、余れば読み飛ばし、
6で右移動、4で左移動… あれ?「キーが離されて止まる」
ことが認識できない!?
// キーボード入力
int getKey()
{
  int result = 0;
  while(kbhit())result = getch();
  return result;
}

16 :10:03/12/16 13:53 ID:AbmLxMwB.net
// メイン
int main( int argc , char *argv[])
{
  〜〜〜初期化〜〜〜
  while(true)
  {
    key = getKey();
    if(key == 0x1b)break;
    〜〜〜各種処理〜〜〜
    wait();
  }
  return 0;
}


17 :10:03/12/16 14:49 ID:AbmLxMwB.net
//変数の宣言
int px, py;// パドルの位置
int pu ;// パドルの進行方向
// 座標系:256単位 = 全角1キャラクタ
int bx, by;// ボールの位置
int bu, bv;// ボールの進行方向
int bs, bc;// ボールのスピードとウェイと用
int stock = 4;// ボールのストック
char block[14][27] = {0};// ブロックテーブル
int norma = 0;// 残りのブロック


18 :10:03/12/16 19:27 ID:AbmLxMwB.net
連続投稿の制限あるんだな
int x, y, key;
displayCursor(0);
clearScreen();
setColor(WHITE, WHITE);
for(y=0; y<25; y++)
{
setCursorPos( 0, y); printf("■");
setCursorPos( 50, y); printf("■");
setCursorPos(y*2, 0); printf("■");
}
for(y=0; y<6; y++)for(x=0; x<12; x++)
{
setColor(RED+y, RED+y);
setCursorPos(x*4+2, y+3); printf("[##]");
block[x+1][y+3] = 1;
norma++;
}
px = 26-4; py = 22;
pu = 0;
bx = 26; by = 21;
bu = 1; bv = -1;
bs = 4; bc = 0;


19 :10:03/12/16 19:31 ID:AbmLxMwB.net
// ボール移動
bc++;
if(bc >= bs)
{
if(bx <= 2)bu = 1;
if(bx >= 49)bu = -1;
if(by <= 1)bv = 1;
setColor(WHITE, BLACK);
setCursorPos(bx, by); printf(" ");
if(block[(bx+2+bu)/4][by])
{
block[(bx+2+bu)/4][by] = 0;
norma--; bs = norma/18 + 1;
setColor(WHITE, BLACK);
setCursorPos((bx+2+bu)/4*4-2, by); printf(" ");
bu = -bu;
}else bx += bu;
if(block[(bx+2)/4][by+bv])
{
block[(bx+2)/4][by+bv] = 0;
norma--; bs = norma/18 + 1;
setColor(WHITE, BLACK);
setCursorPos((bx+2)/4*4-2, by+bv); printf(" ");
bv = -bv;
}else by += bv;
bc = 0;
}
setColor(YELLOW, GREEN);
setCursorPos(bx, by); printf("O");


20 :名前は開発中のものです。:03/12/16 19:38 ID:55g8ZfCO.net
ブロックブロックー

総レス数 177
42 KB
新着レスの表示

掲示板に戻る 全部 前100 次100 最新50
read.cgi ver 2014.07.20.01.SC 2014/07/20 D ★