0
0

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 1 year has passed since last update.

pico-8 > SMC-777 > tiny Mysterious boy

Last updated at Posted at 2022-05-29

前置き

自分が小さいころに親が所有していたSMC-777で遊んだMysterious Boyというゲームを雰囲気で実装してみた(細かい動作は全然異なる)。

実行例

image.png

ソース

ソース全部はesa.ioに記載している。

Sprite

image.png

実装の概要

ジャンプ

zボタンを押した時に等速で上下するだけの実装にしている。

enemy1..3の生成

enemy1..3それぞれにnew(), update(), draw()を用意して、それぞれをコール。
もっとコンパクトな実装はできるかもしれない。

enemyXの壁衝突判定

mapとの衝突判定のためmget()を使った。

	clx1 = flr(enemy1.x/8)
	cly1 = flr(enemy1.y/8)
	if (mget(clx1, cly1) == 2) enemy1.vx *= -1  -- hit wall

enemyXとplayerの衝突判定

二つのspriteの衝突判定については見学習の状態である。
今回はpget()を用いて、代表的な色の値を使って衝突判定している。

enemy1.update = function()
	enemy1.x += enemy1.vx
	clx1 = flr(enemy1.x/8)
	cly1 = flr(enemy1.y/8)
	if (mget(clx1, cly1) == 2) enemy1.vx *= -1  -- hit wall
	if (pget(player.x, player.y) == 5) player.miss = true -- hit enemy
end

階段を昇る処理

階段のスプライトでの代表的な色として12を判断に使用している。
加えて、floorの代表的な色として3を判断に使用している。
スムーズな処理にはなっていない。

function isStairAscending(x, y)
	if (pget(x,y) == 12) return true -- hit stair
	if (pget(x+8,y+8) == 12) return true -- hit stair
	if (pget(x,y) == 3) return true -- hit floor
	if (pget(x+8,y+8) == 3) return true -- hit floor
	return false
end
player.update = function()
...
	if (btn(2) and player.jumping == false) then
		if (isStairAscending(player.x, player.y)) then
			player.x -= 5
			player.y -= 5
		end
	end

以下のようにすると多少良くなったが、まだ改善点はある。

function isOnTheStair(x, y)
	if (pget(x,y) == 12) return true -- hit stair
	if (pget(x+8,y) == 12) return true -- hit stair
	if (pget(x,y+8) == 12) return true -- hit stair
	if (pget(x+8,y+8) == 12) return true -- hit stair
	if (pget(x,y) == 3) return true -- hit floor
	if (pget(x+8,y) == 3) return true -- hit floor
	if (pget(x,y+8) == 3) return true -- hit floor
	if (pget(x+8,y+8) == 3) return true -- hit floor
	return false
end
	if (btn(2) and player.jumping == false) then
		if (isOnTheStair(player.x, player.y)) then
			player.x -= 2
			player.y -= 2
		end
	end

関連

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?