プログラミング言語「Python」で制作 Part95 | Photoshop CC Tutorials

今回はプログラミング言語の「Python」を使って作成しました。

 

放物運動をするプログラムです。

 

■ プログラム

import sys
import pygame
from pygame.locals import QUIT, Rect
import random

pygame.init()
SURFACE = pygame.display.set_mode((600, 600))
FPSCLOCK = pygame.time.Clock()

def main():
    """ メインルーチン """
    rect = Rect(0, 300, 10, 10)
    velocity = [5, -10]
    accel = (0, random.random() * 2)
    while True:
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit()

        SURFACE.fill((0, 0, 0))
        velocity[1] += accel[1]
        rect.move_ip(velocity)

        if rect.x > 600:
            rect.x = 0
        if rect.y > 600:
            velocity[1] = -10
            accel = (0, random.random() * 2)

        #pygame.draw.rect(SURFACE, (255, 255, 255), rect)
        pygame.draw.circle(SURFACE, (255, 255, 0), (rect.x + 5, rect.y + 5), 10)

        #pygame.time.delay(100)

        pygame.display.update()
        FPSCLOCK.tick(60)

if __name__ == '__main__':
    main()

 

■ 参考書

「Pythonゲームプログラミング 知っておきたい数学と物理の基本」

 

■ ゲーム用ライブラリ

「Pygame」

 

■ プログラミング言語