写的代码报错,Python3环境,不知道如何解决,求大神指点
报错如下:
Traceback (most recent call last):
File "D:/Python Project/Test.py", line 36, in <module>
bullet.move()
File "D:/Python Project/Test.py", line 12, in move
if self.y<0:
AttributeError: 'Zidan' object has no attribute 'y'
源码如下:
import pygame
from sys import exit
class Zidan:
def _init_(self):
self.x=0
self.y=-1
self.image=pygame.image.load("zidan.png").convert_alpha()
def move(self):
if self.y<0:
mouseX,mouseY=pygame.mouse.get_pos()
self.x=mouseX-self.image.get_width()/2
self.y=mouseY-self.image.get_height()/2
else:
self.y -= 5
pygame.init()
screen = pygame.display.set_mode((450, 800), 0, 32)
pygame.display.set_caption("Hello, World!")
background = pygame.image.load('background.png').convert()
plane=pygame.image.load("airplain.png").convert_alpha()
bullet = Zidan()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit()
screen.blit(background, (0,0))
bullet.move()
screen.blit(bullet.image, (bullet.x, bullet.y))
x,y=pygame.mouse.get_pos()
x-=plane.get_width()/2
y-=plane.get_height()/2
screen.blit(plane,(x,y))
pygame.display.update()