-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrippy.py
185 lines (148 loc) · 5.49 KB
/
trippy.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#trySprites.py
from pygame import *
from random import *
from math import *
screen=display.set_mode((800,600))
pic=image.load("M161.png")
m16=image.load("M162.png")
cx,cy=400,300
class Player:
'''
Player keeps track of:
x,y - current position
ang - current angle the Player is facing
pic - sprite to display
'''
def __init__(self,x,y,ang,pic):
self.x = x
self.y = y
self.ang = ang
self.pic = pic
def move(self,destX,destY):
moveX = destX - self.x
moveY = destY - self.y
self.ang = degrees(atan2(-moveY, moveX)) + 270
def draw(self,surface):
self.move(mx,my)
newpic=transform.rotate(pic,self.ang)
surface.blit(newpic,get_center(newpic,400,300))
class Bullet:
'''
Bullet keeps track of:
ex,ey - current end position
tx,ty - current tip position
ang - current angle bullet is going from player when it was shot
'''
def __init__(self,ex,ey,tx,ty,ang):
self.ex = ex
self.ey = ey
self.tx = tx
self.ty = ty
self.ang = ang
def move(self,player):
self.ex, self.ey = self.ex + cos(player.ang) * 50, self.ey - sin(player.ang) * 50
self.tx, self.ty = self.tx + cos(player.ang) * 45, self.ty - sin(player.ang) * 45
def draw(self,surface):
draw.line(surface,(255,0,0),(self.ex,self.ey),(self.tx,self.ty),14)
def erase(self,bList):
if self.tx > 800 or 0 > self.tx or self.ty > 600 or 0 > self.ty:
bList.remove(self)
def make(player):
endX, endY = player.x + cos(player.ang), player.y - sin(player.ang)
tipX, tipY = player.x + cos(player.ang), player.y - sin(player.ang)
return ((endX,endY,tipX,tipY,player.ang))
def drawScene(surface,player,bList):
player.draw(surface)
for b in bList:
b.draw(surface)
def get_center(surface,h,k):
x=surface.get_width()
y=surface.get_height()
return h-(x//2),k-(y//2)
def get_quadrant(center,point):
''' y
2 | 1
-----|-----x
3 | 4
'''
if point[0]>center[0] and point[1]<=center[1]:
return 1
elif point[0]<=center[0] and point[1]<center[1]:
return 2
elif point[0]<center[0] and point[1]>=center[1]:
return 3
elif point[0]>=center[0] and point[1]>center[1]:
return 4
else : #if the center is also the point
return 0
def bullets(bulletList,bulletDistance):
for i in range(len(bulletList)):
draw.line(screen,(255,0,0),(cx+cos(bulletList[i][0])*(bulletDistance[i]-5),cy-sin(bulletList[i][0])*(bulletDistance[i]-5)),
(cx+cos(bulletList[i][0])*bulletDistance[i],cy-sin(bulletList[i][0])*bulletDistance[i]),3)
bulletList=[]
bulletDistance=[]
myClock=time.Clock()
ticktock=0
shot=False
clip=1000
running=True
while running:
for e in event.get():
if e.type==QUIT:
running=False
screen.fill((255,255,255))
mx,my=mouse.get_pos()
mb=mouse.get_pressed()
'''if mb[0]==1:
for i in range(0,60,5):
if ticktock==i:
if clip>0:
shot=True
clip-=1
if get_quadrant((400,300),(mx,my))==1:
#bulletlist.append((angle,bullet tip))
ang=90-degrees(acos(max(abs(cy-my),1)/(sqrt((mx-cx)**2+(my-cy)**2))))
bulletList.append((radians(ang),cx+cos(radians(ang))*0,cy-sin(radians(ang))*0))
bulletDistance.append(35)
elif get_quadrant((400,300),(mx,my))==2:
#bulletlist.append((angle,bullet tip))
ang=90+degrees(acos(max(abs(cy-my),1)/(sqrt((mx-cx)**2+(my-cy)**2))))
bulletList.append((radians(ang),cx+cos(radians(ang))*0,cy-sin(radians(ang))*0))
bulletDistance.append(35)
elif get_quadrant((400,300),(mx,my))==3:
#bulletlist.append((angle,bullet tip))
ang=270-degrees(acos(max(abs(cy-my),1)/(sqrt((mx-cx)**2+(my-cy)**2))))
bulletList.append((radians(ang),cx+cos(radians(ang))*0,cy-sin(radians(ang))*0))
bulletDistance.append(35)
elif get_quadrant((400,300),(mx,my))==4:
#bulletlist.append((angle,bullet tip))
ang=270+degrees(acos(max(abs(cy-my),1)/(sqrt((mx-cx)**2+(my-cy)**2))))
bulletList.append((radians(ang),cx+cos(radians(ang))*0,cy-sin(radians(ang))*0))
bulletDistance.append(35)
else :
ticktock=59
bullets(bulletList,bulletDistance)
for i in range(len(bulletDistance)):
bulletDistance[i]+=30 #the speed of the bullet
#bulletDistance[i]+=597165 -> thats for how fast the bullet travels in real life :) ... but thats so fast that you dont even see it
'''
player = Player(400,300,0,pic)
dist=(sqrt((mx-cx)**2+(my-cy)**2))
ang=acos(max(abs(cy-my),1)/dist)
if mb[0] == 1:
if clip > 0:
player.move(mx,my)
bull = make(player)
bulletList.append(Bullet(bull[0],bull[1],bull[2],bull[3],bull[4]))
for i in range(len(bulletList)):
bulletList[i].move(player)
#bulletList[i].erase(bulletList)
print(bulletList)
drawScene(screen,player,bulletList)
if ticktock==59:
ticktock=0
else :
ticktock+=1
myClock.tick(60)
display.flip()
quit()