国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

坦克穿衣服 ?| Python編程開發(fā)坦克大戰(zhàn)游戲

2023-07-31 15:01 作者:是星星與然然呀  | 我要投稿

我哪里錯了呀,嗚嗚嗚[大哭]

點(diǎn)空格報(bào)錯并閃退

報(bào)錯:

Traceback (most recent call last):

?File "d:\python_procedure\tank_war\tank_war.py", line 116, in <module>

??player.shoot()

?File "d:\python_procedure\tank_war\tank_war.py", line 64, in shoot

??bullet = Bullet(self.rect.centerx,self.rect.centery,self.direction)

???????^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

?File "d:\python_procedure\tank_war\tank_war.py", line 73, in __init__

??self.bullet = pygame.image.load(self.bullets[0])

?????????^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

FileNotFoundError: No file './img/bullet/bullet_up.png' found in working directory 'D:\python_procedure'.

報(bào)錯的圖片:

文件是有的:

源代碼:

import pygame

import os

import random

import pathlib


FPS = 120

WIDTH = 1000

HEIGHT = 600

COLOR1 = (0,0,0)

COLOR2 = (255,255,255)

COLOR3 = (30,210,240)

COLOR4 = (40,220,180)


pygame.init()

screen = pygame.display.set_mode((WIDTH,HEIGHT))

pygame.display.set_caption('坦克大戰(zhàn)')

clock = pygame.time.Clock()


folder = pathlib.Path(__file__).parent.resolve()


running = True


class Player(pygame.sprite.Sprite):

? ? def __init__(self):

? ? ? ? super().__init__()

? ? ? ? tank_img = pygame.image.load(os.path.join(folder,"img/myTank","tank_T1_0.png")).convert()

? ? ? ? self.tank = tank_img

? ? ? ? self.tank.set_colorkey(COLOR2)

? ? ? ? self.image = self.tank.subsurface((0,0),(48,48))

? ? ? ? self.rect = self.image.get_rect()

? ? ? ? self.rect.centerx = WIDTH / 2

? ? ? ? self.rect.bottom = HEIGHT - 10

? ? ? ? self.speed = 8

? ? ? ? self.direction = "UP"


? ? def update(self):

? ? ? ? key_pressed = pygame.key.get_pressed()

? ? ? ? if key_pressed[pygame.K_RIGHT]:

? ? ? ? ? ? self.rect.x += self.speed

? ? ? ? ? ? self.direction = "RIGHT"

? ? ? ? ? ? self.image = self.tank.subsurface((0,144),(48,48))

? ? ? ? if key_pressed[pygame.K_LEFT]:

? ? ? ? ? ? self.rect.x -= self.speed

? ? ? ? ? ? self.direction = "LEFT"

? ? ? ? ? ? self.image = self.tank.subsurface((0,96),(48,48))

? ? ? ? if key_pressed[pygame.K_DOWN]:

? ? ? ? ? ? self.rect.y += self.speed

? ? ? ? ? ? self.direction = "DOWN"

? ? ? ? ? ? self.image = self.tank.subsurface((0,48),(48,48))

? ? ? ? if key_pressed[pygame.K_UP]:

? ? ? ? ? ? self.rect.y -= self.speed

? ? ? ? ? ? self.direction = "UP"

? ? ? ? ? ? self.image = self.tank.subsurface((0,0),(48,48))

? ? ? ? if(self.rect.right > WIDTH):

? ? ? ? ? ? self.rect.right = WIDTH

? ? ? ? if(self.rect.left < 0):

? ? ? ? ? ? self.rect.left = 0

? ? ? ? if(self.rect.bottom > HEIGHT):

? ? ? ? ? ? self.rect.bottom = HEIGHT

? ? ? ? if(self.rect.top < 0):

? ? ? ? ? ? self.rect.top = 0


? ? def shoot(self):

? ? ? ? bullet = Bullet(self.rect.centerx,self.rect.centery,self.direction)

? ? ? ? all_sprites.add(bullet)


class Bullet(pygame.sprite.Sprite):

? ? def __init__(self,x,y,direction):

? ? ? ? super().__init__()

? ? ? ? self.bullets = ['./img/bullet/bullet_up.png','./img/bullet/bullet_down.png','./img/bullet/bullet_right.png','./img/bullet/bullet_left.png']

? ? ? ? self.direction = direction

? ? ? ? if self.direction == "UP":

? ? ? ? ? ? self.bullet = pygame.image.load(self.bullets[0])

? ? ? ? if self.direction == "DOWN":

? ? ? ? ? ? self.bullet = pygame.image.load(self.bullets[1])

? ? ? ? if self.direction == "RIGHT":

? ? ? ? ? ? self.bullet = pygame.image.load(self.bullets[2])

? ? ? ? if self.direction == "LEFT":

? ? ? ? ? ? self.bullet = pygame.image.load(self.bullets[3])

? ? ? ? self.image = self.bullet

? ? ? ? self.image.set_colorkey(COLOR2)

? ? ? ? self.rect = self.image.get_rect()

? ? ? ? self.rect.x = x

? ? ? ? self.rect.y = y

? ? ? ? self.speed = 10


? ? def update(self):

? ? ? ? if self.direction == "UP":

? ? ? ? ? ? self.rect.y -= self.speed

? ? ? ? if self.direction == "DOWN":

? ? ? ? ? ? self.rect.y += self.speed

? ? ? ? if self.direction == "LEFT":

? ? ? ? ? ? self.rect.x -= self.speed

? ? ? ? if self.direction == "RIGHT":

? ? ? ? ? ? self.rect.x += self.speed

? ? ? ? if self.rect.bottom > HEIGHT:

? ? ? ? ? ? self.kill()

? ? ? ? if self.rect.top < 0:

? ? ? ? ? ? self.kill()

? ? ? ? if self.rect.right > WIDTH:

? ? ? ? ? ? self.kill()

? ? ? ? if self.rect.left < 0:

? ? ? ? ? ? self.kill()


all_sprites = pygame.sprite.Group()

player =Player()

all_sprites.add(player)


while running:

? ? clock.tick(FPS)

? ? for event in pygame.event.get():

? ? ? ? if event.type == pygame.QUIT:

? ? ? ? ? ? running = False

? ? ? ? elif event.type == pygame.KEYDOWN:

? ? ? ? ? ? if(event.key == pygame.K_SPACE):

? ? ? ? ? ? ? ? player.shoot()

? ? screen.fill(COLOR1)

? ? all_sprites.update()

? ? all_sprites.draw(screen)

? ? pygame.display.update()

pygame.quit()

坦克穿衣服 ?| Python編程開發(fā)坦克大戰(zhàn)游戲的評論 (共 條)

分享到微博請遵守國家法律
乾安县| 哈尔滨市| 黎城县| 峡江县| 天祝| 密山市| 瓮安县| 静安区| 重庆市| 合水县| 木兰县| 新郑市| 田林县| 三原县| 固安县| 北票市| 颍上县| 沁阳市| 社旗县| 宣恩县| 新邵县| 天门市| 普宁市| 广宁县| 茶陵县| 汉寿县| 沁阳市| 社旗县| 宜州市| 县级市| 山西省| 行唐县| 新宾| 板桥市| 哈密市| 都安| 镇巴县| 江口县| 周口市| 永顺县| 安丘市|