-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconstants.py
117 lines (101 loc) · 3.48 KB
/
constants.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
import math
import random
import os
ColorKey =(234, 154, 45)
#class used to pass constants around
class constant():
def __init__(self):
self.constants = {}
def addC(self,key,value):
self.constants[key] = value
def getC(self,key):
return self.constants[key]
def getImage(name):
""" Arguments: the name of the file
returns the absolute path to said file as a string
(Keaton's side note, doesn't this just do the exact same thing as os.path.abspath(filename)?
"""
current_path = os.path.dirname(__file__)
image_path = os.path.join(current_path, name)
return(image_path)
def angleToVector(angle,size):
"""arguments: the angle in radians, the magnitude of the vecto
returns a list with list[0] being the x component, and list[1] being the y component
"""
return [round(size*math.cos(angle),3),round(size*math.sin(angle),3)]
def vectorToAngle(vector):
"""Agruments: A list, list[0] represents the x component of the vector, list[1] represents the Y
if the x component of a the vector has a magnitude of less then 10, return pi/2.
else, return the angle in radians
"""
if abs(vector[0])-.001<0:
return math.pi/2
if vector[0]>0:
return math.atan(vector[1]/vector[0])
else:
return round(math.pi-math.atan(vector[1]/-vector[0]),3)
def roundVector(vector):
end = [0,0]
if vector[0]>0:
end[0] = int(vector[0]+.5)
elif vector[0]<0:
end[0] = int(vector[0]-.5)
if vector[1]>0:
end[1] = int(vector[1]+.5)
elif vector[1]<0:
end[1] = int(vector[1]-.5)
return end
def makeConstants():
end = constant()
end.addC("PlayerSpeed",3)
end.addC("FPS",60)
end.addC("PlayerFPS",60)
end.addC("enemiesFPS",60)
end.addC("projectleFPS",60)
end.addC("screenSize",(1280,800))
end.addC("backgroundScroll",2)
return end
#speed
PlayerSpeed = 3
#framerate
FPS =60
PlayerFPS = 60
enemiesFPS = 60
projectleFPS = 60
screenSize = (1280,800)
backgroundScroll =4
def getImage(name):
""" Arguments: the name of the file
returns the absolute path to said file as a string
(Keaton's side note, doesn't this just do the exact same thing as os.path.abspath(filename)?
"""
current_path = os.path.dirname(__file__)
image_path = os.path.join(current_path, name)
return(image_path)
def angleToVector(angle,size):
"""arguments: the angle in radians, the magnitude of the vecto
returns a list with list[0] being the x component, and list[1] being the y component
"""
return [round(size*math.cos(angle),3),round(size*math.sin(angle),3)]
def vectorToAngle(vector):
"""Agruments: A list, list[0] represents the x component of the vector, list[1] represents the Y
if the x component of a the vector has a magnitude of less then 10, return pi/2.
else, return the angle in radians
"""
if abs(vector[0])-.001<0:
return math.pi/2
if vector[0]>0:
return math.atan(vector[1]/vector[0])
else:
return round(math.pi-math.atan(vector[1]/-vector[0]),3)
def roundVector(vector):
end = [0,0]
if vector[0]>0:
end[0] = int(vector[0]+.5)
elif vector[0]<0:
end[0] = int(vector[0]-.5)
if vector[1]>0:
end[1] = int(vector[1]+.5)
elif vector[1]<0:
end[1] = int(vector[1]-.5)
return end