-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbullet.py
95 lines (76 loc) · 2.67 KB
/
bullet.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
import os
import globalvariables as gv
import math
import time
from colorama import Fore,Back
#Creating a bullet class that will be used by both the Mandalorian as well as Viserion(the enemy dragon)
class Bullet():
def __init__(self,x,y,grid):
self.__initialy = y
self.__initialx = x
self.__haveigoneup = 0
self.x = x
self.y = y
self.bulletfigure = gv.Bullet
def bullet_vanished(self,grid):
grid[self.x][math.floor(self.y)] = ' '
def bullet_appears(self,grid):
grid[self.x][math.floor(self.y)] = self.bulletfigure
def bullet_move(self,grid):
if self.y+2 < gv.MAX_Y:
self.bullet_vanished(grid)
self.y+=2
self.bullet_appears(grid)
def bullet_start(self,grid):
if self.x > self.__initialx - 20 and self.x > 1:
self.bullet_vanished(grid)
self.x-=1
self.__haveigoneup+=1
self.bullet_appears(grid)
# A function to simulate gravity in the bullet...enables parabolic trajectory
def bullet_gravity(self,grid):
if self.x < 37:
self.bullet_vanished(grid)
self.x+=1
self.bullet_appears(grid)
# A function to check whether the bullet strikes anything or not
def bullet_strike(self,grid,masterlist):
for i in range(2):
for j in range(2):
if self.y + j < 1000 and self.x + i < 40 and grid[self.x + i][self.y + j] == gv.Obstacle:
tup = (self.x+i,self.y+j)
for x in masterlist:
if tup in x:
return masterlist.index(x)
grid[self.x + i][self.y + j] = ' '
return -1
def enemykill(self,grid,drogo):
for j in range(10):
if self.x == drogo.y + j:
for i in range(8):
if self.y == drogo.x + i:
drogo.lives-=0.01
def bulletgetter(self):
coordlist = []
coordlist.append(self.x)
coordlist.append(self.y)
coordlist.append(self.__initialx)
coordlist.append(self.__initialy)
coordlist.append(self.__haveigoneup)
return coordlist
class Ice(Bullet):
def __init__(self,x,y,grid):
Bullet.__init__(self, x, y, grid)
self.x = x
self.y = y
self.bulletfigure =gv.Iceball
def ice_move(self,grid):
self.bullet_vanished(grid)
if self.y > 10:
self.y-=5
self.bullet_appears(grid)
def sendcoods(self):
cood = []
cood.append(self.x)
cood.append(self.y)
return cood