ぷるぷるプログラミング

返信
どぶろく
記事: 75
登録日時: 11年前

ぷるぷるプログラミング

#1

投稿記事 by どぶろく » 6年前

何のことはないプログラムが面白い。

どぶろく
記事: 75
登録日時: 11年前

Re: ぷるぷるプログラミング

#2

投稿記事 by どぶろく » 6年前

コード:

#include "DxLib.h"

#define  DD_GRAY     85, 85, 85    // 暗い灰色         -1
#define  BLACK        0,  0,  0    // 黒                0
#define  D_RED       28,  0,  0    // 暗い赤            1
#define  D_GREEN      0,128,  0    // 暗い緑            2
#define  D_YELLOW   128,128,  0    // 暗い黄色(深黄色)3
#define  D_BLUE       0,  0,128    // 暗い青            4
#define  D_MAGENTA  128,  0,128    // 暗いマゼンタ      5
#define  D_CYAN       0,128,128    // 暗いシアン        6

#define  MD_RED     191, 0,   0    // やや暗い赤             _1
#define  MD_GREEN     0,191,  0    // やや暗い緑             _2
#define  MD_YELLOW  191,191,  0    // やや暗い黄色(黄銅色) _3
#define  MD_BLUE      0,  0,191    // やや暗い青             _4
#define  MD_MAGENTA 191,  0,191    // やや暗いマゼンタ       _5
#define  MD_CYAN      0,191,191    // やや暗いシアン         _6

#define  GRAY       192,192,192    // 明るい灰色              7
#define  M_GREEN    192,220,192    // マネーグリーン          8
#define  S_BLUE     166,202,240    // スカイブルー            9

#define  CREAM      255,251,240    // クリーム(淡黄色)      246
#define  M_GRAY     160,160,164    // ミディアムグレー        247
#define  D_GRAY     128,128,128    // 暗い灰色                248
#define  RED        255,  0,  0    // 明るい赤                249
#define  GREEN        0,255,  0    // 明るい緑                250
#define  YELLOW     255,255,  0    // 明るい黄色              251
#define  BLUE         0,  0,255    // 明るい青                252
#define  MAGENTA    255,  0,255    // マゼンタ(紫:淡紅色)  253
#define  CYAN         0,255,255    // シアン(水色:輝淡青色)254
#define  WHITE      255,255,255    // 白(最大輝度白色光)    255

//------------------------------------------------
#define  KURO        0    // 黒                        0
#define  AKA         1    // 明るい赤                249
#define  MIDORI      2    // 明るい緑                250
#define  KIIRO       3    // 明るい黄色              251
#define  AO          4    // 明るい青                252
#define  MURASAKI    5
#define  MIZUIRO     6
#define  SIRO        7    // 白(最大輝度白色光)    255
#define  D_AKA       8
#define  D_MIDORI    9
#define  D_KIIRO    10
#define  D_AO       11
#define  D_MURASAKI 12
#define  D_MIZUIRO  13
#define  DD_HAIIRO  14
#define  HAIIRO     21
#define  SORAIRO    23
#define  D_HAIIRO   26

//-----------------------------------------------------------------------------
// パレットに色をセットする
//-----------------------------------------------------------------------------
void set_pal(int handle)
{
    SetPaletteSoftImage( handle, 0, BLACK, 0 ) ;
    SetPaletteSoftImage( handle, 1, RED, 0 ) ;
    SetPaletteSoftImage( handle, 2, GREEN, 0 ) ;
    SetPaletteSoftImage( handle, 3, YELLOW, 0 ) ;
    SetPaletteSoftImage( handle, 4, BLUE, 0 ) ;
    SetPaletteSoftImage( handle, 5, MAGENTA, 0 ) ;
    SetPaletteSoftImage( handle, 6, CYAN, 0 ) ;
    SetPaletteSoftImage( handle, 7, WHITE, 0 ) ;

    SetPaletteSoftImage( handle, 8, D_RED, 0 ) ;
    SetPaletteSoftImage( handle, 9, D_GREEN, 0 ) ;
    SetPaletteSoftImage( handle,10, D_YELLOW, 0 ) ;
    SetPaletteSoftImage( handle,11, D_BLUE, 0 ) ;
    SetPaletteSoftImage( handle,12, D_MAGENTA, 0 ) ;
    SetPaletteSoftImage( handle,13, D_CYAN, 0 ) ;
    SetPaletteSoftImage( handle,14, DD_GRAY, 0 ) ;

    SetPaletteSoftImage( handle,15, MD_RED, 0 ) ;
    SetPaletteSoftImage( handle,16, MD_GREEN, 0 ) ;
    SetPaletteSoftImage( handle,17, MD_YELLOW, 0 ) ;
    SetPaletteSoftImage( handle,18, MD_BLUE, 0 ) ;
    SetPaletteSoftImage( handle,19, MD_MAGENTA, 0 ) ;
    SetPaletteSoftImage( handle,20, MD_CYAN, 0 ) ;

    SetPaletteSoftImage( handle,21, GRAY, 0 ) ;
    SetPaletteSoftImage( handle,22, M_GREEN, 0 ) ;
    SetPaletteSoftImage( handle,23, S_BLUE, 0 ) ;
    SetPaletteSoftImage( handle,24, CREAM, 0 ) ;
    SetPaletteSoftImage( handle,25, M_GRAY, 0 ) ;
    SetPaletteSoftImage( handle,26, D_GRAY, 0 ) ;
}

//-----------------------------------------------------------------------------
// 画像データ
//-----------------------------------------------------------------------------
char img[16][16] ={
    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
    { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
    { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 },
    { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 },
    { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 },
    { 5, 5, 5, 7, 1, 5, 5, 5, 7, 1, 5, 5, 5, 7, 2, 5 },
    { 5, 5, 5, 7,10, 5, 5, 5, 7,10, 5, 5, 5, 7,20, 5 },
    { 5, 5, 5, 7,10, 5, 5, 5, 7,10, 5, 5, 5, 7,20, 5 },
    { 5, 5, 5, 7,10, 5, 5, 5, 7,10, 5, 5, 5, 7,20, 5 },
    { 5, 5, 5, 7,10, 5, 5, 5, 7,10, 5, 5, 5, 7,20, 5 },
    { 5, 5, 5, 7,10, 5, 5, 5, 7,10, 5, 5, 5, 7,20, 5 },
    { 5, 5, 5, 7,10, 5, 5, 5, 7,10, 5, 5, 5, 7,20, 5 },
    { 5, 5, 5, 7,10, 5, 5, 5, 7,10, 5, 5, 5, 7,20, 5 },
    { 5, 5, 5, 7,10, 5, 5, 5, 7,10, 5, 5, 5, 7,20, 5 },
    { 5, 5 ,5, 7,10, 5, 5, 5, 7,10, 5, 5, 5, 7,20, 5 },
    { 5, 5, 5, 7,10, 5, 5, 5, 7,10, 5, 5, 5, 7,20, 5 }
};

//-----------------------------------------------------------------------------
// エントリポイント
//-----------------------------------------------------------------------------
int WINAPI WinMain( HINSTANCE, HINSTANCE, LPSTR, int )
{
    int handle, i, j, grhandle ;

    ChangeWindowMode(TRUE);
    if( DxLib_Init() < 0 ) return -1;

    handle = MakePAL8ColorSoftImage( 16, 16 ) ; // 空のパレット画像を作成する
    set_pal(handle);            // パレットに色をセットする

    for( j = 0; j < 16; j ++ ){
        for( i = 0; i < 16; i ++ ){
            DrawPixelPalCodeSoftImage( handle, i, j, img[j][i] ) ;  // パレット番号をセット
        }
    }
    grhandle = CreateGraphFromSoftImage( handle ) ;           // グラフィックハンドルを作成
    DeleteSoftImage( handle ) ;    // 使い終わったら解放

    DrawExtendGraph( 0, 0, 16*4, 16*4, grhandle, FALSE ) ;    // グラフィックハンドルを描画(四倍に拡大する)
    DeleteGraph( grhandle ) ;      // グラフィックハンドルの削除

    WaitKey();      // キー入力待ち
    DxLib_End();    // DXライブラリの後始末

    return 0;
}

どぶろく
記事: 75
登録日時: 11年前

Re: ぷるぷるプログラミング

#3

投稿記事 by どぶろく » 6年前

んん、前に書いた記事の編集ができない?!
時間がたつと編集できなくなるのか・・・
まぁ、いけど。
前回は構造体の画像データを表示できたので、今回はキャラ作りです。
つまりドット絵。ぴこぴこ構造体に画像データを打ち込むのがいいのだ、めんどいけど(笑)
それが、ぷるぷるプログラミングなのだ!

どぶろく
記事: 75
登録日時: 11年前

Re: ぷるぷるプログラミング

#4

投稿記事 by どぶろく » 6年前

コード:

#include "DxLib.h"

#define  DD_GRAY     85, 85, 85    // 暗い灰色         -1
#define  BLACK        0,  0,  0    // 黒                0
#define  D_RED       28,  0,  0    // 暗い赤            1
#define  D_GREEN      0,128,  0    // 暗い緑            2
#define  D_YELLOW   128,128,  0    // 暗い黄色(深黄色)3
#define  D_BLUE       0,  0,128    // 暗い青            4
#define  D_MAGENTA  128,  0,128    // 暗いマゼンタ      5
#define  D_CYAN       0,128,128    // 暗いシアン        6

#define  MD_RED     191, 0,   0    // やや暗い赤             _1
#define  MD_GREEN     0,191,  0    // やや暗い緑             _2
#define  MD_YELLOW  191,191,  0    // やや暗い黄色(黄銅色) _3
#define  MD_BLUE      0,  0,191    // やや暗い青             _4
#define  MD_MAGENTA 191,  0,191    // やや暗いマゼンタ       _5
#define  MD_CYAN      0,191,191    // やや暗いシアン         _6

#define  GRAY       192,192,192    // 明るい灰色              7
#define  M_GREEN    192,220,192    // マネーグリーン          8
#define  S_BLUE     166,202,240    // スカイブルー            9

#define  CREAM      255,251,240    // クリーム(淡黄色)      246
#define  M_GRAY     160,160,164    // ミディアムグレー        247
#define  D_GRAY     128,128,128    // 暗い灰色                248
#define  RED        255,  0,  0    // 明るい赤                249
#define  GREEN        0,255,  0    // 明るい緑                250
#define  YELLOW     255,255,  0    // 明るい黄色              251
#define  BLUE         0,  0,255    // 明るい青                252
#define  MAGENTA    255,  0,255    // マゼンタ(紫:淡紅色)  253
#define  CYAN         0,255,255    // シアン(水色:輝淡青色)254
#define  WHITE      255,255,255    // 白(最大輝度白色光)    255
#define  LD_CYAN      0,150,255    // 少しだけ暗いシアン

//-----------------------------------------------------------------------------
// パレットに色をセットする
//-----------------------------------------------------------------------------
void set_pal(int handle)
{
    SetPaletteSoftImage( handle, 0, BLACK, 0 ) ;
    SetPaletteSoftImage( handle, 1, WHITE, 0 ) ;
    SetPaletteSoftImage( handle, 2, RED, 0 ) ;
    SetPaletteSoftImage( handle, 3, D_YELLOW, 0 ) ;
    SetPaletteSoftImage( handle, 4, D_GREEN, 0 ) ;
    SetPaletteSoftImage( handle, 5, LD_CYAN, 0 ) ;
    SetPaletteSoftImage( handle, 6, YELLOW, 0 ) ;
    SetPaletteSoftImage( handle, 7, CYAN, 0 ) ;

}

//-----------------------------------------------------------------------------
// 画像データ
//-----------------------------------------------------------------------------
char img[32][32] ={
    { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    { 0,0,0,0,0,0,0,0,0,0,0,5,5,5,5,6,5,5,5,5,0,0,0,0,0,0,0,0,0,0,0,0},
    { 0,0,0,0,0,0,0,0,0,0,0,5,5,5,5,6,5,5,5,5,0,0,0,0,0,0,0,0,0,0,0,0},
    { 0,0,0,0,0,2,2,2,2,0,5,5,7,5,5,6,5,5,7,5,5,0,0,2,2,2,2,0,0,0,0,0},
    { 0,0,0,7,7,7,7,4,7,7,0,5,5,5,5,6,5,5,5,5,0,0,7,7,4,7,7,7,7,7,0,0},
    { 0,0,0,7,7,7,7,4,7,7,0,5,5,5,5,6,5,5,5,5,0,0,7,7,4,7,7,7,7,7,0,0},
    { 0,0,7,7,7,7,7,4,7,7,7,7,7,6,6,6,6,6,6,7,7,7,7,7,4,7,7,7,7,7,7,0},
    { 0,0,7,7,7,7,7,4,7,7,7,7,7,6,6,6,6,6,6,7,7,7,7,7,4,7,7,7,7,7,7,0},
    { 0,7,7,7,7,7,7,4,4,4,4,4,4,4,6,6,6,6,4,4,4,4,4,4,4,7,7,7,7,7,7,7},
    { 0,7,7,7,7,7,7,4,4,4,4,4,4,4,6,6,6,6,4,4,4,4,4,4,4,7,7,7,7,7,7,7},
    { 0,7,7,7,7,7,7,7,7,7,7,7,7,7,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7},
    { 0,7,7,7,7,7,7,7,7,7,7,7,7,7,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7},
    { 0,0,7,4,4,4,4,4,4,4,4,4,4,4,6,6,6,6,4,4,4,4,4,4,4,4,4,4,7,7,0,0},
    { 0,0,7,4,4,4,4,4,4,4,4,4,4,4,6,6,6,6,4,4,4,4,4,4,4,4,4,4,7,7,0,0},
    { 0,0,0,4,0,4,4,4,4,4,4,4,4,4,6,6,6,6,4,4,4,4,4,4,4,4,0,4,0,0,0,0},
    { 0,0,0,4,0,4,4,4,4,4,4,4,4,4,6,6,6,6,4,4,4,4,4,4,4,4,0,4,0,0,0,0},
    { 0,0,0,4,0,4,0,0,0,0,0,6,6,6,6,6,6,6,6,6,6,0,0,0,0,4,0,4,0,0,0,0},
    { 0,0,0,4,0,4,0,0,0,0,0,6,6,6,6,6,6,6,6,6,6,0,0,0,0,4,0,4,0,0,0,0},
    { 0,0,0,4,0,4,0,0,0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,0,4,0,4,0,0,0,0},
    { 0,0,0,4,0,4,0,0,0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,0,4,0,4,0,0,0,0},
    { 0,2,2,2,0,4,0,0,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,0,4,0,2,2,2,0,0},
    { 0,2,2,2,0,4,0,0,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,0,4,0,2,2,2,0,0},
    { 0,0,0,0,0,4,0,0,0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,0,4,0,0,0,0,0,0},
    { 0,0,0,0,0,4,0,0,0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,0,4,0,0,0,0,0,0},
    { 0,0,2,2,2,2,0,0,0,0,6,6,6,6,6,6,6,6,6,6,6,6,0,0,0,2,2,2,2,0,0,0},
    { 0,0,2,2,2,2,0,0,0,0,6,6,6,6,6,6,6,6,6,6,6,6,0,0,0,2,2,2,2,0,0,0},
    { 0,0,0,0,0,0,0,0,0,0,0,3,3,3,3,3,3,3,3,3,3,0,0,0,0,0,0,0,0,0,0,0},
    { 0,0,0,0,0,0,0,0,0,0,0,3,3,3,3,3,3,3,3,3,3,0,0,0,0,0,0,0,0,0,0,0},
    { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,6,6,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,6,6,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
};

//-----------------------------------------------------------------------------
// エントリーポイント
//-----------------------------------------------------------------------------
int WINAPI WinMain( HINSTANCE, HINSTANCE, LPSTR, int )
{
    int handle, i, j, grhandle ;

    ChangeWindowMode(TRUE);
    if( DxLib_Init() < 0 ) return -1;

    handle = MakePAL8ColorSoftImage( 32, 32 ) ; // 空のパレット画像を作成する
    set_pal(handle);            // パレットに色をセットする

    //ドット絵を描く
    for( j = 0; j < 32; j ++ ){
        for( i = 0; i < 32; i ++ ){
            DrawPixelPalCodeSoftImage( handle, i, j, img[j][i] ) ;
        }
    }
    grhandle = CreateGraphFromSoftImage( handle ) ;           // グラフィックハンドルを作成
    DeleteSoftImage( handle ) ;    // 使い終わったら解放

    int x=0, y=100;
    DrawExtendGraph( x, y, x+30*4, y+32*4, grhandle, FALSE ) ;    // 描画(4倍に拡大する)

    x=100, y=0;
    DrawExtendGraph( x, y, x+30*4, y+32*4, grhandle, FALSE ) ;    // 描画(4倍に拡大する)
    
    x=200; y=200;
    DrawExtendGraph( x, y, x+30*4, y+32*4, grhandle, FALSE ) ;    // 描画(4倍に拡大する)
    
    DrawString(300, 100, "ぶんぶんぶんハチが飛ぶ", GetColor(WHITE));

    DrawString(220, 100, "))", GetColor(WHITE));
    DrawString(120, 200, "))", GetColor(WHITE));
    DrawString(320, 300, "))", GetColor(WHITE));

    DeleteGraph( grhandle ) ;      // グラフィックハンドルの削除

    WaitKey();      // キー入力待ち
    DxLib_End();    // DXライブラリの後始末

    return 0;
}

どぶろく
記事: 75
登録日時: 11年前

Re: ぷるぷるプログラミング

#5

投稿記事 by どぶろく » 6年前

前回は、画像データを数字で書いたけど、
見にくい!読みにくい!ので、
アルファベット1文字に置き換えてみました。
格段に見やすくなったぜ!!やったね!!

コード:

#include "DxLib.h"

#define  DD_GRAY     85, 85, 85    // 暗い灰色         -1
#define  BLACK        0,  0,  0    // 黒                0
#define  D_RED       28,  0,  0    // 暗い赤            1
#define  D_GREEN      0,128,  0    // 暗い緑            2
#define  D_YELLOW   128,128,  0    // 暗い黄色(深黄色)3
#define  D_BLUE       0,  0,128    // 暗い青            4
#define  D_MAGENTA  128,  0,128    // 暗いマゼンタ      5
#define  D_CYAN       0,128,128    // 暗いシアン        6

#define  MD_RED     191,  0,  0    // やや暗い赤             _1
#define  MD_GREEN     0,191,  0    // やや暗い緑             _2
#define  MD_YELLOW  191,191,  0    // やや暗い黄色(黄銅色) _3
#define  MD_BLUE      0,  0,191    // やや暗い青             _4
#define  MD_MAGENTA 191,  0,191    // やや暗いマゼンタ       _5
#define  MD_CYAN      0,191,191    // やや暗いシアン         _6

#define  GRAY       192,192,192    // 明るい灰色              7
#define  M_GREEN    192,220,192    // マネーグリーン          8
#define  S_BLUE     166,202,240    // スカイブルー            9

#define  CREAM      255,251,240    // クリーム(淡黄色)      246
#define  M_GRAY     160,160,164    // ミディアムグレー        247
#define  D_GRAY     128,128,128    // 暗い灰色                248
#define  RED        255,  0,  0    // 明るい赤                249
#define  GREEN        0,255,  0    // 明るい緑                250
#define  YELLOW     255,255,  0    // 明るい黄色              251
#define  BLUE         0,  0,255    // 明るい青                252
#define  MAGENTA    255,  0,255    // マゼンタ(紫:淡紅色)  253
#define  CYAN         0,255,255    // シアン(水色:輝淡青色)254
#define  WHITE      255,255,255    // 白(最大輝度白色光)    255
#define  L_BLUE       0,150,255    // ライトブルー

//-----------------------------------------------------------------------------
// パレットに色をセットする
//-----------------------------------------------------------------------------
void set_pal(int handle)
{
    SetPaletteSoftImage( handle, 0, BLACK, 0 ) ;
    SetPaletteSoftImage( handle, 1, WHITE, 0 ) ;
    SetPaletteSoftImage( handle, 2, RED, 0 ) ;
    SetPaletteSoftImage( handle, 3, D_YELLOW, 0 ) ;
    SetPaletteSoftImage( handle, 4, D_GREEN, 0 ) ;
    SetPaletteSoftImage( handle, 5, L_BLUE, 0 ) ;
    SetPaletteSoftImage( handle, 6, YELLOW, 0 ) ;
    SetPaletteSoftImage( handle, 7, CYAN, 0 ) ;

}

//-----------------------------------------------------------------------------
// 画像データ
//-----------------------------------------------------------------------------
char img[32][33] ={
    "              b b               ",
    "              b b               ",
    "           bbbbYbbbb            ",
    "           bbbbYbbbb            ",
    "     RRRR bbCbbYbbCbb  RRRR     ",
    "     RRRR bbCbbYbbCbb  RRRR     ",
    "   CCCCgCC bbbbYbbbb  CCgCCCCC  ",
    "   CCCCgCC bbbbYbbbb  CCgCCCCC  ",
    "  CCCCCgCCCCCYYYYYYCCCCCgCCCCCC ",
    "  CCCCCgCCCCCYYYYYYCCCCCgCCCCCC ",
    " CCCCCCgggggggYYYYYggggggCCCCCCC",
    " CCCCCCgggggggYYYYYggggggCCCCCCC",
    " CCCCCCCCCCCCCYYYYCCCCCCCCCCCCCC",
    " CCCCCCCCCCCCCYYYYCCCCCCCCCCCCCC",
    "  CgggggggggggYYYYggggggggggCC  ",
    "  CgggggggggggYYYYggggggggggCC  ",
    "   gggggggggggYYYYgggggggg g    ",
    "   g gggggggggYYYYgggggggg g    ",
    "   g g     YYYYYYYYYY    g g    ",
    "   g g     YYYYYYYYYY    g g    ",
    "   g g   yyyyyyyyyyyyyy  g g    ",
    "   g g   yyyyyyyyyyyyyy  g g    ",
    " RRR g  YYYYYYYYYYYYYYYY g RRR  ",
    " RRR g  YYYYYYYYYYYYYYYY g RRR  ",
    "     g   yyyyyyyyyyyyyy  g      ",
    "     g   yyyyyyyyyyyyyy  g      ",
    "  RRRR    YYYYYYYYYYYY   RRRR   ",
    "  RRRR    YYYYYYYYYYYY   RRRR   ",
    "           yyyyyyyyyy           ",
    "           yyyyyyyyyy           ",
    "              YYYY              ",
    "              YYYY              "
};

//-----------------------------------------------------------------------------
// エントリーポイント
//-----------------------------------------------------------------------------
int WINAPI WinMain( HINSTANCE, HINSTANCE, LPSTR, int )
{
    int handle, grhandle ;
    int i, j, x, y, c;
    int color = GetColor(WHITE);
 
    ChangeWindowMode(TRUE);
    if( DxLib_Init() < 0 ) return -1;

    handle = MakePAL8ColorSoftImage( 32, 32 ) ; // 空のパレット画像を作成する
    set_pal(handle);            // パレットに色をセットする

    //ドット絵を描く
    for( j = 0; j < 32; j ++ ){
        for( i = 0; i < 32; i ++ ){
            if(img[j][i]==' ') c=0;
            if(img[j][i]=='R') c=2;
            if(img[j][i]=='y') c=3;
            if(img[j][i]=='g') c=4;
            if(img[j][i]=='b') c=5;
            if(img[j][i]=='Y') c=6;
            if(img[j][i]=='C') c=7;
            
            DrawPixelPalCodeSoftImage( handle, i, j, c ) ;
        }
    }
    grhandle = CreateGraphFromSoftImage( handle ) ;           // グラフィックハンドルを作成
    DeleteSoftImage( handle ) ;    // 使い終わったら解放

    x=150; y=0;
    DrawExtendGraph( x, y, x+32*4, y+32*4, grhandle, FALSE ) ;    // 描画(4倍に拡大する)
    
    x=0; y=100;
    DrawExtendGraph( x, y, x+32*4, y+32*4, grhandle, FALSE ) ;    // 描画(4倍に拡大する)

    x=200; y=200;
    DrawExtendGraph( x, y, x+32*4, y+32*4, grhandle, FALSE ) ;    // 描画(4倍に拡大する)
    
    DrawString(350, 150, "ぶんぶんぶんハチが飛ぶ", color);

    DrawString(300,  50, "))", color);
    DrawString(150, 150, "))", color);
    DrawString(350, 250, "))", color);

    DeleteGraph( grhandle ) ;      // グラフィックハンドルの削除

    WaitKey();      // キー入力待ち
    DxLib_End();    // DXライブラリの後始末

    return 0;
}

どぶろく
記事: 75
登録日時: 11年前

Re: ぷるぷるプログラミング

#6

投稿記事 by どぶろく » 6年前

懐かしのN88BASICのゲームを移植したよ。
動きもまんまBASICしてるよ。これは笑える。
砲台もカッコいい宇宙飛行機みたいに見えてくる。
ではこの射撃ゲームを楽しんでください。

コード:

#include "DxLib.h"

#define  WHITE      255,255,255    // 白(最大輝度白色光)    255
#define  RED        255,  0,  0    // 明るい赤                249
#define  YELLOW     255,255,  0    // 明るい黄色              251

#define  KARASU     20             // カラスの出現数

//-----------------------------------------------------------------------------
// ゲームオーバーの処理
//-----------------------------------------------------------------------------
int owari(int s)
{
    if( s > (KARASU/2)){
        DrawString(15*8, 10*16, "あなたの勝ち!", GetColor(YELLOW));
    }else {
        DrawString(15*8, 10*16, "あなたの負け!", GetColor(RED));
    }
    DrawString(16*8, 12*16, "[ESC] 終了", GetColor(WHITE));
    ScreenFlip();

    WaitTimer(1000);                    // 少し待たせる

    if(WaitKey()==KEY_INPUT_ESCAPE){    // ESCでゲーム終了
        return 1;
    }
    return 0;                           // ゲーム継続
}

//-----------------------------------------------------------------------------
// エントリーポイント
//-----------------------------------------------------------------------------
int WINAPI WinMain( HINSTANCE, HINSTANCE, LPSTR, int )
{
    int  color = GetColor(WHITE);// 文字の色
    int  x=0, y=15;              // x*8,y*16の文字座標
    int  s=0;        // 撃ち落としたカラスの数
    int  n=1;        // カラスの出現数
    int  hit=0;      // 弾が命中した
    int  sw=0;       // 弾の発射
    int  key;        // キー押し下げ

    ChangeWindowMode(TRUE);
    if( DxLib_Init() < 0 ) return -1;
    SetDrawScreen( DX_SCREEN_BACK ) ;

    while(ProcessMessage() == 0 && ClearDrawScreen() == 0 )
    {
        DrawString(29*8, 15*16, " A ", color);
        DrawString(29*8, 16*16, "MIM", color);
        DrawString( 0*8, 17*16, "-------------------------------------", color);

        key = GetJoypadInputState( DX_INPUT_KEY_PAD1 ) ;

        if( key & PAD_INPUT_9 )  break; // ESCで終了
        if( key & PAD_INPUT_10 ) sw=1;  // SPACEで弾を発射

        if(sw==1){      // 弾を発射
            y--;
            if(y<0){        // 弾が上まで来たら
                if(x==30){  // 当たり判定
                    DrawString(30*8, 0, "X", GetColor(RED));
                    s++; x=40; hit=1;
                }
                sw=0; y=15;
            }
            DrawString(30*8, y*16, "I", color); // 弾を描く
        }
        DrawFormatString(0, 16, color, " %d / %d", s, n ); // 出現数と当った数
        
        if(x>=40){   // カラスが右端まで来たら
            x=0; n++;
        }else {
            x++; 
            DrawString(x*8, 0, "W", color);    // 動いてるカラス
        }
        ScreenFlip() ;

        if(hit){
            hit=0;
            WaitTimer(100);      // ビープ音のために少し待ってやる
            Beep(700, 800);      // 撃ち落とした時のビープ音を鳴らす
        }else {
            WaitTimer(10);       // ビープ音のために少し待ってやる
            Beep(1300, 60);      // カラスの移動の時のビープ音を鳴らす
        }
        if(n>KARASU){   // カラスが20羽出たら終わり
            if(owari(s)){
                break;  // 終了
            }
            x=0; y=15; s=0; n=1; sw=0;  // ゲームをもう一度やる場合
            WaitTimer(200);             // キー押下げをかわすため少し待つ
        }
    }
    DxLib_End();    // DXライブラリの後始末

    return 0;
}

どぶろく
記事: 75
登録日時: 11年前

Re: ぷるぷるプログラミング

#7

投稿記事 by どぶろく » 6年前

おかげさまで大好評!「昔懐かしシリーズ」の、はじまり、はじまり。
またまたN88BASICのゲームを移植しましたよ。
動きもまんまBASICしてるよ。これは笑える。

●内容●
コントロールはカーソルキーで行います(左右のみ)。制限時間は1分で、1つの旗門
をクリアするごとに10点増えます。もし旗門の端にぶつかると、10点減点されます。

●応用●
旗門の幅を広くしたりせまくしたりして、その旗門によって得点を変えたりするともっ
と面白くなります。
また制限時間を変えたりしても楽しめます。
私は旗門をゲートだと勘違いして旗門の真中を通るゲームにしてしまいました。
本来のスキーのように旗門をかわしていくゲームにするのもいいでしょう。(笑)

それでは、このスラロームゲームを楽しんでください。

コード:

/*-----------------------------------------------------------------------------
    2017-12-06(水)

    スラローム

-----------------------------------------------------------------------------*/
#include "DxLib.h"

#define  BLACK        0,  0,  0     // 黒                      0
#define  WHITE      255,255,255     // 白(最大輝度白色光)  255
#define  RED        255,  0,  0     // 明るい赤              249
#define  YELLOW     255,255,  0     // 明るい黄色            251

#define  TIME       (60)            // 制限時間(60秒)
#define  WAIT       (150)           // ウェイト

//-----------------------------------------------------------------------------
// ゲートの構造体
//-----------------------------------------------------------------------------
struct SGate {
    int x;
    int y;
};

//-----------------------------------------------------------------------------
// 制限時間を超えたら
//-----------------------------------------------------------------------------
int owari(int& HiScore, int score, int time)
{
    DrawBox(0, 0, 41*8, 16, GetColor(RED), TRUE);
    DrawFormatString(0, 0, GetColor(YELLOW), "HiScore %d  score %d  time %d", HiScore, score, time/1000);
    
	if(HiScore < score){
        HiScore = score;
        DrawBox(13*8, 6*16, 29*8, 9*16, GetColor(RED), TRUE);
        DrawString(14*8, 7*16, "あなたの勝ち!", GetColor(YELLOW));
    }else {
        DrawBox(13*8, 6*16, 29*8, 9*16, GetColor(WHITE), TRUE);
        DrawString(14*8, 7*16, "あなたの負け!", GetColor(BLACK));
    }
    ScreenFlip() ;
    WaitTimer(1000);

    if(WaitKey()==KEY_INPUT_ESCAPE){    // ESCでゲーム終了
        return 1;
    }
    return 0;
}

//-----------------------------------------------------------------------------
// エントリーポイント
//-----------------------------------------------------------------------------
int WINAPI WinMain( HINSTANCE, HINSTANCE, LPSTR, int )
{
    int a=20;           // 自分の位置(x座標)
    int rol=0;          // ゲートの配列番号
    int score=0;        // スコア
    int HiScore=0;      // ハイスコア
    int key;            // キー押し下げ
    int start, end, time=0;         // 経過時間用
    int color = GetColor(WHITE);    // 文字色
    SGate gate[25];                 // ゲートのx座標とy座標を保存する構造体

    memset(gate, 0, sizeof(SGate)*25);	// 0で初期化(こういう使い方だったっけ?)
    ChangeWindowMode(TRUE);
    if( DxLib_Init() < 0 ) return -1;
    SetDrawScreen( DX_SCREEN_BACK ) ;

    start = GetNowCount();          // スタート時間を記憶させる

    while(!ProcessMessage() && !ClearDrawScreen())
    {
        key = GetJoypadInputState( DX_INPUT_KEY_PAD1 ) ;

        if( key & PAD_INPUT_9 )  break;   // ESCで終了
        if( key & PAD_INPUT_LEFT )  a--;  // [←]キー
        if( key & PAD_INPUT_RIGHT ) a++;  // [→]キー

        if( a<0 ) a=0;          // 左端にきたら
        if( a>39) a=39;         // 右端にきたら

        DrawString(a*8, 10*16, "●", color);

        gate[rol].x = GetRand(34);      // 乱数でゲートの表示位置(x座標)を決める
        gate[rol].y = 24;               // y座標は一番下から

        for(int i=0; i<25 ; i++)        // 当たり判定と全ゲートを表示
        {
            if(((gate[i].x == a)||(gate[i].x == (a+1))||(gate[i].x+6 == a)||(gate[i].x+6 == (a+1))) && (gate[i].y==10)){
                score-=10;
                Beep(3000, 5);          // ゲートの端に当った時
            }
            else if((gate[i].x < a) && ((gate[i].x+6) > a) && (gate[i].y==10)){
                score+=10;
                Beep(1000, 5);          // ゲートをうまく通過した時
            }
            DrawString(gate[i].x*8, gate[i].y*16, "|====|", color);     // ゲートを表示
            gate[i].y--;                // 表示後ゲートのy座標を1つ上にする。
        }
        DrawBox(0, 0, 41*8, 2*16, GetColor(BLACK), TRUE);
        DrawFormatString(0, 0, color, "HiScore %d  score %d  time %d/%d", HiScore, score, time/1000, TIME);

        rol++;
        if(rol>24) rol=0;               // ゲートの配列番号をセットしていくため

        end  = GetNowCount();           // プレイ時間を計るため
        time = end-start;               // 経過時間を保存

        if(time > TIME*1000){           // タイムオーバーの時
            if(owari(HiScore, score, time)){
                break;                  // ゲーム終了
            }
            start = GetNowCount();      // もう一度ゲームをする場合
            a=20; score=0;
            memset(gate, 0, sizeof(SGate)*25);
        }
        ScreenFlip() ;
        WaitTimer(WAIT);                // ゲーム全体のウェイト
    }
    DxLib_End();    // DXライブラリの後始末

    return 0;
}

どぶろく
記事: 75
登録日時: 11年前

Re: ぷるぷるプログラミング

#8

投稿記事 by どぶろく » 6年前

大好評!昔なつかしシリーズ第三弾!
その名も「ただ観てるだけ~~~の綱引き」。
やはりC言語の構文は解りやすい。
そして参考にしているN88-BASICはメッチャ難しい。
記述量は少ないのだが、完全なスパゲッティープログラムじゃん・・・
泣きながら「N88互換BASIC for Windows」に打ち込んで実行してます。
もちろん、原文そのままでは動かないので・・・何とか動くようにする。
それからC言語(C++)に移植する。これが楽しい。

コード:

/*-----------------------------------------------------------------------------

	2017(H29).12/09(土)

	綱引きシミュレーション

-----------------------------------------------------------------------------*/
#include "DxLib.h"

#define WHITE	255,255,255		// 白(最大輝度白色光)		255
#define BLACK	  0,  0,  0     // 黒						0
#define WAIT	(300)			// 全体のウェイト
#define SCORE	(2)				// この得点で勝ち

//-----------------------------------------------------------------------------
// エントリーポイント
//-----------------------------------------------------------------------------
int WINAPI WinMain( HINSTANCE, HINSTANCE, LPSTR, int )
{
	int key;
	int r, x=8, s1=0, s2=0;
	int color = GetColor(WHITE);

	ChangeWindowMode(TRUE);
	if( DxLib_Init() < 0 ) return -1;
	SetDrawScreen( DX_SCREEN_BACK ) ;

    while(!ProcessMessage() && !ClearDrawScreen())
	{
		key = GetJoypadInputState( DX_INPUT_KEY_PAD1 ) ;
		
		if( key & PAD_INPUT_9 )  break;		// ESCで終了
		
		DrawString(15*8, 1*16, "*-----------*", color);
		DrawString(15*8, 2*16, "|  &  |  $  |", color);
		DrawString(15*8, 3*16, "|-----+-----|", color);
		DrawString(15*8, 4*16, "|     |     |", color);
		DrawString(15*8, 5*16, "*-----------*", color);
		DrawFormatString(15*8, 4*16, color, "   %d  |  %d", s1, s2);
		
		if(GetRand(1)){
			r = 1;
		}else {
			r = -1;
		}
		x=x+r;
		DrawString(x*8, 10*16,"&&&&&&&-----+-----$$$$$$$", color);
		DrawString(0, 11*17, "-------------+-----+-----+-------------", color);
		ScreenFlip();
		
		Beep(3000, 10);Beep(2000, 5);
		WaitTimer(WAIT);

		if(x<=1){						// & の勝ち
			s1++; Beep(1000, 1000); x=8;
		}
		if(x>=15){						// $ の勝ち
			s2++; Beep(1000, 1000); x=8;
		}
		
		if(s1>=SCORE || s2>=SCORE)		// 2点とった方が勝ち
		{
			DrawBox(16*8, 4*16, 28*8, 5*16, GetColor(BLACK), TRUE);
			DrawFormatString(15*8, 4*16, color, "   %d  |  %d", s1, s2);
			DrawString(16*8, 18*13, "HIT ANY KEY", color);
			DrawString(16*8, 18*15, "ESC:終了", color);
			ScreenFlip();
			if(WaitKey()==KEY_INPUT_ESCAPE){	// ESCでゲーム終了
				break;
    		}
			s1=0; s2=0;
		}
	}
	DxLib_End();    // DXライブラリの後始末
	
	return 0;
}

どぶろく
記事: 75
登録日時: 11年前

Re: ぷるぷるプログラミング

#9

投稿記事 by どぶろく » 6年前

では、さっそく、大好評の第4弾、発射~~~~~~~~~~~~~~!!
今回のは互換BASICでは動かせなかった。
本の文章と写真とBASICのソースから推察してみたが分からない・・・
しかたがないので、こうやったらいいんじゃないかプログラムになりました。
けっこう長いプログラムになりました。
でも、なぜかしら操作性が悪いんだよね。
しかしN88-BASICだと思えば楽しい操作性です(笑)

●目的●
左上から右下の出口に向かって、どのくらいの時間で出られるかを計ります。

●内容●
コントロールキーはカーソルキー(上、下、左、右)によって行います。
一定時間ごとに乱数によって爆弾を移動して表示しています。これにぶつからずに出口に向かってください。
3回までなら、ぶつかって爆発しても大丈夫です。

●応用●
ゲーム中に、ある時間ごとに乱数を使って出口を変えても面白いと思います。

コード:

/*-----------------------------------------------------------------------------
	2017-12-12(火)

	出口はどこだ?

-----------------------------------------------------------------------------*/
#include "DxLib.h"

#define	 BLACK		  0,  0,  0		// 黒                      0
#define	 WHITE		255,255,255		// 白(最大輝度白色光)  255
#define	 RED		255,  0,  0		// 明るい赤              249
#define	 YELLOW		255,255,  0		// 明るい黄色            251
#define	 GREEN		  0,255,  0		// 明るい緑              250

#define	 WAIT		(120)			// 全体のウェイト
#define	 KOSUU		(300)			// 爆弾の個数
#define	 KAISUU		(4)				// 爆発3回までOK!
#define	 IDOU		(50)			// 爆弾移動個数
#define	 WAIT_B		(15)			// 爆弾移動までの時間

//-----------------------------------------------------------------------------
// 爆弾の構造体
//-----------------------------------------------------------------------------
struct SBakudan {
	int x;
	int y;
};

//-----------------------------------------------------------------------------
// 爆弾を配置する
//-----------------------------------------------------------------------------
void make_bakudan(SBakudan bakudan[])
{
	memset(bakudan, 0, sizeof(SBakudan)*(KOSUU+1));

	for(int i=0; i<KOSUU; i++){
	lavel:
		bakudan[i].x = GetRand(37)+2;
		bakudan[i].y = GetRand(20)+2;
		if(bakudan[i].x==3 && bakudan[i].y==2){	// 自分の表示位置には無し
			goto lavel;
		}
	}
}

//-----------------------------------------------------------------------------
// 枠の描画
//-----------------------------------------------------------------------------
void make_waku()
{
	int White = GetColor(WHITE);	// 文字色
	int Black = GetColor(BLACK);
	int Yellow= GetColor(YELLOW);

	for(int x=0; x<40 ;x++){
		DrawString(x*16,  1*16, "■", White);
		DrawString(x*16, 23*16, "■", White);
	}
	for(int y=1; y<23; y++){
		DrawString(0,	  y*16, "■", White);
		DrawString(39*16, y*16, "■", White);
	}
	DrawString(36*16, 23*16, "■", Black);
	DrawString(36*16, 24*16+3, "GOAL", Yellow);
}

//-----------------------------------------------------------------------------
// 終わりの処理
//-----------------------------------------------------------------------------
int owari(int win, int &rec, int time1, int e)
{
	int White = GetColor(WHITE);	// 文字色
	int Black = GetColor(BLACK);
	int Red	  = GetColor(RED);
	int Yellow= GetColor(YELLOW);

	if(win==1 && rec<time1){
		win=2;					// 時間で負けた
	}
	if(e<1) e=1;
	DrawBox(0, 0, 40*16, 1*16, Black, TRUE);
	DrawFormatString(0, 0, Yellow, "rec %d  time %d  あと %d", rec/100, time1/100, e-1) ;
	DrawBox(9*16, 8*16, 19*16, 15*16, Black, TRUE);
	DrawBox(9*16, 8*16, 19*16, 15*16, Yellow, 0);
	DrawString(11*16, 11*16, "Hit Any Key", White);
	DrawString(11*16, 13*16, "[ESC] 終了", White);

	if(win==1){
		DrawString(11*16, 9*16,	 "あなたの勝ち", Yellow);
		ScreenFlip() ;
		rec = time1;
		Beep(3000, 100);Beep(1000, 100);Beep(1500, 100);
		Beep(3000, 100);Beep(1000, 100);Beep(1500, 100);
	}
	else if(win==2){
		DrawString(11*16, 9*16,	 "時間で負けた", Red);
		Beep(2000, 100);Beep(1000, 100);
		ScreenFlip() ;
	}else {
		DrawString(11*16, 9*16,	 "あなたの負け", Red);
		ScreenFlip() ;
	}
	WaitTimer(1000);
	if(WaitKey()==KEY_INPUT_ESCAPE){	// [ESC]で終了
		return 1;
	}
	return 0;
}

//-----------------------------------------------------------------------------
// エントリーポイント
//-----------------------------------------------------------------------------
int WINAPI WinMain( HINSTANCE, HINSTANCE, LPSTR, int )
{
	int White = GetColor(WHITE);	// 文字色
	int Green = GetColor(GREEN);
	int Red	  = GetColor(RED);
	int Yellow= GetColor(YELLOW);
	int key;					// キー押し下げ
	int start, end, time1=0;	// 経過時間用
	int x=3, y=1;
	int e=KAISUU;				// 爆発可回数
	int win;					// 勝ちか?
	int r;						// ランダム
	int c=0;					// 時間かせぎ
	int rec=1000*60*3;			// 記録
	int osita=1;				// 押下げしたか
	SBakudan bakudan[KOSUU+1];	// 爆弾の座標の構造体の配列

	ChangeWindowMode(TRUE);
	if( DxLib_Init() < 0 ) return -1;
	SetFontThickness(1);				// 文字の太さを1ドットにする
	SetDrawScreen( DX_SCREEN_BACK ) ;

	make_bakudan(bakudan);			// 爆弾を配置する
	start = GetNowCount();			// スタート時間を記憶させる

	while(!ProcessMessage() && !ClearDrawScreen())
	{
		key = GetJoypadInputState( DX_INPUT_KEY_PAD1 ) ;

		if( key & PAD_INPUT_9 )	 break;	  // ESCで終了
		if( key & PAD_INPUT_LEFT )	{x--;  osita=1;}// [←]キー
		if( key & PAD_INPUT_RIGHT ) {x++;  osita=1;}// [→]キー
		if( key & PAD_INPUT_UP )	{y--;  osita=1;}// [↑]キー
		if( key & PAD_INPUT_DOWN )	{y++;  osita=1;}// [↓]キー

		if( x<1 ) x=1;
		if( x>38) x=38;
		if( y<2 ) y=2;
		if( y>22){
			if(x==36) y=23;		// ゴール
			else	  y=22;
		}
		make_waku();			// 枠をつくる

		c++;
		if(c>WAIT_B){			// 爆弾を移動させるまでの時間かせぎ
			c=0;
			for(int i=0 ; i<IDOU ; i++){	// 爆弾をランダムに移動させる
				r=GetRand(KOSUU);
				bakudan[r].x = GetRand(37)+2;
				bakudan[r].y = GetRand(20)+2;
			}
		}
		for(int i=0; i<KOSUU; i++){			// 爆弾を表示
			DrawString(bakudan[i].x*16, bakudan[i].y*16, "@", Green);
		}
		for(int i=0; i<KOSUU; i++){			// 当たり判定
			if(x==bakudan[i].x && y==bakudan[i].y){
				DrawString(x*16, y*16, "●", Red);	// 爆発
				if(osita==1 ){
					Beep(3000, 100);
					osita=0; e--;
				}
				if(e<1){			// 爆死して残り無し
					win=0;
					goto lavel;
				}
			}
			else {
				DrawString(x*16, y*16, "○", White);
			}
		}
		DrawFormatString(0, 0, Yellow, "rec %d  time %d  あと %d", rec/100, time1/100, e-1) ;

		end	 = GetNowCount();			// プレイ時間を計るため
		time1 = end-start;				// 経過時間を保存

		if(x==36 && y==23){				// ゴールしたら
			win=1;
lavel:
			if(owari(win, rec, time1, e)){
				break;					// ゲーム終了
			}
			else {						// もう一度ゲームをする場合
				x=3; y=1; e=KAISUU; osita=1; c=0;
				make_bakudan(bakudan);
				start = GetNowCount();
			}
		}
		ScreenFlip() ;
		WaitTimer(WAIT);				// ゲーム全体のウェイト
	}
	DxLib_End();	// DXライブラリの後始末

	return 0;
}

どぶろく
記事: 75
登録日時: 11年前

Re: ぷるぷるプログラミング

#10

投稿記事 by どぶろく » 6年前

あら、まあ、大好評の第5弾、いくよ~~~~~~!!

●内容●
出走馬数(1~12)を入力します。入力した数だけ馬の構造体をnewで確保してます。
一斉に走り出します。文字幅の8ドット単位ではなく微妙な差がつくんではないかな、
と。いう思惑で、1~21ドット単位の移動にしました。

●応用●
コースの設定を右端まで行ったら向きをかえて戻ってくるようにしたり、
また落馬などの処理を追加すると面白くなるでしょう。

コード:

//-----------------------------------------------------------------------------
// 2017-12-17(日)
//
// 競馬ゲーム
//
//-----------------------------------------------------------------------------
#include "DxLib.h"

#define	 WHITE		255,255,255		// 白(最大輝度白色光)  255
#define	 YELLOW		255,255,  0		// 明るい黄色            251

#define	 WAIT		(120)			// 全体のウェイト

//-----------------------------------------------------------------------------
// 馬の構造体
//-----------------------------------------------------------------------------
struct SHorse {
	int   x, y;
	char *horse;

	SHorse(){				// コンストラクタ
		x=0; y=0;
		horse = "/■^";		// 馬
	}
};

//-----------------------------------------------------------------------------
// エントリーポイント
//-----------------------------------------------------------------------------
int WINAPI WinMain( HINSTANCE, HINSTANCE, LPSTR, int )
{
	int White  = GetColor(WHITE);
	int Yellow = GetColor(YELLOW);
	int i;
	int n;			// 馬の数
	SHorse *p;		// 構造体へのポインタ
	
	ChangeWindowMode(TRUE);
	if( DxLib_Init() < 0 ) return -1;
	ChangeFont( "MS ゴシック" ) ;
	SetFontThickness(1);			// 文字の太さを1ドットにする
	SetDrawScreen( DX_SCREEN_BACK ) ;

lavel:
	DrawString(250, 150, "馬の数?", Yellow) ;
	n = KeyInputNumber(250+72 , 150 , 12 , 1 , TRUE ) ;
	p = new SHorse[n];
	
	while(!ProcessMessage() && !ClearDrawScreen())
	{
		DrawLine(72*8, 0, 72*8, 400, White);
		for(i=0; i<n ; i++){
			p[i].x += GetRand(20)+1;
			DrawString(p[i].x, i*32+20, p[i].horse, White) ;
		}
		ScreenFlip();

		for(i=0; i<n ; i++){
			if(p[i].x > (68*8)){	// ゴール
				delete []p;
				if(WaitKey()==KEY_INPUT_ESCAPE){	// [ESC]で終了
					goto end;
				}
				goto lavel;
			}
		}
		Beep(1000, 10);Beep(1000, 5);
		WaitTimer(WAIT);				// ゲーム全体のウェイト
	}
	delete []p;		// ねんのため
end:
	DxLib_End();	// DXライブラリの後始末
	return 0;
}

どぶろく
記事: 75
登録日時: 11年前

Re: ぷるぷるプログラミング

#11

投稿記事 by どぶろく » 6年前

ちまたで大反響!思わず手がぷるぷるしてくる。
さあ、老眼と手の震えがきたら、ぷるぷるプログラミングのはじまりだ!

●目的●
どこからか一羽のカラスが大きな柿の木に飛んできて、その実を全部食べてしまいます。

●内容●
カラスの動きは上下左右に変化します。縦横とも乱数によって -1 から 1 の範囲で求めます。
X座標の範囲は 1 から 38 まで、Y座標の範囲は 1 から 26 までとしています。
また、柿を食べると幹と枝が表示されるようにしています。

●応用●
このように乱数を利用して、いろいろなプログラムを考えて下さい。

コード:

//-----------------------------------------------------------------------------
//	2017-12-26(火)
//
//	柿を食べるカラス
//
//-----------------------------------------------------------------------------
#include "DxLib.h"
#include "memory.h"

#define	 WHITE		255,255,255		// 白(最大輝度白色光)  255
#define	 WAIT		(150)			// 全体のウェイト

//-----------------------------------------------------------------------------
// 柿の実
//-----------------------------------------------------------------------------
char kaki[30][80]={
"                                                                              ",
"                                                                              ",
"                                                                              ",
"                                                                              ",
"                                                                              ",
"                                    ●●●                                    ",
"                                  ●●●●●                                  ",
"                                ●●●●●●●                                ",
"                              ●●●●●●●●●                              ",
"                            ●●●●●●●●●●●                            ",
"                          ●●●●●●●●●●●●●                          ",
"                        ●●●●●●●●●●●●●●●                        ",
"                      ●●●●●●●●●●●●●●●●●                      ",
"                    ●●●●●●●●●●●●●●●●●●●                    ",
"                  ●●●●●●●●●●●●●●●●●●●●●                  ",
"                ●●●●●●●●●●●●●●●●●●●●●●●                ",
"              ●●●●●●●●●●●●●●●●●●●●●●●●●              ",
"            ●●●●●●●●●●●●●●●●●●●●●●●●●●●            ",
"          ●●●●●●●●●●●●●●●●●●●●●●●●●●●●●          ",
"        ●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●        ",
"              ●●●●●●●●●●●●●●●●●●●●●●●●●              ",
"                    ●●●●●●●●●●●●●●●●●●●                    ",
"                          ●●●●●●●●●●●●●                          ",
"                                ●●●●●●●                                ",
"                                                                              ",
"                                                                              ",
"                                                                              ",
"                                                                              ",
"                                                                              ",
"                                                                              "
};
//-----------------------------------------------------------------------------
// 柿の木(幹と枝)
//-----------------------------------------------------------------------------
void kakinoki()
{
	int White  = GetColor(WHITE);
	
	DrawLine(316,  96, 288, 464, White);
	DrawLine(316,  96, 336, 464, White);

	DrawLine(170, 250, 300, 310, White);
	DrawLine(170, 250, 299, 325, White);

	DrawLine(210, 230, 220, 273, White);
	DrawLine(165, 300, 230, 287, White);

	DrawLine(450, 240, 325, 270, White);
	DrawLine(450, 240, 329, 281, White);

	DrawLine(390, 260, 450, 280, White);
	DrawLine(370, 260, 405, 216, White);

	DrawLine(220, 170, 305, 220, White);
	DrawLine(220, 170, 305, 230, White);

	DrawLine(240, 155, 253, 190, White);

	DrawLine(375, 135, 320, 165, White);
	DrawLine(375, 135, 320, 170, White);

	DrawLine(370, 150, 350, 150, White);
}

//-----------------------------------------------------------------------------
// エントリーポイント
//-----------------------------------------------------------------------------
int WINAPI WinMain( HINSTANCE, HINSTANCE, LPSTR, int )
{
	int White  = GetColor(WHITE);
	int i, j, x=0, y=0;
	
	ChangeWindowMode(TRUE);
	if( DxLib_Init() < 0 ) return -1;
	ChangeFont( "MS ゴシック" ) ;
	SetFontThickness(1);				// 文字の太さを1ドットにする
	SetDrawScreen( DX_SCREEN_BACK ) ;

	while(!ProcessMessage() && !ClearDrawScreen())
	{
		kakinoki();					// 柿の木の幹と枝を表示
		for(j=0; j<30; j++){		// 柿の実を表示
			for(i=0; i<40; i++){
				DrawString(i*16, j*16, &kaki[j][i*2], White);
			}
		}
		x+=(GetRand(2)-1);
		y+=(GetRand(2)-1);
		if(x<1) { x= 1; }
		if(x>38){ x=38; }
		if(y<1) { y= 1; }
		if(y>26){ y=26; }
		
		if(!memcmp(&kaki[y][x*2], "●", 2)){
			kaki[y][x*2  ] = ' ';
			kaki[y][x*2+1] = ' ';
		}
		DrawString(x*16, y*16, "W", White);
		ScreenFlip();
		WaitTimer(WAIT);				// ゲーム全体のウェイト
	}
	DxLib_End();	// DXライブラリの後始末
	return 0;
}

どぶろく
記事: 75
登録日時: 11年前

Re: ぷるぷるプログラミング

#12

投稿記事 by どぶろく » 6年前

あけましておめでとうございます。
今年も、ぷるぷるプログラミングをよろしくおねがいいたします。
さっそく、ぷるぷるしてプログラムが出来上がりました。

●目的●
道の幅は16文字分あり、そこに乱数によって障害物を発生させます。障害物にぶつかると
ゲームは終了となります。
カーソルキーを使って、ぶつからないようにうまくコントロールしてください。

●応用●
スピードを変えたり、道幅を変えたりしてプログラムを少し変更するだけで、もっと面白
くなります。また、指定回数分だけぶつかったら終了するようにしてもよいでしょう。

コード:

//-----------------------------------------------------------------------------
//	2018-01-01(月)
//
//	通り抜けゲーム
//
//-----------------------------------------------------------------------------
#include "DxLib.h"

#define WHITE		255,255,255		// 白(最大輝度白色光)  255
#define RED			255,  0,  0		// 明るい赤              249

//-----------------------------------------------------------------------------
// 障害物の構造体
//-----------------------------------------------------------------------------
struct SObst {
	int x;
	int y;
};
//-----------------------------------------------------------------------------
// エントリーポイント
//-----------------------------------------------------------------------------
int WINAPI WinMain( HINSTANCE, HINSTANCE, LPSTR, int )
{
	int White = GetColor(WHITE);	// 文字色
	int Red   = GetColor(RED);
	int score=0;        // スコア
	int HiScore=0;      // ハイスコア
	int wait=150;       // ウェイト
	int a=20;           // 自分の初期位置(x座標)
	int rol=0;          // 障害物の配列番号
	int speed=0;        // スピードの変化用
	int key;            // キー押し下げ
	SObst obst[25];		// 障害物のx座標とy座標を保存する構造体

	ChangeWindowMode(TRUE);
	if( DxLib_Init() < 0 ) { return -1; };
	ChangeFont( "MS ゴシック" ) ;
	SetFontThickness(1);				// 文字の太さを1ドットにする
	SetDrawScreen( DX_SCREEN_BACK ) ;

	memset(obst, 0, sizeof(SObst)*25);  // 0で初期化

	while(!ProcessMessage() && !ClearDrawScreen())
	{
		key = GetJoypadInputState( DX_INPUT_KEY_PAD1 ) ;

		if( key & PAD_INPUT_9 )     { break; }	// ESCで終了
		if( key & PAD_INPUT_LEFT )  { a--;   }	// [←]キー
		if( key & PAD_INPUT_RIGHT ) { a++;   }	// [→]キー

		if( a<10 ) { a=10; }		// 左端にきたら
		if( a>25 ) { a=25; }		// 右端にきたら
		
		DrawLine(8*9,  0, 8*9,  26*16, White);
		DrawLine(8*27, 0, 8*27, 26*16, White);
		DrawString(a*8, 16, "&", White);

		obst[rol].x = GetRand(15)+10;	// 乱数で障害物の表示位置(x座標)を決める
		obst[rol].y = 24;				// y座標は一番下から

		for(int i=0; i<25 ; i++){        
			if((obst[i].x==a) && (obst[i].y==1)){		// 当たり判定
				DrawString(obst[i].x*8, obst[i].y*16, "●", Red);
				DrawString(14*8, 10*16, "game over", Red);
				DrawFormatString(29*8, 0, White, "%d  score %d", HiScore, score);
				ScreenFlip() ;
				if(HiScore<score){
					HiScore=score;
				}
				Beep(700, 1000);
				if(WaitKey()==KEY_INPUT_ESCAPE){
					goto end;
				}
				memset(obst, 0, sizeof(SObst)*25);
				a=20; rol=0; speed=0; wait=150; score=0;
			}
			DrawString(obst[i].x*8, obst[i].y*16, "*", White); // 障害物を表示
			obst[i].y--;		// 表示後のy座標を1つ上にする。
		}
		rol++;
		if(rol>24){ 
			rol=0;				// 障害物の配列番号をセットしていくため
		}
		speed++;
		if(speed>60){
			speed=0;
			wait-=10;			// だんだんスピードを速くする
			if(wait<30){ wait=150; }
		}
		score++;
		DrawFormatString(29*8, 0, White, "%d  score %d", HiScore, score);
		ScreenFlip() ;
		WaitTimer(wait);		// ゲーム全体のウェイト
	}
end:
	DxLib_End();		// DXライブラリの後始末
	return 0;
}

どぶろく
記事: 75
登録日時: 11年前

Re: ぷるぷるプログラミング

#13

投稿記事 by どぶろく » 6年前

どうも、ちまたで、うわさの、ぷるぷるプログラミングです。
なんだか今年も絶好調だよ。
ところで文字にハートとかクラブとかあったと思ってたけど無かった・・・。
というわけで、グラフィックを作ってみました。
ちっちゃい絵だね~。もっと大きく作れば良かったなぁ・・・。

●目的●
動いているタマをキャッチして得点を競うゲームです。
前回の避けゲーとは逆の感じ。避けるのではなくキャッチしていきます。

●内容●
ミットのコントロールは、カーソルキー(左右のみ)で行い、制限時間は1分となっています。
タマの発生場所と種類は乱数によって設定します。タマの種類と得点は次のとおりです。

ハート 10点
ダイヤ 20点
クラブ -10点
スペード -20点

●応用●
タマの種類は乱数によって均等に発生していますが、種類によって発生確率をかえてみるとよいでしょう。
例)乱数を1から10の範囲で発生させて、その値によって次のようにします。

1~2 ダイヤ
3~6 ハート
7~9 クラブ
10 スペード

コード:

//-----------------------------------------------------------------------------
//	2018-01-03(水)
//
//	キャッチゲーム
//
//-----------------------------------------------------------------------------
#include "DxLib.h"

#define WHITE		255,255,255		// 白(最大輝度白色光)    255
#define CYAN		  0,255,255		// シアン(水色:輝淡青色)254
#define MAGENTA		255,  0,255		// マゼンタ(紫:淡紅色)  253
#define BLUE		  0,  0,255		// 明るい青                252
#define YELLOW		255,255,  0		// 明るい黄色              251
#define GREEN		  0,255,  0		// 明るい緑                250
#define RED			255,  0,  0		// 明るい赤                249
#define BLACK		  0,  0,  0		// 黒                        0

#define WAIT		(130)			// 全体のウェイト
#define TIME		(60)			// 制限時間(60秒)

//-----------------------------------------------------------------------------
// マークの構造体
//-----------------------------------------------------------------------------
struct SMark {
	int x;
	int y;
	int m;	// マークの種類(0~3を入れる)
};

//-----------------------------------------------------------------------------
// マーク(ハート、ダイヤ、クラブ、スペード)
//-----------------------------------------------------------------------------
char g_img1[16][9] ={
    "        ",
    "        ",
    "        ",
    "        ",
    " RR  RR ",
    "RRR  RRR",
    "RRRRRRRR",
    "RRRRRRRR",
    "RRRRRRRR",
    "RRRRRRRR",
    " RRRRRR ",
    " RRRRRR ",
    "  RRRR  ",
    "  RRRR  ",
    "   RR   ",
    "        "
};

char g_img2[16][9] ={
    "        ",
    "   YY   ",
    "   YY   ",
    "  YYYY  ",
    "  YYYY  ",
    " YYYYYY ",
    " YYYYYY ",
    "YYYYYYYY",
    "YYYYYYYY",
    " YYYYYY ",
    " YYYYYY ",
    "  YYYY  ",
    "  YYYY  ",
    "   YY   ",
    "   YY   ",
    "        "
};

char g_img3[16][9] ={
    "        ",
    "        ",
    "   SS   ",
    "  SSSS  ",
    "  SSSS  ",
    "  SSSS  ",
    "   SS   ",
    " SSSSSS ",
    "SSSSSSSS",
    "SSSSSSSS",
    "SSSSSSSS",
    " S SS S ",
    "   SS   ",
    "   SS   ",
    "  SSSS  ",
    "        "
};

char g_img4[16][9] ={
    "        ",
    "        ",
    "        ",
    "   GG   ",
    "  GGGG  ",
    "  GGGG  ",
    " GGGGGG ",
    " GGGGGG ",
    "GGGGGGGG",
    "GGGGGGGG",
    "GGGGGGGG",
    "GGGGGGGG",
    " G GG G ",
    "   GG   ",
    "   GG   ",
    "        "
};

//-----------------------------------------------------------------------------
// パレットに色をセットする
//-----------------------------------------------------------------------------
void set_pal(int hImg)
{
    SetPaletteSoftImage( hImg, 0, BLACK, 0 ) ;
    SetPaletteSoftImage( hImg, 1, WHITE, 0 ) ;
    SetPaletteSoftImage( hImg, 2, YELLOW, 0 ) ;
    SetPaletteSoftImage( hImg, 3, CYAN, 0 ) ;
    SetPaletteSoftImage( hImg, 4, MAGENTA, 0 ) ;
    SetPaletteSoftImage( hImg, 5, GREEN, 0 ) ;
}

//-----------------------------------------------------------------------------
// ドット絵を描く
//-----------------------------------------------------------------------------
void make_dot(int hImg, char (*img)[9])
{
	int x, y, c;

	for( y=0; y<16 ; y++ ){
		for( x=0; x<8 ; x++ ){
			c=0;
			if(img[y][x]==' '){ c=0; }	// BLACK
			if(img[y][x]=='Y'){ c=2; }	// YELLOW
			if(img[y][x]=='S'){ c=3; }	// CYAN
			if(img[y][x]=='R'){ c=4; }	// MAGENTA
			if(img[y][x]=='G'){ c=5; }	// GREEN

			DrawPixelPalCodeSoftImage( hImg, x, y, c ) ;
		}
	}
}

//-----------------------------------------------------------------------------
// 右に得点表を表示する
//-----------------------------------------------------------------------------
void put_tokuten(int hGraph[])
{
	int White  = GetColor(WHITE);
	int Yellow = GetColor(YELLOW);

	DrawBox(43*8, 2*16, 53*8, 11*16, White, FALSE);

	DrawGraph(45*8, 3*16, hGraph[0], FALSE);		// ハートを表示
	DrawGraph(45*8, 5*16, hGraph[1], FALSE);		// ダイヤを表示
	DrawGraph(45*8, 7*16, hGraph[2], FALSE);		// クラブを表示
	DrawGraph(45*8, 9*16, hGraph[3], FALSE);		// スペードを表示

	DrawString(48*8, 3*16, " 10", Yellow);			// ハートの点数を表示
	DrawString(48*8, 5*16, " 20", Yellow);			// ダイヤの点数を表示
	DrawString(48*8, 7*16, "-10", Yellow);			// クラブの点数を表示
	DrawString(48*8, 9*16, "-20", Yellow);			// スペードの点数を表示
}

//-----------------------------------------------------------------------------
// 終わりの処理
//-----------------------------------------------------------------------------
int owari(int &HiScore, int score, int time1)
{
	int White  = GetColor(WHITE);
	int Black  = GetColor(BLACK);
	int Yellow = GetColor(YELLOW);

	DrawBox(0, 0, 38*8, 16, Black, TRUE);
	DrawFormatString(0, 0, White, " HiScore %d  score %d  time %d/%d", HiScore, score, time1/1000, TIME);
	DrawBox(6*16, 8*16, 16*16, 15*16, Black, TRUE);
	DrawBox(6*16, 8*16, 16*16, 15*16, Yellow, 0);
	DrawString(8*16,  9*16, "  TIME UP", Yellow);
	DrawString(8*16, 11*16, "HIT ANY KEY", White);
	DrawString(8*16, 13*16, "[ESC] 終了", White);
	ScreenFlip() ;
	Beep(1000,1000);
	WaitTimer(1000);

	if(WaitKey()==KEY_INPUT_ESCAPE){
		return 1;
	}
	if(HiScore < score){
		HiScore = score;
	}
	return 0;
}
//-----------------------------------------------------------------------------
// エントリーポイント
//-----------------------------------------------------------------------------
int WINAPI WinMain( HINSTANCE, HINSTANCE, LPSTR, int )
{
	int White = GetColor(WHITE);
	int Black = GetColor(BLACK);
	int score=0;				// スコア
	int HiScore=0;				// ハイスコア
	int a=20;					// 自分のx座標
	int rol=0;					// 障害物の配列番号
	int key;					// キー押し下げ
	int hImg[4];				// パレット画像のハンドル
	int hGraph[4];				// グラフィックハンドル
	int StartTime, time1=0;		// 時間
	SMark mark[25];				// マークの構造体

	memset(mark, 0, sizeof(SMark)*25);	// 0で初期化

	ChangeWindowMode(TRUE);
	if( DxLib_Init() < 0 ){ return -1; }
	ChangeFont( "MS ゴシック" ) ;
	SetFontSize( 16 ) ;
	SetFontThickness( 1 );				// 文字の太さを1ドットにする
	SetAlwaysRunFlag( TRUE ) ;			// バックグランドでも実行する
	SetDrawScreen( DX_SCREEN_BACK ) ;

	// 空のパレット画像を作成する
	hImg[0] = MakePAL8ColorSoftImage( 8, 16 ) ;
	hImg[1] = MakePAL8ColorSoftImage( 8, 16 ) ;
	hImg[2] = MakePAL8ColorSoftImage( 8, 16 ) ;
	hImg[3] = MakePAL8ColorSoftImage( 8, 16 ) ;

	// パレットに色をセットする
	set_pal(hImg[0]);
	set_pal(hImg[1]);
	set_pal(hImg[2]);
	set_pal(hImg[3]);

	//ドット絵を描く
	make_dot(hImg[0], g_img1);	// ハート
	make_dot(hImg[1], g_img2);	// ダイヤ
	make_dot(hImg[2], g_img3);	// クラブ
	make_dot(hImg[3], g_img4);	// スペード

	// グラフィックハンドルを作成
	hGraph[0] = CreateGraphFromSoftImage( hImg[0] ) ;
	hGraph[1] = CreateGraphFromSoftImage( hImg[1] ) ;
	hGraph[2] = CreateGraphFromSoftImage( hImg[2] ) ;
	hGraph[3] = CreateGraphFromSoftImage( hImg[3] ) ; 

	// 使い終わったら解放
	DeleteSoftImage( hImg[0] ) ;
	DeleteSoftImage( hImg[1] ) ;
	DeleteSoftImage( hImg[2] ) ;
	DeleteSoftImage( hImg[3] ) ;

	StartTime = GetNowCount();

	while(!ProcessMessage() && !ClearDrawScreen())
	{
		key = GetJoypadInputState( DX_INPUT_KEY_PAD1 ) ;

		if( key & PAD_INPUT_9 )    { break; }	// ESCで終了
		if( key & PAD_INPUT_LEFT ) { a--;   }	// [←]キー
		if( key & PAD_INPUT_RIGHT ){ a++;   }	// [→]キー

		if( a<0 ) { a=0; }			// 左端にきたら
		if( a>36 ){ a=36; }			// 右端にきたら
		
		DrawString(a*8, 3*16, "|--|", White);
		put_tokuten(hGraph);		// 得点表を表示
		
		mark[rol].m = GetRand(3);	// 乱数でマークの種類を決める
		mark[rol].x = GetRand(37)+1;// 乱数でマークの表示位置(x座標)を決める
		mark[rol].y = 24;			// y座標は一番下から
		
		for(int i=0; i<25 ; i++){
			if((mark[i].x >= a+1) && (mark[i].x <= a+2) && (mark[i].y == 3)){	// 当たり判定
				if(mark[i].m==0){ score+=10; Beep(1000, 30);}					// ハート
				if(mark[i].m==1){ score+=20; Beep(1500, 30);Beep(1000, 30);}	// ダイヤ
				if(mark[i].m==2){ score-=10; Beep( 500, 30);}					// クラブ
				if(mark[i].m==3){ score-=20; Beep( 500, 30);Beep( 500, 30);}	// スペード
			}
		    DrawGraph( mark[i].x*8, mark[i].y*16, hGraph[mark[i].m], FALSE ) ;	// 描画
			mark[i].y--;		// 表示後のy座標を1つ上にする。
		}
		rol++;
		if(rol>24){ 
			rol=0;				// マークの配列番号をセットしていくため
		}
		if(time1>TIME*1000){	// 60秒過ぎたら
			if(owari(HiScore, score, time1)){
				goto end;
			}
			memset(mark, 0, sizeof(SMark)*25);		// 0で初期化
			rol=0; score=0; StartTime=GetNowCount();
		}
		time1 = GetNowCount() - StartTime;			// 経過時間

		DrawBox(0, 0, 38*8, 16, Black, TRUE);
		DrawFormatString( 0, 0, White, " HiScore %d  score %d  time %d/%d", HiScore, score, time1/1000, TIME);

		ScreenFlip() ;
		WaitTimer(WAIT);		// ゲーム全体のウェイト
	}
end:
	for(int i=0; i<4 ; i++){
    	DeleteGraph( hGraph[i] );	// グラフィックハンドルの削除
	}
	DxLib_End();				// DXライブラリの後始末
	return 0;
}

どぶろく
記事: 75
登録日時: 11年前

Re: ぷるぷるプログラミング

#14

投稿記事 by どぶろく » 6年前

どうも、ちまたで、ちまった、ぷるぷるプログラミングです。
今回で、ちまったのだ。いや~、面白かったねぇ。
何個ゲーム作ったか覚えてないけど。(笑)
BASIC面白かったよぉ。今度はHSPを勉強して移植しようかな。
では、ちまたで、ちまった、ゲームを堪能してください。

●目的●
カーソルキー(上、下、左、右)を使って、トンボを採るゲームです。

●内容●
発生するトンボ(T)を、網(○)で採った分だけ得点となります。
時間は1分にしてあります。
乱数を利用して、トンボを表示しているわけですが、ゆっくりしていると、
トンボはどんどん移動していきます。
また、トンボを採ると音が発生するようにしました。

●応用●
トンボ採りの場所の形(現在は正方形)を変えたり、障害物(木とか池)などを画面上に
表示させると、もっと高度なゲームになります。
また、他の昆虫なども表示するよう考えてみてください。

コード:

//-----------------------------------------------------------------------------
//	2018-01-11(木)
//
//	トンボ採りゲーム
//
//-----------------------------------------------------------------------------
#include "DxLib.h"

#define WHITE		255,255,255		// 白(最大輝度白色光)    255
#define YELLOW		255,255,  0		// 明るい黄色              251
#define BLACK		  0,  0,  0		// 黒                        0

#define WAIT		(150)			// 全体のウェイト
#define TIME		(60)			// 制限時間(60秒)
#define TOMBO		(17)			// トンボの数
#define SPEED		(2)				// トンボのスピード(大きくすると遅くなる)

//-----------------------------------------------------------------------------
// トンボの構造体
//-----------------------------------------------------------------------------
struct STombo {
	int x;
	int y;
};

//-----------------------------------------------------------------------------
// 得点を表示
//-----------------------------------------------------------------------------
void put_score(int HiScore, int score, int time1)
{
	int White  = GetColor(WHITE);
	int Black  = GetColor(BLACK);

	DrawBox(28*16, 2*16, 36*16, 7*16, Black, TRUE);
	DrawFormatString(28*16, 2*16, White, "HiScore %d", HiScore);
	DrawFormatString(28*16, 4*16, White, "Score   %d", score);
	DrawFormatString(28*16, 6*16, White, "Time %3d/%d", time1/1000, TIME);
}

//-----------------------------------------------------------------------------
// 終わりの処理
//-----------------------------------------------------------------------------
int owari(int& HiScore, int score, int time1)
{
	int White  = GetColor(WHITE);
	int Black  = GetColor(BLACK);
	int Yellow = GetColor(YELLOW);

	put_score(HiScore, score, time1);
	
	DrawBox(8*16, 8*16, 18*16, 15*16, Black, TRUE);
	DrawBox(8*16, 8*16, 18*16, 15*16, Yellow, 0);
	DrawString(11*16,    9*16, "TIME UP", Yellow);
	DrawString(10*16,   11*16, "HIT ANY KEY", White);
	DrawString(10*16+4, 13*16, "[ESC] 終了", White);
	ScreenFlip() ;
	Beep(1000,1000);
	WaitTimer(300);

	if(WaitKey()==KEY_INPUT_ESCAPE){
		return 1;
	}
	if(HiScore < score){
		HiScore = score;
	}
	return 0;
}
//-----------------------------------------------------------------------------
// エントリーポイント
//-----------------------------------------------------------------------------
int WINAPI WinMain( HINSTANCE, HINSTANCE, LPSTR, int )
{
	int White = GetColor(WHITE);
	int Yellow= GetColor(YELLOW);
	int score=0;			// スコア
	int HiScore=0;			// ハイスコア
	int x=12, y=12;			// 自分の位置
	int speed=0;			// トンボのスピードカウンタ
	int time1=0;			// 経過時間
	int StartTime;			// スタート時間
	int key;				// キー押し下げ
	STombo tombo[TOMBO];	// トンボの構造体

	ChangeWindowMode(TRUE);
	if( DxLib_Init() < 0 ){ return -1; }
	ChangeFont( "MS ゴシック" ) ;
	SetFontSize( 16 ) ;
	SetFontThickness( 6 );				// 文字の太さを2ドットにする
	SetAlwaysRunFlag( TRUE ) ;			// バックグランドでも実行する
	SetDrawScreen( DX_SCREEN_BACK ) ;

	for(int i=0; i<TOMBO ; i++){        
		tombo[i].x = GetRand(24)+1;
		tombo[i].y = GetRand(24)+1;
	}
	StartTime = GetNowCount();
	
	while(!ProcessMessage() && !ClearDrawScreen())
	{
		key = GetJoypadInputState( DX_INPUT_KEY_PAD1 ) ;

		if( key & PAD_INPUT_9 )    { break; }	// ESCで終了
		if( key & PAD_INPUT_LEFT ) { x--;   }	// [←]キー
		if( key & PAD_INPUT_RIGHT ){ x++;   }	// [→]キー
		if( key & PAD_INPUT_UP )   { y--;   }	// [↑]キー
		if( key & PAD_INPUT_DOWN ) { y++;   }	// [↓]キー

		if( x<1 ) { x=1; }		// 左端にきたら
		if( x>25 ){ x=25;}		// 右端にきたら
		if( y<1 ) { y=1; }		// 上端にきたら
		if( y>25 ){ y=25;}		// 下端にきたら
		
		DrawBox(8, 8, 26*16+8, 26*16+8, White, FALSE);	// 枠を表示
		DrawString(x*16, y*16, "○", Yellow);			// 網を表示

		for(int i=0; i<TOMBO ; i++){        
			DrawString(tombo[i].x*16, tombo[i].y*16, "T", White); // トンボを表示
		}
		for(int i=0; i<TOMBO ; i++){        
			if((tombo[i].x==x) && (tombo[i].y==y)){		// 当たり判定
				put_score(HiScore, score, time1);
				ScreenFlip() ;
				score++;
				Beep(2000, 100);Beep(1000, 100);
				tombo[i].x = GetRand(24)+1;			// 新しくトンボを作る
				tombo[i].y = GetRand(24)+1;
			}
		}
		speed++;
		if(speed > SPEED){				// トンボのスピード調整
			speed=0;
			for(int i=0; i<TOMBO ; i++){		// トンボを動かす
				tombo[i].x += GetRand(2)-1;
				tombo[i].y += GetRand(2)-1;
				if( tombo[i].x<1 ) { tombo[i].x=1; }	// 左端にきたら
				if( tombo[i].x>25 ){ tombo[i].x=25;}	// 右端にきたら
				if( tombo[i].y<1 ) { tombo[i].y=1; }	// 上端にきたら
				if( tombo[i].y>25 ){ tombo[i].y=25;}	// 下端にきたら
			}
		}
		time1 = GetNowCount() - StartTime;		// 経過時間

		if(time1>TIME*1000){	// 60秒過ぎたら
			if(owari(HiScore, score, time1)){
				goto end;
			}
			x=12; y=12; score=0; 
			StartTime = GetNowCount();
		}
		put_score(HiScore, score, time1);
		ScreenFlip() ;
		WaitTimer(WAIT);		// ゲーム全体のウェイト
	}
end:
	DxLib_End();		// DXライブラリの後始末
	return 0;
}

どぶろく
記事: 75
登録日時: 11年前

Re: ぷるぷるプログラミング

#15

投稿記事 by どぶろく » 6年前

あちゃ~、 DxLib_Init 呼び出す前に GetColor 使っちゃったよ。戻り値も int じゃなく unsigned int じゃん。
WaitTimer も使っちゃてるし、ScreenFlip も複数使ってる、よく見れば goto も使ってる。
こうやって失敗を重ねて成長して行くんだね。また一つ(5つも)賢くなったのだ、のだ、野田の玉川。

どぶろく
記事: 75
登録日時: 11年前

Re: ぷるぷるプログラミング

#16

投稿記事 by どぶろく » 6年前

画像データをキーボードでピコピコ打ち込んでいたのたが、
めっちゃ大変なのでドット絵エディターを作ることにしました。
もちろん色をアルファベット1文字にするために作成中です。

つまり、

コード:

char img[32][33] ={
    "              b b               ",
    "              b b               ",
    "           bbbbYbbbb            ",
    "           bbbbYbbbb            ",
    "     RRRR bbCbbYbbCbb  RRRR     ",
    "     RRRR bbCbbYbbCbb  RRRR     ",
    "   CCCCgCC bbbbYbbbb  CCgCCCCC  ",
    "   CCCCgCC bbbbYbbbb  CCgCCCCC  ",
    "  CCCCCgCCCCCYYYYYYCCCCCgCCCCCC ",
    "  CCCCCgCCCCCYYYYYYCCCCCgCCCCCC ",
    " CCCCCCggggggYYYYYYggggggCCCCCCC",
    " CCCCCCggggggYYYYYYggggggCCCCCCC",
    " CCCCCCCCCCCCCYYYYCCCCCCCCCCCCCC",
    " CCCCCCCCCCCCCYYYYCCCCCCCCCCCCCC",
    "  CgggggggggggYYYYggggggggggCC  ",
    "  CgggggggggggYYYYggggggggggCC  ",
    "   gggggggggggYYYYgggggggg g    ",
    "   g gggggggggYYYYgggggggg g    ",
    "   g g     YYYYYYYYYY    g g    ",
    "   g g     YYYYYYYYYY    g g    ",
    "   g g   yyyyyyyyyyyyyy  g g    ",
    "   g g   yyyyyyyyyyyyyy  g g    ",
    " RRR g  YYYYYYYYYYYYYYYY g RRR  ",
    " RRR g  YYYYYYYYYYYYYYYY g RRR  ",
    "     g   yyyyyyyyyyyyyy  g      ",
    "     g   yyyyyyyyyyyyyy  g      ",
    "  RRRR    YYYYYYYYYYYY   RRRR   ",
    "  RRRR    YYYYYYYYYYYY   RRRR   ",
    "           yyyyyyyyyy           ",
    "           yyyyyyyyyy           ",
    "              YYYY              ",
    "              YYYY              "
};
こういうのを作るためのエディタ。

途中経過のエディターの画像をアップしようとしたけど、画像のアップの仕方が分かんなかった。
ということで、制作途中のソースだけどアップするので暇つぶしに見て下さい。
BMPファイルを変換する方が早いとも思ったが、そっちの方が大変だよね?

コード:

//-----------------------------------------------------------------------------
//	2018-01-21(日)
//
//	ドット絵エディタ(色データを文字にする)
//
//-----------------------------------------------------------------------------
#include "DxLib.h"

#define DD_GRAY     85, 85, 85    // 暗い灰色         -1
#define BLACK        0,  0,  0    // 黒                0
#define D_RED      128,  0,  0    // 暗い赤            1
#define D_GREEN      0,128,  0    // 暗い緑            2
#define D_YELLOW   128,128,  0    // 暗い黄色(深黄色)3
#define D_BLUE       0,  0,128    // 暗い青            4
#define D_MAGENTA  128,  0,128    // 暗いマゼンタ      5
#define D_CYAN       0,128,128    // 暗いシアン        6

#define MD_RED     191,  0,  0    // やや暗い赤             _1
#define MD_GREEN     0,191,  0    // やや暗い緑             _2
#define MD_YELLOW  191,191,  0    // やや暗い黄色(黄銅色) _3
#define MD_BLUE      0,  0,191    // やや暗い青             _4
#define MD_MAGENTA 191,  0,191    // やや暗いマゼンタ       _5
#define MD_CYAN      0,191,191    // やや暗いシアン         _6

#define GRAY       192,192,192    // 明るい灰色              7
#define M_GREEN    192,220,192    // マネーグリーン          8
#define S_BLUE     166,202,240    // スカイブルー            9

//#define CREAM      255,251,240    // クリーム(淡黄色)      246
#define CREAM      255,251,200    // クリーム(淡黄色)      246
#define M_GRAY     160,160,164    // ミディアムグレー        247
#define D_GRAY     128,128,128    // 暗い灰色                248
#define RED        255,  0,  0    // 明るい赤                249
#define GREEN        0,255,  0    // 明るい緑                250
#define YELLOW     255,255,  0    // 明るい黄色              251
#define BLUE         0,  0,255    // 明るい青                252
#define MAGENTA    255,  0,255    // マゼンタ(紫:淡紅色)  253
#define CYAN         0,255,255    // シアン(水色:輝淡青色)254
#define WHITE      255,255,255    // 白(最大輝度白色光)    255
#define L_BLUE      0,150,255     // ライトブルー

//-----------------------------------------------------------------------------
// 構造体
//-----------------------------------------------------------------------------
struct SDot{
	int   L_x;			// 左ボタンで選択した色に L を付けるため
	int   R_x;			// 右ボタンで選択した色に R を付けるため
	UINT  L_color;		// 左ボタンで選択した色
	UINT  R_color;		// 右ボタンで選択した色
	UINT  mesh_color;	// メッシュの色
	UCHAR L_num;		// 左ボタンで選択した色の配列番号
	UCHAR R_num;		// 右ボタンで選択した色の配列番号
	UCHAR masu[35][60];	// 色データを格納
};

//-----------------------------------------------------------------------------
// グローバル変数
//-----------------------------------------------------------------------------
SDot g_dot;


//-----------------------------------------------------------------
// スタティックカラーをセット
//-----------------------------------------------------------------
void set_color(UINT aColor[])
{
	aColor[ 0] = GetColor(BLACK);
	aColor[ 1] = GetColor(D_RED);
	aColor[ 2] = GetColor(D_GREEN);
	aColor[ 3] = GetColor(D_YELLOW);
	aColor[ 4] = GetColor(D_BLUE);
	aColor[ 5] = GetColor(D_MAGENTA);
	aColor[ 6] = GetColor(D_CYAN);
	aColor[ 7] = GetColor(GRAY);
	aColor[ 8] = GetColor(M_GREEN);
	aColor[ 9] = GetColor(S_BLUE);

	aColor[10] = GetColor(CREAM);
	aColor[11] = GetColor(M_GRAY);
	aColor[12] = GetColor(D_GRAY);
	aColor[13] = GetColor(RED);
	aColor[14] = GetColor(GREEN);
	aColor[15] = GetColor(YELLOW);
	aColor[16] = GetColor(BLUE);
	aColor[17] = GetColor(MAGENTA);
	aColor[18] = GetColor(CYAN);
	aColor[19] = GetColor(WHITE);
}

//-----------------------------------------------------------------------------
// パレット表示
//-----------------------------------------------------------------------------
void put_pallet(UINT aColor[])
{
	UINT White = GetColor(WHITE);
	UINT Black = GetColor(BLACK);
	UINT Gray  = GetColor(GRAY);
	
	set_color(aColor);

	for(int i=0 ; i<20 ; i++){
		DrawBox(224+(20*i), 7, 243+(20*i), 41, aColor[i], TRUE);	// 色を表示
	}
	DrawBox(222, 5, 245+(20*19), 43, Gray, FALSE);			// 色の枠

	// 色選択時、左ボタン(L)か、右ボタン(R)かを表示
	DrawBox(g_dot.L_x-1, 14, g_dot.L_x+8, 14+16, White, TRUE);
	DrawBox(g_dot.R_x-1, 14, g_dot.R_x+8, 14+16, White, TRUE);
	DrawString(g_dot.L_x, 14, "L", Black);
	DrawString(g_dot.R_x, 14, "R", Black);
}

//-----------------------------------------------------------------
// ディスプレイ画面
//-----------------------------------------------------------------
void disp(UINT aColor[])
{
	UINT White = GetColor(WHITE);
	UINT Blue  = GetColor(BLUE);
	UINT Gray  = GetColor(GRAY);
	int  x, y;

	DrawBox(2, 5, 140, 35, Gray, FALSE);	// メニュー枠を表示
	DrawString(8, 12, "読込  保存  消去", White);	// メニューを表示

	//DrawBox(150, 5, 213, 45, Gray, FALSE);	// 実寸画像用の枠を表示

	put_pallet(aColor);

	//------ 縦と横の線(お絵かき画面作成)----------------

	for(y=80 ; y<=420 ; y+=10){				// 10ドット単位の横線
		DrawLine(40, y, 640, y, Blue);
	}
	for(y=80 ; y<=430 ; y+=50){				// 50ドット単位の横線
		DrawLine(30, y, 650, y, Blue);
	}

	for(x=40 ; x<=640 ; x+=10){				// 10ドット単位の縦線
		DrawLine(x, 80, x, 430, Blue);
	}
	for(x=40 ; x<=640 ; x+=50){				// 50ドット単位の縦線
		DrawLine(x, 70, x, 440, Blue);
	}

	for(x=135; x<=640 ; x+=100){
		DrawFormatString(x, 50, White, "%d", x/10-3);	// 横ドット数を表示
	}
	for(y=170; y<=430 ; y+=100){
		DrawFormatString(10, y, White , "%d", y/10-7);	// 縦ドット数を表示
	}
}

//-----------------------------------------------------------------
// マウスによる色の選択
//-----------------------------------------------------------------
void select_color(int x, UINT aColor[], int LR)
{
	int n;

	n = (x-225)/20;				// 選択色をセット
	x = n * 20 + 230;			// 座標を計算

	if(LR==1){
		g_dot.L_color = aColor[n];
		g_dot.L_x = x;				// x座標を保存
		g_dot.L_num = (UCHAR)n;		// 色の配列番号
	}
	else {
		g_dot.R_color = aColor[n];
		g_dot.R_x = x;				// x座標を保存 
		g_dot.R_num = (UCHAR)n;		// 色の配列番号
	}
}

//-----------------------------------------------------------------------------
// マスを塗る(ドット絵作成)
//-----------------------------------------------------------------------------
void draw_dot(int x,int y, int LR)
{
	UINT Black = GetColor(BLACK);
	UINT White = GetColor(WHITE);
	int  mx, my;

	if((x>=40 && x<640) && (y>=80 && y<430)){
		mx = x/10;			// 配列に入れるため。
		my = y/10;
		x  = x/10*10;		// 10ドット単位にするため端数を切り捨てる
		y  = y/10*10;

		if(LR==1){	// 左ボタン
			DrawBox(x+1, y+1, x+10, y+10, g_dot.L_color, TRUE);	// マスを塗る
			DrawPixel(mx+148, my, g_dot.L_color);
			g_dot.masu[my-8][mx-4] = g_dot.L_num;
		}
		else {		// 右ボタン
			DrawBox(x+1, y+1, x+10, y+10, g_dot.R_color, TRUE);	// マスを塗る
			DrawPixel(mx+148, my, g_dot.R_color);
			g_dot.masu[my-8][mx-4] = g_dot.R_num;
		}
		DrawBox(40, 50, 50+10*8, 50+16, Black, TRUE);
		DrawFormatString(40, 50, White, "(%2d,%2d)", mx-3, my-7);	// 座標を表示
	}
}

//-----------------------------------------------------------------------------
// エントリーポイント
//-----------------------------------------------------------------------------
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
	UINT aColor[20];
	int  x, y;
	int  Mouse;
	
	ChangeWindowMode(TRUE);
	SetGraphMode( 800 , 600 , 32 ) ;
	DxLib_Init();
	ChangeFont( "MS ゴシック" ) ;
	SetFontSize( 16 ) ;
	SetFontThickness( 1 );				// 文字の太さを1ドットにする
	SetDrawScreen( DX_SCREEN_BACK ); 
	
	g_dot.L_x = 230+19*20;
	g_dot.R_x = 230;
	UINT White = g_dot.L_color = GetColor(WHITE);
	UINT Black = g_dot.R_color = GetColor(BLACK);
	
	while( !ScreenFlip() && !ProcessMessage() /*&& !ClearDrawScreen()*/ )
	{
		Mouse = GetMouseInput();	// マウスの入力状態取得
		GetMousePoint( &x, &y );	// マウスの座標取得

		disp(aColor);
		DrawBox(40, 32*16, 50+10*8, 32*16+16, Black, TRUE);
		DrawFormatString(40, 32*16, White, "%d, %d  ", x, y);  // 座標を表示
		
		if( Mouse & MOUSE_INPUT_LEFT ){		//マウスの左ボタンが押された
			draw_dot(x, y, 1);
			if((x>225 && x<625) && (y>5 && y<40)){
				select_color(x, aColor, 1);		// 色を選択する
			}
			if((x>2 && x<140) && (y>5 && y<35)){
				//load_save(x, y);				// ロードとセーブ
			}
		}
		if( Mouse & MOUSE_INPUT_RIGHT ){	//マウスの左ボタンが押された
			draw_dot(x, y, 2);
			if((x>225 && x<625) && (y>5 && y<40)){
				select_color(x, aColor, 2);		// 色を選択する
			}
		}
	}
	DxLib_End();
	return 0;
}

どぶろく
記事: 75
登録日時: 11年前

Re: ぷるぷるプログラミング

#17

投稿記事 by どぶろく » 6年前

ドット絵を保存できるようにしたので、アイコンを作ってみました。
このアイコンは自分でデザインしたわけじゃないけどね。BASIC の本に載ってたものです。
懐かしいなぁ、ここでも BASIC を再現してるよん。
本当は画面の上にアイコンが並んでるだけど、下に並べちゃった。
まだまだ完成はしてないけど、じゅうぶんに遊べる。早く保存したやつを読み込み出来るように
したいけど、ちょっと難しそうなんだよね。

コード:

//-----------------------------------------------------------------------------
//	2018.01.21(日)~ 2018.01.30(火)
//
//	ドット絵エディタ(色データを文字にする)
//
//-----------------------------------------------------------------------------
#include "DxLib.h"
#include <stdio.h>

#define DD_GRAY     85, 85, 85    // 暗い灰色         -1
#define BLACK        0,  0,  0    // 黒                0
#define D_RED      128,  0,  0    // 暗い赤            1
#define D_GREEN      0,128,  0    // 暗い緑            2
#define D_YELLOW   128,128,  0    // 暗い黄色(深黄色)3
#define D_BLUE       0,  0,128    // 暗い青            4
#define D_MAGENTA  128,  0,128    // 暗いマゼンタ      5
#define D_CYAN       0,128,128    // 暗いシアン        6

#define MD_RED     191,  0,  0    // やや暗い赤             _1
#define MD_GREEN     0,191,  0    // やや暗い緑             _2
#define MD_YELLOW  191,191,  0    // やや暗い黄色(黄銅色) _3
#define MD_BLUE      0,  0,191    // やや暗い青             _4
#define MD_MAGENTA 191,  0,191    // やや暗いマゼンタ       _5
#define MD_CYAN      0,191,191    // やや暗いシアン         _6

#define GRAY       192,192,192    // 明るい灰色              7
#define M_GREEN    192,220,192    // マネーグリーン          8
#define S_BLUE     166,202,240    // スカイブルー            9

//#define CREAM      255,251,240    // クリーム(淡黄色)      246
#define CREAM      255,251,200    // クリーム(淡黄色)      246
#define M_GRAY     160,160,164    // ミディアムグレー        247
#define D_GRAY     128,128,128    // 暗い灰色                248
#define RED        255,  0,  0    // 明るい赤                249
#define GREEN        0,255,  0    // 明るい緑                250
#define YELLOW     255,255,  0    // 明るい黄色              251
#define BLUE         0,  0,255    // 明るい青                252
#define MAGENTA    255,  0,255    // マゼンタ(紫:淡紅色)  253
#define CYAN         0,255,255    // シアン(水色:輝淡青色)254
#define WHITE      255,255,255    // 白(最大輝度白色光)    255
#define L_BLUE      0,150,255     // ライトブルー

#define SCREEN_W	800
#define SCREEN_H	600
#define MESH_W		64
#define MESH_H		32
#define MAX_COLOR	256
#define MAX_PALLET	20
#define MAX_ICON	13

//----------------------------------------------------------------------
// 定数(遷移用)
//----------------------------------------------------------------------
enum EState {
	STATE_MAIN,
	STATE_PUT_ALPHA,
	STATE_LOAD,
	STATE_SAVE,
	STATE_MESH,
	STATE_CLEAR,
	STATE_END
};

//-----------------------------------------------------------------------------
// 構造体
//-----------------------------------------------------------------------------
struct SDot{
	int    L_x;			// 左ボタンで選択した色に L を付けるため
	int    R_x;			// 右ボタンで選択した色に R を付けるため
	UINT   L_color;		// 左ボタンで選択した色
	UINT   R_color;		// 右ボタンで選択した色
	UINT   mesh_nColor;	// メッシュの色
	UCHAR  L_num;		// 左ボタンで選択した色番号
	UCHAR  R_num;		// 右ボタンで選択した色番号
	UCHAR  masu[MESH_H][MESH_W];	// 色データを格納(色番号)
	char   moji[MESH_H][MESH_W+5];	// 変換したアルファベットを格納
	char   alpha[MAX_COLOR];		// 変換するアルファベット
	EState eState;					// 遷移用
};

//-----------------------------------------------------------------
// プロトタイプ宣言
//-----------------------------------------------------------------
EState main_dot(int x, int y, int Mouse, UINT aColor[]);
EState select_color(int x, UINT aColor[], int LR);
EState put_alpha(UINT aColor[], int hIcon[]);
EState put_mesh(UINT aColor[], int hIcon[]);
EState cls(UINT aColor[]);
EState save(UINT aColor[]);
void   set_pallet(UINT aColor[]);
void   put_pallet(UINT aColor[]);
void   put_dot(UINT aColor[]);
void   put_disp(UINT aColor[], int hIcon[]);
void   draw_dot(int x,int y, int LR);
void   put_icon(int hIcon[]);
void   set_iconPallet(int &hImg);
void   make_iconDot(int hImg, char (*img)[31], int num);
void   make_icon(int hIcon[]);
void   set_msgbox(int style, char *title="Message");
int    msgbox(LPSTR pform, ...);
void   print(int x, int y, LPSTR pform, ...);


//-----------------------------------------------------------------------------
// グローバル変数
//-----------------------------------------------------------------------------
SDot  g_dot;
UINT  g_White;
UINT  g_Blue;
UINT  g_Gray;
UINT  g_Black;
UINT  g_Yellow;
UINT  g_strColor;	// 関数 print の文字の色
UINT  g_bakColor;	// 関数 print の文字の背景色
UINT  g_msgStyle; 
char *g_msgTitle; 


//-----------------------------------------------------------------
// アイコン
//-----------------------------------------------------------------
char dot_e0[30][31]={
"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"b   b   b   b   b   b   b   b ",
"b   b   b   b   b   b   b   b ",
"b   b   b  gb   b   b   b   b ",
"bbbbbbbbbbbbggbbbbbbbbbbbbbbbb",
"b   b   b   bgggb   b   b   b ",
"b   b   b   b gggg  b   b   b ",
"b   b   b   b  gggggb   b   b ",
"bbbbbbbbbbbbbbbbggggggbbbbbbbb",
"b   b   b   b   bgggggggb   b ",
"b   b   b   b   b ggggggggg b ",
"b   b   b   b   b  gggg b   b ",
"bbbbbbbbbbbbbbbbbbbbgggbbbbbbb",
"b   b   b   b   b   bgg b   b ",
"b   b   b   b   b   b g b   b ",
"b   b ggggggg   b   b   b   b ",
"bbbbbbbbbgbbbbbbbbbbbbbbbbbbbb",
"b   g   bg  b g b   b   b   b ",
"b   g   bg  b g b   b   b   b ",
"b   g   b   b g b   b   b   b ",
"bbbbggggbbbggggbbbbbbbbbbbbbbb",
"b   g   b   b g b   b   b   b ",
"b   g   bg  b g b   b   b   b ",
"b   g   bg  b g b   b   b   b ",
"bbbbbbbbbgbbbbbbbbbbbbbbbbbbbb",
"b   b ggggggg   b   b   b   b ",
"b   b   b   b   b   b   b   b ",
"b   b   b   b   b   b   b   b ",
"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"b   b   b   b   b   b   b   b "
};

//------------------------------------------------------------------
char dot_e1[30][31]={
" w w  bb    w w w w w w w w w ",
"w      bbb                   w",
"        bbbb                  ",
"w        bbbbb               w",
"          bbbbbb              ",
"w          bbbbbbb           w",
"   gg       bbbbbbbb          ",
"w   ggg      bbbbbbbbb       w",
"     gggg     bbbbbbbbbb      ",
"w     ggggg    bbbbbbbbbbb   w",
"       gggggg   bbbbbbbbbbbb  ",
"        ggggggg  bbbbbbbbbbbbb",
"rr       gggggggg bbbbbb      ",
" rrr      gggggggggbbbbb      ",
"  rrrr     ggggggggggbbb     w",
"   rrrrr    gggggggggggb      ",
"w   rrrrrr   gggggggggggg     ",
"     rrrrrrr  ggggggggggggg  w",
"w     rrrrrrrr ggggggg        ",
"       rrrrrrrrrggggg         ",
"w       rrrrrrrrrrggg        w",
"         rrrrrrrrrrrg         ",
"w         rrrrrrrrrrrr        ",
"           rrrrrrrrrrrrr     w",
"w           rrrrrr            ",
"             rrrrr            ",
"w             rrrr           w",
"               rrr            ",
"w               rr           w",
" w w w w w w w   r  w w w w w "
};

//------------------------------------------------------------------
char dot_e2[30][31]={
"  b  b  b  b  b  b            ",
"  b  b  b  b  b  b            ",
"bbbbbbbbbbbbbbbbbbbb          ",
"  b  b  b  b  b  b            ",
"  b  b  b  b  b  b            ",
"bbbbbbbrbbrbbrbbrbbr  r       ",
"  b  b rb rb rb rb r  r       ",
"  b  rrrrrrrrrrrrrrrrrrrr     ",
"bbbbbbbrbbrbbrbbrbbr  r       ",
"  b  b rb rb rb rb r  r       ",
"  b  rrrrrrrgrrgrrgrrgrrg  g  ",
"bbbbbbbrbbrbgrbgrbgr gr g  g  ",
"  b  b rb gggggggggggggggggggg",
"  b  rrrrrrrgrrgrrgrrgrrg  g  ",
"bbbbbbbrbbrbgrbgrbgr gr g  g  ",
"  b  b rb gggggggggggggggggggg",
"  b  rrrrrrrgrrgrrgrrgrrg  g  ",
"bbbbbbbrbbrbgrbgrbgr gr g  g  ",
"  b  b rb gggggggggggggggggggg",
"  b  rrrrrrrgrrgrrgrrgrrg  g  ",
"       r  r gr gr gr gr g  g  ",
"       r  gggggggggggggggggggg",
"     rrrrrrrgrrgrrgrrgrrg  g  ",
"       r  r gr gr gr gr g  g  ",
"       r  gggggggggggggggggggg",
"            g  g  g  g  g  g  ",
"            g  g  g  g  g  g  ",
"          gggggggggggggggggggg",
"            g  g  g  g  g  g  ",
"            g  g  g  g  g  g  "
};

//------------------------------------------------------------------
char dot_e3[30][31]={
" wwwwwwwwwwwwwwwwwwwwwwwwwwww ",
"w                            w",
"w  gggggggggggggggggggggggg  w",
"w  gg ggggg  ggg   gg   ggg  w",
"w  gg gggg gg gg g gg gg gg  w",
"w  gg gggg gg g ggg g gg gg  w",
"w  gg gggg gg g     g gg gg  w",
"w  gg    gg  gg ggg g   ggg w ",
"w  gggggggggggggggggggggggg w ",
"w                            w",
"w                            w",
"w            wwww            w",
"w           w    w           w",
"w          w      w          w",
"w          w      w          w",
"w          w      w          w",
"w          w      w ww       w",
"w           w    w  ww       w",
"w            wwww            w",
"w                            w",
"w                            w",
"w             ww             w",
"w            w  w            w",
"w            w  w            w",
"w            w  w            w",
"w            w  w            w",
"w            w  w            w",
"w             ww             w",
"w                            w",
" wwwwwwwwwwwwwwwwwwwwwwwwwwww "
};

//------------------------------------------------------------------
char dot_e4[30][31]={
" w w w w w w w w w w          ",
"w                   w         ",
"   wwwwwwwwwwwwwww            ",
"w  ww w w w w w w w w w       ",
"   w                   w      ",
"w     wwwwwwwwwwwwwww         ",
"   w  ww w w w w w w w w w    ",
"w     w                   w   ",
"   w     wwwwwwwwwwwwwww      ",
"w     w  wwwwwwwwwwwwwwwwwwwww",
"   w     w                   w",
"w     w  w  wwwwwwwwwwwwwww  w",
"   w     w  wwwwwwwwwwwwwww  w",
"w     w  w  wwwwwwwwwwwwwww  w",
"   w     w                  w ",
"w     w  w                   w",
"   w     w        www        w",
"w     w  w       w   w       w",
"   w     w      w     w      w",
"w     w  w      w     w      w",
" w w     w      w     w ww   w",
"      w  w       w   w  ww   w",
"   w     w        www        w",
"    w w  w                   w",
"         w         w         w",
"      w  w        w w        w",
"       w w        w w        w",
"         w        w w        w",
"         w        w w        w",
"          wwwwwwwwwwwwwwwwwww "
};

//------------------------------------------------------------------
char dot_e5[30][31]={
" wwwwwwwwwwwwwwwwwwwwwwwwwwww ",
"w                            w",
"w  yyyyyyyyyyyyyyyyyyyyyyyy  w",
"w  yy    yy   yy yy y    yy  w",
"w  yy yyyy yyy y yy y yyyyy  w",
"w  yy    y     y yy y    yy  w",
"w  yyyyy y yyy y yy y yyyyy  w",
"w  yy    y yyy yy  yy    yy w ",
"w  yyyyyyyyyyyyyyyyyyyyyyyy w ",
"w                            w",
"w                            w",
"w            wwww            w",
"w           w    w           w",
"w          w      w          w",
"w          w      w          w",
"w          w      w          w",
"w          w      w ww       w",
"w           w    w  ww       w",
"w            wwww            w",
"w                            w",
"w                            w",
"w             ww             w",
"w            w  w            w",
"w            w  w            w",
"w            w  w            w",
"w            w  w            w",
"w            w  w            w",
"w             ww             w",
"w                            w",
" wwwwwwwwwwwwwwwwwwwwwwwwwwww "
};

//------------------------------------------------------------------
char dot_e6[30][31]={
" cccccccccccccccccccccccccccc ",
"cccccccccccccccccccccccccccccc",
"cccccccccccccccccccccccccccccc",
"cccccccccccccccccccccccccccccc",
"cccccccccccccccccccccccccccccc",
"cccccccccccccccccccccccccccccc",
"cccccccccc          cccccccccc",
"ccccccc                ccccccc",
"ccccc                    ccccc",
"cccc                      cccc",
"ccc                        ccc",
"cc                          cc",
"                              ",
"                              ",
"c                            c",
"cc                          cc",
"ccc                        ccc",
"cccc      cccccccccc      cccc",
"ccccc  cccccccccccccccc  ccccc",
"cccccccccccccccccccccc  cccccc",
"ccccccccccccccccccccc  ccccccc",
"cccccccccccccccccccc  cccccccc",
"cccccccccccccccccc   ccccccccc",
"ccccccccccccccccc   cccccccccc",
"cccccccccccccccc    cccccccccc",
"ccccccccccccccc    ccccccccccc",
"cccccccccccccc    cccccccccccc",
"ccccccccccccc    ccccccccccccc",
"cccccccccccc    cccccccccccccc",
" cccccccccc    cccccccccccccc "
};

//------------------------------------------------------------------
char dot_e7[30][31]={
"bbbbbbbbb  bb     bbbbbbbbbbbb",
"                              ",
"cccccccc   cc     cccccccccccc",
"ccccccccc  cc     cccccccccccc",
"cc     cc  cc     cc    cc    ",
"                              ",
"gggggggg   gg     gggggggggggg",
"ggggggggg  gg     gggggggggggg",
"gg     gg  gg     gg    gg    ",
"gg     gg  gg     gg          ",
"gg     gg  gg     gg          ",
"                              ",
"yyyyyyyy   yy     yyyyyyyyyyyy",
"yy     yy  yy     yyyyyyyyyyyy",
"yy      y  yy     yy    yy    ",
"yy      y  yy     yy    yy    ",
"yy      y  yy     yy    yy    ",
"yyyyyyyyy  yy     yy    yy    ",
"yyyyyyyy   yy     yy    yy    ",
"                              ",
"wwwwwwww   ww     wwwwwwwwwwww",
"wwwwwwww   ww     wwwwwwwwwwww",
"w       w  ww     ww    ww    ",
"w       w  ww     ww    ww    ",
"w       w  ww     ww    ww    ",
"wwwwwwwww  ww     ww    ww    ",
"wwwwwwww   ww     ww    ww    ",
"ww         ww     ww    ww    ",
"ww         wwwwwwwww    ww    ",
"ww          wwwwwww     ww    "
};

//------------------------------------------------------------------
char dot_e8[30][31]={
"      r r r r r r r r r r r r ",
"     r r r r r r r r r r r r r",
"      r r r r r r r r r r r r ",
"     r r r r r r r r r r r r r",
"      r r r r r r r r r r r r ",
"     r r r r r r r r r r r r r",
"      r r r r r r r r r r r r ",
"     r r r r r r r r r r r r r",
"bbbbb w w w w w w w w w w r r ",
"b   br r r r r r r r r r r r r",
"b   b r w r w r w r w r w r r ",
"b   br r r r r r r r r r r r r",
"bbbbb w w w w w w w w w w r r ",
"b   br r r r r r r r r r r r r",
"b   b r w r w r w r w r w r r ",
"b   br r r r r r r r r r r r r",
"bbbbb w w w w w w w w w w r r ",
"b   br r r r r r r r r r r r r",
"b   b r w r w r w r w r w r r ",
"b   br r r r r r r r r r r r r",
"bbbbb r w r w r w r w r w r r ",
"bbbbbbbbbbbbbbbbbbbbbbbbb     ",
"b   b   b   b   b   b   b     ",
"b   b   b   b   b   b   b     ",
"b   b   b   b   b   b   b     ",
"bbbbbbbbbbbbbbbbbbbbbbbbb     ",
"b   b   b   b   b   b   b     ",
"b   b   b   b   b   b   b     ",
"b   b   b   b   b   b   b     ",
"bbbbbbbbbbbbbbbbbbbbbbbbb     "
};

//------------------------------------------------------------------
char dot_e9[30][31]={
" wwwwwwwwwwwwwwwwwwwwwwwwwwww ",
"w                            w",
"w  rrrrrrrrrrrrrrrrrrrrrrrr  w",
"w  rrrwwwwrrwrrrrwwwwwwwwrr  w",
"w  rrwrrrrwrwrrrrwrrrwrrrrr  w",
"w  rrwrrrrwrwrrrrwrrrwrrrrr  w",
"w  rrwrrrrwrwrrrrwrrrwrrrrr  w",
"w  rrrwwwwrrrwwwwrrrrwrrrrr w ",
"w  rrrrrrrrrrrrrrrrrrrrrrrr w ",
"w                            w",
"w                            w",
"w            wwww            w",
"w           w    w           w",
"w          w      w          w",
"w          w      w          w",
"w          w      w          w",
"w          w      w ww       w",
"w           w    w  ww       w",
"w            wwww            w",
"w                            w",
"w                            w",
"w             ww             w",
"w            w  w            w",
"w            w  w            w",
"w            w  w            w",
"w            w  w            w",
"w            w  w            w",
"w             ww             w",
"w                            w",
" wwwwwwwwwwwwwwwwwwwwwwwwwwww "
};

//------------------------------------------------------------------
char dot_e10[30][31]={
"    wwwwwwwwwwwwwwwwwwwwww    ",
"   w                      w   ",
"   w  w w w w w w w w w   w   ",
"   w   w w w w w w w w    www ",
" www  w w w w w w w w w   w ww",
"ww w                     w w w",
"w ww                     ww ww",
"ww w                      ww w",
"w ww         wwww         w ww",
"ww w        w    w        ww w",
"w ww       w      w       w ww",
"ww w       w      w       ww w",
"wwwwwwwwwwwwwwwwwwwwwwwwwwwwww",
"wwwwwwwwwwwwwwwwwwwwwwwwwwwwww",
"wwwwwwwwwwwwwwwwwwwwwwwwwwwwww",
"wwwwwwwwwwwwwwwwwwwwwwwwwwwwww",
"wwrrrrrrrwwrrwwwwrrwwrrrrrwwww",
"wwrrrrrrrwwrrrwwwrrwwrrrrrrwww",
"wwrrwwwwwwwrrrwwwrrwwrrwwrrrww",
"wwrrwwwwwwwrrrrwwrrwwrrwwwrrww",
"wwrrwwwwwwwrrwrwwrrwwrrwwwrrww",
"wwrrrrrrrwwrrwrrwrrwwrrwwwrrww",
"wwrrrrrrrwwrrwwrwrrwwrrwwwrrww",
"wwrrwwwwwwwrrwwrrrrwwrrwwwrrww",
"wwrrwwwwwwwrrwwwrrrwwrrwwwrrww",
"wwrrwwwwwwwrrwwwrrrwwrrwwrrrww",
"wwrrrrrrrwwrrwwwrrrwwrrrrrrwww",
"wwrrrrrrrwwrrwwwwrrwwrrrrrwwww",
"wwwwwwwwwwwwwwwwwwwwwwwwwwwwww",
"wwwwwwwwwwwwwwwwwwwwwwwwwwwwww"
};

//------------------------------------------------------------------
char dot_e11[30][31]={
"         mmmmmmm              ",
"        mmmmmmm               ",
"       mmmmmmm                ",
"       mmmmmmm                ",
"       mmmmmmm                ",
"      wwwwwwwww               ",
"     w         w              ",
"     w         w              ",
"  wwwwwwwwwwwwwwwww           ",
" w   wmw           w          ",
" w   mwm           w          ",
" wwwwwmwwwwwwwwwwwww          ",
" wwwwmwmwwwwwwwwwwww          ",
" wmmmwmwmmmmmmmmmmmw          ",
" wmmmmwmmmmmmmmmmmmw          ",
" wmmmwmwmmmmmmmmmmmw          ",
" wmmmmwmmmmmmmmmmmmw          ",
" wmmmwmwmmmmmmmmmmmw          ",
" wmmmmwmmmmmmmmmmmmw          ",
" wmmmwmwmmmmmmmmmmmw          ",
" wmmmmwmmmmmmmmmmmmw          ",
" wwwwwwwwwwwwwwwwwww          ",
" wwwwwwwwwwwwwwwwwww          ",
"w    wmw            w         ",
"w    mwm            w         ",
"w    wmw            w         ",
"wwwwwmwmwwwwwwwwwwwww         ",
"w                   w         ",
"w                   w         ",
"wwwwwwwwwwwwwwwwwwwww         "
};

//------------------------------------------------------------------
char dot_e12[30][31]={
"                              ",
"                              ",
"   wwwwwwwwwwwwwww            ",
"   w             w            ",
"   w             w            ",
"   wwwwwwwwwwwwwww            ",
"     w         w              ",
"     w         w              ",
"  wwwwwwwwwwwwwwwww           ",
" w   wmw           w          ",
" w   mwm           w          ",
" wwwwwmwwwwwwwwwwwww          ",
" wwwwmwmwwwwwwwwwwww          ",
" wmmmwmwmmmmmmmmmmmw          ",
" wmmmmwmmmmmmmmmmmmw          ",
" wmmmwmwmmmmmmmmmmmw          ",
" wmmmmwmmmmmmmmmmmmw          ",
" wmmmwmwmmmmmmmmmmmw          ",
" wmmmmwmmmmmmmmmmmmw          ",
" wmmmwmwmmmmmmmmmmmw          ",
" wmmmmwmmmmmmmmmmmmw          ",
" wwwwwwwwwwwwwwwwwww          ",
" wwwwwwwwwwwwwwwwwww          ",
"w    wmw            w         ",
"w    mwm            w         ",
"w    wmw            w         ",
"wwwwwmwmwwwwwwwwwwwww         ",
"w                   w         ",
"w                   w         ",
"wwwwwwwwwwwwwwwwwwwww         "
};

//-----------------------------------------------------------------------------
// エントリーポイント
//-----------------------------------------------------------------------------
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
	UINT aColor[MAX_COLOR];		// ドット絵用のパレット
	int  hIcon[MAX_ICON];		// アイコンのグラフィックハンドル
	int  x, y;
	int  Mouse;
	
	ChangeWindowMode(TRUE);
	SetGraphMode( 800 , 600 , 32 ) ;
	if(DxLib_Init()==-1) {return -1;}
	ChangeFont( "MS ゴシック" ) ;
	SetFontSize( 16 ) ;
	SetFontThickness( 1 );				// 文字の太さを1ドットにする
	SetDrawScreen( DX_SCREEN_BACK ); 

	g_White    = GetColor(WHITE);
	g_Blue     = GetColor(BLUE);
	g_Gray     = GetColor(GRAY);
	g_Black    = GetColor(BLACK);
	g_Yellow   = GetColor(YELLOW);
	g_strColor = GetColor(WHITE);
	g_bakColor = GetColor(BLACK);
	
	g_dot.L_x   = 230+19*20;	// 左ボタン(L)の色のX座標
	g_dot.R_x   = 230;			// 右ボタン(R)の色のX座標
	g_dot.L_num = 19;			// 左ボタンの色(白)
	g_dot.R_num = 0;			// 右ボタンの色(黒)
	g_dot.L_color = g_White;
	g_dot.R_color = g_Black;
	g_dot.mesh_nColor = 16;		// メッシュの色(青)
	g_dot.eState = STATE_MAIN;

	set_msgbox(MB_YESNO);
	set_pallet(aColor);
	strcpy( &g_dot.alpha[0], " RGYBMCunscodrgybmcw"); // 変換用アルファベット
	make_icon(hIcon);				// アイコンを作成
	
	while( !ScreenFlip() && !ProcessMessage() /*&& !ClearDrawScreen()*/ )
	{
		Mouse = GetMouseInput();	// マウスの入力状態取得
		GetMousePoint( &x, &y );	// マウスの座標取得

		put_disp(aColor, hIcon);

		switch(g_dot.eState ) {
		case STATE_MAIN:		// メイン処理
			g_dot.eState = main_dot(x, y, Mouse, aColor);
			break;

		case STATE_MESH:		// メッシュの色を変更する
			g_dot.eState = put_mesh(aColor, hIcon);
			break;

		case STATE_PUT_ALPHA:	// アルファベットに変換して表示
			g_dot.eState = put_alpha(aColor, hIcon);
			break;

		case STATE_LOAD:		//
			//g_dot.eState = load(aColor);
			break;

		case STATE_SAVE:		// セーブ
			g_dot.eState = save(aColor);
			break;

		case STATE_CLEAR:		// 画面のクリア
			g_dot.eState = cls(aColor);
			break;

		case STATE_END:	//
			if(IDYES==msgbox("終了しますか?")){ goto end;}
			g_dot.eState = STATE_MAIN;
			break;
		}
		print(40, 32*16, "%d, %d  ", x, y);  // マウス座標を表示
	}
end:
	DxLib_End();
	return 0;
}

//-----------------------------------------------------------------------------
// メイン処理
//-----------------------------------------------------------------------------
EState main_dot(int x, int y, int Mouse, UINT aColor[])
{
	if( Mouse & MOUSE_INPUT_RIGHT ){	// マウスの右ボタンが押された

		if((x>=40 && x<640+40) && (y>=80 && y<430-30)){
			draw_dot(x, y, 2);				// ドット絵を描く
			return STATE_MAIN;				// ロード
		}
		if((x>225 && x<625) && (y>5 && y<40)){
			select_color(x, aColor, 2);		// 色を選択する
			return STATE_MAIN;				// ロード
		}
	}
	
	if( Mouse & MOUSE_INPUT_LEFT ){			// マウスの左ボタンが押された
		
		if((x>=40 && x<640+40) && (y>=80 && y<430-30)){
			draw_dot(x, y, 1);				// ドット絵を描く
			return STATE_MAIN;
		}
		if((x>225 && x<625) && (y>5 && y<40)){
			select_color(x, aColor, 1);		// 色を選択する
			return STATE_MAIN;				// ロード
		}
		if((x>8*2 && x<8*9) && (y>5 && y<35)){
			return STATE_MAIN;				// ロード
		}
		if((x>8*9 && x<8*19) && (y>5 && y<35)){
			return STATE_SAVE;				// セーブ
		}
		if((x>40*1 && x<40*2) && (y>16*28 && y<16*30)){
			return STATE_MAIN;				// マウスの形を変える
		}
		if((x>40*2 && x<40*3) && (y>16*28 && y<16*30)){
			return STATE_MAIN;				// マウスの色を変える
		}
		if((x>40*3 && x<40*4) && (y>16*28 && y<16*30)){
			return STATE_MESH;				// メッシュの色を変える
		}
		if((x>40*4 && x<40*5) && (y>16*28 && y<16*30)){
			return STATE_MAIN;				// 
		}
		if((x>40*5 && x<40*6) && (y>16*28 && y<16*30)){
			return STATE_MAIN;				// 
		}
		if((x>40*6 && x<40*7) && (y>16*28 && y<16*30)){
			return STATE_SAVE;				// セーブ
		}
		if((x>40*7 && x<40*8) && (y>16*28 && y<16*30)){
			return STATE_CLEAR;				// 消去
		}
		if((x>40*8 && x<40*9) && (y>16*28 && y<16*30)){
			return STATE_PUT_ALPHA;			// アルファベットに変換して表示する
		}
		if((x>40*9 && x<40*10) && (y>16*28 && y<16*30)){
			return STATE_MAIN;				// 
		}
		if((x>40*10 && x<40*11) && (y>16*28 && y<16*30)){
			return STATE_MAIN;				// 
		}
		if((x>40*11 && x<40*12) && (y>16*28 && y<16*30)){
			return STATE_END;				// 終了
		}
	}
	return STATE_MAIN;
}

//-----------------------------------------------------------------
// マウスによる色の選択
//-----------------------------------------------------------------
EState select_color(int x, UINT aColor[], int LR)
{
	int n;

	n = (x-225)/20;				// 選択色をセット
	x = n * 20 + 230;			// 座標を計算

	if(LR==1){						// 左ボタン
		g_dot.L_color = aColor[n];
		g_dot.L_x = x;				// x座標を保存
		g_dot.L_num = (UCHAR)n;		// 色の番号
	}
	else {							// 右ボタン
		g_dot.R_color = aColor[n];
		g_dot.R_x = x;				// x座標を保存 
		g_dot.R_num = (UCHAR)n;		// 色の番号
	}
	return STATE_MAIN;
}

//-----------------------------------------------------------------------------
// ドット絵の色データをアルファベットにして表示
//-----------------------------------------------------------------------------
EState put_alpha(UINT aColor[], int hIcon[])
{
	int   i, j;
	UCHAR n;
	
	ClearDrawScreen();
	DrawString(16*2, 16, "アルファベットに変換しました。", g_White);

	for(j=0; j<MESH_H ; j++){
		for(i=0; i<MESH_W ; i++){
			n = g_dot.masu[j][i];
			DrawFormatString(i*12+15, j*14+45, aColor[n], "%c", g_dot.alpha[n]);
		}
	}
	ScreenFlip();
	WaitKey();				// キー入力待ち
	ClearDrawScreen();
	put_dot(aColor);
	put_disp(aColor, hIcon);
	ScreenFlip();
	WaitTimer(200);
	
	return STATE_MAIN;
}

//-----------------------------------------------------------------------------
// メッシュの色を変える
//-----------------------------------------------------------------------------
EState put_mesh(UINT aColor[], int hIcon[])
{
	g_dot.mesh_nColor++;
	
	if(g_dot.mesh_nColor >= MAX_PALLET){
		g_dot.mesh_nColor = 0;
	}
	put_disp(aColor, hIcon);
	ScreenFlip();
	WaitTimer(200);
	
	return STATE_MAIN;
}

//-----------------------------------------------------------------------------
// 画像の消去
//-----------------------------------------------------------------------------
EState cls(UINT aColor[])
{
	int x, y;
	
	
	if(IDNO==msgbox("画像を消去しますか?")){
		return STATE_MAIN;
	}
	
	for(y=0 ; y<MESH_H ; y++)
		for(x=0; x<MESH_W ; x++){
			g_dot.masu[y][x] = 0 ;{	// 消去
		}
	}
	put_dot(aColor);				// 消去したのを表示
	ScreenFlip();
	WaitTimer(200);

	return STATE_MAIN;
}

//-----------------------------------------------------------------------------
// ファイルに保存
//-----------------------------------------------------------------------------
EState save(UINT aColor[])
{
	int  i, j, w, h;
	static int  HH=32, WW=32;
	
	ClearDrawScreen();

    DrawFormatString( 16 , 16 , g_White, "横ドット数 = %d (1~64)" ,  WW) ;
    w = KeyInputNumber( 16*13 , 16 , MESH_W , 1 , TRUE ) ;
	if (w==MESH_W+1) {	// [ESC]を押された場合
		ClearDrawScreen(); put_dot(aColor); 
		return STATE_MAIN; 
	}
	else { WW=w; }

    DrawFormatString( 16 , 16*3 , g_White, "縦ドット数 = %d (1~32)",  HH) ;
    h = KeyInputNumber( 16*13 , 16*3 , MESH_H , 1 , TRUE ) ;
	if (h==MESH_H+1) {	// [ESC]を押された場合
		ClearDrawScreen(); put_dot(aColor);
		return STATE_MAIN;
	}
	else { HH=h; }
	
	for(j=0; j<h ; j++){
		for(i=0; i<w ; i++){
			g_dot.moji[j][i+1] = g_dot.alpha[g_dot.masu[j][i]];
		}
		g_dot.moji[j][  0]='"';
		g_dot.moji[j][w+1]='"';
		g_dot.moji[j][w+2]=',';
		g_dot.moji[j][w+3]='\n';
		g_dot.moji[j][w+4]='\0';
	}
	g_dot.moji[j-1][w+2]='\0';

	FILE *p = fopen("ドット絵.txt", "a");
	char szW[128];
	char szH[128];
	char str[256];

	memset(str, 0, 256);
	w++;					// NULL文字用に1個増やす
	itoa(h, szH, 10);		// 配列の要素数
	itoa(w, szW, 10);		// 配列の要素数
	
	strcat(str, "char dot_e[" );
	strcat(str, szH);
	strcat(str, "][");
	strcat(str, szW);
	strcat(str, "]={\n");

	fputs("//------------------------------------------------------------------\n", p);
	fputs(str, p);
	for(i=0; i<h ; i++){
		fputs(&g_dot.moji[i][0], p);
	}
	fputs("\n};\n\n", p);
	
	fclose(p);

    DrawString( 16 , 16*5 , "ドット絵.txt に保存しました。" , g_Yellow ) ;
	ScreenFlip();
	
	WaitKey();
	ClearDrawScreen();
	put_dot(aColor);
	WaitTimer(200);
	
	return STATE_MAIN;
}

//-----------------------------------------------------------------
// ドット絵用のパレットにスタティックカラーをセット
//-----------------------------------------------------------------
void set_pallet(UINT aColor[])
{
	aColor[ 0] = GetColor(BLACK);
	aColor[ 1] = GetColor(D_RED);
	aColor[ 2] = GetColor(D_GREEN);
	aColor[ 3] = GetColor(D_YELLOW);
	aColor[ 4] = GetColor(D_BLUE);
	aColor[ 5] = GetColor(D_MAGENTA);
	aColor[ 6] = GetColor(D_CYAN);
	aColor[ 7] = GetColor(GRAY);
	aColor[ 8] = GetColor(M_GREEN);
	aColor[ 9] = GetColor(S_BLUE);

	aColor[10] = GetColor(CREAM);
	aColor[11] = GetColor(M_GRAY);
	aColor[12] = GetColor(D_GRAY);
	aColor[13] = GetColor(RED);
	aColor[14] = GetColor(GREEN);
	aColor[15] = GetColor(YELLOW);
	aColor[16] = GetColor(BLUE);
	aColor[17] = GetColor(MAGENTA);
	aColor[18] = GetColor(CYAN);
	aColor[19] = GetColor(WHITE);

	aColor[20] = GetColor(MD_RED);
	aColor[21] = GetColor(MD_GREEN);
	aColor[22] = GetColor(MD_YELLOW);
	aColor[23] = GetColor(MD_BLUE);
	aColor[24] = GetColor(MD_MAGENTA);
	aColor[25] = GetColor(MD_CYAN);
	aColor[26] = GetColor(L_BLUE);
}

//-----------------------------------------------------------------------------
// ドット絵用のパレットを表示
//-----------------------------------------------------------------------------
void put_pallet(UINT aColor[])
{
	for(int i=0 ; i<MAX_PALLET ; i++){
		DrawBox(224+(20*i), 7, 243+(20*i), 41, aColor[i], TRUE);	// 色を表示
	}
	DrawBox(222, 5, 245+(20*19), 43, g_Gray, FALSE);			// 色の枠

	// 色選択時、左ボタン(L)か、右ボタン(R)かを表示
	DrawBox(g_dot.L_x-1, 14, g_dot.L_x+8, 14+16, g_White, TRUE);
	DrawBox(g_dot.R_x-1, 14, g_dot.R_x+8, 14+16, g_White, TRUE);
	DrawString(g_dot.L_x, 14, "L", g_Black);
	DrawString(g_dot.R_x, 14, "R", g_Black);
}

//-----------------------------------------------------------------------------
// ドット絵の表示
//-----------------------------------------------------------------------------
void put_dot(UINT aColor[])
{
	int x, y;
	
	for(y=0; y<MESH_H ; y++){
		for(x=0; x<MESH_W ; x++){
			DrawBox(x*10+40+1, y*10+80+1, x*10+40+10, y*10+80+10, aColor[g_dot.masu[y][x]], TRUE);	// マスを塗る
		}
	}
	
	for(y=0; y<MESH_H ; y++){
		for(x=0; x<MESH_W ; x++){
			DrawPixel(x+148+4, y+8, aColor[g_dot.masu[y][x]]);  // 実寸で表示
		}
	}
}

//-----------------------------------------------------------------
// ディスプレイ画面
//-----------------------------------------------------------------
void put_disp(UINT aColor[], int hIcon[])
{
	int  x2, y2;

	DrawBox(8*2, 5, 140, 35, g_Gray, FALSE);		// メニュー枠を表示
	DrawString(8*4, 12, "読込   保存", g_White);	// メニューを表示

	//DrawBox(150, 5, 213, 45, g_Gray, FALSE);	// 実寸用の枠を表示

	put_pallet(aColor);		// パレットを表示
	put_icon(hIcon);		// アイコンを表示

	//------ メッシュ(縦と横の線)----------------

	for(y2=80 ; y2<=420-20 ; y2+=10){				// 10ドット単位の横線
		DrawLine(40, y2, 640+40, y2, aColor[g_dot.mesh_nColor]);
	}
	for(y2=80 ; y2<=430-20 ; y2+=50){				// 50ドット単位の横線
		DrawLine(30, y2, 650+40, y2, aColor[g_dot.mesh_nColor]);
	}

	for(x2=40 ; x2<=640+40 ; x2+=10){				// 10ドット単位の縦線
		DrawLine(x2, 80, x2, 430-30, aColor[g_dot.mesh_nColor]);
	}
	for(x2=40 ; x2<=640+40 ; x2+=50){				// 50ドット単位の縦線
		DrawLine(x2, 70, x2, 440-30, aColor[g_dot.mesh_nColor]);
	}

	for(x2=35; x2<=640 ; x2+=100){
		DrawFormatString(x2, 50, g_White, "%d", x2/10-3);	// 横ドット数を表示
	}
	for(y2=70; y2<=430 ; y2+=100){
		DrawFormatString(10, y2, g_White , "%d", y2/10-7);	// 縦ドット数を表示
	}
}

//-----------------------------------------------------------------------------
// マスを塗る(ドット絵作成)
//-----------------------------------------------------------------------------
void draw_dot(int x,int y, int LR)
{
	int  mx, my;

	mx = x/10;			// 配列に入れるため。
	my = y/10;
	x  = x/10*10;		// 10ドット単位にするため端数を切り捨てる
	y  = y/10*10;

	if(LR==1){	// 左ボタン
		DrawBox(x+1, y+1, x+10, y+10, g_dot.L_color, TRUE);	// マスを塗る
		DrawPixel(mx+148, my, g_dot.L_color);
		g_dot.masu[my-8][mx-4] = g_dot.L_num;
	}
	else {		// 右ボタン
		DrawBox(x+1, y+1, x+10, y+10, g_dot.R_color, TRUE);	// マスを塗る
		DrawPixel(mx+148, my, g_dot.R_color);
		g_dot.masu[my-8][mx-4] = g_dot.R_num;
	}
	print(8*6, 16*26, "(%2d,%2d)", mx-3, my-7);	// マスの座標を表示
}

//-----------------------------------------------------------------------------
// アイコンを表示
//-----------------------------------------------------------------------------
void put_icon(int hIcon[])
{
	DrawGraph( 40*1,  16*28, hIcon[0],  FALSE );
	DrawGraph( 40*2,  16*28, hIcon[1],  FALSE );
	DrawGraph( 40*3,  16*28, hIcon[2],  FALSE );
	DrawGraph( 40*4,  16*28, hIcon[3],  FALSE );
	DrawGraph( 40*5,  16*28, hIcon[4],  FALSE );
	DrawGraph( 40*6,  16*28, hIcon[5],  FALSE );
	DrawGraph( 40*7,  16*28, hIcon[6],  FALSE );
	DrawGraph( 40*8,  16*28, hIcon[7],  FALSE );
	DrawGraph( 40*9,  16*28, hIcon[8],  FALSE );
	DrawGraph( 40*10, 16*28, hIcon[9],  FALSE );
	DrawGraph( 40*11, 16*28, hIcon[10], FALSE );
	DrawGraph( 40*12, 16*28, hIcon[11], FALSE );
}

//-----------------------------------------------------------------------------
// アイコンを作る
//-----------------------------------------------------------------------------
void make_icon(int hIcon[])
{
	int hImg;			// パレット画像のハンドル

	hImg = MakePAL8ColorSoftImage( 30, 30 * MAX_ICON );// 空のパレット画像を作成する
	set_iconPallet(hImg);	// パレットに色をセットする

	//アイコンのドット絵を描く
	make_iconDot(hImg, dot_e0,  0);
	make_iconDot(hImg, dot_e1,  1);
	make_iconDot(hImg, dot_e2,  2);
	make_iconDot(hImg, dot_e3,  3);
	make_iconDot(hImg, dot_e4,  4);
	make_iconDot(hImg, dot_e5,  5);
	make_iconDot(hImg, dot_e6,  6);
	make_iconDot(hImg, dot_e7,  7);
	make_iconDot(hImg, dot_e8,  8);
	make_iconDot(hImg, dot_e9,  9);
	make_iconDot(hImg, dot_e10, 10);
	make_iconDot(hImg, dot_e11, 11);
	make_iconDot(hImg, dot_e12, 12);

	// 分割読み込み
	CreateDivGraphFromSoftImage(hImg, MAX_ICON, 1, MAX_ICON, 30, 30, hIcon);
	DeleteSoftImage( hImg ) ;	// 使い終わったら解放
}

//-----------------------------------------------------------------------------
// アイコンを描く
//-----------------------------------------------------------------------------
void make_iconDot(int hImg, char (*img)[31], int num)
{
	int x, y, y2, color; 

	for(y2=0, y=30*num ; y<30*num+30 ; y++, y2++){
		for(x=0; x<30 ; x++){
			color=0;
			if(img[y2][x] == ' ') { color =  0; }
			if(img[y2][x] == 'R') { color =  1; }
			if(img[y2][x] == 'G') { color =  2; }
			if(img[y2][x] == 'Y') { color =  3; }
			if(img[y2][x] == 'B') { color =  4; }
			if(img[y2][x] == 'M') { color =  5; }
			if(img[y2][x] == 'C') { color =  6; }
			if(img[y2][x] == 'u') { color =  7; }
			if(img[y2][x] == 'n') { color =  8; }
			if(img[y2][x] == 's') { color =  9; }
			if(img[y2][x] == 'c') { color = 10; }
			if(img[y2][x] == 'o') { color = 11; }
			if(img[y2][x] == 'd') { color = 12; }
			if(img[y2][x] == 'r') { color = 13; }
			if(img[y2][x] == 'g') { color = 14; }
			if(img[y2][x] == 'y') { color = 15; }
			if(img[y2][x] == 'b') { color = 16; }
			if(img[y2][x] == 'm') { color = 17; }
			if(img[y2][x] == 'c') { color = 18; }
			if(img[y2][x] == 'w') { color = 19; }

			DrawPixelPalCodeSoftImage( hImg, x, y, color ) ;
		}
	}
}

//-----------------------------------------------------------------------------
// アイコン用のパレットに色をセットする
//-----------------------------------------------------------------------------
void set_iconPallet(int &hImg)
{
	SetPaletteSoftImage( hImg,  0, BLACK,     0 ) ;
	SetPaletteSoftImage( hImg,  1, D_RED,     0 ) ;
	SetPaletteSoftImage( hImg,  2, D_GREEN,   0 ) ;
	SetPaletteSoftImage( hImg,  3, D_YELLOW,  0 ) ;
	SetPaletteSoftImage( hImg,  4, D_BLUE,    0 ) ;
	SetPaletteSoftImage( hImg,  5, D_MAGENTA, 0 ) ;
	SetPaletteSoftImage( hImg,  6, D_CYAN,    0 ) ;
	SetPaletteSoftImage( hImg,  7, GRAY,      0 ) ;
	SetPaletteSoftImage( hImg,  8, M_GREEN,   0 ) ;
	SetPaletteSoftImage( hImg,  9, S_BLUE,    0 ) ;

	SetPaletteSoftImage( hImg, 10, CREAM,     0 ) ;
	SetPaletteSoftImage( hImg, 11, M_GRAY,    0 ) ;
	SetPaletteSoftImage( hImg, 12, D_GRAY,    0 ) ;
	SetPaletteSoftImage( hImg, 13, RED,       0 ) ;
	SetPaletteSoftImage( hImg, 14, GREEN,     0 ) ;
	SetPaletteSoftImage( hImg, 15, YELLOW,    0 ) ;
	SetPaletteSoftImage( hImg, 16, BLUE,      0 ) ;
	SetPaletteSoftImage( hImg, 17, MAGENTA,   0 ) ;
	SetPaletteSoftImage( hImg, 18, CYAN,      0 ) ;
	SetPaletteSoftImage( hImg, 19, WHITE,     0 ) ;
}

//-----------------------------------------------------------------
//  書式付きメッセージボックス
//-----------------------------------------------------------------
int msgbox(LPSTR pform, ...)
{
	va_list	bp;
	char	msg[256];

	va_start(bp, pform);
	vsprintf(msg, pform, bp);
	va_end(bp);

    return MessageBox(NULL, msg, g_msgTitle, g_msgStyle);
}

//-----------------------------------------------------------------
//  メッセージボックスのスタイルとタイトルをセットする
//-----------------------------------------------------------------
void set_msgbox(int style, char *title)
{
	g_msgStyle = style;
	g_msgTitle = title;
}

//-----------------------------------------------------------------
//  書式付き文字出力
//-----------------------------------------------------------------
void print(int x, int y, LPSTR pform, ...)
{
	va_list	bp;
	char	str[256];
	int		len;

	va_start(bp, pform);
	len = vsprintf(str, pform, bp);
	va_end(bp);

	DrawBox(x, y, x+len*8, y+16, g_bakColor, TRUE);
	DrawString(x, y, str, g_strColor);
}

どぶろく
記事: 75
登録日時: 11年前

Re: ぷるぷるプログラミング

#18

投稿記事 by どぶろく » 6年前

それにしても誰も参加してこないなぁ。
自己紹介と雑談のトピックでも作ろうかな。

ドット絵エディタの方は、まだ、保存したデータを読み込むことは出来てません。
考えとしては、ファイルを読み込んで、メモリ上であれこれするんですね。
そもそも、追加書き込みしてるのがヤバイのかなぁ?
まぁ、明後日の日曜日にでも考えようっと。

話は変わるが前回アップしたドット絵エディタの若干の訂正箇所を発見しました。
WinMain内で初期化している変換用アルファベットの中に小文字の c が2つ入っていました。

コード:

strcpy( &g_dot.alpha[0], " RGYBMCunscodrgybmcw"); // 変換用アルファベット
これを下のように訂正します。

コード:

strcpy( &g_dot.alpha[0], " RGYBMCunstodrgybmcw"); // 変換用アルファベット
最初に出てくる c を t にしただけ。

また、

コード:

//-----------------------------------------------------------------------------
// アイコンを描く
//-----------------------------------------------------------------------------
void make_iconDot(int hImg, char (*img)[31], int num)
{
    int x, y, y2, color; 
 
    for(y2=0, y=30*num ; y<30*num+30 ; y++, y2++){
        for(x=0; x<30 ; x++){
            color=0;
            if(img[y2][x] == ' ') { color =  0; }
            if(img[y2][x] == 'R') { color =  1; }
            if(img[y2][x] == 'G') { color =  2; }
            if(img[y2][x] == 'Y') { color =  3; }
            if(img[y2][x] == 'B') { color =  4; }
            if(img[y2][x] == 'M') { color =  5; }
            if(img[y2][x] == 'C') { color =  6; }
            if(img[y2][x] == 'u') { color =  7; }
            if(img[y2][x] == 'n') { color =  8; }
            if(img[y2][x] == 's') { color =  9; }
            if(img[y2][x] == 'c') { color = 10; }
            if(img[y2][x] == 'o') { color = 11; }
            if(img[y2][x] == 'd') { color = 12; }
            if(img[y2][x] == 'r') { color = 13; }
            if(img[y2][x] == 'g') { color = 14; }
            if(img[y2][x] == 'y') { color = 15; }
            if(img[y2][x] == 'b') { color = 16; }
            if(img[y2][x] == 'm') { color = 17; }
            if(img[y2][x] == 'c') { color = 18; }
            if(img[y2][x] == 'w') { color = 19; }
 
            DrawPixelPalCodeSoftImage( hImg, x, y, color ) ;
        }
    }
}
を以下のように訂正します。
これにより、変換用アルファベットのデータをそのまま使うことになり、いちいち変更する手間が省けます。

コード:

//-----------------------------------------------------------------------------
// アイコンを描く
//-----------------------------------------------------------------------------
void make_iconDot(int hImg, char (*img)[31], int num)
{
	int i, x, y, y2, color; 

	for(y2=0, y=30*num ; y<30*num+30 ; y++, y2++){
		for(x=0; x<30 ; x++){
			color=0;
			for(i=0 ; i<MAX_PALLET; i++){
				if(img[y2][x] == g_dot.alpha[i]){	// 同じアルファベットなら
					color = i;
					break;
				}
			}
			DrawPixelPalCodeSoftImage( hImg, x, y, color ) ;
		}
	}
}

どぶろく
記事: 75
登録日時: 11年前

Re: ぷるぷるプログラミング

#19

投稿記事 by どぶろく » 6年前

現在、このコミュに参加しやすいように

<自己紹介>
<投稿作品(ソース公開)>
<雑談>

のトピを作成中です(トピの説明の文章を作成中)。

ドット絵エディタの進行状況は、仕事が忙しくて、
保存したドット絵を読み込む作業がまだ出来ないよぉ(o>ω<o)
ところで、ちょっと手直しするところを発見?したので手直し又は関数を追加してみました。
変換用アルファベットをセットする関数を追加しましたよ。
アルファベットが重複するかもしれなのでチェックするようにしました。

WinMainの中で

strcpy( &g_dot.alpha[0], " RGYBMCunstodrgybmcw");

としていたのを、

set_alpha(" RGYBMCunstodrgybmcw");

としました。

コード:

//-----------------------------------------------------------------------------
// 変換用アルファベットをセットする
//-----------------------------------------------------------------------------
void set_alpha(PSTR alpha)
{
	int  i, j;
	char ch;
	
	for(i=0 ; i<MAX_PALLET; i++){
		ch = alpha[i];
		for(j=0 ; j < MAX_PALLET ; j++){
			if((ch == alpha[j]) && (i != j)){
				msgbox("\"%s\"\n変換用アルファベットの \n%d 文字目と %d 文字目の %c が重複してます。", alpha, i+1, j+1, ch);
				goto label;
			}
		}
	}
label:
	strcpy( &g_dot.alpha[0], alpha);
}
また、関数 set_print を追加して、文字色と背景色をセットするようにしました。
それから print と、msgbox で使うグローバル変数を m_で始まるように変更しました。

コード:

//-----------------------------------------------------------------------------
// グローバル変数
//-----------------------------------------------------------------------------
UINT  m_strColor;	// 関数 print の文字の色
UINT  m_bakColor;	// 関数 print の文字の背景色
UINT  m_msgStyle;	// メッセージボックスのスタイル
PSTR  m_msgTitle;	// メッセージボックスのタイトル(デフォルトは "Message")

//-----------------------------------------------------------------------------
// メッセージボックスのスタイルとタイトルをセットする
//-----------------------------------------------------------------------------
void set_msgbox(UINT style, PSTR title)
{
	m_msgStyle = style;
	m_msgTitle = title;
}

//-----------------------------------------------------------------------------
// 書式付きメッセージボックス
//-----------------------------------------------------------------------------
int msgbox(PSTR pform, ...)
{
	va_list	bp;
	char	msg[256];

	va_start(bp, pform);
	vsprintf(msg, pform, bp);
	va_end(bp);

    return MessageBox(NULL, msg, m_msgTitle, m_msgStyle);
}

//-----------------------------------------------------------------------------
// 関数 print の文字色と背景色をセットする
//-----------------------------------------------------------------------------
void set_print(UINT c1, UINT c2)
{
	m_strColor = c1;
	m_bakColor = c2;
}

//-----------------------------------------------------------------------------
// 書式付き文字出力
//-----------------------------------------------------------------------------
void print(int x, int y, PSTR pform, ...)
{
	va_list	bp;
	char	str[256];
	int		len;

	va_start(bp, pform);
	len = vsprintf(str, pform, bp);
	va_end(bp);

	DrawBox(x, y, x+len*8, y+16, m_bakColor, TRUE);
	DrawString(x, y, str, m_strColor);
}

どぶろく
記事: 75
登録日時: 11年前

Re: ぷるぷるプログラミング

#20

投稿記事 by どぶろく » 6年前

今日は牡蠣などを運ぶ仕事で5時30分に出勤し、埼玉県まで行ってきたぜ、片道4時間30分、往復9時間じゃん。
ほとんど車の中なので、めっちゃ疲れたわい。ちなみに私の仕事は運送業じゃないよ。
そして、またもや訂正箇所を発見してしまったわい。スペル間違いでした。

コード:

#define MAX_PALLET   20
じゃなく

コード:

#define MAX_PALETTE   20
でした。しかし、PALETTE より PALLET の方が良くね?フランス語?すべて置き換えてくださいね。
あと、ドット絵を保存する関数が早くも理解不能になりました。
自分で書いたソースなのに読めないのだ(老眼に関係なく)。記憶力の低下・・・
コメントを追加して解かりやすくしました。
ファイルポインタも、ただの p から pFile にしました。

コード:

//-----------------------------------------------------------------------------
// ファイルに保存
//-----------------------------------------------------------------------------
EState save(UINT aColor[])
{
	static int  HH=32, WW=32;	// 指定した縦横のドット数を保存
	char szW[128];		// 横ドット数(文字に変換)
	char szH[128];		// 縦ドット数(文字に変換)
	char str[256];		// 書き出す文字列
	FILE *pFile;		// ファイルポインタ
	int  i, j, w, h;
	
	memset(str, 0, 256);
	ClearDrawScreen();

	//---------------------------------------
	// 横と縦のドット数を入力する
	//---------------------------------------
    DrawFormatString( 16 , 16 , g_White, "横ドット数 = %d (1~64)" ,  WW) ;
    w = KeyInputNumber( 16*13 , 16 , MESH_W , 1 , TRUE ) ;
	if ( w == MESH_W+1) {	// [ESC]を押された場合
		ClearDrawScreen(); put_dot(aColor); 
		return STATE_MAIN; 
	}
	else { WW=w; }

    DrawFormatString( 16 , 16*3 , g_White, "縦ドット数 = %d (1~32)",  HH) ;
    h = KeyInputNumber( 16*13 , 16*3 , MESH_H , 1 , TRUE ) ;
	if ( h == MESH_H+1) {	// [ESC]を押された場合
		ClearDrawScreen(); put_dot(aColor);
		return STATE_MAIN;
	}
	else { HH=h; }
	
	//---------------------------------------
	// 保存するアルファベットのデータを作成
	//---------------------------------------
	for(j=0; j<h ; j++){
		for(i=0; i<w ; i++){
			g_dot.moji[j][i+1] = g_dot.alpha[g_dot.masu[j][i]];
		}
		g_dot.moji[j][  0]='"';
		g_dot.moji[j][w+1]='"';
		g_dot.moji[j][w+2]=',';
		g_dot.moji[j][w+3]='\n';
		g_dot.moji[j][w+4]='\0';
	}
	g_dot.moji[j-1][w+2]='\0';		// 最後の , を \0 にする。

	//---------------------------------------
	// ファイルに書き出す
	//---------------------------------------
	pFile = fopen("ドット絵.txt", "a");

	w++;					// 配列の横の要素数(ドット数)を+1する(文字列の最後にヌル文字が入るので)
	itoa(w, szW, 10);		// 配列の横の要素数(ドット数)を文字に変換
	itoa(h, szH, 10);		// 配列の縦の要素数(ドット数)を文字に変換
	
	strcat(str, "char dot_e[" );
	strcat(str, szH);
	strcat(str, "][");
	strcat(str, szW);
	strcat(str, "]={\n");

	fputs("//------------------------------------------------------------------\n", pFile);
	fputs(str, pFile);
	for(i=0; i<h ; i++){
		fputs(&g_dot.moji[i][0], pFile);	// アルファベットのデータをファイルに書き出す
	}
	fputs("\n};\n\n", pFile);
	
	fclose(pFile);

    DrawString( 16 , 16*5 , "ドット絵.txt に保存しました。" , g_Yellow ) ;
	ScreenFlip();
	WaitKey();			// キー入力待ち
	ClearDrawScreen();
	put_dot(aColor);
	WaitTimer(200);
	
	return STATE_MAIN;
}
char szW[128]; // 横ドット数(文字に変換)
char szH[128]; // 縦ドット数(文字に変換)
char str[256]; // 書き出す文字列

って要素が多すぎじゃね?(一人つっこみ)

どぶろく
記事: 75
登録日時: 11年前

Re: ぷるぷるプログラミング

#21

投稿記事 by どぶろく » 5年前

やっと、セーブとロードが出来るようになりました。
ファイルオープンダイアログを使った、でけ~。
関数が増えてきたので分割コンパイルすることにしました。

コード:

//-----------------------------------------------------------------------------
//	f00_comsub.cpp
//
//	共通関数
//
//-----------------------------------------------------------------------------
#include "DxLib.h"
#include <stdio.h>

//-----------------------------------------------------------------------------
// ファイル内グローバル変数
//-----------------------------------------------------------------------------
static UINT m_strColor;	// 関数 print の文字の色
static UINT m_bakColor;	// 関数 print の文字の背景色
static UINT m_msgStyle;	// メッセージボックスのスタイル
static PSTR m_msgTitle;	// メッセージボックスのタイトル(デフォルトは "Message")

//-----------------------------------------------------------------------------
// メッセージボックスのスタイルとタイトルをセットする
//-----------------------------------------------------------------------------
void f00_setMsgbox(UINT style, PSTR title)
{
	m_msgStyle = style;
	m_msgTitle = title;
}

//-----------------------------------------------------------------------------
// 書式付きメッセージボックス
//-----------------------------------------------------------------------------
int f00_msgbox(PSTR pform, ...)
{
	va_list	bp;
	char	msg[256];

	va_start(bp, pform);
	vsprintf(msg, pform, bp);
	va_end(bp);

    return MessageBox(NULL, msg, m_msgTitle, m_msgStyle);
}

//-----------------------------------------------------------------------------
// 関数 print の文字色と背景色をセットする
//-----------------------------------------------------------------------------
void f00_setPrint(UINT c1, UINT c2)
{
	m_strColor = c1;
	m_bakColor = c2;
}

//-----------------------------------------------------------------------------
// 書式付き文字出力
//-----------------------------------------------------------------------------
void f00_print(int x, int y, PSTR pform, ...)
{
	va_list	bp;
	char	str[256];
	int		len;

	va_start(bp, pform);
	len = vsprintf(str, pform, bp);
	va_end(bp);

	DrawBox(x, y, x+len*8, y+16, m_bakColor, TRUE);
	DrawString(x, y, str, m_strColor);
}

コード:

//-----------------------------------------------------------------------------
//	f00_main.h
//
//	定数
//
//-----------------------------------------------------------------------------
#ifndef INCLUDE_main_h
#define INCLUDE_main_h

#define DD_GRAY     85, 85, 85    // 暗い灰色         -1
#define BLACK        0,  0,  0    // 黒                0
#define D_RED      128,  0,  0    // 暗い赤            1
#define D_GREEN      0,128,  0    // 暗い緑            2
#define D_YELLOW   128,128,  0    // 暗い黄色(深黄色)3
#define D_BLUE       0,  0,128    // 暗い青            4
#define D_MAGENTA  128,  0,128    // 暗いマゼンタ      5
#define D_CYAN       0,128,128    // 暗いシアン        6

#define MD_RED     191,  0,  0    // やや暗い赤             _1
#define MD_GREEN     0,191,  0    // やや暗い緑             _2
#define MD_YELLOW  191,191,  0    // やや暗い黄色(黄銅色) _3
#define MD_BLUE      0,  0,191    // やや暗い青             _4
#define MD_MAGENTA 191,  0,191    // やや暗いマゼンタ       _5
#define MD_CYAN      0,191,191    // やや暗いシアン         _6

#define GRAY       192,192,192    // 明るい灰色              7
#define M_GREEN    192,220,192    // マネーグリーン          8
#define S_BLUE     166,202,240    // スカイブルー            9

//#define CREAM      255,251,240    // クリーム(淡黄色)      246
#define CREAM      255,251,200    // クリーム(淡黄色)      246
#define M_GRAY     160,160,164    // ミディアムグレー        247
#define D_GRAY     128,128,128    // 暗い灰色                248
#define RED        255,  0,  0    // 明るい赤                249
#define GREEN        0,255,  0    // 明るい緑                250
#define YELLOW     255,255,  0    // 明るい黄色              251
#define BLUE         0,  0,255    // 明るい青                252
#define MAGENTA    255,  0,255    // マゼンタ(紫:淡紅色)  253
#define CYAN         0,255,255    // シアン(水色:輝淡青色)254
#define WHITE      255,255,255    // 白(最大輝度白色光)    255
#define L_BLUE      0,150,255     // ライトブルー

#define SCREEN_W		800
#define SCREEN_H		600
#define MESH_W			64
#define MESH_H			34
#define MAX_COLOR		256
#define MAX_PALETTE		20
#define MAX_ICON		13
#define STR_TITLE 		"ドット絵いいね!"

//-----------------------------------------------------------------------------
// 定数(遷移用)
//-----------------------------------------------------------------------------
enum EState {
	STATE_MAIN,
	STATE_PUT_ALPHA,
	STATE_LOAD,
	STATE_SAVE,
	STATE_MESH,
	STATE_CLEAR,
	STATE_END
};

//-----------------------------------------------------------------------------
// メイン構造体
//-----------------------------------------------------------------------------
struct SDot{
	int    L_x;			// 左ボタンで選択した色に L を付けるため
	int    R_x;			// 右ボタンで選択した色に R を付けるため
	UINT   L_color;		// 左ボタンで選択した色
	UINT   R_color;		// 右ボタンで選択した色
	UINT   mesh_nColor;	// メッシュの色
	BYTE   L_num;		// 左ボタンで選択した色番号
	BYTE   R_num;		// 右ボタンで選択した色番号
	BYTE   masu[MESH_H][MESH_W];	// 色データを格納(色番号)
	char   moji[MESH_H][MESH_W+5];	// 変換したアルファベットを格納
	char   alpha[MAX_COLOR+1];		// 変換するアルファベット
	EState eState;					// 遷移用
};

#endif

コード:

//-----------------------------------------------------------------
//	f00_mainProt.h
//
//	プロトタイプ宣言
//
//-----------------------------------------------------------------
#ifndef INCLUDE_main_prot_h
#define INCLUDE_main_prot_h

//--- f01_main.cpp ------------------------------
EState main_dot(int x, int y, int Mouse, UINT aColor[], int hIcon[]);// メイン処理
EState select_color(int x, UINT aColor[], int LR);// マウスによる色の選択
EState put_alpha(UINT aColor[]);	  // ドット絵の色データをアルファベットにして表示
EState put_mesh(UINT aColor[], int hIcon[]);	  // メッシュの色を変える
EState f01_clsDot(void);			// 画像の消去(ワイパーのアイコン)
void   f01_cls(void);				// 画像の消去
int    ini_main(UINT aColor[], int hIcon[]);	// 初期化
void   draw_dot(int x, int y, int LR);	// マスを塗る(ドット絵作成)
void   set_alpha(PSTR pString );		// 変換用アルファベットのセット
void   set_palette(UINT aColor[]);	// ドット絵用のパレットにスタティックカラーをセット
void   put_palette(UINT aColor[]);	// ドット絵用のパレットを表示
void   f01_putDot(UINT aColor[]);		// ドット絵の表示
void   put_disp(UINT aColor[], int hIcon[]);// ディスプレイ画面

#endif

コード:

//-----------------------------------------------------------------------------
//	f00_main.cpp
//
//	2018-01-21(日)~ 2018-07-07(土)
//
//	ドット絵エディタ(色データを文字にする)
//
//-----------------------------------------------------------------------------
#include "DxLib.h"
#include <stdio.h>
#include "f01_main.h"
#include "f01_mainProt.h"
#include "f03_file.h"

//-----------------------------------------------------------------------------
// グローバル変数
//-----------------------------------------------------------------------------
UINT  g_White;		// 白
UINT  g_Blue;		// 青
UINT  g_Gray;		// 灰色
UINT  g_Black;		// 黒
UINT  g_Yellow;		// 黄色
SDot  g_dot;		// dotメイン構造体

//-----------------------------------------------------------------------------
// 外部グローバル変数の使用宣言
//-----------------------------------------------------------------------------
extern SFile g_file;	// ファイルの構造体(f03_file.cppで宣言)
extern int   g_HH;		// 指定した縦のドット数を保存(f03_file.cppで宣言)
extern int   g_WW;		// 指定した横のドット数を保存(f03_file.cppで宣言)

//-----------------------------------------------------------------
// 外部関数の使用宣言
//-----------------------------------------------------------------
extern void		f00_setMsgbox(UINT style, char *title="Message");// メッセージボックスのスタイルとタイトルをセットする
extern int		f00_msgbox(PSTR pform, ...);		// 書式付きメッセージボックス
extern void		f00_setPrint(UINT c1, UINT c2);	// print の文字色と背景色をセットする
extern void		f00_print(int x, int y, PSTR pform, ...);// 書式付き文字出力
extern void		f02_putIcon(int hIcon[]);		// アイコンを表示
extern void		f02_makeIcon(int hIcon[]);		// 全てのアイコンを作る
extern EState	f03_save(void);					// ファイルに保存
extern EState	f03_load(void);					// ファイルの読み込み

//-----------------------------------------------------------------------------
// 初期化
//-----------------------------------------------------------------------------
int ini_main(UINT aColor[], int hIcon[])
{
	//if(CheckDoubleStart()==TRUE){f00_msgbox("すでに起動されてます。");}
	ChangeWindowMode(TRUE);
	SetGraphMode( 800 , 600 , 32 ) ;
	SetWindowText(STR_TITLE);
	if(DxLib_Init()==-1) {return -1;}
	ChangeFont( "MS ゴシック" ) ;
	SetFontSize( 16 ) ;
	SetFontThickness( 1 );				// 文字の太さを1ドットにする
	SetDrawScreen( DX_SCREEN_BACK ); 

	g_White  = GetColor(WHITE);
	g_Blue   = GetColor(BLUE);
	g_Gray   = GetColor(GRAY);
	g_Black  = GetColor(BLACK);
	g_Yellow = GetColor(YELLOW);
	
	g_dot.L_x   = 230+19*20;	// 左ボタン(L)の色のX座標
	g_dot.R_x   = 230;			// 右ボタン(R)の色のX座標
	g_dot.L_num = 19;			// 左ボタンの色番号(白)
	g_dot.R_num = 0;			// 右ボタンの色番号(黒)
	g_dot.L_color = g_White;	// 左ボタンの色(白)
	g_dot.R_color = g_Black;	// 右ボタンの色(黒)
	g_dot.mesh_nColor = 16;		// メッシュの色(青)
	g_dot.eState = STATE_MAIN;

	set_alpha(" RGYBMCunstodrgybmcw");	// 変換用アルファベットをセットする
	set_palette(aColor);
	f00_setMsgbox(MB_OK);
	f00_setPrint(g_White, g_Black);
	f02_makeIcon(hIcon);				// アイコンを作成

	return 0;
}

//-----------------------------------------------------------------------------
// エントリーポイント
//-----------------------------------------------------------------------------
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
	UINT aColor[MAX_COLOR];		// ドット絵用のパレット
	int  hIcon[MAX_ICON];		// アイコンのグラフィックハンドル
	int  x, y;
	int  Mouse;
	
	if(ini_main(aColor, hIcon)){	// 初期化
		return -1;
	}

	while( !ScreenFlip() && !ProcessMessage() )
	{
		Mouse = GetMouseInput();	// マウスの入力状態取得
		GetMousePoint( &x, &y );	// マウスの座標取得

		switch(g_dot.eState){
		case STATE_MAIN:		// メイン処理
			g_dot.eState = main_dot(x, y, Mouse, aColor, hIcon);
			break;

		case STATE_MESH:		// メッシュの色を変更する
			g_dot.eState = put_mesh(aColor, hIcon);
			break;

		case STATE_PUT_ALPHA:	// アルファベットに変換して表示
			g_dot.eState = put_alpha(aColor);
			break;

		case STATE_LOAD:		// ロード
			g_dot.eState = f03_load();
			break;

		case STATE_SAVE:		// セーブ
			g_dot.eState = f03_save();
			break;

		case STATE_CLEAR:		// 画面のクリア(ワイパーアイコン)
			g_dot.eState = f01_clsDot();
			break;

		case STATE_END:	//
			if(IDYES == f00_msgbox("終了しますか?")){
				goto end;
			}
			g_dot.eState = STATE_MAIN;
			break;
		}
	}
end:
	free(g_file.pBuf);
	DxLib_End();
	return 0;
}

//-----------------------------------------------------------------------------
// メイン処理
//-----------------------------------------------------------------------------
EState main_dot(int x, int y, int Mouse, UINT aColor[], int hIcon[])
{
	static int mouseX, mouseY;
	ClearDrawScreen();
	f01_putDot(aColor);
	put_disp(aColor, hIcon);

	if((x>=40 && x<640+40) && (y>=80 && y<430-10)){
		 mouseX = x/10-3, mouseY = y/10-7;
	}
	f00_print( 8*6, 16*31, "(%2d, %2d)", mouseX, mouseY);	// マスの座標を表示
	f00_print( 8*6, 16*33, "(%d, %d)   ", x, y);  // マウス座標を表示
	f00_print(8*20, 16*31, "(幅=%2d, 高さ=%2d)", g_WW, g_HH);

	
	if( Mouse & MOUSE_INPUT_RIGHT ){		// マウスの右ボタンが押された
		if((x>=40 && x<640+40) && (y>=80 && y<430-10)){
			draw_dot(x, y, 2);				// ドット絵を描く
			return STATE_MAIN;
		}
		if((x>225 && x<625) && (y>5 && y<40)){
			select_color(x, aColor, 2);		// 色を選択する
			return STATE_MAIN;
		}
	}
	
	if( Mouse & MOUSE_INPUT_LEFT ){			// マウスの左ボタンが押された
		if((x>=40 && x<640+40) && (y>=80 && y<430-10)){
			draw_dot(x, y, 1);				// ドット絵を描く
			return STATE_MAIN;
		}
		if((x>225 && x<625) && (y>5 && y<40)){
			select_color(x, aColor, 1);		// 色を選択する
			return STATE_MAIN;
		}
		if((x>8*2 && x<8*9) && (y>5 && y<35)){
			return STATE_LOAD;				// ロード
		}
		if((x>8*9 && x<8*19) && (y>5 && y<35)){
			return STATE_SAVE;				// セーブ
		}
		if((x>40*1 && x<40*2) && (y>16*28 && y<16*30)){
			return STATE_MAIN;				// マウスの形を変える
		}
		if((x>40*2 && x<40*3) && (y>16*28 && y<16*30)){
			return STATE_MAIN;				// マウスの色を変える
		}
		if((x>40*3 && x<40*4) && (y>16*28 && y<16*30)){
			return STATE_MESH;				// メッシュの色を変える
		}
		if((x>40*4 && x<40*5) && (y>16*28 && y<16*30)){
			return STATE_LOAD;				// ロード
		}
		if((x>40*5 && x<40*6) && (y>16*28 && y<16*30)){
			return STATE_MAIN;				// 
		}
		if((x>40*6 && x<40*7) && (y>16*28 && y<16*30)){
			return STATE_SAVE;				// セーブ
		}
		if((x>40*7 && x<40*8) && (y>16*28 && y<16*30)){
			return STATE_CLEAR;				// 消去
		}
		if((x>40*8 && x<40*9) && (y>16*28 && y<16*30)){
			return STATE_PUT_ALPHA;			// アルファベットに変換して表示する
		}
		if((x>40*9 && x<40*10) && (y>16*28 && y<16*30)){
			return STATE_MAIN;				// 
		}
		if((x>40*10 && x<40*11) && (y>16*28 && y<16*30)){
			return STATE_MAIN;				// 
		}
		if((x>40*11 && x<40*12) && (y>16*28 && y<16*30)){
			return STATE_END;				// 終了
		}
	}
	return STATE_MAIN;
}

//-----------------------------------------------------------------------------
// マスを塗る(ドット絵作成)
//-----------------------------------------------------------------------------
void draw_dot(int x,int y, int LR)
{
	int  mx, my;

	mx = x/10;			// 配列に入れるため。
	my = y/10;
	x  = x/10*10;		// 10ドット単位にするため端数を切り捨てる
	y  = y/10*10;

	if(LR==1){	// 左ボタン
		DrawBox(x+1, y+1, x+10, y+10, g_dot.L_color, TRUE);	// マスを塗る
		DrawPixel(mx+145, my, g_dot.L_color);
		g_dot.masu[my-8][mx-4] = g_dot.L_num;
	}
	else {		// 右ボタン
		DrawBox(x+1, y+1, x+10, y+10, g_dot.R_color, TRUE);	// マスを塗る
		DrawPixel(mx+145, my, g_dot.R_color);
		g_dot.masu[my-8][mx-4] = g_dot.R_num;
	}
}

//-----------------------------------------------------------------------------
// 変換用アルファベットをセットする
//-----------------------------------------------------------------------------
void set_alpha(PSTR pString)
{
	int  i, j;
	char ch;
	
	for(i=0 ; i < MAX_PALETTE; i++){
		ch = pString[i];
		for(j=0 ; j < MAX_PALETTE ; j++){
			if((ch == pString[j]) && (i != j)){
				f00_msgbox("\"%s\"\n変換用アルファベットの \n%d 文字目と %d 文字目の %c が重複してます。", pString, i+1, j+1, ch);
				goto label;
			}
		}
	}
label:
	strcpy( &g_dot.alpha[0], pString);
}

//-----------------------------------------------------------------------------
// マウスによる色の選択
//-----------------------------------------------------------------------------
EState select_color(int x, UINT aColor[], int LR)
{
	int n;

	n = (x-225)/20;		// 選択色の番号をセット
	x = n * 20 + 230;	// 座標を計算

	if(LR==1){						// 左ボタン
		g_dot.L_color = aColor[n];
		g_dot.L_x = x;				// x座標を保存
		g_dot.L_num = (UCHAR)n;		// 色の番号
	}
	else {							// 右ボタン
		g_dot.R_color = aColor[n];
		g_dot.R_x = x;				// x座標を保存 
		g_dot.R_num = (UCHAR)n;		// 色の番号
	}
	return STATE_MAIN;
}

//-----------------------------------------------------------------------------
// ドット絵用のパレットにスタティックカラーをセット
//-----------------------------------------------------------------------------
void set_palette(UINT aColor[])
{
	aColor[ 0] = GetColor( BLACK );
	aColor[ 1] = GetColor( D_RED );
	aColor[ 2] = GetColor( D_GREEN );
	aColor[ 3] = GetColor( D_YELLOW );
	aColor[ 4] = GetColor( D_BLUE );
	aColor[ 5] = GetColor( D_MAGENTA );
	aColor[ 6] = GetColor( D_CYAN );
	aColor[ 7] = GetColor( GRAY );
	aColor[ 8] = GetColor( M_GREEN );
	aColor[ 9] = GetColor( S_BLUE );

	aColor[10] = GetColor( CREAM );
	aColor[11] = GetColor( M_GRAY );
	aColor[12] = GetColor( D_GRAY );
	aColor[13] = GetColor( RED );
	aColor[14] = GetColor( GREEN );
	aColor[15] = GetColor( YELLOW );
	aColor[16] = GetColor( BLUE );
	aColor[17] = GetColor( MAGENTA );
	aColor[18] = GetColor( CYAN );
	aColor[19] = GetColor( WHITE );

	aColor[20] = GetColor( MD_RED );
	aColor[21] = GetColor( MD_GREEN );
	aColor[22] = GetColor( MD_YELLOW );
	aColor[23] = GetColor( MD_BLUE );
	aColor[24] = GetColor( MD_MAGENTA );
	aColor[25] = GetColor( MD_CYAN );
	aColor[26] = GetColor( L_BLUE );
}

//-----------------------------------------------------------------------------
// 画像の消去
//-----------------------------------------------------------------------------
void f01_cls(void)
{
	int x, y;
	
	for(y=0 ; y<MESH_H ; y++)
		for(x=0; x<MESH_W ; x++){
			g_dot.masu[y][x] = 0 ;{	// 消去
		}
	}
}

//-----------------------------------------------------------------------------
// 画像の消去(ワイパーのアイコンを押して消す)
//-----------------------------------------------------------------------------
EState f01_clsDot(void)
{
	int x, y;
	
	
	if(IDNO == f00_msgbox("画像を消去しますか?")){
		return STATE_MAIN;
	}
	
	for(y=0 ; y<MESH_H ; y++)
		for(x=0; x<MESH_W ; x++){
			g_dot.masu[y][x] = 0 ;{		// 消去
		}
	}
	return STATE_MAIN;
}

//-----------------------------------------------------------------------------
// ドット絵の色データをアルファベットにして表示
//-----------------------------------------------------------------------------
EState put_alpha(UINT aColor[])
{
	int   i, j;
	UCHAR n;
	
	ClearDrawScreen();
	DrawString(16*2, 16, "アルファベットに変換しました。", g_White);

	for(j=0; j<MESH_H ; j++){
		for(i=0; i<MESH_W ; i++){
			n = g_dot.masu[j][i];
			DrawFormatString(i*12+15, j*14+45, aColor[n], "%c", g_dot.alpha[n]);
		}
	}
	ScreenFlip();
	WaitKey();
	WaitTimer(200);
	
	return STATE_MAIN;
}

//-----------------------------------------------------------------------------
// メッシュの色を変える
//-----------------------------------------------------------------------------
EState put_mesh(UINT aColor[], int hIcon[])
{
	g_dot.mesh_nColor++;
	
	if(g_dot.mesh_nColor >= MAX_PALETTE){
		g_dot.mesh_nColor = 0;
	}
	put_disp(aColor, hIcon);
	ScreenFlip();
	WaitTimer(200);
	
	return STATE_MAIN;
}

//-----------------------------------------------------------------------------
// ドット絵用のパレットを表示
//-----------------------------------------------------------------------------
void put_palette(UINT aColor[])
{
	for(int i=0 ; i<MAX_PALETTE ; i++){
		DrawBox(224+(20*i), 7, 243+(20*i), 41, aColor[i], TRUE);	// 色を表示
	}
	DrawBox(222, 5, 245+(20*19), 43, g_Gray, FALSE);			// 色の枠

	// 色選択時、左ボタン(L)か、右ボタン(R)かを表示
	DrawBox(g_dot.L_x-1, 14, g_dot.L_x+8, 14+16, g_White, TRUE);
	DrawBox(g_dot.R_x-1, 14, g_dot.R_x+8, 14+16, g_White, TRUE);
	DrawString(g_dot.L_x, 14, "L", g_Black);
	DrawString(g_dot.R_x, 14, "R", g_Black);
}

//-----------------------------------------------------------------------------
// ドット絵の表示
//-----------------------------------------------------------------------------
void f01_putDot(UINT aColor[])
{
	int x, y;
	
	for(y=0; y<MESH_H ; y++){
		for(x=0; x<MESH_W ; x++){
			DrawBox(x*10+40+1, y*10+80+1, x*10+40+10, y*10+80+10, aColor[g_dot.masu[y][x]], TRUE);	// マスを塗る
		}
	}
	
	for(y=0; y<MESH_H ; y++){
		for(x=0; x<MESH_W ; x++){
			DrawPixel(x+149, y+8, aColor[g_dot.masu[y][x]]);  // 実寸で表示
		}
	}
}

//-----------------------------------------------------------------
// ディスプレイ画面を表示
//-----------------------------------------------------------------
void put_disp(UINT aColor[], int hIcon[])
{
	int  x2, y2;

	DrawBox(8*2, 5, 140, 35, g_Gray, FALSE);		// メニュー枠を表示
	DrawString(8*4, 12, "読込   保存", g_White);	// メニューを表示

	put_palette(aColor);	// パレットを表示
	f02_putIcon(hIcon);		// アイコンを表示

	//------ メッシュ(縦と横の線)----------------

	for(y2=80 ; y2<=420 ; y2+=10){				// 10ドット単位の横線
		DrawLine(40, y2, 640+40, y2, aColor[g_dot.mesh_nColor]);
	}
	for(y2=80 ; y2<=420 ; y2+=50){				// 50ドット単位の横線
		DrawLine(30, y2, 650+40, y2, aColor[g_dot.mesh_nColor]);
	}

	for(x2=40 ; x2<=640+40 ; x2+=10){				// 10ドット単位の縦線
		DrawLine(x2, 80, x2, 430-10, aColor[g_dot.mesh_nColor]);
	}
	for(x2=40 ; x2<=640+40 ; x2+=50){				// 50ドット単位の縦線
		DrawLine(x2, 70, x2, 440-10, aColor[g_dot.mesh_nColor]);
	}

	for(x2=35; x2<=640 ; x2+=100){
		DrawFormatString(x2, 50, g_White, "%d", x2/10-3);	// 横ドット数を表示
	}
	for(y2=70; y2<=430 ; y2+=100){
		DrawFormatString(10, y2, g_White , "%d", y2/10-7);	// 縦ドット数を表示
	}
}

どぶろく
記事: 75
登録日時: 11年前

Re: ぷるぷるプログラミング

#22

投稿記事 by どぶろく » 5年前

続き

コード:

//-----------------------------------------------------------------
//	f02_icon.h
//
//	アイコンの画像データ
//
//-----------------------------------------------------------------
#ifndef INCLUDE_icon_h
#define INCLUDE_icon_h

char dot_e0[30][31]={
"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"b   b   b   b   b   b   b   b ",
"b   b   b   b   b   b   b   b ",
"b   b   b  gb   b   b   b   b ",
"bbbbbbbbbbbbggbbbbbbbbbbbbbbbb",
"b   b   b   bgggb   b   b   b ",
"b   b   b   b gggg  b   b   b ",
"b   b   b   b  gggggb   b   b ",
"bbbbbbbbbbbbbbbbggggggbbbbbbbb",
"b   b   b   b   bgggggggb   b ",
"b   b   b   b   b ggggggggg b ",
"b   b   b   b   b  gggg b   b ",
"bbbbbbbbbbbbbbbbbbbbgggbbbbbbb",
"b   b   b   b   b   bgg b   b ",
"b   b   b   b   b   b g b   b ",
"b   b ggggggg   b   b   b   b ",
"bbbbbbbbbgbbbbbbbbbbbbbbbbbbbb",
"b   g   bg  b g b   b   b   b ",
"b   g   bg  b g b   b   b   b ",
"b   g   b   b g b   b   b   b ",
"bbbbggggbbbggggbbbbbbbbbbbbbbb",
"b   g   b   b g b   b   b   b ",
"b   g   bg  b g b   b   b   b ",
"b   g   bg  b g b   b   b   b ",
"bbbbbbbbbgbbbbbbbbbbbbbbbbbbbb",
"b   b ggggggg   b   b   b   b ",
"b   b   b   b   b   b   b   b ",
"b   b   b   b   b   b   b   b ",
"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"b   b   b   b   b   b   b   b "
};

//------------------------------------------------------------------
char dot_e1[30][31]={
" w w  bb    w w w w w w w w w ",
"w      bbb                   w",
"        bbbb                  ",
"w        bbbbb               w",
"          bbbbbb              ",
"w          bbbbbbb           w",
"   gg       bbbbbbbb          ",
"w   ggg      bbbbbbbbb       w",
"     gggg     bbbbbbbbbb      ",
"w     ggggg    bbbbbbbbbbb   w",
"       gggggg   bbbbbbbbbbbb  ",
"        ggggggg  bbbbbbbbbbbbb",
"rr       gggggggg bbbbbb      ",
" rrr      gggggggggbbbbb      ",
"  rrrr     ggggggggggbbb     w",
"   rrrrr    gggggggggggb      ",
"w   rrrrrr   gggggggggggg     ",
"     rrrrrrr  ggggggggggggg  w",
"w     rrrrrrrr gggggg         ",
"       rrrrrrrrrggggg         ",
"w       rrrrrrrrrrggg        w",
"         rrrrrrrrrrrg         ",
"w         rrrrrrrrrrrr        ",
"           rrrrrrrrrrrrr     w",
"w           rrrrrr            ",
"             rrrrr            ",
"w             rrrr           w",
"               rrr            ",
"w               rr           w",
" w w w w w w w   r  w w w w w "
};

//------------------------------------------------------------------
char dot_e2[30][31]={
"  b  b  b  b  b  b            ",
"  b  b  b  b  b  b            ",
"bbbbbbbbbbbbbbbbbbbb          ",
"  b  b  b  b  b  b            ",
"  b  b  b  b  b  b            ",
"bbbbbbbrbbrbbrbbrbbr  r       ",
"  b  b rb rb rb rb r  r       ",
"  b  rrrrrrrrrrrrrrrrrrrr     ",
"bbbbbbbrbbrbbrbbrbbr  r       ",
"  b  b rb rb rb rb r  r       ",
"  b  rrrrrrrgrrgrrgrrgrrg  g  ",
"bbbbbbbrbbrbgrbgrbgr gr g  g  ",
"  b  b rb gggggggggggggggggggg",
"  b  rrrrrrrgrrgrrgrrgrrg  g  ",
"bbbbbbbrbbrbgrbgrbgr gr g  g  ",
"  b  b rb gggggggggggggggggggg",
"  b  rrrrrrrgrrgrrgrrgrrg  g  ",
"bbbbbbbrbbrbgrbgrbgr gr g  g  ",
"  b  b rb gggggggggggggggggggg",
"  b  rrrrrrrgrrgrrgrrgrrg  g  ",
"       r  r gr gr gr gr g  g  ",
"       r  gggggggggggggggggggg",
"     rrrrrrrgrrgrrgrrgrrg  g  ",
"       r  r gr gr gr gr g  g  ",
"       r  gggggggggggggggggggg",
"            g  g  g  g  g  g  ",
"            g  g  g  g  g  g  ",
"          gggggggggggggggggggg",
"            g  g  g  g  g  g  ",
"            g  g  g  g  g  g  "
};

//------------------------------------------------------------------
char dot_e3[30][31]={
" wwwwwwwwwwwwwwwwwwwwwwwwwwww ",
"w                            w",
"w  gggggggggggggggggggggggg  w",
"w  gg ggggg  ggg   gg   ggg  w",
"w  gg gggg gg gg g gg gg gg  w",
"w  gg gggg gg g ggg g gg gg  w",
"w  gg gggg gg g     g gg gg  w",
"w  gg    gg  gg ggg g   ggg w ",
"w  gggggggggggggggggggggggg w ",
"w                            w",
"w                            w",
"w            wwww            w",
"w           w    w           w",
"w          w      w          w",
"w          w      w          w",
"w          w      w          w",
"w          w      w ww       w",
"w           w    w  ww       w",
"w            wwww            w",
"w                            w",
"w                            w",
"w             ww             w",
"w            w  w            w",
"w            w  w            w",
"w            w  w            w",
"w            w  w            w",
"w            w  w            w",
"w             ww             w",
"w                            w",
" wwwwwwwwwwwwwwwwwwwwwwwwwwww "
};

//------------------------------------------------------------------
char dot_e4[30][31]={
" w w w w w w w w w w          ",
"w                   w         ",
"   wwwwwwwwwwwwwww            ",
"w  ww w w w w w w w w w       ",
"   w                   w      ",
"w     wwwwwwwwwwwwwww         ",
"   w  ww w w w w w w w w w    ",
"w     w                   w   ",
"   w     wwwwwwwwwwwwwww      ",
"w     w  wwwwwwwwwwwwwwwwwwwww",
"   w     w                   w",
"w     w  w  wwwwwwwwwwwwwww  w",
"   w     w  wwwwwwwwwwwwwww  w",
"w     w  w  wwwwwwwwwwwwwww  w",
"   w     w                  w ",
"w     w  w                   w",
"   w     w        www        w",
"w     w  w       w   w       w",
"   w     w      w     w      w",
"w     w  w      w     w      w",
" w w     w      w     w ww   w",
"      w  w       w   w  ww   w",
"   w     w        www        w",
"    w w  w                   w",
"         w         w         w",
"      w  w        w w        w",
"       w w        w w        w",
"         w        w w        w",
"         w        w w        w",
"          wwwwwwwwwwwwwwwwwww "
};

//------------------------------------------------------------------
char dot_e5[30][31]={
" wwwwwwwwwwwwwwwwwwwwwwwwwwww ",
"w                            w",
"w  yyyyyyyyyyyyyyyyyyyyyyyy  w",
"w  yy    yy   yy yy y    yy  w",
"w  yy yyyy yyy y yy y yyyyy  w",
"w  yy    y     y yy y    yy  w",
"w  yyyyy y yyy y yy y yyyyy  w",
"w  yy    y yyy yy  yy    yy w ",
"w  yyyyyyyyyyyyyyyyyyyyyyyy w ",
"w                            w",
"w                            w",
"w            wwww            w",
"w           w    w           w",
"w          w      w          w",
"w          w      w          w",
"w          w      w          w",
"w          w      w ww       w",
"w           w    w  ww       w",
"w            wwww            w",
"w                            w",
"w                            w",
"w             ww             w",
"w            w  w            w",
"w            w  w            w",
"w            w  w            w",
"w            w  w            w",
"w            w  w            w",
"w             ww             w",
"w                            w",
" wwwwwwwwwwwwwwwwwwwwwwwwwwww "
};

//------------------------------------------------------------------
char dot_e6[30][31]={
" cccccccccccccccccccccccccccc ",
"cccccccccccccccccccccccccccccc",
"cccccccccccccccccccccccccccccc",
"cccccccccccccccccccccccccccccc",
"cccccccccccccccccccccccccccccc",
"cccccccccccccccccccccccccccccc",
"cccccccccc          cccccccccc",
"ccccccc                ccccccc",
"ccccc                    ccccc",
"cccc                      cccc",
"ccc                        ccc",
"cc                          cc",
"                              ",
"                              ",
"c                            c",
"cc                          cc",
"ccc                        ccc",
"cccc      cccccccccc      cccc",
"ccccc  cccccccccccccccc  ccccc",
"cccccccccccccccccccccc  cccccc",
"ccccccccccccccccccccc  ccccccc",
"cccccccccccccccccccc  cccccccc",
"cccccccccccccccccc   ccccccccc",
"ccccccccccccccccc   cccccccccc",
"cccccccccccccccc    cccccccccc",
"ccccccccccccccc    ccccccccccc",
"cccccccccccccc    cccccccccccc",
"ccccccccccccc    ccccccccccccc",
"cccccccccccc    cccccccccccccc",
" cccccccccc    cccccccccccccc "
};

//------------------------------------------------------------------
char dot_e7[30][31]={
"bbbbbbbbb  bb     bbbbbbbbbbbb",
"                              ",
"cccccccc   cc     cccccccccccc",
"ccccccccc  cc     cccccccccccc",
"cc     cc  cc     cc    cc    ",
"                              ",
"gggggggg   gg     gggggggggggg",
"ggggggggg  gg     gggggggggggg",
"gg     gg  gg     gg    gg    ",
"gg     gg  gg     gg    gg    ",
"gg     gg  gg     gg    gg    ",
"                              ",
"yyyyyyyy   yy     yyyyyyyyyyyy",
"yyyyyyyyy  yy     yyyyyyyyyyyy",
"yy      y  yy     yy    yy    ",
"yy      y  yy     yy    yy    ",
"yy      y  yy     yy    yy    ",
"yyyyyyyyy  yy     yy    yy    ",
"yyyyyyyy   yy     yy    yy    ",
"                              ",
"wwwwwwww   ww     wwwwwwwwwwww",
"wwwwwwwww  ww     wwwwwwwwwwww",
"w       w  ww     ww    ww    ",
"w       w  ww     ww    ww    ",
"w       w  ww     ww    ww    ",
"wwwwwwwww  ww     ww    ww    ",
"wwwwwwww   ww     ww    ww    ",
"ww         ww     ww    ww    ",
"ww         wwwwwwwww    ww    ",
"ww          wwwwwww     ww    "
};

//------------------------------------------------------------------
char dot_e8[30][31]={
"      r r r r r r r r r r r r ",
"     r r r r r r r r r r r r r",
"      r r r r r r r r r r r r ",
"     r r r r r r r r r r r r r",
"      r r r r r r r r r r r r ",
"     r r r r r r r r r r r r r",
"      r r r r r r r r r r r r ",
"     r r r r r r r r r r r r r",
"bbbbb w w w w w w w w w w r r ",
"b   br r r r r r r r r r r r r",
"b   b r w r w r w r w r w r r ",
"b   br r r r r r r r r r r r r",
"bbbbb w w w w w w w w w w r r ",
"b   br r r r r r r r r r r r r",
"b   b r w r w r w r w r w r r ",
"b   br r r r r r r r r r r r r",
"bbbbb w w w w w w w w w w r r ",
"b   br r r r r r r r r r r r r",
"b   b r w r w r w r w r w r r ",
"b   br r r r r r r r r r r r r",
"bbbbb r w r w r w r w r w r r ",
"bbbbbbbbbbbbbbbbbbbbbbbbb     ",
"b   b   b   b   b   b   b     ",
"b   b   b   b   b   b   b     ",
"b   b   b   b   b   b   b     ",
"bbbbbbbbbbbbbbbbbbbbbbbbb     ",
"b   b   b   b   b   b   b     ",
"b   b   b   b   b   b   b     ",
"b   b   b   b   b   b   b     ",
"bbbbbbbbbbbbbbbbbbbbbbbbb     "
};

//------------------------------------------------------------------
char dot_e9[30][31]={
" wwwwwwwwwwwwwwwwwwwwwwwwwwww ",
"w                            w",
"w  rrrrrrrrrrrrrrrrrrrrrrrr  w",
"w  rrrwwwwrrwrrrrwwwwwwwwrr  w",
"w  rrwrrrrwrwrrrrwrrrwrrrrr  w",
"w  rrwrrrrwrwrrrrwrrrwrrrrr  w",
"w  rrwrrrrwrwrrrrwrrrwrrrrr  w",
"w  rrrwwwwrrrwwwwrrrrwrrrrr w ",
"w  rrrrrrrrrrrrrrrrrrrrrrrr w ",
"w                            w",
"w                            w",
"w            wwww            w",
"w           w    w           w",
"w          w      w          w",
"w          w      w          w",
"w          w      w          w",
"w          w      w ww       w",
"w           w    w  ww       w",
"w            wwww            w",
"w                            w",
"w                            w",
"w             ww             w",
"w            w  w            w",
"w            w  w            w",
"w            w  w            w",
"w            w  w            w",
"w            w  w            w",
"w             ww             w",
"w                            w",
" wwwwwwwwwwwwwwwwwwwwwwwwwwww "
};

//------------------------------------------------------------------
char dot_e10[30][31]={
"    wwwwwwwwwwwwwwwwwwwwww    ",
"   w                      w   ",
"   w  w w w w w w w w w   w   ",
"   w   w w w w w w w w    www ",
" www  w w w w w w w w w   w ww",
"ww w                     w w w",
"w ww                     ww ww",
"ww w                      ww w",
"w ww         wwww         w ww",
"ww w        w    w        ww w",
"w ww       w      w       w ww",
"ww w       w      w       ww w",
"wwwwwwwwwwwwwwwwwwwwwwwwwwwwww",
"wwwwwwwwwwwwwwwwwwwwwwwwwwwwww",
"wwwwwwwwwwwwwwwwwwwwwwwwwwwwww",
"wwwwwwwwwwwwwwwwwwwwwwwwwwwwww",
"wwrrrrrrrwwrrwwwwrrwwrrrrrwwww",
"wwrrrrrrrwwrrrwwwrrwwrrrrrrwww",
"wwrrwwwwwwwrrrwwwrrwwrrwwrrrww",
"wwrrwwwwwwwrrrrwwrrwwrrwwwrrww",
"wwrrwwwwwwwrrwrwwrrwwrrwwwrrww",
"wwrrrrrrrwwrrwrrwrrwwrrwwwrrww",
"wwrrrrrrrwwrrwwrwrrwwrrwwwrrww",
"wwrrwwwwwwwrrwwrrrrwwrrwwwrrww",
"wwrrwwwwwwwrrwwwrrrwwrrwwwrrww",
"wwrrwwwwwwwrrwwwrrrwwrrwwrrrww",
"wwrrrrrrrwwrrwwwrrrwwrrrrrrwww",
"wwrrrrrrrwwrrwwwwrrwwrrrrrwwww",
"wwwwwwwwwwwwwwwwwwwwwwwwwwwwww",
"wwwwwwwwwwwwwwwwwwwwwwwwwwwwww"
};

//------------------------------------------------------------------
char dot_e11[30][31]={
"         mmmmmmm              ",
"        mmmmmmm               ",
"       mmmmmmm                ",
"       mmmmmmm                ",
"       mmmmmmm                ",
"      wwwwwwwww               ",
"     w         w              ",
"     w         w              ",
"  wwwwwwwwwwwwwwwww           ",
" w   wmw           w          ",
" w   mwm           w          ",
" wwwwwmwwwwwwwwwwwww          ",
" wwwwmwmwwwwwwwwwwww          ",
" wmmmwmwmmmmmmmmmmmw          ",
" wmmmmwmmmmmmmmmmmmw          ",
" wmmmwmwmmmmmmmmmmmw          ",
" wmmmmwmmmmmmmmmmmmw          ",
" wmmmwmwmmmmmmmmmmmw          ",
" wmmmmwmmmmmmmmmmmmw          ",
" wmmmwmwmmmmmmmmmmmw          ",
" wmmmmwmmmmmmmmmmmmw          ",
" wwwwwwwwwwwwwwwwwww          ",
" wwwwwwwwwwwwwwwwwww          ",
"w    wmw            w         ",
"w    mwm            w         ",
"w    wmw            w         ",
"wwwwwmwmwwwwwwwwwwwww         ",
"w                   w         ",
"w                   w         ",
"wwwwwwwwwwwwwwwwwwwww         "
};

//------------------------------------------------------------------
char dot_e12[30][31]={
"                              ",
"                              ",
"   wwwwwwwwwwwwwww            ",
"   w             w            ",
"   w             w            ",
"   wwwwwwwwwwwwwww            ",
"     w         w              ",
"     w         w              ",
"  wwwwwwwwwwwwwwwww           ",
" w   wmw           w          ",
" w   mwm           w          ",
" wwwwwmwwwwwwwwwwwww          ",
" wwwwmwmwwwwwwwwwwww          ",
" wmmmwmwmmmmmmmmmmmw          ",
" wmmmmwmmmmmmmmmmmmw          ",
" wmmmwmwmmmmmmmmmmmw          ",
" wmmmmwmmmmmmmmmmmmw          ",
" wmmmwmwmmmmmmmmmmmw          ",
" wmmmmwmmmmmmmmmmmmw          ",
" wmmmwmwmmmmmmmmmmmw          ",
" wmmmmwmmmmmmmmmmmmw          ",
" wwwwwwwwwwwwwwwwwww          ",
" wwwwwwwwwwwwwwwwwww          ",
"w    wmw            w         ",
"w    mwm            w         ",
"w    wmw            w         ",
"wwwwwmwmwwwwwwwwwwwww         ",
"w                   w         ",
"w                   w         ",
"wwwwwwwwwwwwwwwwwwwww         "
};

#endif

コード:

//-----------------------------------------------------------------------------
//	f02_icon.cpp
//
//	アイコンを作成する
//
//-----------------------------------------------------------------------------
#include "DxLib.h"
#include "f01_main.h"
#include "f02_icon.h"

//-----------------------------------------------------------------------------
// 全てのアイコンを表示
//-----------------------------------------------------------------------------
void f02_putIcon(int hIcon[])
{
	int x=40, y=16*28;
	
	DrawGraph( x*1,  y, hIcon[0],  FALSE );
	DrawGraph( x*2,  y, hIcon[1],  FALSE );
	DrawGraph( x*3,  y, hIcon[2],  FALSE );
	DrawGraph( x*4,  y, hIcon[3],  FALSE );
	DrawGraph( x*5,  y, hIcon[4],  FALSE );
	DrawGraph( x*6,  y, hIcon[5],  FALSE );
	DrawGraph( x*7,  y, hIcon[6],  FALSE );
	DrawGraph( x*8,  y, hIcon[7],  FALSE );
	DrawGraph( x*9,  y, hIcon[8],  FALSE );
	DrawGraph( x*10, y, hIcon[9],  FALSE );
	DrawGraph( x*11, y, hIcon[10], FALSE );
	DrawGraph( x*12, y, hIcon[11], FALSE );
}

//-----------------------------------------------------------------------------
// アイコン用のパレットに色をセットする
//-----------------------------------------------------------------------------
static void set_iconPallet(int &hImg)
{
	SetPaletteSoftImage( hImg,  0, BLACK,     0 ) ;
	SetPaletteSoftImage( hImg,  1, D_RED,     0 ) ;
	SetPaletteSoftImage( hImg,  2, D_GREEN,   0 ) ;
	SetPaletteSoftImage( hImg,  3, D_YELLOW,  0 ) ;
	SetPaletteSoftImage( hImg,  4, D_BLUE,    0 ) ;
	SetPaletteSoftImage( hImg,  5, D_MAGENTA, 0 ) ;
	SetPaletteSoftImage( hImg,  6, D_CYAN,    0 ) ;
	SetPaletteSoftImage( hImg,  7, GRAY,      0 ) ;
	SetPaletteSoftImage( hImg,  8, M_GREEN,   0 ) ;
	SetPaletteSoftImage( hImg,  9, S_BLUE,    0 ) ;

	SetPaletteSoftImage( hImg, 10, CREAM,     0 ) ;
	SetPaletteSoftImage( hImg, 11, M_GRAY,    0 ) ;
	SetPaletteSoftImage( hImg, 12, D_GRAY,    0 ) ;
	SetPaletteSoftImage( hImg, 13, RED,       0 ) ;
	SetPaletteSoftImage( hImg, 14, GREEN,     0 ) ;
	SetPaletteSoftImage( hImg, 15, YELLOW,    0 ) ;
	SetPaletteSoftImage( hImg, 16, BLUE,      0 ) ;
	SetPaletteSoftImage( hImg, 17, MAGENTA,   0 ) ;
	SetPaletteSoftImage( hImg, 18, CYAN,      0 ) ;
	SetPaletteSoftImage( hImg, 19, WHITE,     0 ) ;
}

//-----------------------------------------------------------------------------
// アイコンのドット絵(一つ)を作成
//-----------------------------------------------------------------------------
static void make_iconDot(int hImg, char (*img)[31], int num)
{
	int i, x, y, y2, color; 
	char *alpha = " RGYBMCunstodrgybmcw";	// 変換用アルファベットをセットする

	for(y2=0, y=30*num ; y<30*num+30 ; y++, y2++){
		for(x=0; x<30 ; x++){
			color=0;
			for(i=0 ; i<MAX_PALETTE; i++){
				if(img[y2][x] == alpha[i]){	// 同じアルファベットなら
					color = i;
					break;
				}
			}
			DrawPixelPalCodeSoftImage( hImg, x, y, color ) ;
		}
	}
}

//-----------------------------------------------------------------------------
// すべてのアイコンを作成
//-----------------------------------------------------------------------------
void f02_makeIcon(int hIcon[])
{
	int hImg;			// パレット画像のハンドル

	hImg = MakePAL8ColorSoftImage( 30, 30 * MAX_ICON );// 空のパレット画像を作成する
	set_iconPallet(hImg);	// パレットに色をセットする

	//アイコンのドット絵を描く
	make_iconDot( hImg, dot_e0,  0 );
	make_iconDot( hImg, dot_e1,  1 );
	make_iconDot( hImg, dot_e2,  2 );
	make_iconDot( hImg, dot_e3,  3 );
	make_iconDot( hImg, dot_e4,  4 );
	make_iconDot( hImg, dot_e5,  5 );
	make_iconDot( hImg, dot_e6,  6 );
	make_iconDot( hImg, dot_e7,  7 );
	make_iconDot( hImg, dot_e8,  8 );
	make_iconDot( hImg, dot_e9,  9 );
	make_iconDot( hImg, dot_e10, 10);
	make_iconDot( hImg, dot_e11, 11);
	make_iconDot( hImg, dot_e12, 12);

	// 分割読み込み
	CreateDivGraphFromSoftImage(hImg, MAX_ICON, 1, MAX_ICON, 30, 30, hIcon);
	DeleteSoftImage( hImg ) ;	// 使い終わったら解放
}

コード:

//-----------------------------------------------------------------------------
//	f03_file.h
//
//	ファイル関係のヘッダファイル
//
//-----------------------------------------------------------------------------
#ifndef INCLUDE_file_h
#define INCLUDE_file_h

struct SFile {
	char   szFileName[MAX_PATH];	// フルパス名
	char   szFileTitle[128];		// ファイル名
	PSTR   pBuf;			// ファイルを読み込んだバッファのポインタ
	DWORD  accBytes;		// 読み込んだファイルのバイト数
};

#endif

コード:

//-----------------------------------------------------------------------------
//	f03_file.cpp
//
//	ファイル関係
//
//-----------------------------------------------------------------------------
#include "DxLib.h"
#include <stdlib.h>
#include "f01_main.h"
#include "f03_file.h"

//-----------------------------------------------------------------------------
// グローバル変数
//-----------------------------------------------------------------------------
SFile  g_file;			// ファイルの構造体
int    g_HH = 32;		// 指定した縦のドット数を保存
int    g_WW = 32;		// 指定した横のドット数を保存

//-----------------------------------------------------------------------------
// ファイル内グローバル変数
//-----------------------------------------------------------------------------
static OPENFILENAME  m_ofn;		// オープンファイルネーム構造体

//-----------------------------------------------------------------------------
// 外部グローバル変数の使用宣言
//-----------------------------------------------------------------------------
extern UINT g_White;	// 白  (f01_main.cppで宣言)
extern SDot g_dot;		// dotメイン構造体(f01_main.cppで宣言)

//-----------------------------------------------------------------
// 外部関数の使用宣言
//-----------------------------------------------------------------
extern int		f00_msgbox(PSTR pform, ...);		// 書式付きメッセージボックス
extern void		f00_print(int x, int y, PSTR pform, ...);// 書式付き文字出力
extern void		f01_cls();						// 画像の消去
extern void		f01_putDot(UINT aColor[]);		// ドット絵の表示

//-----------------------------------------------------------------
// ofn構造体をセット
//-----------------------------------------------------------------
static void set_ofn(DWORD style)
{
	m_ofn.lStructSize	= sizeof(OPENFILENAME);	  // 構造体サイズ
	m_ofn.hwndOwner		= NULL;				// 親ウィンドウのハンドル
	m_ofn.lpstrFilter	= "*.txt\0*.txt\0*.*\0*.*\0\0";		// フィルタ文字
	m_ofn.lpstrFile		= g_file.szFileName;	// ファイル名(フルパス名)
	m_ofn.lpstrFileTitle= g_file.szFileTitle;	// ファイル名
	m_ofn.nMaxFile		= MAX_PATH;			// パス名の最大サイズ
	m_ofn.nMaxFileTitle	= 128;				// ファイル名の最大サイズ
	m_ofn.Flags			= style;// ダイアログのスタイル
}
//-----------------------------------------------------------------------------
// ファイルのデータを読み込む
//-----------------------------------------------------------------------------
static int open_file(void)
{
	HANDLE fh;			// ファイルハンドル
	DWORD  size;		// ファイルサイズ
	PSTR   buf;			// 読み込んだバッファのポインタ
	DWORD  byte;		// 読み込んだバイト数

	set_ofn(OFN_FILEMUSTEXIST|OFN_HIDEREADONLY);

	if(!GetOpenFileName(&m_ofn)){
		return -1 ;
	}

	fh = CreateFile(	// ファイルをオープン
			m_ofn.lpstrFile,
			GENERIC_READ,
			0,
			NULL,
			OPEN_EXISTING, //OPEN_ALWAYS,
			FILE_ATTRIBUTE_NORMAL,
			NULL);
	
	if(fh == INVALID_HANDLE_VALUE){
		f00_msgbox("ファイル(%s)オープンエラー", m_ofn.lpstrFile);
		return -1;
	}
	
	size = GetFileSize(fh, NULL);
	buf = (PSTR)malloc(sizeof(char)*(size+1));

	if(!buf){
		f00_msgbox("ファイルのメモリが確保できません");
		return -1;
	}

	// ファイルを読み込む
	ReadFile(fh, buf, size, &byte, NULL);
	buf[byte] = '\0';		// メモリの最後にヌル文字をセット
	CloseHandle(fh);		// ファイルをクローズ
	
	g_file.accBytes = byte;	// 読み込んだバイト数を保存
	g_file.pBuf = buf;		// 読み込んだバッファのポインタを保存

	return 0;
}

//-----------------------------------------------------------------------------
// 画像データをロード
//-----------------------------------------------------------------------------
EState f03_load(void)
{
	PSTR  pStr;
	char  szW[5];
	char  szH[5];
	int   w, h;
	DWORD i, j;
	int   x, y;
	
	if(open_file() == -1){
		return  STATE_MAIN;
	}
	f01_cls();
	
	pStr = strchr(g_file.pBuf, (int)'[');	// 最初の配列番号の位置
	szH[0]=pStr[1];
	szH[1]=pStr[2];
	szH[2]='\0';

	pStr = strchr((pStr+3), (int)'[');		// 次の配列番号の位置
	szW[0]=pStr[1];
	szW[1]=pStr[2];
	szW[2]='\0';
	
	g_HH = h = atoi(szH);
	g_WW = w = atoi(szW);
	g_WW--;
	
	pStr = strchr(pStr, (int)'"');
	pStr++;		// データの位置

	for(i=0; i < g_file.accBytes; i++){
		if(g_file.pBuf[i] == '\r'){
			g_file.pBuf[i]   = '\0';
		}
	}
	for(j=0, y=0; y < h ; y++){
		for(x=0; x < w ; x++){
			if(pStr[y*w+x+j]=='\0'){
				j+=4;		// 次の行に行く
				x=0;
			}
			for(i=0 ; i<MAX_PALETTE; i++){
				if(pStr[y*w+x+j] == g_dot.alpha[i]){
					g_dot.masu[y][x] = (BYTE)i;
					break;
				}
			}
		}
	}
	free(g_file.pBuf);
	WaitTimer(200);
	
	return STATE_MAIN;
}

//-----------------------------------------------------------------------------
// ファイルに保存
//-----------------------------------------------------------------------------
EState f03_save(void)
{
	char szW[5];		// 横ドット数(文字に変換)
	char szH[5];		// 縦ドット数(文字に変換)
	char str[128];		// 書き出す文字列
	FILE *fp;			// ファイルポインタ
	int  i, j, w, h;
	
	memset(str, 0, 128);
	memset(szW, 0, 5);
	memset(szH, 0, 5);
	ClearDrawScreen();

	//---------------------------------------
	// 横と縦のドット数を入力する
	//---------------------------------------
    DrawFormatString( 16 , 16 , g_White, "横のドット数 = (1~64) %d:" ,  g_WW) ;
    w = KeyInputNumber( 16*15 , 16 , MESH_W , 1 , TRUE ) ;
	if ( w == MESH_W+1) {	// [ESC]を押された場合
		return STATE_MAIN; 
	}
	else {
		g_WW = w; 
	    DrawFormatString( 16*15 , 16 , g_White, "%d" ,  g_WW) ;
		ScreenFlip();
	}

    DrawFormatString( 16 , 16*3 , g_White, "縦のドット数 = (1~34) %d :",  g_HH) ;
    h = KeyInputNumber( 16*15 , 16*3 , MESH_H , 1 , TRUE ) ;
	if ( h == MESH_H+1) {	// [ESC]を押された場合
		return STATE_MAIN;
	}
	else { 
		g_HH = h; 
	    DrawFormatString( 16*15 , 16*3 , g_White, "%d",  g_HH) ;
		ScreenFlip();
	}
	
	//---------------------------------------
	// 保存するアルファベットのデータを作成
	//---------------------------------------
	for(j=0; j<h ; j++){
		for(i=0; i<w ; i++){
			g_dot.moji[j][i+1] = g_dot.alpha[g_dot.masu[j][i]];
		}
		g_dot.moji[j][  0]='"';
		g_dot.moji[j][w+1]='"';
		g_dot.moji[j][w+2]=',';
		g_dot.moji[j][w+3]='\n';
		g_dot.moji[j][w+4]='\0';
	}
	g_dot.moji[j-1][w+2]='\0';		// 最後の , を 0 にする。

	//---------------------------------------
	// ファイルに書きだす
	//---------------------------------------
	set_ofn(OFN_OVERWRITEPROMPT|OFN_HIDEREADONLY);

	if(!GetSaveFileName(&m_ofn)){
		return  STATE_MAIN;
	}
	fp = fopen(m_ofn.lpstrFile, "w");

	w++;					// 配列の横の要素数(ドット数)を+1する(文字列の最後にヌル文字が入るので)
	itoa(w, szW, 10);		// 配列の横の要素数(ドット数)を文字に変換
	itoa(h, szH, 10);		// 配列の縦の要素数(ドット数)を文字に変換
	
	strcat(str, "char dot_e[" );
	strcat(str, szH);
	strcat(str, "][");
	strcat(str, szW);
	strcat(str, "]={\n");

	//fputs("//------------------------------------------------------------------\n", fp);
	fputs(str, fp);
	for(i=0; i<h ; i++){
		fputs(&g_dot.moji[i][0], fp);	// アルファベットのデータをファイルに書き出す
	}
	fputs("\n};\n\n", fp);
	
	fclose(fp);

	f00_msgbox("%s に保存しました。", g_file.szFileTitle);
	
	return STATE_MAIN;
}

どぶろく
記事: 75
登録日時: 11年前

Re: ぷるぷるプログラミング

#23

投稿記事 by どぶろく » 5年前

ファイル名の訂正
f00_main.h --> f01_main.h
f00_mainProt.h --> f01_mainProt.h
f00_main.cpp --> f01_main.cpp

どぶろく
記事: 75
登録日時: 11年前

Re: ぷるぷるプログラミング

#24

投稿記事 by どぶろく » 5年前

BASICのミニゲームを探していたら、以前作った射撃ゲームに似たやつがありました。
砲台が移動できて、敵のY座標が変わるものでした。
さっそくマネして作ってみました。
プレイしていると、いろいろ発展させたくなってきました。
カラスが逆に出てくるとか、弾を撃ってくるとか、
いっそのことインベーダーゲーム風にしようか!とか(笑)

コード:

//-----------------------------------------------------------------------------
//	2018-08-01(水)
//
//	射撃ゲーム2
//
//-----------------------------------------------------------------------------
#include "DxLib.h"

#define WHITE	   255,255,255	  // 白(最大輝度白色光)  255
#define RED		   255,	 0,	 0	  // 明るい赤			   249
#define YELLOW	   255,255,	 0	  // 明るい黄色			   251

#define KARASU	   20			  // カラスの出現回数

//-----------------------------------------------------------------------------
// グローバル変数
//-----------------------------------------------------------------------------
UINT g_White;
UINT g_Red;
UINT g_Yellow;

//-----------------------------------------------------------------------------
// ゲームオーバーの処理
//-----------------------------------------------------------------------------
int owari(int s)
{
	if( s > (KARASU/2)){
		DrawString(15*8, 8*16, "あなたの勝ち!", g_Yellow);
	}else {
		DrawString(15*8, 8*16, "あなたの負け!", g_Red);
	}
	DrawString(16*8, 10*16, "Hit Any Key", g_White);
	DrawString(16*8, 12*16, "[ESC] 終了", g_White);
	ScreenFlip();

	WaitTimer(500);						// 少し待たせる

	if(WaitKey()==KEY_INPUT_ESCAPE){	// ESCでゲーム終了
		return 1;
	}
	return 0;							// ゲーム継続
}

//-----------------------------------------------------------------------------
// 初期化
//-----------------------------------------------------------------------------
int init_main(void)
{
	ChangeWindowMode(TRUE);
	if( DxLib_Init() < 0 ) { return -1; }
	SetDrawScreen( DX_SCREEN_BACK ) ;
	
	g_White  = GetColor(WHITE);
	g_Red    = GetColor(RED);
	g_Yellow = GetColor(YELLOW);
	
	return 0;
}

//-----------------------------------------------------------------------------
// エントリーポイント
//-----------------------------------------------------------------------------
int WINAPI WinMain( HINSTANCE, HINSTANCE, LPSTR, int )
{
	int jiki_x=25, jiki_y=15;	// 自機の座標
	int tama_x=7, tama_y=15;	// 弾の座標
	int teki_x=0, teki_y=0;		// カラスの座標
	int tamaF=0;		// 弾が発射されているかのフラグ
	int s=0;			// 撃ち落としたカラスの数
	int n=1;			// カラスの出現数
	int hit=0;			// 弾が命中した
	int shot=0;			// 弾の発射
	int key;			// キー押し下げ
	
	if(init_main() == -1){
		return -1;
	}

	while(!ProcessMessage() && !ClearDrawScreen())
	{
		key = GetJoypadInputState( DX_INPUT_KEY_PAD1 ) ;

		if( key & PAD_INPUT_9 )     break;		// ESCで終了
		if( key & PAD_INPUT_10 )    shot=1;		// SPACEで弾を発射
        if( key & PAD_INPUT_LEFT )  jiki_x--;	// [←]キー
        if( key & PAD_INPUT_RIGHT ) jiki_x++;	// [→]キー

		if(jiki_x < 0 ) jiki_x=0;
		if(jiki_x > 40) jiki_x=40;
				
		DrawString(jiki_x*8, (jiki_y+0)*16, " A ", g_White);
		DrawString(jiki_x*8, (jiki_y+1)*16, "MIM", g_White);
		DrawString( 0, (jiki_y+2)*16, "-------------------------------------", g_White);

		if(shot==1 && tamaF==0){		// 弾が発射された
			shot=0; tamaF=1;
			tama_x=jiki_x;
		}
		else if(tamaF){
			if(tama_x == teki_x && tama_y == teki_y){	 // 当たり判定
				DrawString((tama_x+1)*8, tama_y*16, "X", g_Red);
				hit=1; s++; shot=0; tamaF=0; tama_y=15; teki_x=40;
			}
			else {
				DrawString((tama_x+1)*8, tama_y*16, "I", g_White); // 弾を描く
			}
			if(tama_y<0){		// 弾が上まで来たら
				shot=0; tamaF=0; tama_y=15;
			}
			tama_y--;
		}
		DrawFormatString(0, 16, g_White, " %d / %d", s, n ); // 出現数と当った数

		if(teki_x>=40){	 // カラスが右端まで来たら
			teki_y = GetRand(13);
			teki_x=0; n++;
		}else {
			teki_x++;
			DrawString(teki_x*8, teki_y*16, "W", g_White);	   // 動いてるカラス
		}
		ScreenFlip() ;

		if(hit){
			hit=0;
			WaitTimer(100);		// ビープ音のために少し待ってやる
			Beep(700, 800);		// 撃ち落とした時のビープ音を鳴らす
		}
		else {
			int oto = GetRand(13)*100;	// ビープ音をランダムにする
			WaitTimer(10);		// ビープ音のために少し待ってやる
			Beep(oto, 60);		// カラスの移動の時のビープ音を鳴らす
		}
		if(n>KARASU){			// カラスが20羽出たら終わり
			if(owari(s)){
				break;			// 終了
			}
			teki_x=0; tama_y=15; s=0; n=1; shot=0;	// ゲームをもう一度やる場合
			WaitTimer(200);					// キー押下げをかわすため少し待つ
		}
	}
	Beep(0, 1000);
	DxLib_End();		// DXライブラリの後始末

	return 0;
}

どぶろく
記事: 75
登録日時: 11年前

Re: ぷるぷるプログラミング

#25

投稿記事 by どぶろく » 5年前

この前の射撃ゲームを改良して、
敵が増えていくようにしました。
処理が増えてきたので関数を増やしました。
どんどん本格的になってきてるなぁ。
そろそろ本腰を入れてゲームプログラムの勉強を
しなければならない時期にきたのかもしれません。
今までいったい何をしてきたのだろうか?!(笑)

コード:

//-----------------------------------------------------------------------------
//	2018-08-08(水)
//
//	射撃ゲーム3(敵が複数出る)
//
//-----------------------------------------------------------------------------
#include "DxLib.h"

#define WHITE	   255,255,255		// 白(最大輝度白色光)	255
#define RED		   255,	 0,	 0		// 明るい赤				249
#define YELLOW	   255,255,	 0		// 明るい黄色			251

//-----------------------------------------------------------------------------
// 敵の構造体
//-----------------------------------------------------------------------------
struct STeki {
	int  x;
	int  y;
	char ch;
	int  num;
	int  f;
};

//-----------------------------------------------------------------------------
// グローバル変数
//-----------------------------------------------------------------------------
UINT g_White;
UINT g_Red;
UINT g_Yellow;
STeki* g_pTeki;			// 敵の構造体

//-----------------------------------------------------------------------------
// メインの初期化
//-----------------------------------------------------------------------------
int init_main(void)
{
	ChangeWindowMode(TRUE);
	if( DxLib_Init() < 0 ) { return -1; }
	SetDrawScreen( DX_SCREEN_BACK ) ;
	
	g_White  = GetColor(WHITE);
	g_Red    = GetColor(RED);
	g_Yellow = GetColor(YELLOW);
	
	return 0;
}

//-----------------------------------------------------------------------------
// 敵の初期化
//-----------------------------------------------------------------------------
void init_teki(int kindTeki)
{
	delete []g_pTeki;						// 敵の構造体配列を解放
	g_pTeki = new STeki[kindTeki];			// 敵の構造体配列を確保
	
	memset(g_pTeki, 0, sizeof(STeki)*kindTeki);
	
	for(int i=0 ; i < kindTeki ; i++){
		g_pTeki[i].x = GetRand(40)*(-1);	// x座標
		g_pTeki[i].y = GetRand(13);			// y座標
		g_pTeki[i].ch = (char)(GetRand(25)+'A');	// 敵(アルファベット1文字)
	}
}

//-----------------------------------------------------------------------------
// 自機を表示
//-----------------------------------------------------------------------------
void draw_jiki(int &x, int &y)
{
	if(x < 0 ) x=0;
	if(x > 40) x=40;
				
	DrawString(x*8, (y+0)*16, " A ", g_White);
	DrawString(x*8, (y+1)*16, "MIM", g_White);
	DrawString( 0, (y+2)*16, "-------------------------------------", g_White);
}

//-----------------------------------------------------------------------------
// 弾を表示
//-----------------------------------------------------------------------------
void draw_tama(int &jiki_x, int &tama_x, int &tama_y, int &shoot, int &tamaF)
{
	if(shoot==1 && tamaF==0){		// 弾が発射された
		shoot=0; tamaF=1;
		tama_x = jiki_x;
	}
	else if(tamaF){
		tama_y--;
		DrawString((tama_x+1)*8, tama_y*16, "I", g_White); // 弾を描く
	}
	if(tama_y<0){		// 弾が上まで来たら
		shoot=0; tama_y=15; tamaF=0;
	}
}

//-----------------------------------------------------------------------------
// 敵を表示
//-----------------------------------------------------------------------------
int draw_teki(int &n, int kindTeki)
{
	for(int i=0; i < kindTeki; i++){
		if(g_pTeki[i].f==1){
			continue;
		}
		if(g_pTeki[i].x >= 40 ){	 // 敵が右端まで来たら
			g_pTeki[i].x = GetRand(40)*(-1);
			g_pTeki[i].y = GetRand(13);
		}
		else{
			g_pTeki[i].x++;
			if(g_pTeki[i].x==0){
				 n++;	// 敵の出現数を数える
			}
			DrawFormatString(g_pTeki[i].x*8, g_pTeki[i].y*16, g_White, "%c", g_pTeki[i].ch );	   // 動いてるカラス
		}
	}
	return 0;
}

//-----------------------------------------------------------------------------
// 当たり判定
//-----------------------------------------------------------------------------
int Judg_atari(int tama_x, int tama_y, int &s, int &clear, int kindTeki, int &score)
{
	for(int i=0; i < kindTeki ; i++){
		if(tama_x+1 == g_pTeki[i].x && tama_y == g_pTeki[i].y && g_pTeki[i].f==0){	 // 当たり判定
			g_pTeki[i].f = 1;
			s++; score++;
			if( s == kindTeki){
				clear = 1;
			}
			return i;
		}
	}
	return -1;
}

//-----------------------------------------------------------------------------
// 面クリア後
//-----------------------------------------------------------------------------
int clr_owari(void)
{
	DrawString(15*8, 7*16, "あなたの勝ち!", g_Yellow);
	DrawString(16*8, 9*16, "Hit Any Key", g_White);
	DrawString(16*8, 11*16, "[ESC] 終了", g_White);
	ScreenFlip();

	WaitTimer(200);		// 少し待たせる

	if(WaitKey()==KEY_INPUT_ESCAPE){	// ESCでゲーム終了
		return 1;
	}
	return 0;			// ゲーム継続
}

//-----------------------------------------------------------------------------
// エントリーポイント
//-----------------------------------------------------------------------------
int WINAPI WinMain( HINSTANCE, HINSTANCE, LPSTR, int )
{
	int jiki_x=25, jiki_y=15;	// 自機の座標
	int tama_x=7, tama_y=15;	// 弾の座標
	int tamaF=0;		// 現在弾が発射されているかのフラグ
	int s=0;			// 撃ち落とした敵の数
	int n=0;			// 敵の出現数
	int cnt_wait=0;		// カウント(ウェイト用)
	int shoot=0;		// 弾の発射
	int hit;			// 敵に命中
	int clear=0;		// 面をクリア
	int kindTeki=5;		// 敵の種類(敵の数)
	int wait=180;		// ウェイト(1/60秒単位)
	int stage=1;		// ステージ数
	int score=0;		// スコア
	int key;			// キー押し下げ
	
	if(init_main() == -1){
		return -1;
	}
	init_teki(kindTeki);

	while(!ProcessMessage() && !ClearDrawScreen())
	{
		key = GetJoypadInputState( DX_INPUT_KEY_PAD1 ) ;
		cnt_wait++;
		if( !(cnt_wait % wait)){
			cnt_wait=0;
			if( key & PAD_INPUT_9 )     break;		// ESCで終了
			if( key & PAD_INPUT_10 )    shoot=1;	// SPACEで弾を発射
        	if( key & PAD_INPUT_LEFT )  jiki_x--;	// [←]キー
        	if( key & PAD_INPUT_RIGHT ) jiki_x++;	// [→]キー

			draw_jiki(jiki_x, jiki_y);
			draw_teki(n, kindTeki);
			draw_tama(jiki_x, tama_x, tama_y, shoot, tamaF);

			hit = Judg_atari(tama_x, tama_y, s, clear, kindTeki, score);
			if(-1 < hit){
				DrawString(g_pTeki[hit].x *8-4, tama_y*16, "●", g_Red);
				shoot=0; tamaF=0;  tama_y=16;
			}
			
			DrawFormatString(8*43, 16*1, g_White, "%d / %d / %d", s, kindTeki, n); // 当った数と敵の種類と出現数
			DrawFormatString(8*43, 16*3, g_White, "Stage %d", stage);	// ステージ数
			DrawFormatString(8*43, 16*5, g_White, "Score %d", score);	// 点数を表示
			ScreenFlip() ;
			
			if(-1 < hit){
				Beep(1300, 1000);
			}
		}
		if(clear){			// 面クリア
			if(clr_owari()){
				break;			// 終了
			}
			clear=0; tama_y=15; s=0; n=1; shoot=0;	// ゲームをもう一度やる場合
			stage++; kindTeki++;
			init_teki(kindTeki);
			WaitTimer(200);				// キー押下げをかわすため少し待つ
		}
	}
	delete []g_pTeki;
	
	DxLib_End();		// DXライブラリの後始末

	return 0;
}

返信

“52歳からはじめるC言語” へ戻る