/*L*/

/*ƒuƒƒbƒNƒpƒYƒ‹‚̍ì‚è•û@’†ŠÔƒ\[ƒX‚S*/

/*–ÚŽŸ‚Ö–ß‚é*/

#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_init_var2(void); void my_ed(void); void my_make_block(void); void my_gameover(void); void my_get_key(void); void my_move_block(void); void my_collision_left(void); void my_collision_right(void); void my_collision_bottom(void); void my_collision_center(void); void my_fix_block(void); void my_save_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 game_state; int block_x; int block_y; float block_y_count; float block_speed; int collision_flag; int gameover_flag; int make_block_flag; int Color_Red; int Color_Black; int Color_Green; 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(); switch(game_state){ case 0: game_state = 5; break; case 5: my_make_block(); my_gameover(); my_get_key(); my_move_block(); my_draw_back(); my_draw_variable(); my_draw_block(); my_draw_stage(); my_fix_block(); my_fall_block(); if(gameover_flag == 1){ game_state = 10; } break; case 10: my_draw_back(); my_draw_block(); my_draw_stage(); my_ed(); break; default: break; } 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; } } game_state = 0; block_x = 7; block_y = 0; block_y_count = 0; block_speed = 0.5f; collision_flag = 0; gameover_flag = 0; make_block_flag = 1; Color_Red = GetColor(255,0,0); Color_Black = GetColor(0,0,0); Color_Green = GetColor(0,255,0); back_img1 = LoadGraph("./back_img1.jpg"); } void my_init_var2(){ block_x = 7; block_y = 0; block_y_count = 0; make_block_flag = 1; } void my_ed(){ DrawFormatString(400,400,Color_Black,"GAME OVER"); } void my_make_block(){ int x,y; if(make_block_flag == 1){ for(y=0;y<BLOCK_HEIGHT;y++){ for(x=0;x<BLOCK_WIDTH;x++){ block[y][x] = blocks[y][x]; } } make_block_flag = 0; } } void my_gameover(){ my_collision_center(); if(collision_flag != 0){ gameover_flag = 1; } } 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++; } } if(key[KEY_INPUT_DOWN] % 5 == 1){ my_collision_bottom(); if(collision_flag == 0){ block_y++; block_y_count = block_y * DRAW_BLOCK_WIDTH; } } } 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_collision_bottom(){ 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 + 1)][block_x + x] != 0){ collision_flag = 1; } } } } } void my_collision_center(){ 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] != 0){ collision_flag = 1; } } } } } void my_fix_block(){ my_collision_bottom(); if(collision_flag != 0){ my_save_block(); my_init_var2(); } } void my_save_block(){ int x,y; for(y=0;y<BLOCK_HEIGHT;y++){ for(x=0;x<BLOCK_WIDTH;x++){ stage[block_y + y][block_x + x] += block[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] == 2)DrawFormatString(x * DRAW_BLOCK_WIDTH, y * DRAW_BLOCK_WIDTH,Color_Green,"¡"); else if(stage[y][x] == 9)DrawFormatString(x * DRAW_BLOCK_WIDTH, y * DRAW_BLOCK_WIDTH,Color_Black,"¡"); } } } void my_fall_block(){ if(make_block_flag == 0){ 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; } } }

/*ƒy[ƒW‚̐擪‚Ö*/

/*–ÚŽŸ‚Ö–ß‚é*/

/*HOME*/

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

/*L*/