/*広告*/

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

/*目次へ戻る*/

#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_get_key(void); void my_move_block(void); void my_collision_left(void); void my_collision_right(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 collision_flag; int Color_Red; int Color_Black; int back_img1; int key[256]; 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_get_key(); my_move_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; collision_flag = 0; 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_move_block(){ if(key[KEY_INPUT_LEFT] % 5 == 1){ my_collision_left(); if(collision_flag == 0){ block_x--; } } if(key[KEY_INPUT_RIGHT] % 5 == 1){ my_collision_right(); if(collision_flag == 0){ block_x++; } } } void my_collision_left(){ int x,y; collision_flag = 0; for(y=0;y<BLOCK_HEIGHT;y++){ for(x=0;x<BLOCK_WIDTH;x++){ if(block[y][x] != 0){ if(stage[block_y + y][block_x + (x - 1)] != 0){ collision_flag = 1; } else if((int)(block_y_count - (block_y * DRAW_BLOCK_WIDTH)) > 0){ if(stage[block_y + (y + 1)][block_x + (x - 1)] != 0){ collision_flag = 1; } } } } } } void my_collision_right(){ int x,y; collision_flag = 0; for(y=0;y<BLOCK_HEIGHT;y++){ for(x=0;x<BLOCK_WIDTH;x++){ if(block[y][x] != 0){ if(stage[block_y + y][block_x + (x + 1)] != 0){ collision_flag = 1; } else if((int)(block_y_count - (block_y * DRAW_BLOCK_WIDTH)) > 0){ if(stage[block_y + (y + 1)][block_x + (x + 1)] != 0){ collision_flag = 1; } } } } } } 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; } void my_get_key(){ int i; char keys[256]; GetHitKeyStateAll(keys); for(i=0;i<256;i++){ if(keys[i] != 0){ key[i]++; } else{ key[i] = 0; } } }

/*ページの先頭へ*/

/*目次へ戻る*/

/*HOME*/

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

/*広告*/