Nevermind that last question, I just figured it out. Now for my real question. The reason I'm writing this code is to create a scenario where someone falls when they get shot (i.e. a projectile hits the avatar, activated by a mouse click). I have modeled my code from the duckcourt demo but can't get the enemy to stay on the ground when shot. I'm thinking it has to do with the way the avatar is "viewed" by the program. I was wondering if you could help me figure out how to distinguish between each element in the array and denote who's getting shot. For now I would be happy just being able to click on the avatars in this code and have them fall and stay down. I think I can go from there. Thanks again
Code:
import viz
viz.go()
avatars = []
FREEZE_AVATAR = 0
#Go through a loop six times.
for i in range(4):
#Each time you go through the loop, create a new duck and
male = viz.add('male.cfg')
male.translate(-i, 0,10)
male.rotate(180,0,0)
#Add the new male to the "avatars" array.
avatars.append(male)
def onkeydown(key):
if key == 'r':
print 'R pressed'
# Kill timer FREEZE_AVATAR
viz.killtimer(FREEZE_AVATAR)
male.clear(viz.ALL)
male.clear(viz.CURRENT_ACTION)
male.state(1)
viz.callback(viz.KEYDOWN_EVENT,onkeydown)
def ontimer(num):
if num == FREEZE_AVATAR:
#Freeze the avatar
male.speed(0)
viz.callback(viz.TIMER_EVENT,ontimer)
def onmousedown(button):
#The mouse button 'button' is being pressed
if button == viz.MOUSEBUTTON_LEFT:
#Perform the action
male.act(7)
#Start a timer to freeze the avatar when the action is over
viz.starttimer(FREEZE_AVATAR,(male.getduration(7)-.07),1)
#male.act(8) pass
viz.callback(viz.MOUSEDOWN_EVENT,onmousedown)
viz.mouse(viz.OFF)