Well, apart from being totally out of proportion my zombie is alive at least! He doesn’t move around too much and he move’s a tad too fast for my liking but it’s a great start.
To do this I got my code to make the object move towards the camera (player) when within in certain amount of distance from each other. So first off I set up this:
- cpz=camera position z(1)
- cpx=camera position x(1)
- zpx=object position x(6)
- zpz=object position z(6)
These are my variables for the camera z and x positions on camera (1), then the same for my object (which is the zombie) object (6). Oh I called my variables CPZ which is “Camera Position z” and ZPZ which is “Zombie Position Z”
Then the code to work out who’s where and what to do if they meet:
- IF cpx<zpx+400 AND cpz<zpz+400 AND cpx>zpx-400 AND cpz>zpz-400
- SET OBJECT SPEED 6,2
- SET OBJECT FRAME 6,31
- LOOP OBJECT 6,31,50
- MOVE OBJECT 6,-1
If you read it back to yourself and reference the variables it should make sense. Line 1 is saying that if the camera position is within the range of 400 from the zombie position then carry on to line 2.
Lines 2,3,4 and 5 tell our object (6) which is the Zombie, what to do.
Now, the code wont stay like this, I need to trigger a time event so that the zombie/s are “released” after x amount of time and then move towards the camera. Also, for some reason the zombie doesn’t move towards the camera like it should do on it’s X axis, so I need to spend a bit more time on the above code trying to work out why.
Other updates, I had a problem with the gun. When holding down A to fire the gun animation was being displayed on screen for as long as the button was held down. I didn’t want this, I want my player to have to press A every-time they want to shoot. So I came up with this bit of code:
I set up a meter for the gun count:
- shots# = INT(0)
// when fire key pressed increased the shot meter by one
- IF KEYSTATE(30)=1 THEN INC shots#,1.
//display the gun shot graphic in its position.
- IF KEYSTATE(30)=1 THEN SPRITE 4,297,144,4
//if the fire key is held for more than 4 hide the gun shot graphic
- IF shots# =>4 THEN SPRITE 4,-10000,-10000,4
//when the fire key is released reset the shot meter
- .IF KEYSTATE(30)=0 THEN shots# =0
I think that’s all I did yesterday, it may not look like much but it took a while and I’m pretty happy my zombie is now moving!