' game main loop ' mmsystemを利用 #include "windows.bi" #include "win/mmsystem.bi" ' fbgfxモードを使う #Include "fbgfx.bi" Using fb ' 画像読み込み用ライブラリ FBImage を使う #include once "FBImage.bi" ' 円周率を定義 Const PI As Double = 3.1415926535897932 Dim As Double start_time, prev_time, now_time, diff_time, one_frame Dim As Integer frame_count Dim As String fps_text = "FPS" Dim As Integer scrw, scrh, imgw, imgh ' カレントディレクトリを exeファイルのある場所にする chdir exepath() ' ウインドウサイズと色深度を指定 scrw = 1280 scrh = 720 Screenres scrw, scrh, 32 ' 画像読み込み var img = LoadRGBAFile("image_circle_96x96.png") ' 画像の幅と高さを取得 imageinfo img, imgw, imgh ' タイマー精度を1msecに向上 timeBeginPeriod(1) ' 1フレームあたりの本来の時間 Dim As Double MAX_FPS = 60.0 one_frame = 1.0 / MAX_FPS start_time = Timer prev_time = start_time frame_count = 0 Dim As Boolean running = True Dim As Double angle = 0.0 ' メインループ While (running) ' 前回のフレームから何秒経過しているのかを取得。単位は秒(小数点以下有り) now_time = Timer If now_time >= prev_time Then diff_time = now_time - prev_time Else diff_time = one_frame End If prev_time = now_time If now_time >= start_time Then If (now_time - start_time) >= 1.0 Then ' FPSを取得 fps_text = "FPS: " & frame_count start_time += 1.0 frame_count = 0 End If Else start_time = now_time End If If inkey() <> "" Then ' 何かのキーが押されたのでループ終了 running = False End If angle += (1.0 * MAX_FPS) * diff_time ' 描画開始 ScreenLock ' 画面クリア color RGB(255, 255, 255), RGB(30, 60, 120) cls ' 画像群を描画 Dim As Integer x, y For i As Integer = 0 To 48 Dim As Double ang = (angle + (i * 5.0)) * PI / 180.0 x = (scrh * 0.4) * Cos(ang) + (scrw / 2) - (imgw / 2) y = (scrh * 0.4) * sin(ang) + (scrh / 2) - (imgh / 2) Put (x, y), img, TRANS ' 画像を描画 Next i ' 文字列を描画 Draw String (10, 10), fps_text ' 描画終了 ScreenUnlock If Timer < (now_time + one_frame) Then ' 本来のフレーム時間がまだ経過してないので sleep させる sleep ((now_time + one_frame) - Timer) * 1000.0 End If frame_count += 1 Wend ' タイマー精度を本来のスペックに戻す timeEndPeriod(1) ' 画像を使い終わったので破棄 ImageDestroy img ' 最後まで処理が来たのか確認するためにメッセージボックスを表示してみる ' MB_TOPMOST Or MB_SETFOREGROUND を指定しないと、メインウインドウの後ろに隠れてしまう ' MessageBox(NULL, "Cleanup", "Message", MB_OK Or MB_TOPMOST Or MB_SETFOREGROUND)