python中建立乙個簡單的遊戲窗體

2021-10-04 07:42:16 字數 565 閱讀 7203

想要做乙個2d的遊戲,不需要用c++來編寫,那就大材小用了,python是乙個更好的選擇,pygame等包非常適用於2d遊戲的開發,下面是一段建立基於pygame來建立的乙個簡單的窗體:

import pygame

import sys

def run_game():

pygame.init()#初始化背景設定

screen = pygame.display.set_mode((1200,800))

bg_color = 230,230,230

screen.fill(bg_color)

pygame.display.set_caption("game")

while true:

for event in pygame.event.get():

if event.type == pygame.quit:

pygame.quit()

sys.exit()

pygame.display.flip()#讓最近繪製的螢幕可見

run_game()

建立乙個簡單的執行緒

handle createthread in opt lpsecurity attributes lpthreadattributes,security attributes 結構指定了這個執行緒的安全屬性,如果填 null 則就以預設的安全描述子建立,並且返回的控制代碼不會被繼承。in size ...

建立乙個簡單的畫板

1.cv.createtrackbar 有5個引數 滑動條的名字 視窗的名字 數值的最小值 數值的最大值 函式2.cv.gettrackbarpos 有2個引數 滑動條的名字 視窗的名字 函式的返回值是滑動條的數值。import cv2 as cv import numpy as np def no...

建立乙個簡單的systemverilog程式

作為乙個物件導向的語言,免不了來乙個國際慣例 hello world!下面是完整的 program tb initial begin display hello,world endendprogram 用modelsim進行編譯和執行 hello,world 解釋 跟c語言的main函式類似,sv語...