開発環境
- macOS Sierra - Apple (OS)
- Emacs (Text Editor)
- Python 3.6 (プログラミング言語)
Python Crash Course (Eric Matthes (著)、No Starch Press)のPART 2(PROJECTS)、PROJECT 1(ALIEN INVASION)、Chapter 12.(A SHIP THAT FIRES BULLETS)のTRY IT YOURSELF 12-1.(Blue Sky)、12-2.(Game Character)(No.6848)を取り組んでみる。
TRY IT YOURSELF 12-1.(Blue Sky)、12-2.(Game Character)(No.6848)
コード(Emacs)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
import pygame
def run_game():
pygame.init()
screen = pygame.display.set_mode((1200, 800))
image = pygame.image.load('cat.bmp')
rect = image.get_rect()
screen_rect = screen.get_rect()
rect.centerx = screen_rect.centerx
rect.centery = screen_rect.centery
pygame.display.set_caption('Alien Invasion')
bg_color = (0, 0, 255)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
screen.fill(bg_color)
screen.blit(image, rect)
pygame.display.flip()
if __name__ == '__main__':
run_game()
入出力結果(Terminal, IPython)
$ ./sample1.py $
0 コメント:
コメントを投稿