<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Pyxeleditor on Xainome Blog</title><link>https://xainome-blog.beeskynohito.workers.dev/tags/pyxeleditor/</link><description>Recent content in Pyxeleditor on Xainome Blog</description><generator>Hugo</generator><language>ja</language><lastBuildDate>Fri, 27 Dec 2024 00:00:00 +0000</lastBuildDate><atom:link href="https://xainome-blog.beeskynohito.workers.dev/tags/pyxeleditor/index.xml" rel="self" type="application/rss+xml"/><item><title>Pyxelを使って簡単なゲームの作成を試してみたい！part2</title><link>https://xainome-blog.beeskynohito.workers.dev/posts/2024/12/build-game-with-pyxel-part-2/</link><pubDate>Fri, 27 Dec 2024 00:00:00 +0000</pubDate><guid>https://xainome-blog.beeskynohito.workers.dev/posts/2024/12/build-game-with-pyxel-part-2/</guid><description>&lt;h2 id="pyxeleditorでキャラの動きやサウンド">pyxeleditorでキャラの動きやサウンド&lt;/h2>
&lt;p>&lt;a href="https://xainome-blog.beeskynohito.workers.dev/posts/2024/12/build-game-with-pyxel-part-1/">前回&lt;/a>&lt;a href="https://github.com/kitao/pyxel">pyxel&lt;/a>のインストールからドット絵を描いて表示させるところまでやってみました。今回は実際にキャラクターを動かしたり、サウンドを作ったりしたいと思います。&lt;/p>
&lt;h3 id="pyxeleditorで作った部分">pyxeleditorで作った部分&lt;/h3>
&lt;p>実際に動いた画面がこちら。&lt;/p>
&lt;h3 id="コードの中身_init">コードの中身_init&lt;/h3>
&lt;p>一旦各コードを簡単に見ていこうと思います。まずは__init__内ですね。前回も話したのでざっくりと見ます。&lt;/p>
&lt;pre tabindex="0">&lt;code>pyxel.init(128, 128, title=&amp;#39;Scrolling Game&amp;#39;)
pyxel.load(&amp;#39;assets/scroll_game.pyxres&amp;#39;)
self.char_x = 50 # キャラクターのX座標
self.char_y = 50 # キャラクターのY座標
&lt;/code>&lt;/pre>&lt;p>initで画面サイズの設定、char_xとchar_yはキャラ座標を設定しています。loadでpixel editで作成したものをロードしています。ドット絵、タイルマップ、サウンドなど全て一旦ロードしています。&lt;/p>
&lt;pre tabindex="0">&lt;code>self.char_frame = 0 # 表示する画像のインデックス (0 または 1)
self.frame_count = 0 # フレームカウンター
self.is_moving = False # 移動中フラグを追加
self.last_input = False #直前のフレームでキー入力があったか
pyxel.run(self.update, self.draw)
&lt;/code>&lt;/pre>&lt;p>他のコードはコメントも記載していますが、キャラ画像の入れ替えやフラグの設定をしています。後はpyxelの起動ですね。&lt;/p>
&lt;h3 id="コードの中身_update">コードの中身_update&lt;/h3>
&lt;p>次はupdate関数ですね。&lt;/p>
&lt;pre tabindex="0">&lt;code># ゲーム中断
if pyxel.btnp(pyxel.KEY_Q):
pyxel.quit()
# キー入力と移動処理
self.is_moving = False
key_pressed = False # 今のフレームでキーが押されているか
&lt;/code>&lt;/pre>&lt;p>Qを押したらゲームを中断します。それからフラグとキー入力の初期設定をしています。&lt;/p>
&lt;pre tabindex="0">&lt;code># キー入力処理とキャラクターの移動
if pyxel.btn(pyxel.KEY_LEFT):
self.char_x -= 1
self.is_moving = True # 移動中フラグを立てる
key_pressed = True
if pyxel.btn(pyxel.KEY_RIGHT):
self.char_x += 1
self.is_moving = True
key_pressed = True
if pyxel.btn(pyxel.KEY_UP):
self.char_y -= 1
self.is_moving = True
key_pressed = True
if pyxel.btn(pyxel.KEY_DOWN):
self.char_y += 1
self.is_moving = True
key_pressed = True
&lt;/code>&lt;/pre>&lt;p>ここでは各方向キーを入力した時の設定をしています。上下左右分書いてるので記述は多いですが、内容はシンプルです。キャラクターの座標をずらして、フラグを書き換えています。というか関数化したほうがもっとシンプルになりますね…&lt;/p></description></item></channel></rss>