日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python游戏循环设置_Pygame:游戏循环前的初始菜单

發布時間:2023/12/1 python 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python游戏循环设置_Pygame:游戏循环前的初始菜单 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我正在制作一個this game的版本,并嘗試將起始菜單設置為:

我的計劃是先做surface.fill(overlaycolor),然后將這個圖像blitting到屏幕上。在一個while循環中。之后,在用戶想玩(另一個問題除外)之后,我們將進入另一個while循環。在

我試過這么做,但這只會給我一個黑幕。在

這是我的代碼:import pygame, sys, random

from pygame.locals import *

# set up pygame

pygame.init()

mainClock = pygame.time.Clock()

# set up the window

width = 800

height = 600

thesurface = pygame.display.set_mode((width, height), 0, 32)

pygame.display.set_caption('')

bg = pygame.image.load("bg.png")

menu1 = pygame.image.load("menu1.png")

basicFont = pygame.font.SysFont('calibri', 36)

# set up the colors

BLACK = (0, 0, 0)

GREEN = (0, 255, 0)

WHITE = (255, 255, 255)

BLUE = (0, 0, 255)

overlay = (121, 126, 128)

playercolor = BLUE

# set up the player and food data structure

foodCounter = 0

NEWFOOD = 20

FOODSIZE = 10

splitting = False

player = pygame.draw.circle(thesurface, playercolor, (60, 250), 40)

foods = []

for i in range(20):

foods.append(pygame.Rect(random.randint(0, width - FOODSIZE), random.randint(0, height - FOODSIZE), FOODSIZE, FOODSIZE))

# set up movement variables

moveLeft = False

moveRight = False

moveUp = False

moveDown = False

MOVESPEED = 10

size = 10

score = size

gameisplaying = False

while True:

thesurface.fill(overlay)

thesurface.blit(menu1, (400,400))

for event in pygame.event.get():

if event.type == pygame.MOUSEBUTTONUP:

pos = pygame.mouse.get_pos()

gameisplaying = True

break

# run the game loop

while gameisplaying:

thesurface.blit(bg, (0, 0))

# check for events

for event in pygame.event.get():

if event.type == QUIT:

pygame.quit()

sys.exit()

if event.type == KEYDOWN:

# change the keyboard variables

if event.key == K_LEFT or event.key == ord('a'):

moveRight = False

moveLeft = True

if event.key == K_RIGHT or event.key == ord('d'):

moveLeft = False

moveRight = True

if event.key == K_UP or event.key == ord('w'):

moveDown = False

moveUp = True

if event.key == K_DOWN or event.key == ord('s'):

moveUp = False

moveDown = True

if event.key == K_SPACE and size >= 32: # XXX if size and space set splitting to true

splitting = True

if event.type == KEYUP:

if event.key == K_ESCAPE:

pygame.quit()

sys.exit()

if event.key == K_LEFT or event.key == ord('a'):

moveLeft = False

if event.key == K_RIGHT or event.key == ord('d'):

moveRight = False

if event.key == K_UP or event.key == ord('w'):

moveUp = False

if event.key == K_DOWN or event.key == ord('s'):

moveDown = False

if event.key == ord('x'):

player.top = random.randint(0, height - player.height)

player.left = random.randint(0, width - player.width)

if event.type == MOUSEBUTTONUP:

foods.append(pygame.Rect(event.pos[0], event.pos[1], FOODSIZE, FOODSIZE))

foodCounter += 1

if foodCounter >= NEWFOOD:

# add new food

foodCounter = 0

foods.append(pygame.Rect(random.randint(0, width - FOODSIZE), random.randint(0, height - FOODSIZE), FOODSIZE, FOODSIZE))

if 100>score>50:

MOVESPEED = 9

elif 150>score>100:

MOVESPEED = 8

elif 250>score>150:

MOVESPEED = 6

elif 400>score>250:

MOVESPEED = 5

elif 600>score>400:

MOVESPEED = 3

elif 800>score>600:

MOVESPEED = 2

elif score>800:

MOVESPEED = 1

# move the player

if moveDown and player.bottom < height:

player.top += MOVESPEED

if moveUp and player.top > 0:

player.top -= MOVESPEED

if moveLeft and player.left > 0:

player.left -= MOVESPEED

if moveRight and player.right < width:

player.right += MOVESPEED

# splitting

if not splitting:

pygame.draw.circle(thesurface, playercolor, player.center, size)

else:

pygame.draw.circle(thesurface, playercolor,(player.centerx,player.centery),int(size/2))

pygame.draw.circle(thesurface, playercolor,(player.centerx+size,player.centery+size),int(size/2))

# check if the player has intersected with any food squares.

for food in foods[:]:

if player.colliderect(food):

foods.remove(food)

size+=1

# draw the food

for i in range(len(foods)):

pygame.draw.rect(thesurface, GREEN, foods[i])

printscore = basicFont.render("Score: %d" % size, True, (0,0,0))

thesurface.blit(printscore, (10, 550))

pygame.display.update()

# draw the window onto the thesurface

pygame.display.update()

mainClock.tick(80)

感謝幫助!在

總結

以上是生活随笔為你收集整理的python游戏循环设置_Pygame:游戏循环前的初始菜单的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。