Added mecha and visual subpackages
This commit is contained in:
parent
1e27e28a39
commit
c4b850e349
Before Width: | Height: | Size: 983 B After Width: | Height: | Size: 983 B |
BIN
assets/ship.gif
Normal file
BIN
assets/ship.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 983 B |
19
main.py
19
main.py
@ -16,7 +16,7 @@ size = width, height = 1366, 720
|
|||||||
TICK_RATE=60
|
TICK_RATE=60
|
||||||
camera=np.array([0.,0.])
|
camera=np.array([0.,0.])
|
||||||
origin=camera=np.array([0.,0.])
|
origin=camera=np.array([0.,0.])
|
||||||
follow=0
|
follow=1
|
||||||
screen = pygame.display.set_mode(size)
|
screen = pygame.display.set_mode(size)
|
||||||
|
|
||||||
class satellite(pygame.sprite.Sprite):
|
class satellite(pygame.sprite.Sprite):
|
||||||
@ -45,14 +45,15 @@ tick=(time.time(), time.time(), 0)
|
|||||||
def clip(val, minval, maxval):
|
def clip(val, minval, maxval):
|
||||||
return min(max(val, minval), maxval)
|
return min(max(val, minval), maxval)
|
||||||
elements=[satellite() for _ in range(3)]
|
elements=[satellite() for _ in range(3)]
|
||||||
for element in elements:
|
"""for element in elements:
|
||||||
element.pos=np.array([random.randint(0,width), random.randint(0,height)], dtype='float64')
|
element.pos=np.array([random.randint(0,width), random.randint(0,height)], dtype='float64')
|
||||||
element.speed=np.array([random.randint(0,50), random.randint(0,50)], dtype='float64')
|
element.speed=np.array([random.randint(0,50), random.randint(0,50)], dtype='float64')"""
|
||||||
elements[1].pos= np.array([float(width/2), float(height/2)])
|
elements[1].pos= np.array([-500.,0.])
|
||||||
elements[0].pos= np.array([float(width/4), float(height/4)])
|
elements[0].pos= np.array([-100.,0.])
|
||||||
elements[0].speed[1]=10
|
elements[0].speed[1]=20
|
||||||
elements[1].mass=100
|
elements[1].mass=300
|
||||||
elements[2].mass=30
|
elements[2].mass=30
|
||||||
|
elements[2].speed[1]=100
|
||||||
keys=set()
|
keys=set()
|
||||||
while 1:
|
while 1:
|
||||||
dtick=tick
|
dtick=tick
|
||||||
@ -79,9 +80,13 @@ while 1:
|
|||||||
for element in elements:
|
for element in elements:
|
||||||
element.apply_gravity(elements)
|
element.apply_gravity(elements)
|
||||||
element.tick(camera=camera)
|
element.tick(camera=camera)
|
||||||
|
for element in elements:
|
||||||
|
element.pos = element.pos - elements[-1].pos
|
||||||
|
element.speed = element.speed - elements[-1].speed
|
||||||
origin=elements[follow].pos
|
origin=elements[follow].pos
|
||||||
for element in elements:
|
for element in elements:
|
||||||
element.apply(camera=camera, origin=origin)
|
element.apply(camera=camera, origin=origin)
|
||||||
screen.blit(element.image, element.position)
|
screen.blit(element.image, element.position)
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
time.sleep(0.001)
|
time.sleep(0.001)
|
||||||
|
if tick[2]%60 == 0 : print(elements[follow].pos)
|
46
mecha.py
Executable file
46
mecha.py
Executable file
@ -0,0 +1,46 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""
|
||||||
|
Created on Mon Jan 27 16:32:02 2020
|
||||||
|
|
||||||
|
@author: suwako
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
|
||||||
|
class Mass():
|
||||||
|
def __init__(self, pos=(0,0), speed=(0,0), mass=1):
|
||||||
|
self.pos = np.array(pos, dtype='float64')
|
||||||
|
self.speed = np.array(speed, dtype='float64')
|
||||||
|
self.mass = mass
|
||||||
|
self.G = 0.0000001
|
||||||
|
|
||||||
|
def tick(self):
|
||||||
|
self.pos += self.speed
|
||||||
|
|
||||||
|
def apply_gravity(self, elements):
|
||||||
|
for element in elements:
|
||||||
|
d = element.pos - self.pos
|
||||||
|
norm_d = np.linalg.norm(d)
|
||||||
|
if norm_d != 0:
|
||||||
|
u = d/norm_d
|
||||||
|
norm = self.G * element.mass * (d[0]**2 + d[1]**2)
|
||||||
|
self.speed += norm*u
|
||||||
|
|
||||||
|
|
||||||
|
class Player(Mass):
|
||||||
|
def __init__(self, keys={},
|
||||||
|
orientation=0,
|
||||||
|
pos=(0, 0),
|
||||||
|
speed=(0, 0),
|
||||||
|
mass=1):
|
||||||
|
Mass.__init__(self, pos=pos, speed=speed, mass=mass)
|
||||||
|
self.orientation = orientation
|
||||||
|
self.actions = {"thrust": False, "fire": False}
|
||||||
|
self.actions.update(keys)
|
||||||
|
|
||||||
|
def action(self, keys):
|
||||||
|
self.actions.update(keys)
|
||||||
|
if __name__ == "__main__":
|
||||||
|
pass
|
28
server.py
28
server.py
@ -43,34 +43,6 @@ def error(*s): print(Fore.RED +
|
|||||||
level = 1
|
level = 1
|
||||||
for i in range(level):
|
for i in range(level):
|
||||||
exec("debug info warn error".split()[i] + "= lambda *x: None")
|
exec("debug info warn error".split()[i] + "= lambda *x: None")
|
||||||
class Satellite():
|
|
||||||
def __init__(self, pos=np.array([0., 0.]),
|
|
||||||
speed=np.array([0., 0.]),
|
|
||||||
mass=1):
|
|
||||||
self.pos = pos
|
|
||||||
self.speed = speed
|
|
||||||
self.mass = mass
|
|
||||||
self.G = 0.0000001
|
|
||||||
|
|
||||||
def tick(self):
|
|
||||||
self.pos += self.speed
|
|
||||||
|
|
||||||
def apply_gravity(self, elements):
|
|
||||||
for element in elements:
|
|
||||||
if element.pos != self.pos:
|
|
||||||
d = element.pos - self.pos
|
|
||||||
u = d/np.linalg.norm(d)
|
|
||||||
norm = self.G * element.mass * (d[0]**2 + d[1]**2)
|
|
||||||
self.speed += norm*u
|
|
||||||
|
|
||||||
|
|
||||||
class Player():
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class Map():
|
|
||||||
def __init__(self):
|
|
||||||
self.elements = []
|
|
||||||
|
|
||||||
|
|
||||||
def handle(connection, address):
|
def handle(connection, address):
|
||||||
|
14
visual.py
Executable file
14
visual.py
Executable file
@ -0,0 +1,14 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""
|
||||||
|
Created on Tue Jan 28 10:54:33 2020
|
||||||
|
|
||||||
|
@author: suwako
|
||||||
|
"""
|
||||||
|
import mecha
|
||||||
|
|
||||||
|
class Player():
|
||||||
|
def __init__(self):
|
||||||
|
self.mass = mecha.Mass()
|
||||||
|
self.image = pygame.image.load("assets/ship.gif").convert_alpha()
|
||||||
|
self.position = self.image.get_rect()
|
Loading…
Reference in New Issue
Block a user