クォータービューの移動範囲を求め、移動するアルゴリズムについて
Posted: 2010年7月19日(月) 14:51
こんにちは、TKOZです。
また、クォータービューで分からない所が出てきました。
それは、移動範囲を求め、表示し、クリックした座標へ移動する処理の事です。
VBのサンプルでKone's D Stationというサイトのサンプルを参考にやっているのですが、
うまくいきません。
とりあえず、プログラム本体とは切り離して、サンプルをとりあえず、クォータービューではなく、
矩形(くけい)のマスで計算し、移植しているのですが、上手くいきません。
具体的には、Timer1_Timer()の処理や、Command1.enableの値をどうするのか分かりません。
Cに移植したソースを載せます。
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<time.h>
#include"DxLib.h"
#include<windows.h>
int MX,MY;//キャラ座標
int FPX[7];int FPY[7];int Way;//移動経路座標と移動するマス数
int ImageBG,ImageChara;
Part Parts[9][9];//各地形
void Command1_Click();
void MoveAreaPaint();
class T{
public:
bool Enabled;//フラグ
int Interval;
int NowTime;
T()
{
Enabled=false;
Interval=0;
NowTime=0;
}
void SetTimer1_Timer()
{
NowTime=GetTickCount();
}
int GetTimer1_Timer()
{
if(Enabled==true && Interval>0)
{
if(GetTickCount()-NowTime>Interval)
{
NowTime=GetTickCount();
Timer1_Timer();
}
}
}
void Timer1_Timer()
{
DrawBox(FPX[Way]*32,FPY[Way]*32,
FPX[Way]*32+32,FPY[Way]*32+32,GetColor(255,255,0),TRUE);
Way--;
if(Way==-1)
{
MX=FPX[0];
MY=FPY[0];
Way=0;
Enabled =false;
MoveAreaPaint();
Command1_Click();
}
}
};
void MoveAreaPaint()
{
int a,b,c,d;
for(a=0;a<9;a++)
{
for(b=0;b<9;b++)
{
DrawRectGraph(a*32,b*32,
(Parts[a].PType/2)*32,(Parts[a].PType%2)*32,
32,32,ImageBG,FALSE,FALSE);
Parts[a].FPointX =0;
Parts[a].FPointY = 0;
Parts[a].LMPoint = 0;
}
}
//メイン判定ルーチン
Parts[MX][MY].LMPoint = 7;
for(c=1;c<=7;c++)
{
for(a=MX-c;a<=MX+c;a++)
{
for(b=(7-abs(MX-a));b<=abs(7-abs(MX-a));b++)
{
if( a>=0 && a<10 && b>=0 && b<10)
{
//左側判定
if(a>=0)
{
if(Parts[a].MPoint <= Parts[a - 1].LMPoint && Parts[a].LMPoint <= Parts[a - 1].LMPoint - Parts[a].MPoint)
{
Parts[a][b].LMPoint = Parts[a - 1][b].LMPoint - Parts[a][b].MPoint;
Parts[a][b].FPointX = -1;
Parts[a][b].FPointY = 0;
}
}
//右がわ判定
if (a < 9)
{
if (Parts[a][b].MPoint <= Parts[a + 1][b].LMPoint && Parts[a][b].LMPoint <= Parts[a + 1][b].LMPoint - Parts[a][b].MPoint)
{
Parts[a][b].LMPoint = Parts[a + 1][b].LMPoint - Parts[a][b].MPoint;
Parts[a][b].FPointX = 1;
Parts[a][b].FPointY = 0;
}
}
//上がわ判定
if( b >= 0)
{
if (Parts[a][b].MPoint <= Parts[a][b - 1].LMPoint && Parts[a][b].LMPoint <= Parts[a][b - 1].LMPoint - Parts[a][b].MPoint)
{
Parts[a][b].LMPoint = Parts[a][b - 1].LMPoint - Parts[a][b].MPoint;
Parts[a][b].FPointX = 0;
Parts[a][b].FPointY = -1;
}
}
//下がわ判定
if (b < 9)
{
if (Parts[a][b].MPoint <= Parts[a][b + 1].LMPoint && Parts[a][b].LMPoint <= Parts[a][b + 1].LMPoint - Parts[a][b].MPoint)
{
Parts[a][b].LMPoint = Parts[a][b + 1].LMPoint - Parts[a][b].MPoint;
Parts[a][b].FPointX = 0;
Parts[a][b].FPointY = 1;
}
}
}
}
}
}
for(a=0;a<9;a++)
{
for(b=0;b<9;b++)
{
if(Parts[a][b].FPointX!=0 || Parts[a][b].FPointY!=0)
{
DrawBox(a*32,b*32,a*32+32,b*32+32,GetColor(255,0,0),FALSE);
}
}
}
DrawBox(MX*32,MY*32,MX*32+32,MY*32+32,GetColor(255,255,255),TRUE);
}

また、クォータービューで分からない所が出てきました。
それは、移動範囲を求め、表示し、クリックした座標へ移動する処理の事です。
VBのサンプルでKone's D Stationというサイトのサンプルを参考にやっているのですが、
うまくいきません。
とりあえず、プログラム本体とは切り離して、サンプルをとりあえず、クォータービューではなく、
矩形(くけい)のマスで計算し、移植しているのですが、上手くいきません。
具体的には、Timer1_Timer()の処理や、Command1.enableの値をどうするのか分かりません。
Cに移植したソースを載せます。
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<time.h>
#include"DxLib.h"
#include<windows.h>
int MX,MY;//キャラ座標
int FPX[7];int FPY[7];int Way;//移動経路座標と移動するマス数
int ImageBG,ImageChara;
Part Parts[9][9];//各地形
void Command1_Click();
void MoveAreaPaint();
class T{
public:
bool Enabled;//フラグ
int Interval;
int NowTime;
T()
{
Enabled=false;
Interval=0;
NowTime=0;
}
void SetTimer1_Timer()
{
NowTime=GetTickCount();
}
int GetTimer1_Timer()
{
if(Enabled==true && Interval>0)
{
if(GetTickCount()-NowTime>Interval)
{
NowTime=GetTickCount();
Timer1_Timer();
}
}
}
void Timer1_Timer()
{
DrawBox(FPX[Way]*32,FPY[Way]*32,
FPX[Way]*32+32,FPY[Way]*32+32,GetColor(255,255,0),TRUE);
Way--;
if(Way==-1)
{
MX=FPX[0];
MY=FPY[0];
Way=0;
Enabled =false;
MoveAreaPaint();
Command1_Click();
}
}
};
void MoveAreaPaint()
{
int a,b,c,d;
for(a=0;a<9;a++)
{
for(b=0;b<9;b++)
{
DrawRectGraph(a*32,b*32,
(Parts[a].PType/2)*32,(Parts[a].PType%2)*32,
32,32,ImageBG,FALSE,FALSE);
Parts[a].FPointX =0;
Parts[a].FPointY = 0;
Parts[a].LMPoint = 0;
}
}
//メイン判定ルーチン
Parts[MX][MY].LMPoint = 7;
for(c=1;c<=7;c++)
{
for(a=MX-c;a<=MX+c;a++)
{
for(b=(7-abs(MX-a));b<=abs(7-abs(MX-a));b++)
{
if( a>=0 && a<10 && b>=0 && b<10)
{
//左側判定
if(a>=0)
{
if(Parts[a].MPoint <= Parts[a - 1].LMPoint && Parts[a].LMPoint <= Parts[a - 1].LMPoint - Parts[a].MPoint)
{
Parts[a][b].LMPoint = Parts[a - 1][b].LMPoint - Parts[a][b].MPoint;
Parts[a][b].FPointX = -1;
Parts[a][b].FPointY = 0;
}
}
//右がわ判定
if (a < 9)
{
if (Parts[a][b].MPoint <= Parts[a + 1][b].LMPoint && Parts[a][b].LMPoint <= Parts[a + 1][b].LMPoint - Parts[a][b].MPoint)
{
Parts[a][b].LMPoint = Parts[a + 1][b].LMPoint - Parts[a][b].MPoint;
Parts[a][b].FPointX = 1;
Parts[a][b].FPointY = 0;
}
}
//上がわ判定
if( b >= 0)
{
if (Parts[a][b].MPoint <= Parts[a][b - 1].LMPoint && Parts[a][b].LMPoint <= Parts[a][b - 1].LMPoint - Parts[a][b].MPoint)
{
Parts[a][b].LMPoint = Parts[a][b - 1].LMPoint - Parts[a][b].MPoint;
Parts[a][b].FPointX = 0;
Parts[a][b].FPointY = -1;
}
}
//下がわ判定
if (b < 9)
{
if (Parts[a][b].MPoint <= Parts[a][b + 1].LMPoint && Parts[a][b].LMPoint <= Parts[a][b + 1].LMPoint - Parts[a][b].MPoint)
{
Parts[a][b].LMPoint = Parts[a][b + 1].LMPoint - Parts[a][b].MPoint;
Parts[a][b].FPointX = 0;
Parts[a][b].FPointY = 1;
}
}
}
}
}
}
for(a=0;a<9;a++)
{
for(b=0;b<9;b++)
{
if(Parts[a][b].FPointX!=0 || Parts[a][b].FPointY!=0)
{
DrawBox(a*32,b*32,a*32+32,b*32+32,GetColor(255,0,0),FALSE);
}
}
}
DrawBox(MX*32,MY*32,MX*32+32,MY*32+32,GetColor(255,255,255),TRUE);
}
