-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPyphyObject.py
More file actions
153 lines (117 loc) · 4.16 KB
/
PyphyObject.py
File metadata and controls
153 lines (117 loc) · 4.16 KB
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
import pygame
import PyphyTypes
import importlib
import os
class Object:
Name: str
Surface: pygame.Surface
Rect: pygame.Rect
rigidbody = None
Visible = True
UserScriptEnable = False
UserScript = None
UserScriptPath = None
def __init__(self, Isurface, rect=None, name=None, size=None, visible=True, UserScript: str = None):
self.Surface = Isurface
self.Visible = visible
if rect != None:
self.Rect = rect
else:
self.Rect = self.Surface.get_rect()
if name != None:
self.Name = name
if size != None:
self.Surface = pygame.transform.smoothscale(self.Surface, size)
self.Rect.size = size
#self.Rect = self.Surface.get_rect()
if UserScript != None:
self.UserScriptPath = UserScript
UserScript = os.path.splitext(UserScript)[0]
excepted = False
try:
self.UserScript = importlib.import_module(UserScript)
except Exception:
excepted = True
print(name + " : Error importing user script \"" + UserScript + "\"!")
if excepted == False:
self.UserScriptEnable = True
def SetRigidbody(self, mass, Fz_x = False, Fz_y = False):
self.rigidbody = Rigidbody(self.Rect, mass)
self.rigidbody.freeze_x = Fz_x
self.rigidbody.freeze_y = Fz_y
def TransformScale(self, size):
self.Surface = pygame.transform.smoothscale(self.Surface, size)
def Render(self, displaysurf):
if self.Visible == True:
displaysurf.blit(self.Surface, self.Rect)
class Rigidbody:
Rect = None
Mass = 0.0
HeightF = 0.0
HeightA = 0.0
HeightDeltaA = 0.0
HeightDistence = 0.0
WidthF = 0.0
WidthA = 0.0
WidthDeltaA = 0.0
WidthDistence = 0.0
freeze_x = False
freeze_y = False
def __init__(self, Rect: pygame.Rect, mass, Fz_x = False, Fz_y = False):
self.Rect = Rect
self.Mess = mass
(self.WidthDistence, self.HeightDistence) = Rect.topleft
self.freeze_x = Fz_x
self.freeze_y = Fz_y
def SetSpeed(self, vector):
if self.freeze_x == False:
self.WidthDeltaA = vector.getWidthF()
if self.freeze_y == False:
self.HeightDeltaA = vector.getHeightF()
def AddForce(self, vector):
if self.freeze_x == False:
self.WidthF += vector.getWidthF()
if self.freeze_y == False:
self.HeightF += vector.getHeightF()
def AddWidthMomentum(self, p):#p = mv v = p/m
if self.freeze_x == False:
self.WidthDeltaA = p / self.Mess * -1
def AddHeightMomentum(self, p):
if self.freeze_y == False:
self.HeightDeltaA = p / self.Mess
def GetWidthMomentum(self):
return self.Mess * self.WidthDeltaA * -1
def GetHeightMomentum(self):
return self.Mess * self.HeightDeltaA
def Calculate(self, timeDelta):
self.HeightA = self.HeightF / self.Mess
self.HeightF = 0
self.WidthA = self.WidthF / self.Mess
self.WidthF = 0
timedelta_f = timeDelta / 1000
#지속시간에 더함
#timecontinue += timedelta_f
self.HeightDeltaA += self.HeightA * timedelta_f
self.HeightDistence -= self.HeightDeltaA * timedelta_f * 100
self.WidthDeltaA += self.WidthA * timedelta_f
self.WidthDistence -= self.WidthDeltaA * timedelta_f * 100
self.Rect.topleft = (self.WidthDistence, self.HeightDistence)
#print(self.HeightDeltaA)
if(self.HeightDistence > 1000):
self.HeightDistence = -500
if(self.HeightDistence < -1000):
self.HeightDistence = 900
if(self.WidthDistence > 1400):
self.WidthDistence = -500
if(self.WidthDistence < -500):
self.WidthDistence = 1300
class Vector:
HeightF = 0.0
WidthF = 0.0
def __init__(self, WidthF, HeightF):
self.HeightF = HeightF
self.WidthF = WidthF * -1
def getHeightF(self):
return self.HeightF
def getWidthF(self):
return self.WidthF