クォータービュー

アバター
大白定義
記事: 14
登録日時: 14年前
住所: 三重県

クォータービュー

投稿記事 by 大白定義 » 12年前

私、(クォータービューが)気になります!
というわけで、超久々にDXライブラリを弄りました。D言語で。

で、書いたのが以下のようなソースコード。

CODE:

import dxlib;

bool canRun(){
	return 
		CheckHitKey(KEY_INPUT_ESCAPE) == 0 &&
		ProcessMessage() != -1;
}

int map[5][5] = [
		[1,1,1,1,1],
		[1,0,1,0,1],
		[1,1,1,1,1],
		[1,0,1,0,1],
		[1,1,1,1,1],
	];

void main(){
	ChangeWindowMode(TRUE);
	if(DxLib_Init() == -1) return;
	scope(exit) DxLib_End();
	
	int handle[2];
	LoadDivGraph("map2.png", 2, 1, 2, 38, 19, handle.ptr);
	int graph_w, graph_h;
	GetGraphSize(handle[0], &graph_w, &graph_h);
	
	int mouse_x=0, mouse_y=0;
	int select_x, select_y;
	int before_x, before_y;
	int slip_x=0, slip_y=0;
	
	SetDrawScreen(DX_SCREEN_BACK);
	while(canRun()){
		ClearDrawScreen();
		
		before_x = mouse_x;
		before_y = mouse_y;
		GetMousePoint(&mouse_x, &mouse_y);
		
		if((GetMouseInput() & MOUSE_INPUT_RIGHT) != 0){
			slip_x += mouse_x - before_x;
			slip_y += mouse_y - before_y;
		}
		
		select_x = ((mouse_x - slip_x) / graph_w) + ((mouse_y - slip_y) / graph_h);
		select_y = ((mouse_x - slip_x) / graph_w) - ((mouse_y - slip_y) / graph_h);
		
		for(int i=0; i<map.length; i++){
			for(int j=0; j<map[i].length; j++){
				if(map[i][j] == 1){
					int x = (graph_w / 2) * (j + i);
					int y = (graph_h / 2) * (j - i);
					int num = (j == select_x && i == select_y) ? 1 : 0;
					
					DrawGraph(x + slip_x, y + slip_y, handle[num], TRUE);
				}
			}
		}
		
		DrawFormatString(300, 0, GetColor(255,255,255), "mouse_x = %d", mouse_x);
		DrawFormatString(300, 10, GetColor(255,255,255), "mouse_y = %d", mouse_y);
		DrawFormatString(300, 20, GetColor(255,255,255), "select_x = %d", select_x);
		DrawFormatString(300, 30, GetColor(255,255,255), "select_y = %d", select_y);
		DrawFormatString(300, 40, GetColor(255,255,255), "graph_x = %d", graph_w);
		DrawFormatString(300, 50, GetColor(255,255,255), "graph_y = %d", graph_h);
		
		ScreenFlip();
	}
}
右クリックしながらドラッグでマップ全体を移動させようとしたら、なぜかドラッグしている間は移動して、していない時は元の状態に戻るという謎の状態になっていたり、
マウスの位置を元にブロックの色を変えようとしたら一部が反応し無かったりと、修正点は沢山ある様子。

自分のことだし、どうせ凡ミスなんだろうなあと思いつつ、この修正は明日。

(追記)
やっぱり凡ミスだったので修正。
あとはブロックとマウスの当たり判定をどうするかだな…
最後に編集したユーザー 大白定義 on 2013年1月31日(木) 01:49 [ 編集 1 回目 ]

コメントはまだありません。