求错误
不知道哪里错了,小甲鱼也是报错,但是不是这个错误。
麻烦看看
回复有奖!
看代码:
import pygame
import sys
import traceback
import myplane
import enemy
import bullet
import supply
import random
from pygame.locals import *
pygame.init()
pygame.mixer.init()
bg_size = width,height = 480,700
screen = pygame.display.set_mode(bg_size)
pygame.display.set_caption("飞机大战 -- Desnined by WRT")
background = pygame.image.load("images/background.png").convert()
#载入游戏音乐
pygame.mixer.music.load("sound/game_music.ogg")
pygame.mixer.music.set_volume(0.2)
bullet_sound = pygame.mixer.Sound("sound/bullet.wav")
bullet_sound.set_volume(0.2)
bomb_sound = pygame.mixer.Sound("sound/use_bomb.wav")
bomb_sound.set_volume(0.2)
supply_sound = pygame.mixer.Sound("sound/supply.wav")
supply_sound.set_volume(0.2)
get_bomb_sound = pygame.mixer.Sound("sound/get_bomb.wav")
get_bomb_sound.set_volume(0.2)
get_bullet_sound = pygame.mixer.Sound("sound/get_bullet.wav")
get_bullet_sound.set_volume(0.2)
upgrade_sound = pygame.mixer.Sound("sound/upgrade.wav")
upgrade_sound.set_volume(0.2)
enemy3_fly_sound = pygame.mixer.Sound("sound/enemy3_flying.wav")
enemy3_fly_sound.set_volume(0.2)
enemy1_down_sound = pygame.mixer.Sound("sound/enemy1_down.wav")
enemy1_down_sound.set_volume(0.2)
enemy2_down_sound = pygame.mixer.Sound("sound/enemy2_down.wav")
enemy2_down_sound.set_volume(0.2)
enemy3_down_sound = pygame.mixer.Sound("sound/enemy3_down.wav")
enemy3_down_sound.set_volume(0.5)
me_down_sound = pygame.mixer.Sound("sound/me_down.wav")
me_down_sound.set_volume(0.2)
def main():
pygame.mixer.music.play(-1)
#生成我方飞机
me = myplane.MyPlane(bg_size)
clock = pygame.time.Clock()
running = True
while running:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
# 检测用户的键盘操作
key_pressed = pygame.key.get_pressed()
if key_pressed or key_pressed:
me.moveUp()
if key_pressed or key_pressed:
me.moveDown()
if key_pressed or key_pressed:
me.moveLeft()
if key_pressed or key_pressed:
me.moveRight()
screen.blit(background,(0,0))
#绘制我方飞机
screen.blit(me.image,me.rect)
pygame.display.flip()
clock.tick(60)
if __name__ == "__main__":
try:
main()
except SystemExit:
pass
except:
traceback.print_exc()
pygame.quit()
input()
me = myplane.MyPlane(bg_size)、
试试把51行的这行代码,放在main函数外面看行不 myplane.py里面没有MyPlane函数 叼辣条闯世界 发表于 2021-8-31 19:26
myplane.py里面没有MyPlane函数
有呀,代码:
import pygame
class MyPlane(pygame.sprite.Sprite):
def __init__(self,bg__size):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load("me1.png").convert_alpha()
self.rect = self.image.get_rect()
self.widht, self.height = bg_size, bg_size
self.rect.left,self.rect.top = \
(self.width - self.rect.width) // 2,\
self.height - self.rect.heig - 60
self.speed = 10
def moveUp(self):
if self.rect.top > 0:
self.rect.top -= self.speed
else:
self.rect.top = 0
def moveDown(self):
if self.rect.bottom < self.height:
self.rect.top += self.speed
else:
self.rect.bottom = self.height - 60
def moveLeft(self):
if self.rect.left > 0:
self.rect.left -= self.speed
else:
self.rect.left = 0
def moveRight(self):
if self.rect.right < self.width:
self.rect.left += self.speed
else:
self.rect.right = self.width
@小伤口 @不二如是 @wp231957 @Darth_EF 你们也来帮我一下 from myplane import MyPlane myplane模块没有MyPlane方法
可能加载了别的myplane模块,看看你有几个这个模块吧。 看看有没有多个名字为myplane.py的文件 高山 发表于 2021-8-31 19:33
@wp231957 @Darth_EF 你们也来帮我一下
游戏模块木有涉猎也不准备涉猎 抱歉
页:
[1]