Skip to content

Instantly share code, notes, and snippets.

@shiroutosan
Created August 24, 2018 04:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shiroutosan/9236d7fee5e044663ddd109c570972a0 to your computer and use it in GitHub Desktop.
Save shiroutosan/9236d7fee5e044663ddd109c570972a0 to your computer and use it in GitHub Desktop.
while (1):
screen.fill((100,100,255)) # ウィンドウ内の色の設定
frame += 2
clock.tick(120)
pressed_keys = pygame.key.get_pressed() # 押されたキーを取得
if pressed_keys[K_LEFT]:
mame.direction = 12 # プレイヤーの向きを左向きにセット
if mame.x > 0: # 画面左端から出ないようにブロック
mame.x -= vx # 座標の更新
if pressed_keys[K_RIGHT]:
mame.direction = 4 # プレイヤーの向きを右向きにセット
if mame.x<400-32: # 画面右端から出ないようにブロック
mame.x+=vx
if pressed_keys[K_UP]:
mame.direction = 8 # プレイヤーの向きを上向きにセット
if mame.y>0: # 画面上端から出ないようにブロック
mame.y-=vy
if pressed_keys[K_DOWN]:
mame.direction = 0 # プレイヤーの向きを下(正面)向きにセット
if mame.y<320-32: # 画面下端から出ないようにブロック
mame.y+=vy
# 描画
playerImg = mame.imagelist[int(frame / animcycle) % 4 + mame.direction]
screen.blit(playerImg,(mame.x,mame.y))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment