/*広告*/
/*STGの作り方 中間ソース4*/
#include "DxLib.h" #define LEFT_LIMIT -220 #define RIGHT_LIMIT 220 #define TOP_LIMIT 240 #define BOTTOM_LIMIT -240 #define PLAYER_SHOT_MAX 30 void my_init_back_img(void); void my_init_variable(void); void my_init_player(void); void my_init_player_shot(void); void my_set_player_shot(int ); void my_move_back(void); void my_move_player(void); void my_move_player_shot(void); void my_to_center(void); void my_draw_back(void); void my_draw_player(void); void my_draw_player_shot(void); void my_draw_score_board(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 bomb; int power; int life; double range; }; struct PLAYER p1; struct PLAYER_SHOT{ double x[5]; double y[5]; double draw_x[5]; double draw_y[5]; int init_flag; int move_flag; int move_type; int flag[5]; double angle[5]; int max_bullet; int gamecount_point; double range; }; struct PLAYER_SHOT ps1[PLAYER_SHOT_MAX]; int key[256]; double back_img_y; int back_img; int gamecount; int Color_White; int Color_Gray; 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(); my_init_player_shot(); while (ScreenFlip()==0 && ProcessMessage()==0 && ClearDrawScreen()==0 && my_get_key()==0){ my_move_back(); my_move_player(); my_move_player_shot(); my_to_center(); my_draw_back(); my_draw_player(); my_draw_player_shot(); my_draw_score_board(); 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); Color_Gray = GetColor(100, 100, 100); 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.bomb = 1; p1.power = 1; p1.life = 3; p1.range = 10; } void my_init_player_shot(){ for(int i = 0;i < PLAYER_SHOT_MAX;i++){ ps1[i].init_flag = 0; ps1[i].move_flag = 0; ps1[i].move_type = 0; ps1[i].max_bullet = 0; ps1[i].gamecount_point = 0; ps1[i].range = 10; for(int j = 0;j < 5;j++){ ps1[i].x[j] = 0; ps1[i].y[j] = 0; ps1[i].draw_x[j] = 0; ps1[i].draw_y[j] = 0; ps1[i].flag[j] = 0; ps1[i].angle[j] = 0; } } } 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; } if (key[KEY_INPUT_Z] % 5 == 1){ my_set_player_shot(p1.shot_type); } } void my_set_player_shot(int shot_type){ for(int i = 0;i < PLAYER_SHOT_MAX;i++){ if(ps1[i].move_flag == 0){ ps1[i].move_type = shot_type; ps1[i].move_flag = 1; break; } } } void my_move_player_shot(){ for(int i = 0;i < PLAYER_SHOT_MAX;i++){ if(ps1[i].move_flag == 1){ switch(ps1[i].move_type){ case 0: if(ps1[i].init_flag == 0){ ps1[i].max_bullet = 1; for(int j = 0;j < ps1[i].max_bullet;j++){ ps1[i].x[j] = p1.x; ps1[i].y[j] = p1.y; ps1[i].flag[j] = 1; } ps1[i].gamecount_point = gamecount; ps1[i].init_flag = 1; } else{ if(gamecount < ps1[i].gamecount_point + 100){ for(int j = 0;j < ps1[i].max_bullet;j++){ ps1[i].y[j] += 8; } } else{ ps1[i].move_flag = 0; ps1[i].init_flag = 0; } } break; default: break; } } } } void my_to_center(){ p1.draw_x = p1.x + 220; p1.draw_y = ((-1) * p1.y) + 240; for(int i = 0;i < PLAYER_SHOT_MAX;i++){ if(ps1[i].move_flag == 1 && ps1[i].init_flag == 1){ for(int j = 0;j < ps1[i].max_bullet;j++){ ps1[i].draw_x[j] = ps1[i].x[j] + 220; ps1[i].draw_y[j] = ((-1) * ps1[i].y[j]) + 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, 440, 240, Color_White); DrawLine(220, 0, 220, 480, Color_White); DrawFormatString(220, 240, Color_White, "(0,0)"); } void my_draw_player(){ DrawFormatString(p1.draw_x, p1.draw_y, Color_White, "P"); } void my_draw_player_shot(){ for(int i = 0;i < PLAYER_SHOT_MAX;i++){ if(ps1[i].move_flag == 1 && ps1[i].init_flag == 1){ for(int j = 0;j < ps1[i].max_bullet;j++){ if(ps1[i].flag[j] == 1){ DrawFormatString(ps1[i].draw_x[j],ps1[i].draw_y[j],Color_White, "弾"); } } } } } void my_draw_score_board(){ DrawBox(440,0,640,480,Color_Gray,true); DrawFormatString(460, 20, Color_White, "gamecount = %d", gamecount); DrawFormatString(460, 380, Color_White, "操作方法"); DrawFormatString(460, 400, Color_White, "移動:矢印キー"); DrawFormatString(460, 420, Color_White, "ショット:Zキー"); } 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; }/*Copyright 2016 K.N/petitetech.com*/
/*広告*/