【发布时间】:2020-11-06 13:02:06
【问题描述】:
我所有的文件都在同一个目录中 Documents/Coding/My Python Scripts/Doomsday/Doomsday
(我知道我在一个名为 Doomsday 的文件夹内有一个名为 Doomsday 的文件夹)
如果有人可以提供帮助,那就太好了,
LMK 如果您需要更多详细信息!
填料 填料 填料 填料 填料 填料
填料 填料 填料 填料 填料 填料
填料 填料 填料 填料 填料 填料
填料 填料 填料 填料 填料
import pygame
#intialize the pygame
pygame.init()
#Screen
Screenwid=500
Screenh=500
win = pygame.display.set_mode((Screenwid, Screenh))
#Title and Icon
pygame.display.set_caption('Doomsday: Out Of Time')
#Dimisions of Rectangle
height=64
width=64
x = 50
y= 450
vel=5
#Jumping
isJump= False
jumpCount=10
#Character Animation
left=False
right=False
walkCount=0
walkRight = [pygame.image.load('char2.1.1.jpg'), pygame.image.load('char2.1.2.jpg'), pygame.image.load('char2.1.3.jpg'),
pygame.image.load('char2.2.1.jpg'), pygame.image.load('char2.2.2.jpg'), pygame.image.load('char2.2.3.jpg'),
pygame.image.load('char2.3.1.jpg'), pygame.image.load('char2.3.2.jpg'), pygame.image.load('char2.3.3.jpg')]
walkLeft = [pygame.image.load('char3.1.1.jpg'), pygame.image.load('char3.1.2.jpg'), pygame.image.load('char3.1.3.jpg'),
pygame.image.load('char3.2.1.jpg'), pygame.image.load('char3.2.2.jpg'), pygame.image.load('char3.2.3.jpg'),
pygame.image.load('char3.3.1.jpg'), pygame.image.load('char3.3.2.jpg'), pygame.image.load('char3.3.3.jpg')]
bg = pygame.image.load('cityimage.png')
char = pygame.image.load('char1.1.1.jpg')
def redrawGameWindow():
global walkCount
win.blit((bg,(0,0)))
#If we didn't cap the walkCount at 27, we would run out of images, or frames 9 images x 3 frames = 27
if walkCount +1 >= 27:
walkCount=0
if left:
win.blit(walkLeft[walkCount//3],(x,y))
walkCount+=1
elif right:
win.blit(walkRight[walkCount//3],(x,y))
walkCount +=1
else:
win.blit(char, (x,y))
pygame.display.update()
#Frame Rate
clcok= pygame.time.Clock()
#Game Loop
run=True
while run:
Clock.tick(27)
pygame.time.delay(100)
#Color Background
win.fill((255,0,0))
#Background Image
#screen.blit(bkgd,(0,0))
for event in pygame.event.get():
if event.type == pygame.QUIT:
run=False
keys=pygame.key.get_pressed()
if keys[pygame.K_LEFT] and x > vel:
x -= vel
left= True
right=False
elif keys[pygame.K_RIGHT] and x < Screenwid - width- vel:
x += vel
left=False
right=True
else:
right=False
left=False
walkCount=0
if not(isJump):
if keys[pygame.K_SPACE]:
isJump=True
left=False
right=False
walkcount=0
else:
#If the jump is at its orginal state
if jumpCount >= -10:
neg = 1
#neg makes it go down after the Apex
if jumpCount < 0:
#When the jump is at its Apex, neg impacts the Jump Count by making it go down
neg= -1
#The y is decreased so the character goes up, increases 100p,90p, going down by 10.
y -= jumpCount ** 2 * 0.5 * neg
jumpCount -= 1
else:
isJump= False
jumpCount=10
redrawGameWindow()
pygame.quit()
【问题讨论】:
-
你能告诉我你的整个代码吗?
-
我现在将整个代码添加到帖子中:)
标签: python image file directory pygame