画像のサイズについて。DXライブラリ初心者
Posted: 2010年3月31日(水) 22:30
png画像のサイズが384x384なので、それにあわせてコーディングしてみたんですがうまくいきません。
#include "DxLib.h"
typedef struct{
int x; //x座標にいる位置
int y; //y座標にいる位置
int img; //イメージ
int muki; //向き
int walking_flag; //歩けるかどうか
}ch_t;
int hantei[10][20] = {
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1},
{1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1},
{1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
};
int can_or_cannot(int x,int y,int muki){
//上向き
if(muki == 0){
if(hantei[y / 48 - 1][x / 32] == 1){
return 1;
}
}
//左向き
if(muki == 1){
if(hantei[y / 48][x / 32 - 1] == 1){
return 1;
}
}
//下向き
if(muki == 2){
if(hantei[y / 48 + 1][x / 32] == 1){
return 1;
}
}
//右向き
if(muki == 3){
if(hantei[y / 48][x / 32 + 1] == 1){
return 1;
}
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow){
int i,j;
int image[12];
char key[256];
ch_t ch;
if(ChangeWindowMode(TRUE) != DX_CHANGESCREEN_OK || DxLib_Init() == -1){
return -1;
}
ch.x = 320;
ch.y = 240;
ch.walking_flag = 0;
ch.muki = 3;
SetDrawScreen(DX_SCREEN_BACK);
LoadDivGraph("char.png",12, 3, 4, 32, 48,image);
while(!ProcessMessage() && !ClearDrawScreen() && !GetHitKeyStateAll(key) && !key[KEY_INPUT_ESCAPE]){
for(i = 0;i < 10; i++){
for(j = 0;j < 20; j++){
DrawBox(j * 32, i * 48,(j + 1) * 32,(i + 1) * 48,GetColor(255,255,255),TRUE);
}
}
if(ch.x % 32 == 0 && ch.y % 48 == 0){
ch.walking_flag = 1;
if(key[KEY_INPUT_UP] == 1){
ch.muki = 0;
}else if(key[KEY_INPUT_LEFT] == 1){
ch.muki = 1;
}else if(key[KEY_INPUT_DOWN] == 1){
ch.muki = 2;
}else if(key[KEY_INPUT_RIGHT] == 1){
ch.muki = 3;
}else{
ch.walking_flag = 0;
}
if(ch.walking_flag == 1){
if(can_or_cannot(ch.x,ch.y,ch.muki) == 1){
ch.walking_flag = 0;
}
}
}
if(ch.walking_flag == 1){
if(ch.muki == 0){
ch.y--; //上向き
}else if(ch.muki == 1){
ch.x--; //左向き
}else if(ch.muki == 2){
ch.y++; //下向き
}else if(ch.muki == 3){
ch.x++; //右向き
}
}
ch.img = image[(ch.x % 32 + ch.y % 48) / 12 + ch.muki * 3];
DrawGraph(ch.x,ch.y,ch.img,TRUE);
ScreenFlip();
}
DxLib_End();
return 0
}
指南のほどよろしくお願いします。
#include "DxLib.h"
typedef struct{
int x; //x座標にいる位置
int y; //y座標にいる位置
int img; //イメージ
int muki; //向き
int walking_flag; //歩けるかどうか
}ch_t;
int hantei[10][20] = {
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1},
{1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1},
{1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
};
int can_or_cannot(int x,int y,int muki){
//上向き
if(muki == 0){
if(hantei[y / 48 - 1][x / 32] == 1){
return 1;
}
}
//左向き
if(muki == 1){
if(hantei[y / 48][x / 32 - 1] == 1){
return 1;
}
}
//下向き
if(muki == 2){
if(hantei[y / 48 + 1][x / 32] == 1){
return 1;
}
}
//右向き
if(muki == 3){
if(hantei[y / 48][x / 32 + 1] == 1){
return 1;
}
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow){
int i,j;
int image[12];
char key[256];
ch_t ch;
if(ChangeWindowMode(TRUE) != DX_CHANGESCREEN_OK || DxLib_Init() == -1){
return -1;
}
ch.x = 320;
ch.y = 240;
ch.walking_flag = 0;
ch.muki = 3;
SetDrawScreen(DX_SCREEN_BACK);
LoadDivGraph("char.png",12, 3, 4, 32, 48,image);
while(!ProcessMessage() && !ClearDrawScreen() && !GetHitKeyStateAll(key) && !key[KEY_INPUT_ESCAPE]){
for(i = 0;i < 10; i++){
for(j = 0;j < 20; j++){
DrawBox(j * 32, i * 48,(j + 1) * 32,(i + 1) * 48,GetColor(255,255,255),TRUE);
}
}
if(ch.x % 32 == 0 && ch.y % 48 == 0){
ch.walking_flag = 1;
if(key[KEY_INPUT_UP] == 1){
ch.muki = 0;
}else if(key[KEY_INPUT_LEFT] == 1){
ch.muki = 1;
}else if(key[KEY_INPUT_DOWN] == 1){
ch.muki = 2;
}else if(key[KEY_INPUT_RIGHT] == 1){
ch.muki = 3;
}else{
ch.walking_flag = 0;
}
if(ch.walking_flag == 1){
if(can_or_cannot(ch.x,ch.y,ch.muki) == 1){
ch.walking_flag = 0;
}
}
}
if(ch.walking_flag == 1){
if(ch.muki == 0){
ch.y--; //上向き
}else if(ch.muki == 1){
ch.x--; //左向き
}else if(ch.muki == 2){
ch.y++; //下向き
}else if(ch.muki == 3){
ch.x++; //右向き
}
}
ch.img = image[(ch.x % 32 + ch.y % 48) / 12 + ch.muki * 3];
DrawGraph(ch.x,ch.y,ch.img,TRUE);
ScreenFlip();
}
DxLib_End();
return 0
}
指南のほどよろしくお願いします。