/*STGの作り方 中間ソース3*/

/*目次へ戻る*/ #include "DxLib.h" #define LEFT_LIMIT -320 #define RIGHT_LIMIT 320 #define TOP_LIMIT 240 #define BOTTOM_LIMIT -240 void my_init_back_img(void); void my_init_variable(void); void my_init_player(void); void my_move_back(void); void my_move_player(void); void my_to_center(void); void my_draw_back(void); void my_draw_player(void); void my_draw_variable(void); void my_timer(void); int my_get_key(void); struct PLAYER{ double x, y; double draw_x, draw_y; int speed; int shot_type; int power; int life; double range; }; struct PLAYER p1; int key[256]; double back_img_y; int back_img; int gamecount; int Color_White; int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int){ ChangeWindowMode(TRUE); DxLib_Init(); SetDrawScreen(DX_SCREEN_BACK); my_init_back_img(); my_init_variable(); my_init_player(); while (ScreenFlip()==0 && ProcessMessage()==0 && ClearDrawScreen()==0 && my_get_key()==0){ my_move_back(); my_move_player(); my_to_center(); my_draw_back(); my_draw_player(); my_draw_variable(); my_timer(); } DxLib_End(); return 0; } void my_init_back_img(){ back_img = LoadGraph("../back_img.jpg"); } void my_init_variable(){ gamecount = 0; Color_White = GetColor(255, 255, 255); back_img_y = 0; } void my_init_player(){ p1.x = 0; p1.y = -200; p1.draw_x = 0; p1.draw_y = 0; p1.speed = 4; p1.shot_type = 0; p1.power = 100; p1.life = 3; p1.range = 10; } void my_move_back(){ back_img_y++; if (back_img_y > 480){ back_img_y = 0; } } void my_move_player(){ if (key[KEY_INPUT_RIGHT] >= 1 && p1.x < RIGHT_LIMIT){ p1.x += p1.speed; } if (key[KEY_INPUT_DOWN] >= 1 && p1.y > BOTTOM_LIMIT){ p1.y -= p1.speed; } if (key[KEY_INPUT_LEFT] >= 1 && p1.x > LEFT_LIMIT){ p1.x -= p1.speed; } if (key[KEY_INPUT_UP] >= 1 && p1.y < TOP_LIMIT){ p1.y += p1.speed; } } void my_to_center(){ p1.draw_x = p1.x + 320; p1.draw_y = ((-1) * p1.y) + 240; } void my_draw_back(){ DrawGraph(0, back_img_y, back_img, TRUE); DrawGraph(0, back_img_y - 480, back_img, TRUE); DrawLine(0, 240, 640, 240, Color_White); DrawLine(320, 0, 320, 480, Color_White); DrawFormatString(320, 240, Color_White, "(0,0)"); DrawFormatString(100, 0, Color_White, "操作方法 移動:矢印キー"); } void my_draw_player(){ DrawFormatString(p1.draw_x, p1.draw_y, Color_White, "P[%d][%d]", (int)p1.x, (int)p1.y); } void my_draw_variable(){ DrawFormatString(440, 440, Color_White, "gamecount = %d", gamecount); } void my_timer(){ gamecount++; } int my_get_key(){ char keys[256]; GetHitKeyStateAll(keys); for (int i = 0; i < 256; i++){ if (keys[i] != 0){ key[i]++; } else{ key[i] = 0; } } return 0; } /*ページの先頭へ*/ /*目次へ戻る*/ /*HOME*/