Random staff lengths + mouse interaction
This commit is contained in:
parent
60a3048c7a
commit
359e7accb2
1 changed files with 14 additions and 3 deletions
17
pendel.py
17
pendel.py
|
@ -43,9 +43,11 @@ class PendelSim(Game):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(PendelSim,self).__init__(1000,600, 60)
|
super(PendelSim,self).__init__(1000,600, 60)
|
||||||
self.init_data()
|
self.init_data()
|
||||||
|
self.mousedown = False
|
||||||
|
self.mousepos = (0,0)
|
||||||
|
|
||||||
def init_data(self):
|
def init_data(self):
|
||||||
self.staff_lengths = staff_lengths = [ randint(100,200) for i in range(3) ]
|
self.staff_lengths = staff_lengths = [ randint(150,200), randint(100,200), randint(100,150) ]
|
||||||
fixed_joint = Vector( self._width/2, self._height/5 )
|
fixed_joint = Vector( self._width/2, self._height/5 )
|
||||||
joint_a = fixed_joint - Vector(staff_lengths[0],0)
|
joint_a = fixed_joint - Vector(staff_lengths[0],0)
|
||||||
joint_b = joint_a - Vector(0,-staff_lengths[1])
|
joint_b = joint_a - Vector(0,-staff_lengths[1])
|
||||||
|
@ -56,7 +58,10 @@ class PendelSim(Game):
|
||||||
def on_update(self, dtime):
|
def on_update(self, dtime):
|
||||||
new_joints = self.joints[:]
|
new_joints = self.joints[:]
|
||||||
for i in range(1,4):
|
for i in range(1,4):
|
||||||
new_joints[i] += (self.joint_speed[i] + Vector(0,40)) * dtime
|
new_joints[i] += (0.99 * self.joint_speed[i] + Vector(0,40)) * dtime
|
||||||
|
|
||||||
|
if self.mousedown:
|
||||||
|
new_joints[1] = Vector(self.mousepos[0], self.mousepos[1])
|
||||||
|
|
||||||
for i in range(0,4-1):
|
for i in range(0,4-1):
|
||||||
relvec = new_joints[i+1] - new_joints[i]
|
relvec = new_joints[i+1] - new_joints[i]
|
||||||
|
@ -90,7 +95,13 @@ class PendelSim(Game):
|
||||||
|
|
||||||
def on_event(self, event):
|
def on_event(self, event):
|
||||||
if event.type == MOUSEBUTTONDOWN:
|
if event.type == MOUSEBUTTONDOWN:
|
||||||
self.init_data()
|
self.mousedown = True
|
||||||
|
self.mousepos = event.pos[:]
|
||||||
|
elif event.type == MOUSEBUTTONUP:
|
||||||
|
self.mousedown = False
|
||||||
|
self.mousepos = event.pos[:]
|
||||||
|
elif event.type == MOUSEMOTION:
|
||||||
|
self.mousepos = event.pos[:]
|
||||||
else:
|
else:
|
||||||
super(PendelSim, self).on_event(event)
|
super(PendelSim, self).on_event(event)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue