アクションゲームでの色判定で坂道の移動をさせて
いるのですが、どうも動きが思い通りにいきません。例えば、右上の坂があるとして、
右に移動する→上に上がる→右に移動する→少し上に上がるを繰りかえてしまいます。
どうすれば、坂道移動を自然な形で出来るでしょうか。よろしくおねがいします。
#include"Main.h"
Jiki Player;
/*
Teki Enemy[MAX_ENEMY];
Tama Bullet[MAX_BULLET];
System Sys;
*/
int MouseX,MouseY;
int map;
int g=10;
int GetCol(int x,int y)
{
int r,g,b,a;
GetPixelSoftImage(map, x, y, &r, &g, &b, &a ) ;
return GetColor(r,g,b);
}
void DivideColor(int src,int *r,int *g,int *b)
{
*r = ((src
>>16)&0xFF);
*g = ((src
>>8)&0xFF);
*b = (src&0xFF);
}
void HitCheckColor()
{
int i,j;
int white=GetColor(255,255,255);
float speed=0.15f;
float jump_speed=-4.0f;
float jump_accel=0.5f;
static int Jump=1;
static float VX=0;
static float VY=0;
static int ground_y;
if(!Jump)
{
if(CheckHitKey(KEY_INPUT_X))
{
Jump=1;
VY=jump_speed;
}
}
else
{
VY+=jump_accel;
Player.y+=VY;
}
if(CheckHitKey(KEY_INPUT_LEFT)){ Jump=1;Player.x--;}
if(CheckHitKey(KEY_INPUT_RIGHT)){ Jump=1;Player.x++;}
//if(GetPixel(i+1,j)==white) Player.x++;
//if(GetPixel(i-1,j)==white) Player.x--;
//if(GetPixel(i,j+1)==white)
//Player.y++;
//Player.y++;
DrawFormatString(0,45,GetColor(255,0,0),"GetColor=%d",GetColor(255,255,255));
DrawFormatString(0,70,GetColor(255,0,0),"GetPixel(x,y)=%d",GetPixel(Player.x,Player.y+63));
DrawFormatString(0,90,GetColor(255,0,0),"x,y=(%d,%d)",Player.x,Player.y);
DrawFormatString(0,128,GetColor(255,0,0),"Jump=%d",Jump);
if(GetCol(Player.x,Player.y)==white)
{
//MessageBox(NULL,"OK","OK",NULL);
DrawString(0,0,"左上",GetColor(255,255,255));
Player.x++;
Jump=1;
}
if(GetCol(Player.x+31,Player.y)==white)
{
//MessageBox(NULL,"OK","OK",NULL);
DrawString(0,0,"右上",GetColor(255,255,255));
Player.x--;
Jump=1;
}
if(GetCol(Player.x,Player.y+60)==white)
{
//MessageBox(NULL,"OK","OK",NULL);
DrawString(0,0,"左下",GetColor(255,255,255));
Player.y--;
ground_y=Player.y+64;
Jump=0;
}
if(GetCol(Player.x+31,Player.y+60)==white)
{
//MessageBox(NULL,"OK","OK",NULL);
DrawString(0,0,"右下",GetColor(255,255,255));
Player.y--;
Jump=0;
}
}
void Init()
{
Player.x=(640-32)/2;
Player.y=0;
map = LoadSoftImage( "./DATA/Map.png" ) ;
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hP,LPSTR lpC,int nC)
{
ChangeWindowMode(TRUE); //ウィンドウモードで起動
SetGraphMode(640,480,32);
SetMainWindowText("METAL TANK ver0.01"); //ウィンドウのタイトル
if(DxLib_Init() == -1) return (-1); //DXライブラリ初期化
Init();
//データ読み込み中と表示する
DrawString( 0 , 0 , "データ読み込み中" , GetColor(255,255,255) );
//乱数の初期化
srand((unsigned)GetTickCount());
SetDrawScreen(DX_SCREEN_BACK);
//メインループ
while( ProcessMessage()==0 && CheckHitKey(KEY_INPUT_ESCAPE)==0){
ProcessMessage();
ClsDrawScreen(); //画面を初期化
Player.Move();
HitCheckColor();
DrawSoftImage(0,0, map ) ;
Player.Draw();
GetMousePoint( &MouseX, &MouseY );
if(GetPixel(MouseX,MouseY)==GetColor(255,255,255))
{
DrawFormatString( 0 , 25 , GetColor(255,255,255) ,
"(%d,%d)=%d" , MouseX,MouseY,GetPixel(MouseX,MouseY) ) ;
//Player.y--;
//MessageBox(NULL,"OK","OK",NULL);
}
ScreenFlip(); //フリップする
}
DxLib_End(); //DXライブラリ終了処理
return (0); //終了
}