myTank.py
import pygame
import bulletClass
tank_T1_0 = r"..\image\tank_T1_0.png"
tank_T1_1 = r"..\image\tank_T1_1.png"
tank_T1_2 = r"..\image\tank_T1_2.png"
tank_T2_0 = r"..\image\tank_T2_0.png"
tank_T2_1 = r"..\image\tank_T2_1.png"
tank_T2_2 = r"..\image\tank_T2_2.png"
class MyTank(pygame.sprite.Sprite):
def __init__(self, playerNumber):
pygame.sprite.Sprite.__init__(self)
# �������
self.life = True
#���ڼ������ ̹�˵������ȼ�
if playerNumber == 1:
self.tank_L0_image = pygame.image.load(tank_T1_0).convert_alpha()
self.tank_L1_image = pygame.image.load(tank_T1_1).convert_alpha()
self.tank_L2_image = pygame.image.load(tank_T1_2).convert_alpha()
if playerNumber == 2:
self.tank_L0_image = pygame.image.load(tank_T2_0).convert_alpha()
self.tank_L1_image = pygame.image.load(tank_T2_1).convert_alpha()
self.tank_L2_image = pygame.image.load(tank_T2_2).convert_alpha()
self.level = 0
# ��ʼ̹��Ϊ0��
self.tank = self.tank_L0_image
# �˶��е�����ͼƬ
self.tank_R0 = self.tank.subsurface((0, 0),(48, 48))
self.tank_R1 = self.tank.subsurface((48, 0),(48, 48))
self.rect = self.tank_R0.get_rect()
if playerNumber == 1:
self.rect.left, self.rect.top = 3 + 24 * 8, 3 + 24 * 24
if playerNumber == 2:
self.rect.left, self.rect.top = 3 + 24 * 16, 3 + 24 * 24
# ̹���ٶ� ̹�˷��� ̹������ �ӵ���ȴ
self.speed = 3
self.dir_x, self.dir_y = 0, -1
self.life = 3
self.bulletNotCooling = True
self.bullet = bulletClass.Bullet()
#self.bullet.rect.left, self.bullet.rect.right = 3 + 12 * 24, 3 + 24 * 24
def shoot(self):
# �ӵ�
self.bullet.life = True
self.bullet.changeImage(self.dir_x, self.dir_y)
if self.dir_x == 0 and self.dir_y == -1:
self.bullet.rect.left = self.rect.left + 20
self.bullet.rect.bottom = self.rect.top + 1
elif self.dir_x == 0 and self.dir_y == 1:
self.bullet.rect.left = self.rect.left + 20
self.bullet.rect.top = self.rect.bottom - 1
elif self.dir_x == -1 and s