LoginSignup
3
1

More than 3 years have passed since last update.

HSP3.5 HGIMG4 で2Dビューポート表示

Last updated at Posted at 2017-12-03

HSP3.5 HGIMG4 で2Dマップを拡大したり縮小したりする

HSP3.5 HGIMG4 では、やや機能限定ではありますがオフスクリーン(レンダーターゲット)が使用できるようになりました。これを用いてやや広めのマップを窓から覗いたような表現などが可能です。
buffer をオフスクリーンとして生成するには buffer の第4引数に screen_offscreen を指定します。
サンプルコードは以下になります。
ソースコードファイルはインストールフォルダが C:\hsp35 の場合、C:\hsp35\sample\hgimg4 フォルダに保存してください。

#include "hgimg4.as"

#const EG_CALC GPDRAW_OPT_OBJUPDATE
#const EG_DRAW2D (GPDRAW_OPT_DRAW2D | GPDRAW_OPT_DRAW2D_LATE)
#const EG_DRAW3D (GPDRAW_OPT_DRAWSCENE | GPDRAW_OPT_DRAWSCENE_LATE)

#const WID_TV 3
#const WID_DOT 4
#const WID_WIDE 5

#module
#defcfunc sgn double x
    if x == 0.0 {
        return 0.0
    }
    if x < 0.0 {
        return -1.0
    }
    return 1.0
#global

    sx = ginfo(26)
    sy = ginfo(27)

    map_w = 2048
    map_h = 2048

    gpreset
    setcls CLSMODE_NONE

    celload dirinfo(5) + "\\hsptv_img.png", WID_TV
    celdiv WID_TV, 64,64

    celload dirinfo(5) + "\\tamadot.png", WID_DOT
    celdiv WID_DOT, 64,64, 32,32

// 珠音
    dim evs, 16
    c = 0

    repeat 16
        i = cnt

        newevent ev
        repeat 4
            index = cnt + i * 4
            event_prmset ev, PRMSET_SPRCELID,index
            event_wait ev, 15
        loop
        event_jump ev, 0

        evs.c = ev
        c ++
    loop

    gpspr id, WID_DOT, 0
    setevent id, evs.1
    tama = id   

// マップ配列
    xnum = map_w / 64
    ynum = map_h / 64
    num = xnum * ynum
    dim vxpos,num
    dim vypos,num
    dim vcelid,num

    c = 0
    repeat ynum
        i = cnt
        repeat xnum
            j = cnt

            index = 16 + limit(rnd(21) - 14, 0,6)
            if i == 0 | i == ynum - 1 | j == 0 | j == xnum - 1 {
                index = 16 + 7
            }

            //gpspr id, WID_TV, index
            vxpos.c = j * 64
            vypos.c = i * 64
            vcelid.c = index

            c++
        loop
    loop

    buffer WID_WIDE, map_w,map_h, screen_offscreen
    celdiv WID_WIDE, map_w,map_h, map_w/2, map_h/2

    cx = double(map_w / 2)
    cy = double(map_h / 2)
    vr = 1.0

    repeat
        getreq fps, SYSREQ_FPS
        getreq ts, SYSREQ_TIMER

        gsel 0
        mx = mousex
        my = mousey

        dx = double(mx - sx / 2)
        dy = double(my - sy / 2)
        cx += sgn(dx)
        cy += sgn(dy)
        cx = limitf(cx, 96, map_w - 96)
        cy = limitf(cy, 96, map_h - 96)

        setpos tama, cx,cy, 0


        gsel WID_WIDE
        redraw 0
        gpdraw EG_CALC

        celputm vxpos, vypos, vcelid, WID_TV, num
        gpdraw EG_DRAW2D
        redraw 1

        vr = sin(double(ts) * 0.0005) * 0.2 + 0.8

        gsel 0
        redraw 0
        color 0xff,0xcc,0x66
        boxf

        pos - (cx - map_w / 2) * vr + sx/2, - (cy - map_h / 2) * vr + sy/2
        celput WID_WIDE,0, vr,vr

        pos 16,16
        color 0,0,0
        font "",48
        mes strf("%2d [fps]", fps)
        redraw 1
        await 1000/60
    loop

マウスカーソルの位置で上下左右に移動します。

実行結果1
z06map1.png
広い範囲が表示されている状態

拡大率は時間経過で勝手に変化するようになっています。

実行結果2
z06map2.png
狭い範囲が表示されている状態

主に 3D 向けの HGIMG4 ですがスプライトなども活用して 3D と 2D のハイブリッドで様々な表現できるようにどんどん進化していくのではないかと期待されます。

3
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1