貪吃蛇001 設定遊戲視窗和啟動頁面

2021-10-07 13:30:39 字數 1261 閱讀 2162

#視窗變數

windows_width = 800

windows_height = 480

cell_size = 20 #方塊大小

map_width=windows_width//cell_size

map_hight = windows_height//cell_size

#設定顏色變數

red = (255,0,0)

blue = (0,0,255)

blue2 = (4,23,120)

#初始化pygame(退出遊戲時記得使用pygame.quit())

pygame.init()

screen = pygame.display.set_mode((windows_width,windows_height))

screen.fill(blue2)

pygame.display.set_caption("python 貪吃蛇98")

#開始介面

gamestart = pygame.image.load('gamestart.png')

gamestart = pygame.transform.scale(gamestart,(windows_width,windows_height)) # transform.scale縮放

screen.blit(gamestart,(0,0)) #blit 第乙個引數:要顯示的元素,第二個引數:座標

font = pygame.font.font('myfont.ttf',60)

tip = font.render("貪吃蛇",true,red) #渲染

screen.blit(tip,(300,30))

font = pygame.font.font('my_pygame/resources/font/myfont.ttf',40)

tip = font.render("按任意鍵開始遊戲(按esc退出遊戲)",true,blue) #設定需要顯示的文字,true代表開啟抗鋸齒(字型顯示平滑),blue顏色

screen.blit(tip, (100, 300))

pygame.display.update()

#死迴圈可以讓遊戲視窗停住(不會閃退)

while true:

pass

貪吃蛇遊戲

貪吃蛇遊戲 結構化程式設計 c語言程式設計 重要的的是結構化的程式設計思想 include include include include include include define field width 300 就做20個格仔的 define field height 300 define f...

貪吃蛇遊戲

include include include include include 使用當前時間做種子 enum dir 列舉型別enum dir 圍牆 class fencef 定義物件 畫框框 void fence initfence 顯示框框 void fence outputf int snak...

貪吃蛇遊戲

閒暇之餘,學習前輩經驗,再利用執行緒和窗體自己做了個貪吃蛇小遊戲。遊戲帶有加速功能,能顯示遊戲分數。借鑑的朋友們後期還可以在此基礎上增加其他功能。下面給大家顯示遊戲 以及詳細註解 一 bean類 蛇和食物的構造基礎,author deng public class node public node ...