2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

HSP3.6β5 HGIMG4 でドミノ倒し

Posted at

HSP3.6β5 HGIMG4 では gpbox モデルを gppbind で剛体化する際、その前に指定した setscale の設定が、gpbox の剛体の形状に反映されるようになりました。
このおかけで直方体剛体が作成できるようになりドミノ倒しが実現できるようになりました。

サンプルコードは以下のようになります。

# include "hgimg4.as"
# define GRAVY (-9.8 * 3.0)
	gpreset
	setcls CLSMODE_SOLID, 0x000000
	setpos GPOBJ_CAMERA, 30,40,110
	gplookat GPOBJ_CAMERA, 0,2,0
	gosub *make
	repeat
		redraw 0
		gpdraw
		redraw 1
		await 1000/60
	loop

*make
	num = 10
	dist = 6
	offset_y = 10.0
	offset_x = -2.2
// 1段目
	fric = 1.0
	pong = 0.01
	col = 0x606060
	size = double(dist * num) * 0.5, 1.0, 4.0
	ps = size.0, 0.0 + offset_y, 0.0
	id = _box(size, ps, col, 0, fric, pong)
// 2段目
	ps = - double(dist * num) * 0.5 + offset_x, 0.0, 0.0
	id = _box(size, ps, col, 0, fric, pong)

	mass = 10.0
	size = 1.0, 4.0, 2.0
	fric = 0.2
	pong = 0.5
// キックピース
	col = 0xff0000
	ps = double(dist * (num - 1)) - 2.0, 2.0 + offset_y, 0.0
	gpbox id, 2.0, col
	setpos id, ps.0, ps.1, ps.2
	setscale id, size.0, size.1, size.2
	setang id, 0, 0, M_PI * 0.1
	gppbind id, mass, fric
	gppset id, GPPSET_FRICTION, fric, pong

	flup = 2
	mass = 2.0
	repeat num-2, 1 // 1グループ目
		r = (rnd(5 - flup) + flup) * 51
		g = (rnd(5 - flup) + flup) * 51
		b = (rnd(5 - flup) + flup) * 51
		col = (r << 16) | (g << 8) | b
		ps = double(dist * cnt), 2.0 + offset_y, 0.0
		id = _box(size, ps, col, mass, fric, pong)
	loop
	repeat num-1, 1 // 2グループ目
		r = (rnd(5 - flup) + flup) * 51
		g = (rnd(5 - flup) + flup) * 51
		b = (rnd(5 - flup) + flup) * 51
		col = (r << 16) | (g << 8) | b
		ps = offset_x - double(dist * cnt), 4.0, 0.0
		id = _box(size, ps, col, mass, fric, pong)
	loop
	return

// 直方体剛体を作成する
# defcfunc _box array _size, array _pos, int _col, double _mass, double _fric, double _pong, local _id
	gpbox _id, 2, _col
	setpos _id, _pos.0, _pos.1, _pos.2
	setscale _id, _size.0, _size.1, _size.2
	gppbind _id, _mass, _fric
	gppset _id, GPPSET_FRICTION, _fric, _pong
	gppset _id, GPPSET_DAMPING, 0.0, 0.0
	gppset _id, GPPSET_GRAVITY, 0.0, GRAVY, 0.0
	return _id
実行結果1
qdomi1.png
右の赤いドミノから倒れていきます
実行結果2
qdomi2.png
パタパタパタパタ、、、

デフォルトの重力値だと少し動きがもっさりしている気がするので値を大きくしています。

2
1
0

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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?