forked from AlexanderLuasan/Tailgunner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprojectile.py
141 lines (134 loc) · 5.4 KB
/
projectile.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import pygame
import constants
class zeroShot(pygame.sprite.Sprite):
def __init__(self,x,y,angle):
super().__init__()
inAir=True
onGround = True
self.image=pygame.Surface([4,10])
self.image.fill((255,0,0))
self.speed=8
self.rect=self.image.get_rect()
self.rect.center=(x,y)
self.angle=angle
self.heading = constants.angleToVector(self.angle,self.speed)
def hit(self):
self.kill()
return 1
def update(self):
self.rect.x+=self.heading[0]
self.rect.y+=self.heading[1]
if abs(self.rect.x-constants.screenSize[0]/2)>50+constants.screenSize[0]/2 or abs(self.rect.y-constants.screenSize[1]/2)>50+constants.screenSize[1]/2:
self.kill()
class shot(pygame.sprite.Sprite):
def __init__(self,x,y,angle):
super().__init__()
inAir=True
onGround = True
self.image=pygame.Surface([10,10])
self.image.fill((0,0,0))
pygame.draw.ellipse(self.image,(255,0,0),(0,0,10,10),0)
self.image.set_colorkey((0,0,0))
self.speed=4
self.rect=self.image.get_rect()
self.rect.center=(x,y)
self.angle=angle
self.direction = constants.angleToVector(self.angle,1)
def hit(self):
self.kill()
return 1
def update(self):
self.rect.x+=self.direction[0]*self.speed
self.rect.y+=self.direction[1]*self.speed
if abs(self.rect.x-constants.screenSize[0]/2)>50+constants.screenSize[0]/2 or abs(self.rect.y-constants.screenSize[1]/2)>50+constants.screenSize[1]/2:
self.kill()
class playershot(pygame.sprite.Sprite):
def __init__(self,x,y,angle):
super().__init__()
inAir=True
onGround = True
size = [20,10]
self.image=pygame.Surface(size)
self.image.fill((0,0,0))
pygame.draw.rect(self.image,(255,0,0),(0,0,3,size[1]))
pygame.draw.rect(self.image,(255,0,0),(size[0]-3,0,3,size[1]))
self.image.set_colorkey((0,0,0))
self.speed=12
self.rect=self.image.get_rect()
self.rect.center=(x,y)
self.angle=angle
self.direction = constants.angleToVector(self.angle,1)
def hit(self):
self.kill()
return 1
def update(self):
self.rect.x+=self.direction[0]*self.speed
self.rect.y+=self.direction[1]*self.speed
if abs(self.rect.x-constants.screenSize[0]/2)>50+constants.screenSize[0]/2 or abs(self.rect.y-constants.screenSize[1]/2)>50+constants.screenSize[1]/2:
self.kill()
class scaterShots(pygame.sprite.Sprite):
def __init__(self,x,y,angle):
super().__init__()
inAir=True
onGround = True
size = [10,10]
edge = 3
shape = constants.angleToVector(angle,10)
self.image=pygame.Surface((abs(shape[0])+1+2*edge,abs(shape[1])+1+2*edge))
self.image.fill((0,0,0))
self.image.set_colorkey((0,0,0))
self.rect=self.image.get_rect()
self.rect.center=(x,y)
#draw a line in the
if shape[1]<0:
if shape[0]<0:
pygame.draw.line(self.image,(255,0,0),[0+edge,0+edge],[self.rect.width-edge,self.rect.height-edge],3)
elif shape[0]==0:
pygame.draw.line(self.image,(255,0,0),[0+edge,0+edge],[0+edge,self.rect.height-edge],3)
elif shape[0]>0:
pygame.draw.line(self.image,(255,0,0),[0+edge,self.rect.height-edge],[self.rect.width-edge,0+edge],3)
if shape[1]>0:
if shape[0]<0:
pygame.draw.line(self.image,(255,0,0),[self.rect.width+edge,0+edge],[0+edge,self.rect.height-edge],3)
elif shape[0]==0:
pygame.draw.line(self.image,(255,0,0),[0+edge,0+edge],[0+edge,self.rect.height-edge],3)
elif shape[0]>0:
pygame.draw.line(self.image,(255,0,0),[0+edge,0+edge],[self.rect.width-edge,self.rect.height-edge],3)
elif shape[1]==0:
pygame.draw.line(self.image,(255,0,0),[self.rect.width,0],[0,0],3)
self.speed=1
self.direction = constants.roundVector(constants.angleToVector(angle,12))
def hit(self):
self.kill()
return 1
def setheading(self,direction):
self.direction = direction
def getheading(self):
return self.direction
def update(self):
self.rect.x+=self.direction[0]
self.rect.y+=self.direction[1]
if abs(self.rect.x-constants.screenSize[0]/2)>50+constants.screenSize[0]/2 or abs(self.rect.y-constants.screenSize[1]/2)>50+constants.screenSize[1]/2:
self.kill()
class turretshot(pygame.sprite.Sprite):
def __init__(self,x,y,direction):
super().__init__()
inAir=True
onGround = True
size = [7,7]
self.image=pygame.Surface(size)
self.image.fill((0,0,0))
pygame.draw.ellipse(self.image,(255,0,0),(0,0,7,7),0)
self.image.set_colorkey((0,0,0))
self.speed=12
self.rect=self.image.get_rect()
self.rect.center=(x,y)
self.direction = direction
def hit(self):
self.kill()
return 1
def update(self):
self.rect.x+=self.direction[0]*self.speed
self.rect.y-=self.direction[1]*self.speed
if abs(self.rect.x-constants.screenSize[0]/2)>50+constants.screenSize[0]/2 or abs(self.rect.y-constants.screenSize[1]/2)>50+constants.screenSize[1]/2:
self.kill()