python
1import pyxel 2 3WIDTH = 128 4HEIGHT = 128 5IMG_NO = 0 6 7class App: 8 my_x = 0 9 my_y = 0 10 11 def__init__(self): 12 pyxel.init(WIDTH, HEIGHT) 13 pyxel.load('mychara.pyxres') 14 pyxel.run(self.update,self.draw) 15 16 def update(self): 17 if pyxel.btn(pyxel.KEY_LEFT) or pyxel.btn(pyxel.GAMEPAD_1_LEFT): 18 self.player_x = max(self.player_x - 2, 0) 19 20 if pyxel.btn(pyxel.KEY_RIGHT) or pyxel.btn(pyxel.GAMEPAD_1_RIGHT): 21 self.player_x = min(self.player_x + 2, pyxel.width - 16) 22 23 if pyxel.btn(pyxel.KEY_UP) or pyxel.btn(pyxel.GAMEPAD_1_UP): 24 self.player_y = max(self.player_y - 2, 0) 25 26 if pyxel.btn(pyxel.KEY_DOWN) or pyxel.btn(pyxel.GAMEPAD_1_DOWN): 27 self.player_y = min(self.player_y + 2, pyxel.height - 16) 28 29 def draw(self): 30 pyxel.cls(7) 31 pyxel.blt(self.my_x,self.my_y,IMG_NO,0,0,16,16,0) 32 33App()
これで実行してもエラーとなりました。
エラーは
Traceback (most recent call last):
File "C:\Users\taked\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\taked\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 87, in run_code
exec(code, run_globals)
File "c:\Users\taked.vscode\extensions\ms-python.python-2021.11.1422169775\pythonFiles\lib\python\debugpy_main.py", line 45, in <module>
cli.main()
File "c:\Users\taked.vscode\extensions\ms-python.python-2021.11.1422169775\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 444, in main
run()
File "c:\Users\taked.vscode\extensions\ms-python.python-2021.11.1422169775\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 285, in run_file
runpy.run_path(target_as_str, run_name=compat.force_str("main"))
File "C:\Users\taked\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 267, in run_path
code, fname = _get_code_from_file(run_name, path_name)
File "C:\Users\taked\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 242, in get_code_from_file
code = compile(f.read(), fname, 'exec')
File "c:\Users\taked\OneDrive\デスクトップ\pyxel Games\sample02.py", line 11
def_init(self):
^
SyntaxError: invalid syntax
PS C:\Users\taked\OneDrive\デスクトップ\pyxel Games>
こういうエラーが出ました。何が問題なのか教えていただきたいです。
回答1件
あなたの回答
tips
プレビュー