#作成しているもの
pygamezeroを用いて、落下系ゲーム
参考 https://sites.google.com/terrace.qld.edu.au/pygameinmu/gem-catcher?authuser=0
7番目の動画
上から刃物を振らせようとするのですが、定義したdef drop(blade)が文法エラーとなります。
どなたか、原因わかる方いましたら、教えてくださると助かります。
ここにコードを書いてね :-)
import random
WIDTH = 500
HEIGHT = 700
CENTER = WIDTH/2
score = 0
'''Player'''
player = Actor('idle')
player.pos = midbottom=(CENTER,HEIGHT-96)
player_speed = 8
def player_move():
if keyboard.left and player.left >0 :
player.x -= player_speed
elif keyboard.right and player.right<WIDTH :
player.x += player_speed
'''Gems'''
gems = [ ]
number_of_gems = 3
def gem_spawn():
gems.append(Actor('gem',pos = (random.randint(0,WIDTH),0)))
def fall(gem):
if gem.y < 620:
gem.y +=4
for i in range(number_of_gems):
clock.schedule(gem_spawn,i)
"""Blades"""
blades = []
number_of_blades = 2
def blade_spawn():
blades.append(Actor('blade',pos = (random.randint(0,WIDTH),0)
def drop(blade):
if blade.y >HEIGHT:
blade.y = 0
blade.y += 2
for i in range(number_of_blades):
clock.schedule(blade_spawn,i*5)
"""GAME"""
def draw():
screen.fill((0,100,200))
player.draw() for gem in gems: gem.draw() for blade in blades: blade.draw() for i in range(8): screen.blit(images.ground,(i*images.ground.get_width(),HEIGHT-images.ground.get_height())) screen.draw.text(f"Score:{score}",midtop=(CENTER,10),fontname='mini_square',fontsize=36) screen.draw.text("Dodge the blades and grab the gems",midbottom=(CENTER,HEIGHT-15),fontname='mini_square',fontsize=14)
def update():
global score
player_move()
for gem in gems: fall(gem) if player.colliderect(gem): gem.pos = (random.randint(0,WIDTH),0) score += 1 for blade in blades: drop(blade)
#表示されるエラー
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
File "/Users/travis/build/mu-editor/mu_portable_python_macos/python/lib/python3.6/runpy.py", line 193, in _run_module_as_main
File "/Users/travis/build/mu-editor/mu_portable_python_macos/python/lib/python3.6/runpy.py", line 85, in _run_code
File "/Applications/mu-editor.app/Contents/Resources/app_packages/pgzero/main.py", line 3, in <module>
main()
File "/Applications/mu-editor.app/Contents/Resources/app_packages/pgzero/runner.py", line 79, in main
code = compile(src, os.path.basename(path), 'exec', dont_inherit=True)
File "test.py", line 43
def drop(blade):
^
SyntaxError: invalid syntax
---------- FINISHED ----------
exit code: 1 status: 0
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/05/24 09:37