-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrider.py
133 lines (111 loc) · 4.28 KB
/
rider.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
from __future__ import print_function
import sys
import time
import os
import globalvariables as gv
import math
from colorama import Back,Fore
from bullet import Bullet
import numpy as np
# Note: We use __ after many of the self.__ variables in order to keep them private
class Entity:
def __init__(self, x, y, grid):
self.x = x
self.y = y
class Rider(Entity):
def __init__(self, x, y, grid):
Entity.__init__(self, x, y, grid)
self.__figure = [['_', '0', '_'], ['|', '-', '|'], ['|', '_', '|']]
self.__dragonfigure1 = [['/','\\',' ',' ','/','\\',' ',' ','/','\\',' ',' ','O'],[' ',' ','\\','/',' ',' ','\\','/',' ',' ','\\','/',' ']]
self.__dragonfigure2 = [[' ',' ','/','\\',' ',' ','/','\\',' ',' ','/','\\',' '],['\\','/',' ',' ','\\','/',' ',' ','\\','/',' ',' ','O']]
self.__bulletlist = []
self.__shieldstatus = 0
self.__setme = 0
def initialplace(self,grid):
if self.__setme == 0:
for i in range(35,38,1):
for j in range(0,3,1):
grid[i][j] = self.__figure[i-35][j]
else:
for i in range(36,38,1):
for j in range(0,13,1):
grid[i][j] = self.__dragonfigure1[i-36][j]
def din_vanished(self,grid):
if self.__setme == 0:
for i in range(self.x,self.x + 3):
for j in range(self.y,self.y + 3):
grid[i][j] = " "
else:
for i in range(self.x,self.x + 2):
for j in range(self.y,self.y + 13):
grid[i][j] = " "
def din_appears(self,grid):
if self.__setme == 0:
for i in range(self.x,self.x + 3):
for j in range(self.y,self.y + 3):
grid[i][j] = self.__figure[i-self.x][j-self.y]
else:
for i in range(self.x,self.x + 2):
for j in range(self.y,self.y + 13):
if np.mod(self.y,2)==0:
grid[i][j] = self.__dragonfigure1[i-self.x][j-self.y]
else:
grid[i][j] = self.__dragonfigure2[i-self.x][j-self.y]
def din_move(self,grid,cin,Din):
#Move to the right
if(cin==1):
if Din.y <=958:
Din.din_vanished(grid)
Din.y+=1
Din.din_appears(grid)
#Move to the left
if(cin == 2):
Din.din_vanished(grid)
Din.y-=1
Din.din_appears(grid)
#Move upwards
if(cin == 3):
Din.din_vanished(grid)
if(Din.x-10 <= 0):
Din.x = 1
else:
Din.x-=10
Din.din_appears(grid)
def shoot(self,Din,grid):
self.__bulletlist.append(Bullet(Din.x + 1,Din.y + 4,grid))
def bullethit(self,grid,drogo,masterlist):
for shot in self.__bulletlist:
shot.bullet_move(grid)
a = shot.bulletgetter()
i = shot.bullet_strike(grid,masterlist)
if i!=-1:
return i
shot.enemykill(grid,drogo)
if a[4] >= 0 and a[4] <= 19:
shot.bullet_start(grid)
if a[4] >= 19 or a[0]<=1: #shot.x <= 1:
shot.bullet_gravity(grid)
# if(math.floor(shot.y - shot.initialy) == 150):
if(math.floor(a[1] - a[3]) == 150):
shot.bullet_vanished(grid)
try:
self.__bulletlist.remove(shot)
except ValueError:
pass
if a[0] == 37:
shot.bullet_vanished(grid)
try:
self.__bulletlist.remove(shot)
except ValueError:
pass
return -1
def activate_shield(self,grid):
self.__figure = [[Fore.LIGHTRED_EX + '/', '0', '\\' + '\x1b[0m' ], [Fore.LIGHTRED_EX+'|', '-', '|'+'\x1b[0m'], [Fore.LIGHTRED_EX+ '|', '_', '|' +'\x1b[0m']]
self.__shieldstatus = 1
def deactivate_shield(self,grid):
self.__figure = [['_', '0', '_'], ['|', '-', '|'], ['|', '_', '|']]
self.__shieldstatus = 0
def checkpowerup(self,setme):
self.__setme = setme
def getshieldstatus(self):
return self.__shieldstatus