-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlayerTankTurret.py
52 lines (37 loc) · 1.29 KB
/
PlayerTankTurret.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import pygame, math
from FShell import fShell
class playerTurret(pygame.sprite.Sprite):
def __init__(self, screen, playerTank, allsprites, prey):
pygame.sprite.Sprite.__init__(self)
self.screen = screen
self.turret = pygame.image.load("tankturret.png")
self.turret = self.turret.convert_alpha()
self.rect = self.turret.get_rect()
self.image = self.turret
self.x = 490
self.y = 320
self.dir = 0
self.turnR = 5
self.power = 0
self.allSprites = allsprites
self.playerShellPower = 60
self.tank = playerTank
self.enemy = prey
def update(self):
self.setPos()
self.getDirection()
self.rotate()
def getDirection(self):
mouseX, mouseY = pygame.mouse.get_pos()
x = (self.x-mouseX)
y = (self.y-mouseY)
self.dir = ((math.atan2(y, x)*(180/math.pi))*-1)+180
def rotate(self):
Center = self.rect.center
self.image = pygame.transform.rotate(self.turret, self.dir)
self.rect = self.image.get_rect()
self.rect.center = Center
def setPos(self):
self.x = self.tank.rect.centerx
self.y = self.tank.rect.centery
self.rect.center = (self.x, self.y)