PDA

View Full Version : Arrays


betancourtb82
02-20-2006, 12:50 PM
I am still relatively new to Vizard and had a question on arrays. I have created (with some help from farshizzo) an array that holds 5 avatars.


#Create six avatars
for i in range(NUM_AVATARS):

newX = -math.cos(-2*i+15) * 2
newZ = math.sin(i^2+1) * 2
male = viz.add('male.cfg')
male.translate(newX,0,newZ)
male.rotate(180,0,0)
avatars.append(male) #Save avatar in list
# walkAvatar(_avatars)
walk = male.walkto(0,0,-10.5,1,0,2)

I was able to make each of these avatars walk in a separate way, but now I want to make them "die" once I click on them. I have a shoot bullet animation so it looks like they are getting shot, but in actuality they are just being clicked on. The suggestion made by Farshizzo on the avatar animations (http://www.worldviz.com/forum/showthread.php?t=190&highlight=Avatar+Animations) thread worked for a stationary avatar but once they start moving using the following code, they get up even after I "shoot" them. Any suggestions?:

def mytimer(num):

if num == ANIMATION:

#Calculate elapsed time since last update
elapsed = viz.elapsed()

#Update each active ball
for bullet in bullets:
if bullet.active:
#Move the ball and check if it has collided with any objects
MoveBullet(bullet,elapsed)

#Update the crosshair position
crosshair.translate(viz.mousepos()+[0])

elif num == START_AVATAR:
global nextAvatar
#Get the next available duck and start it
avatar = avatars[nextAvatar]
walkAvatar(avatar)
nextAvatar = (nextAvatar + 1) % NUM_AVATARS
viz.starttimer(START_AVATAR,TIME_BETWEEN_AVATARS)

##Start a timer which starts the next available avatar
viz.starttimer(START_AVATAR,0.01)


Thanks

betancourtb82
02-21-2006, 10:40 AM
Ok, I solve the problem I was having yesterday by adding a

clear(viz.ALL)
clear(viz.CURRENT_ACTION)

Now my next question would be, how can I take the fallen avatar out of the scene and reset him/her to a new avatar, i.e. how can I remove him from the array and place another one in the array.

Thanks

farshizzo
02-21-2006, 11:30 AM
Hi,

The following will remove an avatar from the array:avatars.remove(male)Then you would use the append command to add a new avatar:avatars.append(male)