I’m working on a simple 2-d space shooter called Ballistic (name pending :+)).
I got the spaceship’s movement down pretty good, and same with the weapons system, but when it came to blowing up asteroids, I’m having an unusual amount of trouble.
I keep every bullet movieclip in an array for easy management, so to program the asteroid to be hit by the bullets, I wrote this:
onClipEvent(load){
var hp = 20;
}
onClipEvent(enterFrame){
for(i=0;i<10;i++){ //runs through shot array (its only 10 spaces long)
if(this.hitTest(weapon.sf*._x,weapon.sf*._y,true)){ //weapon.sf is the bullet array (weapon is a global object that holds information about the weapon being used)
hp--; //decrement asteroid hp
weapon.sf*.removeMovieClip(); //removes bullet once it touches the asteroid
weapon.sf* = 0; //makes an "empty" spot in the array that can be filled with another shot
}
}
}
So as you can see, when the asteroid’s surface area touches the exact x,y point of the bullet, it loses 1 hp.
Well, for some ungodly reason, if I fly the ship about 150 pixels to the lower right of the asteroid, the asteroid thinks it’s losing 1 hp every frame, and in a matter of seconds it’s at -6,000 hp.
I’ve traced the weapon.sf array to see what is inside it when I fly to that point, and it says nothing. So, somehow the asteroid thinks there is a bullet touching it when there is actually no bullet, and nothing is touching it.
Now, if I switch it around and use
if(weapon.sf.hitTest(this)){
it seems to work fine, but then I get the cheesy effect where the bullet doesn’t actually touch the asteroid and still dissapears.
I know that there must be a way around this. It’s not like this is the first time I’ve used a hitTest in my games…:h:
The files are attached if you care to look through them. If anyone can figure this out, that would be awesome.
Thanks!
http://darkfuzz.com/flash/ballistic2.fla
http://darkfuzz.com/flash/ballistic2.swf
a = turn left
d = turn right
w = boost
s = brake/reverse
click = fire
df :?)