まずメイン部分が
#include "DxLib.h" //いろいろとか
#include "math.h"
#include "define.h" //定義とか
#include "struct.h" //構造体の宣言とか
#include "GV.h" //グローバル変数の宣言とか
#include "load.h" //ロードとか
#include "Key.h" //キー入力系とか
#include "ini.h" //初期化とか
#include "music.h" //効果音とか
#include "graph.h" //描写とか
#include "char.h" //自機とか
#include "enemy.h" //敵とか
#include "cshot.h" //自機のショットとか
#include "cshot2.h"
#include "shot.h" //敵機のショットとか
#include "Net.h"
//ループで必ず行う3大処理
int ProcessLoop(){
if(ProcessMessage()!=0)return -1;//プロセス処理がエラーなら-1を返す
if(ClearDrawScreen()!=0)return -1;//画面クリア処理がエラーなら-1を返す
GetHitKeyStateAll_2();//現在のキー入力処理を行う
GetHitPadStateAll(); //現在のパッド入力処理を行う
GetHitKeyNetAll(); //今の接続状態を保存する
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow){
SetMainWindowText( "PAKOSTG2" ) ;
ChangeWindowMode(TRUE);//ウィンドウモード
if(DxLib_Init() == -1 || SetDrawScreen( DX_SCREEN_BACK )!=0) return -1;//初期化と裏画面化
func_state=0;
while(ProcessLoop()==0){//メインループ
music_ini();
switch(func_state){
case 0://初回のみ入る処理
load(); //データロード
first_ini(); //初回の初期化
func_state=90;
break;
case 90://STGを始める前に行う初期化
ini(); //初期化処理
func_state=95;
break;
case 95://体験番用自機タイプセレクトとか
KndSelect();
graph_main(); //描画メイン
DrawFormatString( 640/2, 480/2, GetColor( 255 , 25 , 255 ) , "攻撃ボタンで決定です" );//文字列表示
DrawFormatString( 640/2, 480/3, GetColor( 255 , 25 , 255 ) , "現在の自機:%d" , ch.Kad );//文字列表示
if(CheckStatePad(configpad.SHOT)==1){
func_state=100;
if(0<NetMode){
func_state=97;
}
}
break;
case 97://
NetSelect();
if(CheckStatePad(configpad.SHOT)==1){
if(Ip.d1==0 && Ip.d2==0 && Ip.d3==0 && Ip.d4==0){
NetMode=0;
}
else Netini();
func_state=100;
}
break;
case 100://通常処理
if(0<NetMode){
Netmain();
func_state=200;
}
calc_ch(); //キャラクタ計算
ch_move(); //キャラクタの移動制御
if(0<NetMode){
ch2_move(); //キャラクタの移動制御
}
cshot_main();
if(0<NetMode){
cshot_main2();
}
enemy_main(); //敵処理メイン
graph_main(); //描画メイン
stage_count++;
if(func_state==100){
break;
}
case 200:
if( CheckNetWorkRecvUDP( NetUDPHandle ) == 1 ){
// 受信
func_state=100;
int port=PORT;
NetWorkRecvUDP( NetUDPHandle, &Ip, &port, &Net, 1, FALSE ) ;
}
else{
DrawFormatString( 50, 480/8-40, GetColor( 255 , 25 , 255 ) , "%d" ,NetUDPHandle );//文字列表示
}
break;
default:
printfDx("不明なfunc_state\n");
break;
}
music_play();
if(CheckStateKey(KEY_INPUT_ESCAPE)==1)break;//エスケープが入力されたらブレイク
ScreenFlip();//裏画面反映
}
if(0<NetMode){
// UDPソケットハンドルの削除
DeleteUDPSocket( NetUDPHandle ) ;
}
DxLib_End();//DXライブラリ終了処理
return 0;
}
通信関係が
void NetSelect(){
if(CheckStatePad(configpad.UP)%6==1){
if(a==0 && 0<Ip.d1)Ip.d1--;
if(a==1 && 0<Ip.d2)Ip.d2--;
if(a==2 && 0<Ip.d3)Ip.d3--;
if(a==3 && 0<Ip.d4)Ip.d4--;
if(0<CheckStatePad(configpad.slow)){
if(a==0 && 8<Ip.d1)Ip.d1-=9;
if(a==1 && 8<Ip.d2)Ip.d2-=9;
if(a==2 && 8<Ip.d3)Ip.d3-=9;
if(a==3 && 8<Ip.d4)Ip.d4-=9;
}
}
if(CheckStatePad(configpad.DOWN)%6==1){
if(a==0 && Ip.d1<255)Ip.d1++;
if(a==1 && Ip.d2<255)Ip.d2++;
if(a==2 && Ip.d3<255)Ip.d3++;
if(a==3 && Ip.d4<255)Ip.d4++;
if(0<CheckStatePad(configpad.slow)){
if(a==0 && Ip.d1<246)Ip.d1+=9;
if(a==1 && Ip.d2<246)Ip.d2+=9;
if(a==2 && Ip.d3<246)Ip.d3+=9;
if(a==3 && Ip.d4<246)Ip.d4+=9;
}
}
if(CheckStatePad(configpad.LEFT)%6==1){
if(0<a)a--;
}
if(CheckStatePad(configpad.RIGHT)%6==1){
if(a<3)a++;
}
DrawBox(40+a*100,480/8-10,50+50+a*100,480/8+22,GetColor(255,255,255),0);
DrawFormatString( 50, 480/8-40, GetColor( 255 , 25 , 255 ) , "IPアドレス入力" );//文字列表示
DrawFormatString( 50, 480/8, GetColor( 255 , 25 , 255 ) , "%03d.",Ip.d1 );//文字列表示
DrawFormatString( 150, 480/8, GetColor( 255 , 25 , 255 ) , "%03d.",Ip.d2 );//文字列表示
DrawFormatString( 250, 480/8, GetColor( 255 , 25 , 255 ) , "%03d.",Ip.d3 );//文字列表示
DrawFormatString( 350, 480/8, GetColor( 255 , 25 , 255 ) , "%03d",Ip.d4 );//文字列表示
}
void Netini(){
//最初にやること
NetUDPHandle=MakeUDPSocket( PORT );
}
void Netmain(){
// 文字列の送信
printfDx("%d\n",NetWorkSendUDP( NetUDPHandle, Ip, PORT, &Net, 1 ) );
printfDx("%ld\n",Ip.dall);
}
PORTはポート番号で60000で固定しています。
(自分で選べるようにしたほうが良かったりその番号はよくないのなら指摘していただけると嬉しいです。)
プログラムはSTGで龍神録の館を参考にさせていただいてます。
何かわかる方がいらっしゃったら教えてほしいです。
MVC++2010Eをつかってます。
=====
~の使い方が変とか気が付きましたら教えてください。
情報が少なすぎるかもしれませんが、よろしくお願いします。
(提示したほうがいいものがある場合指摘していただけると嬉しいです。)