' put flip test 2 ' 1 line 毎にループ処理して反転描画する。 ' ' Last updated: <2024/02/05 04:57:21 +0900> #ifdef __FB_WIN32__ ' Windowsの場合、mmsystemを利用 #include "windows.bi" #include "win/mmsystem.bi" #endif ' fbgfxモードを使う #Include "fbgfx.bi" Using fb ' Draw h v flip image ' ' x, y : Position, img : Bitmap image pointer ' sx, sy : Source position, sw, sh : Source width, height ' flag : 0 (normal), 1 (H Flip), 2 (V Flip), 3 (HV Flip) Sub PutEx( _ ByVal x As Integer, ByVal y As Integer, _ ByVal img As Any Ptr, _ ByVal sx As Integer, ByVal sy As Integer, _ ByVal sw As Integer, ByVal sh As Integer, _ ByVal flag As Integer ) sw -= 1 sh -= 1 Select Case flag Case 0 ' draw normal Put (x, y), img, (sx, sy) - Step(sw, sh), TRANS Case 1 ' draw H flip image Dim As Integer xx = sx + sw For i As Integer = 0 To sw Put (x, y), img, (xx, sy) - step(0, sh), TRANS x += 1 xx -= 1 Next i Case 2 ' draw V flip image Dim As Integer yy = sy + sh For i As Integer = 0 To sh Put (x, y), img, (sx, yy) - step(sw, 0), TRANS y += 1 yy -= 1 Next i Case 3 ' draw HV flip Dim As Integer yy = sy + sh For yi As Integer = 0 To sh Dim As Integer xx = sx + sw For xi As Integer = 0 To sw Put (x + xi, y + yi), img, (xx, yy) - step(0, 0), TRANS xx -= 1 Next xi yy -= 1 Next yi End Select End Sub ' 時間計測用の変数 Dim As Double start_time, prev_time, now_time, delta, next_time Dim As Integer frame_count Dim As String fps_text = "FPS" Dim As Integer scrw, scrh ' ウインドウサイズ Dim As Integer imgw, imgh ' 画像サイズ chdir exepath() ' カレントディレクトリを exeファイルのある場所にする ' ウインドウサイズと色深度を指定 scrw = 512 scrh = 288 Screenres scrw, scrh, 32 ' 画像読み込み。FreeBASIC標準のbmp読み込みを使う場合 Dim img As any ptr = ImageCreate(128, 64) Bload "obj.bmp", img imageinfo img, imgw, imgh ' 画像の幅と高さを取得 #ifdef __FB_WIN32__ timeBeginPeriod(1) ' タイマー精度を1msecに向上 #endif Dim As Double MAX_FPS = 60.0 ' FPS start_time = Timer ' 開始時間を取得 prev_time = start_time frame_count = 0 Dim As Boolean running = True Dim As Double anime_t = 0.0 Dim As Double x, y x = scrw / 2 y = scrh / 2 ' メインループ While (running) ' 前回フレームから何秒経過したか取得。単位は秒(小数点以下有り) now_time = Timer delta = now_time - prev_time prev_time = now_time next_time = now_time + (1.0 / MAX_FPS) If delta < 0 Then delta = (1.0 / MAX_FPS) If now_time >= start_time Then If (now_time - start_time) >= 1.0 Then ' 1秒経過したのでFPSを取得 fps_text = "FPS: " & frame_count start_time += 1.0 frame_count = 0 End If Else start_time = now_time End If frame_count += 1 ' ESCキー、qキー、ウインドウの閉じるボタンを検出 Dim As String k = inkey$ If k = Chr$(27) Or k = "q" Or k = Chr$(255) + "k" Then running = False ' メインループ終了 End If anime_t += delta ' アニメ表示用カウンタを更新 ScreenLock ' 描画開始 color RGB(255, 255, 255), RGB(52, 164, 255) cls ' 画面クリア ' 画像を描画 Dim As Integer n, sx, sy, sw, sh, px, py n = Int(anime_t / 0.5) Mod 4 ' value = 0 - 6 sw = (imgw / 2) ' 幅 sh = imgh ' 高さ sx = 0 ' 描画元 x sy = 0 ' 描画元 y px = x - (sw / 2) py = y - (sh / 2) Select Case n Case 0 : PutEx px, py, img, sx, sy, sw, sh, 0 Case 1 : PutEx px, py, img, sx, sy, sw, sh, 1 Case 2 : PutEx px, py, img, sx, sy, sw, sh, 3 Case 3 : PutEx px, py, img, sx, sy, sw, sh, 2 End Select ' 文字列を描画 Draw String (10, 10), fps_text Draw String (scrw / 2 - (8 * 6), scrh * 0.8), "HELLO WORLD" ScreenUnlock ' 描画終了 If Timer < next_time Then ' 本来の1フレーム時間がまだ経過してないので sleep させる Dim As Double wait_ms = (next_time - Timer) * 1000.0 If wait_ms > 0.0 Then sleep wait_ms End If Wend While Inkey <> "": Wend ' キーバッファを空にする ImageDestroy img ' 画像を使い終わったので破棄 #ifdef __FB_WIN32__ timeEndPeriod(1) ' タイマー精度を本来のスペックに戻す #endif