/*広告*/

/*ブロックパズルの作り方 中間ソース2*/

/*目次へ戻る*/

#include "DxLib.h" #define BLOCK_HEIGHT 4 #define BLOCK_WIDTH 4 #define STAGE_HEIGHT 23 #define STAGE_WIDTH 18 #define DRAW_BLOCK_WIDTH 20 void my_init_var(void); void my_make_block(void); void my_draw_back(void); void my_draw_variable(void); void my_draw_block(void); void my_draw_stage(void); void my_fall_block(void); int block[BLOCK_HEIGHT][BLOCK_WIDTH]; int stage[STAGE_HEIGHT][STAGE_WIDTH]; int blocks[BLOCK_HEIGHT][BLOCK_WIDTH] = { {0,0,0,0}, {0,1,1,0}, {0,1,1,0}, {0,0,0,0} }; int block_x; int block_y; float block_y_count; float block_speed; int Color_Red; int Color_Black; int back_img1; int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int){ ChangeWindowMode(TRUE); DxLib_Init(); SetDrawScreen(DX_SCREEN_BACK); my_init_var(); while(ProcessMessage() == 0){ ClearDrawScreen(); my_make_block(); my_draw_back(); my_draw_variable(); my_draw_block(); my_draw_stage(); my_fall_block(); if(block_y_count > DRAW_BLOCK_WIDTH * 17){ block_y_count = 0; block_y = 0; } ScreenFlip(); } DxLib_End(); return 0; } void my_init_var(){ int i,j; for(i=0;i<STAGE_HEIGHT;i++){ for(j=0;j<STAGE_WIDTH;j++){ stage[i][0] = 9; stage[i][1] = 9; stage[i][2] = 9; stage[20][j] = 9; stage[21][j] = 9; stage[22][j] = 9; stage[i][15] = 9; stage[i][16] = 9; stage[i][17] = 9; } } block_x = 7; block_y = 0; block_y_count = 0; block_speed = 0.5f; Color_Red = GetColor(255,0,0); Color_Black = GetColor(0,0,0); back_img1 = LoadGraph("./back_img1.jpg"); } void my_make_block(){ int x,y; for(y=0;y<BLOCK_HEIGHT;y++){ for(x=0;x<BLOCK_WIDTH;x++){ block[y][x] = blocks[y][x]; } } } void my_draw_back(){ DrawGraph(0,0,back_img1,TRUE); } void my_draw_variable(){ DrawFormatString(400,400,Color_Black,"block_x = %d",block_x); DrawFormatString(400,420,Color_Black,"block_y = %d",block_y); DrawFormatString(400,440,Color_Black,"block_y_count = %f",block_y_count); } void my_draw_block(){ int x,y; for(y=0;y<BLOCK_HEIGHT;y++){ for(x=0;x<BLOCK_WIDTH;x++){ if(block[y][x] == 1)DrawFormatString(block_x * DRAW_BLOCK_WIDTH + x * DRAW_BLOCK_WIDTH, block_y_count + y * DRAW_BLOCK_WIDTH,Color_Red,"■"); } } } void my_draw_stage(){ int x,y; for(y=0;y<STAGE_HEIGHT - 2;y++){ for(x=2;x<STAGE_WIDTH - 2;x++){ if(stage[y][x] == 1)DrawFormatString(x * DRAW_BLOCK_WIDTH, y * DRAW_BLOCK_WIDTH,Color_Red,"■"); else if(stage[y][x] == 9)DrawFormatString(x * DRAW_BLOCK_WIDTH, y * DRAW_BLOCK_WIDTH,Color_Black,"■"); } } } void my_fall_block(){ block_y_count += block_speed; block_y = block_y_count / DRAW_BLOCK_WIDTH; }

/*ページの先頭へ*/

/*目次へ戻る*/

/*HOME*/

/*Copyright 2016 K.N/petitetech.com*/

/*広告*/