Checkpoint
This commit is contained in:
parent
b1a4fc95cb
commit
c20f9b2578
Binary file not shown.
Before Width: | Height: | Size: 284 B |
Binary file not shown.
Before Width: | Height: | Size: 284 B |
Binary file not shown.
Before Width: | Height: | Size: 329 B After Width: | Height: | Size: 358 B |
@ -1 +0,0 @@
|
||||
../in_Makefile
|
Binary file not shown.
Before Width: | Height: | Size: 229 B After Width: | Height: | Size: 260 B |
@ -1 +0,0 @@
|
||||
../in_Makefile
|
@ -1 +0,0 @@
|
||||
../in_Makefile
|
@ -1 +0,0 @@
|
||||
../in_Makefile
|
6
main.py
6
main.py
@ -81,9 +81,11 @@ while 1:
|
||||
for element in elements:
|
||||
element.apply_gravity(elements)
|
||||
element.tick(camera=camera)
|
||||
ori = elements[-1].pos
|
||||
ori_spe = elements[-1].speed
|
||||
for element in elements:
|
||||
element.pos = element.pos - elements[-1].pos
|
||||
element.speed = element.speed - elements[-1].speed
|
||||
element.pos = element.pos - ori
|
||||
element.speed = element.speed - ori_spe
|
||||
origin=elements[follow].pos
|
||||
for element in elements:
|
||||
element.apply(camera=camera, origin=origin)
|
||||
|
10
mecha.py
10
mecha.py
@ -16,8 +16,14 @@ class Mass():
|
||||
self.mass = mass
|
||||
self.G = 0.0000001
|
||||
|
||||
def tick(self, origin=np.array((0, 0), dtype='float64')):
|
||||
self.pos += self.speed - origin
|
||||
def tick(self):
|
||||
self.pos += self.speed
|
||||
|
||||
def ref(self,
|
||||
origin=np.array((0, 0), dtype='float64'),
|
||||
speed=np.array((0, 0), dtype='float64')):
|
||||
self.pos -= origin
|
||||
self.speed -= speed
|
||||
|
||||
def apply_gravity(self, elements):
|
||||
for element in elements:
|
||||
|
31
visual.py
31
visual.py
@ -26,8 +26,10 @@ class Obj():
|
||||
scale=1,
|
||||
reference=np.array((0, 0), dtype='float64'),
|
||||
size=(0, 0)):
|
||||
npsize=np.array(size, dtype='float64')/(2*scale)
|
||||
scaled_pos = scale * (self.mecha.pos - reference + npsize)
|
||||
npsize=np.array(size, dtype='float64')
|
||||
scaled_pos = scale * (self.mecha.pos - reference + npsize/(2*scale))
|
||||
if np.linalg.norm(scaled_pos - npsize/2) > max(size):
|
||||
return
|
||||
scaled_dimension = (scale*self.dimension()).astype(int)
|
||||
scaled_image = pygame.transform.scale(self.image, scaled_dimension)
|
||||
scaled_image = pygame.transform.rotate(scaled_image,
|
||||
@ -40,21 +42,21 @@ class Obj():
|
||||
class Star(Obj):
|
||||
def __init__(self, **keyargs):
|
||||
self.mecha = mecha.Player(**keyargs)
|
||||
self.image = pygame.image.load("assets/star.gif")
|
||||
self.image = pygame.image.load("assets/ship/loop/00001.png")
|
||||
self.position = self.image.get_rect()
|
||||
|
||||
|
||||
class Planet(Obj):
|
||||
def __init__(self, **keyargs):
|
||||
self.mecha = mecha.Player(**keyargs)
|
||||
self.image = pygame.image.load("assets/planet.gif")
|
||||
self.image = pygame.image.load("assets/planet/loop/00001.png")
|
||||
self.position = self.image.get_rect()
|
||||
|
||||
|
||||
class Player(Obj):
|
||||
def __init__(self, **keyargs):
|
||||
self.mecha = mecha.Player(**keyargs)
|
||||
self.image = pygame.image.load("assets/ship/setup/0").convert_alpha()
|
||||
self.image = pygame.image.load("assets/ship/loop/00001.png").convert_alpha()
|
||||
self.position = self.image.get_rect()
|
||||
|
||||
|
||||
@ -63,12 +65,12 @@ if __name__ == "__main__":
|
||||
pygame.init()
|
||||
black = (0, 0, 0)
|
||||
size = width, height = 1366, 720
|
||||
TICK_RATE = 60
|
||||
TICK_RATE = 30
|
||||
keys = set()
|
||||
tick = (time.time(), time.time(), 0)
|
||||
screen = pygame.display.set_mode(size,
|
||||
flags=pygame.RESIZABLE)
|
||||
elements = [Player(speed=(-5, 30), pos=(10, 1)), Player()]
|
||||
elements = [Player(speed=(5, 0), pos=(10, -200)), Player(speed=(-5, 0), pos=(10, 200), mass = 2), Planet(mass=200)]
|
||||
reference = 1
|
||||
joy=[1, 1]
|
||||
while 1:
|
||||
@ -99,15 +101,18 @@ if __name__ == "__main__":
|
||||
if key in [275,276,273,274]:
|
||||
exec("joy" + ("[0]+","[0]-","[1]+","[1]-")[[275,276,273,274].index(key)] + "=1")
|
||||
elements[1].mecha.orientation=joy[0]*(-3)
|
||||
for element in elements[::-1]:
|
||||
element.mecha.apply_gravity([element.mecha for element in elements])
|
||||
element.mecha.tick(origin=elements[0].mecha.pos)
|
||||
if i <= 2:
|
||||
for element in elements:
|
||||
element.draw(scale=10**(joy[1]*0.05), reference=elements[1].mecha.pos, size=screen.get_size())
|
||||
element.mecha.apply_gravity([element.mecha for element in elements])
|
||||
element.mecha.tick()
|
||||
ori,speed=origin=elements[1].mecha.pos, origin=elements[1].mecha.speed
|
||||
for element in elements:
|
||||
element.mecha.ref(origin=ori, speed=speed)
|
||||
if i < 2:
|
||||
for element in elements:
|
||||
element.draw(scale=10**(joy[1]*0.05), reference=elements[reference].mecha.pos, size=screen.get_size())
|
||||
pygame.display.flip()
|
||||
# for element in elements:
|
||||
# element.apply(camera=camera, origin=origin)
|
||||
# screen.blit(element.image, element.position)
|
||||
time.sleep(0.001)
|
||||
if tick[2]%60 == 0 : print(elements[1].mecha.pos)
|
||||
if tick[2]%60 == 0 : print(elements[2].mecha.pos, elements[2].mecha.speed)
|
Loading…
Reference in New Issue
Block a user