學習-用Python和Pygame寫遊戲-從入門到精通(6)

  • 2019 年 11 月 28 日
  • 筆記

本文乾貨很多,so給一個傳送門,咱們就不搬磚了。http://python.jobbole.com/83523/

代碼記錄在git上 6.xiangsu

下面的小腳本會隨機的在屏幕上畫點:

Python

import pygame from pygame.locals import * from sys import exit from random import randint pygame.init() screen = pygame.display.set_mode((1024,800),0,32) while True: for event in pygame.event.get(): if event.type == QUIT: exit() rand_col = (randint(0,255),randint(0,255),randint(0,255)) for _ in xrange(100): rand_pos = (randint(0,1024),randint(0,799)) screen.set_at(rand_pos,rand_col) pygame.display.update()

12345678910111213141516171819

import pygamefrom pygame.locals import *from sys import exitfrom random import randint pygame.init()screen = pygame.display.set_mode((1024,800),0,32) while True:    for event in pygame.event.get():        if event.type == QUIT:            exit()     rand_col = (randint(0,255),randint(0,255),randint(0,255))    for _ in xrange(100):        rand_pos = (randint(0,1024),randint(0,799))        screen.set_at(rand_pos,rand_col)     pygame.display.update()

效果如上圖。。。