#include "hsp3dish.as"
#include "config.hsp"

; 画面サイズ
#const global DISPLAY_WIDTH	1080
#const global DISPLAY_HEIGHT	1920

; バッファ
#enum global BUFFER_GOATOH_FACE_CC = 1	; ゴートうの顔（閉眼，閉口）
#enum global BUFFER_GOATOH_FACE_CO	; 　　　　　　（閉眼，開口）
#enum global BUFFER_GOATOH_FACE_OC	; 　　　　　　（開眼，閉口）
#enum global BUFFER_GOATOH_FACE_OO	; 　　　　　　（開眼，開口）
#enum global BUFFER_GOATOH_HEAD		; ゴートうの頭
#enum global BUFFER_GOATOH_LEG		; ゴートうの脚
#enum global BUFFER_GOATOH_TAIL		; ゴートうのしっぽ
#enum global BUFFER_GOATOH_TARSO	; ゴートうの胴体
#enum global BUFFER_NIZIKA		; ニジカ
#enum global BUFFER_BG			; https://www.pakutaso.com/20190249044post-18819.html
#enum global BUFFER_CHAR		; 文字セット

; サウンド
#enum global SOUND_MUMUMUMU = 0	; ﾑﾑﾑﾑ
#enum global SOUND_BGM		; 夕餉の街並み（Copyright: Musmus）
#enum global SOUND_EATING_KUSA	; ｸｻﾀﾍﾞﾃﾙ!!!

; 向き
#enum global DIRECTION_LEFT = 1
#enum global DIRECTION_RIGHT

#const global FPS		30
#const global LOOP_INTERVAL	1000 / FPS

#include "./modules/goatoh.mod.hsp"
#include "./modules/chat.mod.hsp"
#include "./modules/char.mod.hsp"
#include "./modules/keyboard.mod.hsp"


#ifdef _DEBUG
	Screen 0, 540, 960

	; デバッグ時は assets ディレクトリを参照する．
	ChDir "assets"
#endif	; not _DEBUG

	Font MSGOTHIC, 96

	ViewCalc VPTYPE_2D, Double (gInfo_winX) / DISPLAY_WIDTH, Double (gInfo_winY) / DISPLAY_HEIGHT

	; 背景
	CelLoad "bg.jpg", BUFFER_BG

	; ゴートうの顔
	files = "goatoh-face-closed-closed.png", "goatoh-face-closed-open.png", "goatoh-face-open-closed.png", "goatoh-face-open-open.png"
	ids   = BUFFER_GOATOH_FACE_CC,           BUFFER_GOATOH_FACE_CO,         BUFFER_GOATOH_FACE_OC,         BUFFER_GOATOH_FACE_OO
	Repeat 4
		CelLoad files.cnt, ids.cnt
		CelDiv ids.cnt, 0, 0, 100, 111
	Loop

	CelLoad "goatoh-head.png", BUFFER_GOATOH_HEAD
	CelDiv BUFFER_GOATOH_HEAD, 0, 0, 77, 143

	CelLoad "goatoh-leg.png", BUFFER_GOATOH_LEG
	CelDiv BUFFER_GOATOH_LEG, 0, 0, 48, 29

	CelLoad "goatoh-tail.png", BUFFER_GOATOH_TAIL
	CelDiv BUFFER_GOATOH_TAIL, 0, 0, 22, 33

	CelLoad "goatoh-tarso.png", BUFFER_GOATOH_TARSO
	CelDiv BUFFER_GOATOH_TARSO, 0, 0, 97, 49

	CelLoad "font.png", BUFFER_CHAR
	CelDiv BUFFER_CHAR, 32, 35, 0, 0

	; ゴートうインスタンス生成
	Goatoh = New@Goatoh (960, 800, DIRECTION_LEFT)

	; サウンド読込み
	MMLoad "mumumumu.wav", SOUND_MUMUMUMU
	MMLoad "MusMus-BGM-097.mp3", SOUND_BGM, MM_REPEAT
	MMLoad "eating-kusa.wav", SOUND_EATING_KUSA

	; BGM 再生
	MMPlay SOUND_BGM

	GMode GMODE_RGB0	; アルファあり

	Show@Keyboard

	Pos 100, 100
	Text = New@Char ("")
	size@Char.Text = 240

	Repeat
		ReDraw False
			Pos 0, 0
			CelPut BUFFER_BG, 0, Double (DISPLAY_HEIGHT) / 533, Double (DISPLAY_HEIGHT) / 533

			Draw@Goatoh Goatoh
			Draw@Char
			Draw@Keyboard

			a = GetChar@Keyboard ()
			text@Char.Text = text@Keyboard
		ReDraw True

		Await LOOP_INTERVAL
	Loop

