みけCATのにっき(仮)
つれづれなるまゝに、日くらし、PCにむかひて、心に移りゆくよしなし事を、そこはかとなく書きつくれば、あやしうこそものぐるほしけれ。
(本当か!?)
出典

HSPでDXライブラリ?

アバター
みけCAT
記事: 6734
登録日時: 14年前
住所: 千葉県
連絡を取る:

HSPでDXライブラリ?

投稿記事 by みけCAT » 12年前

DXライブラリには、本来C#用のDLLがあります。
(まてよ・・・DLLということは普通にDLLとして使えるのではないか?)
というわけで、HSPで使ってみました。
まず、適当に使う関数を定義します。(使っていない関数も定義しているが気にしない)

CODE:

;#module dxlib
#uselib "DxLib.dll"

#const global DX_BLENDMODE_NOBLEND 0
#const global DX_BLENDMODE_ALPHA 1
#const global DX_BLENDMODE_ADD 2
#const global DX_BLENDMODE_SUB 3
#const global DX_BLENDMODE_MUL 4
#const global DX_BLENDMODE_SUB2 5
#const global DX_BLENDMODE_XOR 6
#const global DX_BLENDMODE_DESTCOLOR 8
#const global DX_BLENDMODE_INVDESTCOLOR 9
#const global DX_BLENDMODE_INVSRC 10
#const global DX_BLENDMODE_MULA 11
#const global DX_BLENDMODE_ALPHA_X4 12
#const global DX_BLENDMODE_ADD_X4 13
#const global DX_BLENDMODE_SRCCOLOR 14
#const global DX_BLENDMODE_HALF_ADD 15
#const global DX_SCREEN_FRONT -4
#const global DX_SCREEN_BACK -2
#const global DX_SCREEN_WORK -3
#const global DX_SCREEN_TEMPFRONT -5
#const global DX_CHECKINPUT_KEY 1
#const global DX_CHECKINPUT_PAD 2
#const global DX_CHECKINPUT_MOUSE 4
#const global DX_CHECKINPUT_ALL DX_CHECKINPUT_KEY

#const global KEY_INPUT_ESCAPE 1
#const global KEY_INPUT_LEFT 203
#const global KEY_INPUT_UP 200
#const global KEY_INPUT_RIGHT 205
#const global KEY_INPUT_DOWN 208

#func DxLib_Init "dx_DxLib_Init"
#func DxLib_End "dx_DxLib_End"
#func ProcessMessage "dx_ProcessMessage"
#func ClearDrawScreen "dx_ClearDrawScreen" nullptr
#func SetGraphMode "dx_SetGraphMode" int,int,int
#func SetDrawScreen "dx_SetDrawScreen" int
#func ScreenFlip "dx_ScreenFlip"
#func ChangeWindowMode "dx_ChangeWindowMode" int
#func SetMainWindowText "dx_SetMainWindowText" str
#func WaitTimer "dx_WaitTimer" int
#func WaitKey "dx_WaitKey"
#cfunc GetNowCount_internal "dx_GetNowCount" int
#define ctype global GetNowCount(%1=0) GetNowCount_internal(%1)
#cfunc GetRand "dx_GetRand "int
#cfunc SRand "dx_SRand" int
#cfunc CheckHitKey "dx_CheckHitKey" int
#cfunc CheckHitKeyAll_internal "dx_CheckHitKeyAll" int
#define global ctype CheckHitKeyAll(%1=DX_CHECKINPUT_ALL) CheckHitKeyAll_internal(%1)
#func GetHitKeyStateAll "dx_GetHitKeyStateAll" var
#func DrawLine_internal "dx_DrawLine" int,int,int,int,int,int
#define global DrawLine(%1,%2,%3,%4,%5,%6=1) DrawLine_internal %1,%2,%3,%4,%5,%6
#cfunc GetColor "dx_GetColor" int,int,int
#func DrawBox "dx_DrawBox" int,int,int,int,int,int
#func DrawFullBox "dx_DrawFullBox" int,int,int,int,int
#func DrawLineBox "dx_DrawLineBox" int,int,int,int,int
#func DrawCircle_internal "dx_drawCircle" int,int,int,int,int
#define global DrawCircle(%1,%2,%3,%4,%5=1) DrawCircle_internal %1,%2,%3,%4,%5
#func DrawTriangle "dx_DrawTriangle" int,int,int,int,int,int,int,int
#func DrawQuadrangle "dx_DrawQuadrangle" int,int,int,int,int,int,int,int,int,int
#func DrawPixel "dx_DrawPixel" int,int,int
#func LoadGraphScreen "dx_LoadGraphScreen" int,int,str,int
#func DrawGraph "dx_DrawGraph" int,int,int,int
#func DrawExtendGraph "dx_DrawExtendGraph" int,int,int,int,int,int
#func DrawRotaGraph_internal "dx_DrawRotaGraph" int,int,double,double,int,int,int
#define global DrawRotaGraph(%1,%2,%3,%4,%5,%6,%7=0) DrawRotaGraph_internal %1,%2,%3,%4,%5,%6,%7
#func DrawRotaGraph2_internal "dx_DrawRotaGraph2" int,int,int,int,double,double,int,int,int
#define global DrawRotaGraph2(%1,%2,%3,%4,%5,%6,%7,%8,%9=0) DrawRotaGraph2_internal %1,%2,%3,%4,%5,%6,%7,%8,%9
#func DrawRotaGraph3_internal "dx_DrawRotaGraph3" int,int,int,int,double,double,double,int,int,int
#define global DrawRotaGraph3(%1,%2,%3,%4,%5,%6,%7,%8,%9,%10=0) DrawRotaGraph3_internal %1,%2,%3,%4,%5,%6,%7,%8,%9,%10
#func DrawModiGraph "dx_DrawModiGraph" int,int,int,int,int,int,int,int,int,int
#func DrawTurnGraph "dx_DrawTurnGraph" int,int,int,int
#func SetDrawMode "dx_SetDrawMode" int
#func SetDrawBlendMode "dx_SetDrawBlendMode" int,int
#cfunc LoadGraph_internal "dx_LoadGraph" str,int
#define global ctype LoadGraph(%1,%2=0) LoadGraph_internal(%1,%2)
#func LoadDivGraph_internal "dx_LoadDivGraph" str,int,int,int,int,int,var,int
#define global LoadDivGraph(%1,%2,%3,%4,%5,%6,%7,%8=0) LoadDivGraph_internal %1,%2,%3,%4,%5,%6,%7,%8
#func DrawString_internal "dx_DrawString" int,int,str,int,int
#define global DrawString(%1,%2,%3,%4,%5=0) DrawString_internal %1,%2,%3,%4,%5

;#global
そして、適当にコードを書きます。

CODE:

#include "dxlibhsp.as"

ChangeWindowMode 1
DxLib_Init
SetDrawScreen DX_SCREEN_BACK

x=100
y=100
img=LoadGraph("image.png")
sdim key_buffer,256

repeat
	ProcessMessage
	if stat!=0:break
	ClearDrawScreen
	if stat!=0:break
	GetHitKeyStateAll key_buffer
	if peek(key_buffer,KEY_INPUT_ESCAPE):break

	if peek(key_buffer,KEY_INPUT_LEFT):x-=3
	if peek(key_buffer,KEY_INPUT_UP):y-=3
	if peek(key_buffer,KEY_INPUT_RIGHT):x+=3
	if peek(key_buffer,KEY_INPUT_DOWN):y+=3
	DrawGraph x,y,img,0
	DrawString 10,10,strf("(%d,",x)+strf("%d)",y),GetColor(255-int(x*255/640),255,255-int(y*255/480))

	ScreenFlip
loop

DxLib_End
end
そして、hspのソースがあるディレクトリにDxLib.dllをコピーして起動。
すると・・・
はい、正常にウィンドウが表示できました。
screenshot.png
スクリーンショット
HSPのウィンドウも表示されていますが、気にしない。

・・・この程度ならできますが、構造体を使用した関数は厳しいでしょうか・・・

トントン
記事: 100
登録日時: 15年前

Re: HSPでDXライブラリ?

投稿記事 by トントン » 12年前

おー、なるほど。
既にあるDLLも利用しようと思えばできるんですね!