1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Pyxel】短いプログラムで遊ぶ①

Last updated at Posted at 2024-11-28

Pyxel使ってメガデモライクなものを作りたいと思ってチャレンジ中。
長時間見てると目がおかしくなるので注意!
tamademo.png

#------------------------------------------
# title: Tama Demo
# author: sanbunnoichi
#------------------------------------------
import pyxel

SCREEN_WIDTH		=	256		#画面横サイズ
SCREEN_HEIGHT		=	256		#画面縦サイズ
TAMA_SIZE			=	8
TAMA_WORK			=	0
WORK_END			=	0x8000
_ass = TAMA_WORK
GWK = [TAMA_WORK for _ass in range(WORK_END)]	#変数管理(RAM領域)
TWORK_SIZE			=	0x10		#(TAMA_WORK)玉ワークサイズ
#TAMA_WORKアサイン
cid					=	0x00		#ID
ccond				=	0x01		#状態
cxpos				=	0x02		#X座標
cypos				=	0x03		#Y座標
cxspd				=	0x04		#X移動スピード
cyspd				=	0x05		#Y移動スピード
cwait				=	0x06		#待ち
ctype				=	0x07		#種別
cdeg				=	0x08		#角度
czoom				=	0x09		#拡大率
TAMA_MAX = int( ( WORK_END - TAMA_WORK ) / TWORK_SIZE )
#-----------------------------------------------------------------
#デモ初期化
def demo_init(_wk, _type):
	GWK[_wk + cxpos] = SCREEN_WIDTH / 2
	GWK[_wk + cypos] = SCREEN_HEIGHT / 2
	GWK[_wk + cwait] = pyxel.rndi(0,250)
	_degree = pyxel.rndi(0,359)
	GWK[_wk + cdeg ] = _degree
	GWK[_wk + cxspd ] = pyxel.cos( _degree ) * 1.0
	GWK[_wk + cyspd ] = pyxel.sin( _degree ) * 1.0
	GWK[_wk + czoom ] = 0.1
	GWK[_wk + cid ] = pyxel.rndi(1,15)
	GWK[_wk + ccond ] = 0
	GWK[_wk + ctype ] = _type
#-----------------------------------------------------------------
#デモ更新
def demo_control():
	#変化タイミング
	_type = ( pyxel.frame_count >> 9 ) & 0x03;

	for _cnt in range( TAMA_MAX ):
		_wk = TAMA_WORK + ( TWORK_SIZE * _cnt )
		if( GWK[_wk + ccond] == 0 ):
			GWK[_wk + cwait] = GWK[_wk + cwait] - 1
			if( GWK[_wk + cwait] < 0 ):
				GWK[_wk + ccond] = 1
		else:
			GWK[_wk + czoom] = GWK[_wk + czoom] + 0.01
			GWK[_wk + cxpos] = GWK[_wk + cxpos] + GWK[_wk + cxspd]
			GWK[_wk + cypos] = GWK[_wk + cypos] + GWK[_wk + cyspd]
			#フレームアウトチェック
			if( ( GWK[_wk + cxpos] < ( TAMA_SIZE * (-4) ) ) or
				( GWK[_wk + cxpos] > SCREEN_WIDTH + ( TAMA_SIZE * (4) ) ) or
				( GWK[_wk + cypos] < ( TAMA_SIZE * (-4) ) ) or
				( GWK[_wk + cypos] > SCREEN_HEIGHT + ( TAMA_SIZE * (4) ) ) ):
				demo_init(_wk, _type)
#-----------------------------------------------------------------
#デモ表示
def demo_out():
	for _cnt in range( TAMA_MAX ):
		_wk = TAMA_WORK + ( TWORK_SIZE * _cnt )
		if GWK[_wk + ccond]:
			if GWK[_wk + ctype ] == 0:
				pyxel.circ(GWK[_wk + cxpos], GWK[_wk + cypos], 0x10*GWK[_wk + czoom] ,(GWK[_wk + cid]) & 0x0f)
			elif GWK[_wk + ctype ] == 1:
				pyxel.circb(GWK[_wk + cxpos], GWK[_wk + cypos], 0x10*GWK[_wk + czoom] ,(GWK[_wk + cid]) & 0x0f)
			elif GWK[_wk + ctype ] == 2:
				pyxel.rect(GWK[_wk + cxpos], GWK[_wk + cypos], 0x10*GWK[_wk + czoom], 0x10*GWK[_wk + czoom] ,(GWK[_wk + cid]) & 0x0f)
			elif GWK[_wk + ctype ] == 3:
				pyxel.rectb(GWK[_wk + cxpos], GWK[_wk + cypos], 0x10*GWK[_wk + czoom], 0x10*GWK[_wk + czoom] ,(GWK[_wk + cid]) & 0x0f)
#-----------------------------------------------------------------
#更新&表示
def update():
	demo_control()
def draw():
	pyxel.cls(0)
	demo_out()
#-----------------------------------------------------------------
#INIT&RUN
pyxel.init( SCREEN_WIDTH, SCREEN_HEIGHT, capture_sec=30 )
#玉ワーク初期化
for _cnt in range( TAMA_MAX ):
	_wk = TAMA_WORK + ( TWORK_SIZE * _cnt )
	demo_init(_wk, 0)
pyxel.run(update, draw)

Pyxelはレトロゲームエンジンだけど、出すだけならいっぱい出せるので結構遊べるかなと思います。

動作確認はこちら

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?