Checkpoiny
This commit is contained in:
parent
c4b850e349
commit
f13c042eda
Before Width: | Height: | Size: 983 B After Width: | Height: | Size: 983 B |
BIN
assets/ship.png
Normal file
BIN
assets/ship.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.1 KiB |
BIN
assets/ship.xcf
Normal file
BIN
assets/ship.xcf
Normal file
Binary file not shown.
3
main.py
3
main.py
@ -22,7 +22,8 @@ screen = pygame.display.set_mode(size)
|
||||
class satellite(pygame.sprite.Sprite):
|
||||
def __init__(self):
|
||||
pygame.sprite.Sprite.__init__(self)
|
||||
self.image = pygame.image.load("intro_ball.gif").convert_alpha()
|
||||
self.image = pygame.image.load("assets/ship.png").convert_alpha()
|
||||
self.image = pygame.transform.scale(self.image, (self.image.get_rect().width*5, self.image.get_rect().height*5))
|
||||
self.position = self.image.get_rect()
|
||||
self.speed=np.array([0.,0.])
|
||||
self.pos = np.array([0.,0.])
|
||||
|
10
mecha.py
10
mecha.py
@ -10,14 +10,14 @@ import numpy as np
|
||||
|
||||
|
||||
class Mass():
|
||||
def __init__(self, pos=(0,0), speed=(0,0), mass=1):
|
||||
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 tick(self, origin=np.array((0, 0), dtype='float64')):
|
||||
self.pos += self.speed - origin
|
||||
|
||||
def apply_gravity(self, elements):
|
||||
for element in elements:
|
||||
@ -42,5 +42,7 @@ class Player(Mass):
|
||||
|
||||
def action(self, keys):
|
||||
self.actions.update(keys)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
pass
|
||||
pass
|
||||
|
98
visual.py
98
visual.py
@ -6,9 +6,97 @@ Created on Tue Jan 28 10:54:33 2020
|
||||
@author: suwako
|
||||
"""
|
||||
import mecha
|
||||
import pygame
|
||||
import sys
|
||||
import numpy as np
|
||||
|
||||
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()
|
||||
|
||||
class Obj():
|
||||
def __init__(self, **keyargs):
|
||||
self.mecha = mecha.Player(**keyargs)
|
||||
self.image = pygame.image.load("assets/planet.gif")
|
||||
self.position = self.image.get_rect()
|
||||
self.dimension = np.array((self.position.width, self.position.height))
|
||||
|
||||
def dimension(self):
|
||||
return np.array((self.position.width, self.position.height),
|
||||
dtype='float64')
|
||||
|
||||
def draw(self,
|
||||
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)
|
||||
scaled_dimension = (scale*self.dimension()).astype(int)
|
||||
scaled_image = pygame.transform.scale(self.image, scaled_dimension)
|
||||
scaled_position = scaled_image.get_rect()
|
||||
scaled_position.x, scaled_position.y = map(int, scaled_pos)
|
||||
screen.blit(scaled_image, scaled_position)
|
||||
|
||||
|
||||
class Star(Obj):
|
||||
def __init__(self, **keyargs):
|
||||
self.mecha = mecha.Player(**keyargs)
|
||||
self.image = pygame.image.load("assets/star.gif")
|
||||
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.position = self.image.get_rect()
|
||||
|
||||
|
||||
class Player(Obj):
|
||||
def __init__(self, **keyargs):
|
||||
self.mecha = mecha.Player(**keyargs)
|
||||
self.image = pygame.image.load("assets/ship.png").convert_alpha()
|
||||
self.position = self.image.get_rect()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import time
|
||||
pygame.init()
|
||||
black = (0, 0, 0)
|
||||
size = width, height = 1366, 720
|
||||
TICK_RATE = 60
|
||||
keys = set()
|
||||
tick = (time.time(), time.time(), 0)
|
||||
screen = pygame.display.set_mode(size)
|
||||
elements = [Player(speed=(-5, 10), pos=(10, 1000)), Player()]
|
||||
reference = 1
|
||||
while 1:
|
||||
dtick = tick
|
||||
tick = (tick[0], time.time(), int((time.time() - tick[0])*TICK_RATE))
|
||||
dtick = tick[2] - dtick[2]
|
||||
if dtick > 2:
|
||||
print(dtick)
|
||||
for _ in range(dtick):
|
||||
for event in pygame.event.get():
|
||||
#print(event.type)
|
||||
if event.type == pygame.QUIT: sys.exit()
|
||||
if event.type == pygame.KEYDOWN:
|
||||
keys.update({event.key})
|
||||
print(event.key)
|
||||
# if event.key == 102:
|
||||
# follow = (follow + 1)%len(elements)
|
||||
if event.type == pygame.KEYUP:
|
||||
if event.key in keys:
|
||||
keys.remove(event.key)
|
||||
screen.fill(black)
|
||||
# for key in keys:
|
||||
# if key in [275,276,273,274]:
|
||||
# exec("camera" + ("[0]+","[0]-","[1]-","[1]+")[[275,276,273,274].index(key)] + "=30")
|
||||
for element in elements[::-1]:
|
||||
element.mecha.apply_gravity([element.mecha for element in elements])
|
||||
element.mecha.tick(origin=elements[0].mecha.pos)
|
||||
for element in elements:
|
||||
element.draw(scale=.1, reference=elements[1].mecha.pos, size=size)
|
||||
# for element in elements:
|
||||
# element.apply(camera=camera, origin=origin)
|
||||
# screen.blit(element.image, element.position)
|
||||
pygame.display.flip()
|
||||
time.sleep(0.001)
|
||||
if tick[2]%60 == 0 : print(elements[1].mecha.pos)
|
Loading…
Reference in New Issue
Block a user