python pygame模組的使用

2021-06-08 01:23:33 字數 1706 閱讀 1820

import pygame, sys

from pygame.locals import *

#set up pygame

pygame.init()

windowsu***ce = pygame.display.set_mode((500, 400), 0, 32)

pygame.display.set_caption("hello, world")

black = (0, 0, 0)

white = (255, 255, 255)

red = (255, 0, 0)

green = (0, 255, 0)

blue = (0, 0, 255)

basicfont = pygame.font.sysfont(none, 48)

text = basicfont.render("hello ,world", true, white, blue)

textrect = text.get_rect()

textrect.centerx = windowsu***ce.get_rect().centerx

textrect.centery = windowsu***ce.get_rect().centery

windowsu***ce.fill(white)

pygame.draw.polygon(windowsu***ce, green, ((146, 0),

(291, 106), (236, 277), (56, 277), (0, 106)))

pygame.draw.line(windowsu***ce, blue, (60, 60), (120,

60), 4)

pygame.draw.line(windowsu***ce, blue, (120, 60), (60,

120))

pygame.draw.line(windowsu***ce, blue, (60, 120), (120,

120), 4)

pygame.draw.circle(windowsu***ce, blue, (300, 50), 20, 0)

pygame.draw.ellipse(windowsu***ce, red, (300, 250, 40,

80), 1)

pygame.draw.rect(windowsu***ce, red, (textrect.left - 20,

textrect.top - 20, textrect.width + 40, textrect.height + 40))

pixarray = pygame.pixelarray(windowsu***ce)

pixarray[480][380] = black

del pixarray

windowsu***ce.blit(text, textrect)

pygame.display.update()

while true:

for event in pygame.event.get():

if event.type == quit:

pygame.quit()

sys.exit()

打出的

Python pygame如何安裝?

linux 下安裝 python2 下執行 sudo pip2 install pygame驗證是否安裝成功 python2 m pygame.examples.alienspython3 下執行 sudo pip3 install pygame驗證是否安裝成功 python3 m pygame.e...

python pygame 事件學習

coding utf 8 import pygame import sys from pygame.locals import 初始化pygame pygame.init size width,height 600,400 speed 2,1 bg 255,255,255 rgb 建立指定大小的視窗...

Python Pygame動畫原理

這是動畫原理的第一節,首先需要遊戲的最小系統,在此之後我就不再提遊戲最小系統了,那是最基本的,可以看我的第一篇 所有 配套資源 講解都在github coding notes幫助更多的人,還有python其他資源,以及c 課程 零基礎 python體驗課 第四季 pygame遊戲開發 pygame移...