demo_en.hsp

sample\demo\demo_en.hsp » Plain Format

;------------------------------------------------------
;	HSP3 demo for ver3.7 ( sample script )
;	onion software/onitama
;	サウンドコントロール追加 : Arue (2021/8/6)
;------------------------------------------------------

#include "hspogg.as"
#include "hsp3util.as"
#include "mod_sprite.as"

#packopt name "hsp3demo"

#define global USE_SOUND

#module
#deffunc demo_init

	;	デモ初期化
	;

	tvfolder@ = dir_exe+"\\hsptv\\"

#ifdef USE_SOUND

	dmmini
	m_defvol=0
	m_vol=0			//音量(最小-10000〜最大0)
	m_fade=0
	m_level=0.25		//音量レベル追加(最小0.0〜最大1.0で音量を管理)

	dmmload "theme.ogg",0
	dmmloop 0,268435		; ループポイント設定
	dmmload "oot06.ogg",2
	dmmloop 2,671328		; ループポイント設定
	dmmload tvfolder@+"se_tyuiin.wav",1
	dmmvol 1, vol2db(m_level)	//効果音の音量をただちに適用
#endif
	celload tvfolder@+"bgpeas.bmp",5
	celload tvfolder@+"logop.bmp",6
	celload tvfolder@+"btn_hsptv.bmp",7
	celload tvfolder@+"bgsmoke.bmp",8
	celload tvfolder@+"btn_hard.bmp",9
	gsel 0

	return

#define maxvol 1.0	//最大音量値
#defcfunc vol2db double p1	//p1のボリューム値(0.0〜1.0)をデシベル値(-10000〜0.0)に変換する関数
	if( p1 < 0.005 ):return -10000.0    //最低値を設定しておかないと0除算してしまう
	if p1>maxvol:return 0.0				//最大デシベルは0.0
	return ( ( 20.0 * (logf(p1)/logf(10)) ) * 100.0 )	//デシベル値を返す

#defcfunc getVolume	//現在のボリュームを0.0〜1.0で返す関数
	return m_level		//音量値を返す
#deffunc setVolume double p1	//p1の音量を現在のBGMに適用する(以降再生のBGMにも適用される)
	if m_level!limitf(p1,0.0,1.0):{	//以前と音量が違えば設定する
		m_level=limitf(p1,0.0,1.0)		//ボリューム値を記憶
		dmmvol m_id, vol2db(m_level)	//現在再生中BGMに音量を割り当てる
		dmmvol 1, vol2db(m_level)		//効果音にもこの時点で割り当てる
	}
	return

#deffunc demo_term

	;	デモ終了
	;
#ifdef USE_SOUND
	dmmbye
#endif
	return


#deffunc sndoff

	;	音止め
	;
#ifdef USE_SOUND
	m_fade=0
	dmmstop
#endif
	return


#deffunc snd int id

	;	サウンドを再生
	;
#ifdef USE_SOUND

	if id=1 : goto *nobgm	; 効果音の時
	;
	m_vol=m_defvol
	m_fade=0
	m_id=id
	dmmvol id,vol2db((10000.0+m_vol)/10000*m_level)	//音量にm_levelを反映させる
*nobgm
	dmmplay id
#endif
	return


#deffunc sndexec

	;	サウンドフレーム処理(フェード用)
	;
#ifdef USE_SOUND
	if m_fade=0 : return
	m_vol+=m_fade*3
	if m_vol<=-10000 {			//ボリューム値でフェードするので完全に音が消えてから音を止めるようにした -8000 → -10000に修正
		sndoff
		return
	}
	if m_vol>=0 : m_vol=0 : m_fade=0
	dmmvol m_id,vol2db((10000.0+m_vol)/10000*m_level)	//音量にm_levelを反映させる
#endif
	return


#deffunc sndfade int _p1

	;	サウンドフェード指定
	;
#ifdef USE_SOUND
	if _p1>0 : m_vol=-4000
	m_fade=_p1
#endif
	return


#deffunc exec2 str _p1, int _p2

	;	外部ファイル実行
	;
	exist _p1
	if strsize <= 0 : dialog "該当ファイルがないため実行できません。" : return
	exec _p1,_p2
	return


#deffunc initwall

	buffer 3,640,480
	picload tvfolder@+"gradbg.bmp",1
	x=0:gmode 0,640,16
	repeat 480/16
		if cnt=0 : continue
		y=cnt*16
		pos x,y:gcopy 3
	loop
	gsel 0
	return

#deffunc copywall
	gmode 0,640,480:pos 0,0:gcopy 3
	return

#deffunc fadewall int _p1

	wt=_p1:if wt=0 : wt=16
	repeat 32
	redraw 0
	copywall
	color 0,0,0:gfade (31-cnt)*8
	redraw 1
	await wt
	loop
	return

#deffunc mkwall str a

	;	BGの壁紙作成
	;
	initwall

	gsel 3
	font msgothic,32,1+16
	x=20:y=64
	pos x+2,y+2:color 0,0,0:mes a
	pos x,y:color 192,192,255:mes a
	x+=20:y+=60

	gsel 0:cls 4
	fadewall 15

	pos x,y
	font msgothic,20,1+16:objsize 64,24,22
	return

#deffunc byewall

	repeat 32
		color 0,0,0:gfade 8+cnt
		await 15
	loop
	return

#deffunc wipe_slide int _p1, int _p2

	;	Wipe (curtain)
	;	wipe_slide transfer source id, wait time
	;
	wt=_p2:if wt=0 : wt=48
	mx=-32:repeat 60
		redraw 0
		repeat 32
		a=cnt*20:x=cnt+mx:if x>20 : x=-1
		if x>0 : pos a,0 : gmode 0,x,480 : gcopy _p1,a,0
		loop
		redraw 1
	await wt
	mx+:loop
	return

#deffunc gblur int p1, int p2

	;
	;	Simple blur module
	;	gblur blur strength , direction flag
	;
	;	Apply simple blur to the currently operating buffer.
	;	The greater the blur strength, the stronger it will be (processing will also be heavier).
	;	The direction flag selects the direction of 0=XY, 1=Y, 2=X (usually 0).
	;
	gmode 3, ginfo_sx, ginfo_sy, 128
	if (p2&1)=0 {
		repeat p1
		pos 1,0:gcopy ginfo(3)
		pos 0,0:gcopy ginfo(3),2,0
		loop
	}
	if (p2&2)=0 {
		repeat p1
		pos 0,1:gcopy ginfo(3)
		pos 0,0:gcopy ginfo(3),0,2
		loop
	}
	return

#global

;------------------------------------------------------

*boot
	;	Start demo
	;
	title "HSP3.7 Demonstration"

#ifndef _DEBUG
	chdir dir_exe+"\\sample\\demo\\"
#endif

	x=(ginfo_dispx-640)/2:y=(ginfo_dispy-480)/2
	screen 0,640,480,0,x,y
	cls 4:color 255,255,255
	pos 520,450:mes "Loading..."

	demo_init
	onexit *owari

	;goto *demomain6

	snd 0

*mainmenu
	;	Main menu
	;
	gsel 6
	logosx=ginfo_winx
	logosy=ginfo_winy
	gsel 0
	cls

	sx=640:sy=200:blur=128
	rate=0.0:fa=0.05:fb=0.001
	;
	;color 178,208,227:boxf
	gradf 0,sy,640,480, 1, $b2d0e3,$f8fbfd

	pos 32,400:gcopy 7,0,0,200,26
	objsize 200,28:pos 32,426
	button "HSPTV Browser",*see_hsptv

	;	オブジェクト配置
	;
	;objmode 1+16,1
	font msgothic,16,1+16
	x=114:y=240:objcolor 192,192,255
	color 0,0,160
	pos x,y:mes "Welcome to the world of HSP3. Please press a button.",mesopt_outline
	font msgothic,16,1
	x=294:y=280:pos x,y
	objsize 80,24,30
	objimage 9, 0,0, 0,48, 0,24
	button "readme",*see_readme
	button "demo",*demomain
	button "manual",*see_man
	button "assist",*see_sample
	button "editor",*see_edit
	button "quit",*owari
	objimage -1
	x=390:y=282:pos x,y
	color 0,0,0
	mes "Read me first",mesopt_shadow
	mes "HSP Demonstration",mesopt_shadow
	mes "HSP Comprehensive Manual",mesopt_shadow
	mes "Open HSP Assistant",mesopt_shadow
	mes "Edit script",mesopt_shadow
	mes "Quit",mesopt_shadow

	//スピーカ描画セットアップ
	//※※コントローラが配置されるシーンはredraw 1の更新範囲が狭いので配置と大きさに注意!
	#define VCsize 32	//ボリュームアイコンのサイズ
	#define VCx 32		//ボリュームアイコンの位置X
	#define VCy 150		//ボリュームアイコンの位置Y
	#define VCcnt 8		//ボリュームアイコンの波紋の数
	font "webdings",VCsize	//ボリュームコントロール描画用にフォントを変更

*main1
	;	メインメニュー画面待ち
	;
	redraw 0
	;
	gmode 0,sx,1
	repeat sy
	pos 0,cnt:ff=cos(fa*cnt+rate)
	gcopy 5,blur+(sin(rate+ff)*blur),cnt
	loop
	pos 268,48:gmode 6,logosx,logosy,256:gcopy 6
	;
	
	//ボリュームコントロール
	color	//コントローラの色
	pos VCx,VCy:mes "X"	//スピーカ描画(webdings)
	stick key,256:if key:{		//マウスが押し下げされている場合
		if mousex>VCx & mousex<VCx+VCcnt*8+VCsize*2 & abs(mousey-VCy-VCsize/2)<VCsize:{	//ボリュームコントローラ上にポインタがある
			setVolume double(mousex-(VCx+VCsize/2))/(VCcnt*8)	//ボリュームの値を更新
		}
	}
	repeat VCcnt,1	//ボリュームコントロール(スピーカからの波紋)を描画
		gmode 3,4,(cnt+1)*VCsize/VCcnt,160-(cnt>getVolume()*VCcnt)*112	//波紋の大きさを決定。濃度は現在の音量まで濃く描画
		grect cnt*8+VCx+VCsize/2,VCy+VCsize/2	//波紋を描画
	loop
	
	redraw 1,0,0,640,200
	wait 10
	;
	rate+=0.1
	fa+=fb
	if fa>0.1 : fb=-0.001 : fa=0.1
	if fa<0.05 : fb=0.001 : fa=0.05
	goto *main1

*see_readme
	snd 1
	;sndoff
	mkwall "・Introduction"

	redraw 0
	text 0:color 0,0,128:textmode 2:color 255,255,255
	emes {"
This demo program is designed to introduce
features and usage of Hot Soup Processor (HSP3).
Select the item you want to see from the main menu
 and press the button.
This program is written entirely in HSP.
If you are programming for the first time,
 click the "begin" button
and see "Introduction to HSP for Beginners".
"}
	;
	font msgothic,16,1
	pos 230,360:objsize 80,24,28
	objimage 9, 0,0, 0,48, 0,24
	button "menu",*go_main
	button "begin",*see_begin
	button "home",*see_home
	objimage -1
	pos 330,362
	mes "Back to main menu"
	mes "Introduction to HSP for Beginners"
	mes "To HSPTV! Homepage"
	redraw 1
	stop

*go_main
	snd 1
	goto *mainmenu

*see_home
	snd 1
	exec "https://hsp.tv/",16
	stop
*see_begin
	snd 1
	exec2 dir_exe+"\\doclib\\beginner\\start.htm",16
	stop

*see_sample
	snd 1
	exec2 dir_exe+"\\hspat.exe"
	wait 100
	goto *owari
*see_edit
	snd 1
	exec2 dir_exe+"\\hsed3.exe"
	wait 100
	goto *owari
*see_man
	snd 1
	exec2 dir_exe+"\\index.htm",16
	goto *mainmenu
*see_hsptv
	snd 1
	exec2 dir_exe+"\\hsptv.exe"
	wait 100
	goto *owari
*owari
	demo_term
	end

*demomain
	;	HSPデモ(フライングロゴ)
	;
	;sndoff
	sndfade -20
	;
	buffer 4
	picload tvfolder+"onibtn.gif"
	sx=ginfo_winx:sy=ginfo_winy
	buffer 3
	picload tvfolder+"hsplogo8.bmp"
	gsel 0
	cls 4
	snd 1
	max=100

	init_sprite 80,50,max
	opt_sprite 3,2
	move_sprite1_init

	mx=sx:my=sy:x=-sx:y=240:z=0

	repeat
	redraw 0
	color 0,0,0:boxf
	gradf 0,300,640,480,1,0,128

	move_sprite1
	draw_sprite

	pos x,y:gmode 0,sx,sy
	if z>=260 {
		i=(z-260)*8
		if i>=256 : z++ : goto *skiplogo
		gmode 3,sx,sy,256-i
	}
	grotate 4,0,0,0.01*(320-x),mx,my
	if x>=320 {
		z++
		if z>250 {
			mx+=2:my+=1
		}
		x=320
	} else {
		x+=8
	}

*skiplogo
	redraw 1
	sndexec
	await 15

	if z>300 : break

	loop

	;	ブラークリア
	;
	repeat 32
	redraw 0
	gblur 1
	redraw 1
	sndexec
	await 12
	loop

*demomain2
	;	HSPデモ(テキスト表示)
	;
	cls 4
	snd 2
	mkwall "・What is HSP?"
	text 10:color 0,0,128:textmode 2:color 255,255,255
	emes "HSP3 is an interpreter language that can be easily
	mes " used on Windows.
	emes "By simply writing a text script, anyone can easily
	emes "Games using 2D and 3D images that run on Windows,"
	emes "Screen savers, tools and practical software, etc."
	emes "You can build applications."

	gosub *waitclick
	byewall

	mkwall "・Features of HSP"
	text 10:color 0,0,128:textmode 2:color 255,255,255

	emes "・Powerful instruction set that is easy to learn"
	emes "・You can start using the included editor right away"
	emes "・The programs you create can be freely redistributed"
	emes "・Functional expansion using extension plug-ins"
	emes "・Many user assets and usage results for over 30 years"
	emes "・Equipped with an intermediate language interpreter"

	gosub *waitclick
	byewall

*demomain3
	;	HSPデモ(配置オブジェクト表示)
	;
	cls 4:color 0,0,64:boxf
	gradf 0,300,640,480,1,64,255
	objmode 1,1
	font msgothic,20,3
	x=16:y=20:color 192,255,128
	pos x,y:mes "・HSP3 Placement Object"
	font msgothic,14,1
	x=40:y=50:color 0,192,0:pos x,y
	mes "In HSP, objects such as buttons and input boxes can be"
	mes "You can freely place and use them. The sample below is one example."
	mes "You can also place many other controls and ActiveXs."
	mes "Proceed to the next step when the test is finished."
	sysfont:color 0,192,192
	pos 40,130:mes "・Calculation"
	pos 40,200:mes "・Graph"
	pos 40,270:mes "・Message"
	;
	objsize 48,24:color 192,192,192
	cal1="123":cal2="456"
	caltype=0:calmark="+\n-\n*\n/"
	pos 60,160:input cal1
	pos 160,160:input cal2
	objsize 40,24
	pos 114,159:combox caltype,150,calmark
	;
	objsize 64,24
	grph=10:x=310
	pos 60,230:input grph
	pos 138,230:button "GO",*idgrph
	pos 138+64,230:button "RND",*idrnd
	;
	pos 60,300:ids="Please enter a message here."
	objcolor 0,255,240
	color 64,128,64
	objmode objmode_usecolor+objmode_guifont
	mesbox ids,320,100,1
	button "GO",*idmes
	;
	objsize 120,24
	pos 480,400:button "Finish",*idover
	z=300
*idmain
	color 0,0,64:boxf 210,162,369,179
	color 192,192,192
	cal1b=cal1:cal2b=cal2:caltb=caltype
	cal1a=0.0+cal1:cal2a=0.0+cal2
	if caltb=0 : ans=cal1a+cal2a
	if caltb=1 : ans=cal1a-cal2a
	if caltb=2 : ans=cal1a*cal2a
	if caltb=3 : if cal2a!0.0 : ans=cal1a/cal2a : else : ans=0.0
	pos 210,162:mes "= "+ans
*idloop
	if cal1!cal1b : goto *idmain
	if cal2!cal2b : goto *idmain
	if caltb!caltype : goto *idmain
	;
	if z<=0 : goto *idover
	z--
	wait 10:goto *idloop

*idrnd
	a=(rnd(20)+1)*5:objprm 3,a
	goto *idgrph
*idgrph
	if x>580 : x=580:pos 310,180:gcopy 0,330,180,320,70
	a=250-grph/2:if a>250 : a=250
	if a<180 : a=180
	color 255,0,0:boxf x,a,x+18,250
	x+=20
	goto *idloop
*idmes
	dialog ids
	goto *idloop
*idover

*demomain4
	;	HSPデモ(ノベル表示)
	;
	cls 4
	buffer 3
	picload tvfolder+"sozai4.jpg"
	buffer 4
	picload tvfolder+"jp6girl.bmp"
	sx=ginfo_winx:sy=ginfo_winy

	gsel 6
	mx=ginfo_winx:my=ginfo_winy
	gsel 0:cls 4

	wipe_slide 3

	x=30:color 0,0,0
	repeat 32
		gmode 4,sx,sy,4*cnt
		pos x,0:gcopy 4
		await 16
	loop
	gmode 2,sx,sy:pos x,0:gcopy 4

	font msgothic,26,1+16
	text 20:color 0,0,0:textmode 1:color 255,255,255
	pos 280,80
	emes "Advanced functions"
	emes "that can be used for"
	emes "games, presentations"
	mes ""
	emes "・Complex effects"
	mes ""
	emes "・Color Blending"
	mes ""
	emes "・Sound, Motion Objects"

	gsel 3
	color 0,0,0:gmode 3,640,480,160
	grect 320,240,0
	gsel 0

	wait 700

	y=1:z=0
	repeat 16
		redraw 0
		gmode 0,640,480:pos 0,0:gcopy 3
		i=y>>1
		gmode 0,640,y:pos 0,240-i:gcopy 8,z,100-i
		gmode 2,sx,sy:pos x,0:gcopy 4
		redraw 1
		await 16
		x+=40:y+=4:z++
	loop

	repeat 50-16
		i=y>>1
		gmode 0,640,y:pos 0,240-i:gcopy 8,z,100-i
		await 16
		y+=4:z++
	loop

	color 0,0,0
	repeat 16
		gmode 0,640,y:pos 0,140:gcopy 8,z,0
		gmode 3,640,140,32
		grect 320,70,0
		grect 320,480-70,0
		await 16
		z++
	loop

	repeat 16
		redraw 0
		gmode 0,640,y:pos 0,140:gcopy 8,z,0
		gmode 6,mx,my,cnt*16:pos 258,180:gcopy 6
		redraw 1
		await 16
		z++
	loop

	repeat
		redraw 0
		gmode 0,640,y:pos 0,140:gcopy 8,z,0
		gmode 6,mx,my,256:pos 258,180:gcopy 6
		redraw 1
		await 16
		z++
		if z>=256 : break
	loop

	gsel 3:cls 4:gsel 0
	wipe_slide 3

*demomain5
	;	HSPデモ(サンプル画面表示)
	;
	buffer 4
	picload tvfolder+"hsp3scr.jpg"
	initwall

	gsel 3
	font msgothic,32,1+16
	a="・Main features"
	x=240:y=32
	pos x+2,y+2:color 0,0,0:mes a
	pos x,y:color 192,192,255:mes a
	font msgothic,20,1+16
	pos x+32,y+60
	text 0:color 0,0,128:textmode 2:color 255,255,255
	gsel 0

	fadewall

	max=8
	init_sprite 160,124,max
	opt_sprite 4,0
	move_sprite2_init

	tex={"
● High-performance tab editor
● Development support assistance
● Help browser with search words
● WEB, iOS, android app build
● High-performance 3D display
● Various image format in/out
● Use of webcams, more devices
● TCP/IP, serial communication
● Use of Windows COM, ActiveX"}

	z=0
	repeat
	redraw 0
	copywall

	if cnt=(z*250) {
		notesel tex
		if z<notemax {
			gsel 3
			noteget a,z
			emes a
			mes ""
			gsel 0
		}
		z++
	}

	move_sprite2
	draw_sprite
	redraw 1
	await 15
	if z>10 : break

	loop
	byewall

*demomain6
	;	HSPデモ(テキスト表示2)
	;
	cls 4
	mkwall "・What HSP3 can do"
	text 10:color 0,0,128:textmode 2:color 255,255,255

	emes "From visual novels to 3D games"
	emes "You can create various genres of games,"
	emes "desktop accessories, screen savers,"
	emes "prototype screen layouts, convert data,"
	emes "The range of applications such as tools"
	emes " and program launchers."
	emes "The possibilities are endless."

	gosub *waitclick
	byewall

	mkwall "・Information"
	text 10:color 0,0,128:textmode 2:color 255,255,255

	emes "HSP provides support on its website."
	emes "https://hsp.tv/
	mes ""
	emes "Information about HSP, sample scripts,"
	emes "FAQs, etc. We are always waiting for
	emes " your opinions about HSP,"
	emes "BUG information, and requests."

	gosub *waitclick
	byewall


*demomain7
	;	HSPデモ(エピローグ)
	;
	buffer 3
	picload tvfolder+"onibtn.gif"
	logosx=ginfo_winx
	logosy=ginfo_winy
	gsel 0:cls 4
	font "Arial",16,16

	repeat 32
		redraw 0
		color 0,0,0:boxf
		gosub *edmes2
		pos 260,290:gmode 0,logosx,logosy:gcopy 3
		color 0,0,0:gfade (31-cnt)*8
		redraw 1
		await 16
	loop

	wait 100
	sndfade -10
	repeat 5000/16
		sndexec
		await 16
	loop

	repeat 48
		color 234,234,230:gfade 8+cnt
		sndexec
		await 16
	loop

	snd 0
	goto *mainmenu

*waitclick
	;	クリック待ち
	;
	i=128:ip=16
	sysfont 17
	repeat 200
	stick key:if key : break
	color i,i,i
	i+=ip:if (i=128)or(i=240) : ip=-ip
	pos 480,440:mes "Please click a button."
	wait 10
	loop
	snd 1
	return

*edmes2
	x=200:y=130
	pos x+2,y+2:color 0,0,192:gosub *edmes
	pos x,y:color 255,255,255:gosub *edmes
	return

*edmes
	mes "HSP DEMO script"
	mes "copyright 2025 onion software"
	mes "   Music by CHOBIN,onitama"
	mes "   Music Arranged by ArStudio"
	mes "   Logo designed by sencha and"
	mes "                    YumeYumeYuuka"
	mes "   CG picture by Y-jinn"
	return