Python開發遊戲(一)

首先安裝pygame模塊:

pip install pygame

然後看第一個小例子,展示遊戲屏幕,代碼保存爲game1.py:

import pygame,sys
'''
遇到python不懂的問題,可以加Python學習交流羣:1004391443一起學習交流,羣文件還有零基礎入門的學習資料
'''
pygame.init()
screen = pygame.display.set_mode((600,400))
pygame.display.set_caption("Pygame壁球")

ball = pygame.image.load("apple.png")
ballrect = ball.get_rect()
screen.fill((255,255,255))
screen.blit(ball,ballrect)
pygame.display.update()

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()

pygame.display.update()

允許:python game1.py

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章