View Full Version : Shooter game
cheet0face
06-13-2008, 03:25 AM
Im making this game where heads fly across the screen and you have to shoot them with the cross hair (mouse). The shooting part works fine. When you shoot them, they dissapear, and when they get to the left side of the stage your health decreases in the health meter. My problem is when they get to the left side of the stage they keep on going. I want them to stop at the wall movieclip i have there. I've tried putting hittest's in there but they dont seem to work.
Heres the code for the heads that fly across the screen:
onClipEvent(load)
{
function reset()
{
if(this._name=="face")
{
this._visible=false;
}
else
{
this._visible=true;
}
this.dead=0;
this.speed=random(4)+3;
this._x=700;
this._y=random(300);
}
this.reset();
}
onClipEvent(enterFrame){
if(this.hitTest(_root.wall)){
_root.hp -= (random(1)+1);
}
{
this._x-=this.speed;
if(this._x<-40)
{
this.reset();
}
}
}
////////////////////////////////////////////////////////////////////////////////////////
and this is the code thats on the layer:
for(i=1;i<=5;i++)
{
_root["face"].duplicateMovieClip("face"+i,i+1000,face);
}
_root.hp = 100;
There is no code on the wall Movie Clip
Any help is appreciated
GMaker0507
06-13-2008, 02:44 PM
try this
if(this.hitTest(_root.wall)){
_root.hp -= (random(1)+1);
this.speed=0
}
cheet0face
06-13-2008, 08:16 PM
Thank You!
It worked, I guess i was just putting it in the wrong place.
Once othere question, my canvas size is 700 x 400 and when none of the heads are touching the wall the health will go down.
I dont know if there are heads going out of the area or something.
??
play the game here and see
http://mostplays.com/play/Osama_BETA_30438
GMaker0507
06-13-2008, 08:55 PM
I could solve that problem in three ways:
(A), We remove the movieclip from the stage.
if(this.hitTest(_root.wall)){
_root.hp -= (random(1)+1);
_root.removeMovieClip(this)
this.speed=0
}
(B), We only damage the White House when the movieclip is visible
if(this.hitTest(_root.wall)&&this._visible){
_root.hp -= (random(1)+1);
this.speed=0
}
(C), Once we damage the white house we move somewhere far away so we dont hit it again.
if(this.hitTest(_root.wall)){
_root.hp -= (random(1)+1);
this._x=1000
this._y=1000
this.speed=0
}
I would go with Choice A, but for some unkown reason you might want to choose B, or C. Whatever works best with your design and coding.
cheet0face
06-13-2008, 09:11 PM
I posted code (A) and (B) in there but they didn't seem to work.
There are only 5 heads in the game, and when you shoot one it respawns at the beginning again so spawning it far away would not really work.
I was thinking just separating the picture into two parts one with most of the picture and the other named "wall', a thin strip on the right side so they have to hit that strip to damage the health. So whatever is creating the problem I would be able to see because it would have to hit that strip.
The main reason this creates a problem is that when the health meter reaches zero, I want a message to appear that says "Game Over" or something along those lines with a link to restart.
GMaker0507
06-14-2008, 02:40 PM
Whats the code for actually clicking and killing them, if i see that i might be able to help more.
Well, i guessed that the reason the health would go down even when it seemed that the heads were not touching the wall, was that they were still touching the wall, and that they just werent visible.
I just realized that, if you wait long enough, they wouldnt come unless you delete some of them. So i guess i was wrong.
cheet0face
06-14-2008, 07:51 PM
This is the code on the cross hair:
onClipEvent (load)
{
startDrag(this, true);
Mouse.hide();
this.swapDepths(9999);
}
onClipEvent(mouseDown)
{
playsounds = new Sound(this);
playsounds.attachSound("shot");
playsounds.start(0, 1);
for(i=1;i<=5;i++)
{
if(this.hitTest(_root["face"+i])&&_root["face"+i].dead==0)
{
_root["face"+i].gotoAndPlay(2);
}
}
}
//////////////////////////////////////////////////////////////////////////////////////
But on the head, in edit mode, there are three frames with this on the frames:
1) stop();
2) this.dead=1;
3) this.reset();
GMaker0507
06-15-2008, 01:19 AM
Try setting a breakpoint somewhere, preferrably wherever the root health is changed, then start debugging the flash.
Once the debug menu is up check out the variables and position of all the listed movieclips
cheet0face
06-15-2008, 02:21 AM
I dont really have much experience debugging, so Im not really quite sure how to do it.
I pulled the debug screen up and set a break point when the health started going down but no heads were near it, but im not sure what it means.
?
I also just installed firebug in my firefox browser and I installed thunderbolt on my desktop but I cant seem to get them together???
GMaker0507
06-15-2008, 05:55 PM
Give this a try as well.
if(this.hitTest(_root.wall)&&this.dead==0){
_root.hp -= (random(1)+1);
this.speed=0
}
Debugging:
Debug -> Debug Movie
Click the green arrow to start the flash.
Their should be 4 Tabs: Properties, Variables, Locals, and Watch
Above those tabs should be a list of MC's: _global, _level0, and one for each of your movie clips on the stage.
Select a Mc from the list, then you can look at its variables or properties
Tracing Strings
Also, try using a trace statement. Place it Where ever the health is changed in any way then track it. Like:
trace("Health Changed To "+_root.hp)
The Health Bar:
Does your health box scale instantly, like:
HealthBarMc._xscale=_root.hp
or does it scale gradually, like:
HealthBarMc._xscale+=(_root.hp-HealthBarMc._xscale)/5
If it scales gradually then the problem might be that the damage is being applied too quickly, and that you need to decrease the amount of damage that is taken.
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.