Skip to content

Instantly share code, notes, and snippets.

@jsbain
Created April 1, 2018 08:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsbain/563cf7498dda79c3ca824b12a9103e5a to your computer and use it in GitHub Desktop.
Save jsbain/563cf7498dda79c3ca824b12a9103e5a to your computer and use it in GitHub Desktop.
Untitled_192.py
from scene import *
import math
class myscene(Scene):
def setup(self):
a=SpriteNode('plf:LaserPurple')
self.add_child(a)
self.a=a
a.position=(0,300)
a.vel=[180,120]
a.damping=.5
self.g=100
a=SpriteNode('plf:LaserPurpleDot')
self.add_child(a)
self.a=a
a.position=(0,300)
a.vel=[90,60]
a.damping=.1
self.g=100
def do_physics(self):
''' dumbed down physics
'''
for n in self.children:
# velocity changes per gravity
if hasattr(n,'vel'):
n.vel[1]-=self.g*self.dt
# if we hit the floor, bounce by reflecting vertical velocty, with some damping
if n.position.y+(n.vel[1]*self.dt)<0:
n.vel[1]*=-(1-n.damping)
# add some friction on the ground
if Point(n.position.x,0) in n.bbox:
n.vel[0]*=0.95 #fridtion
n.run_action(Action.move_by(n.vel[0]*self.dt, n.vel[1]*self.dt,self.dt))
n.run_action(Action.rotate_to(math.atan2(n.vel[1],n.vel[0])))
def update(self):
if self.t>1:
self.do_physics()
s=myscene()
run(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment