The Enchanted Cave 2
Delve into a strange cave with a seemingly endless supply of treasure, strategically choos
4.34 / 5.00 31,296 ViewsGhostbusters B.I.P.
COMPLETE edition of the interactive "choose next panel" comic
4.07 / 5.00 10,082 ViewsNote: I've already posted something similar elsewhere, but this is a bit different and also easier to help me with. In addition, I think the title made people become uninterested.
My problem has to do with the enemy when the character is jumping. The "vcam" follows the character up and down (the vcam only being the changing of the level movieclip's _y value). The floor initially drops out from under the enemy, then he falls down towards it. When the character reaches the arc of his jump and falls back down, the ground covers up the enemy as the enemy falls partway through it. At the end of the jump, the enemy pops back up to the top of the ground like nothing happened.
Here's what I've tried that produce the same effect:
onEnterFrame for the enemy:
clip.point = {x:x,y:y};
parent.localToGlobal(clip.point);
while(barrier.hitTest(clip.point.x,clip.point.y + height,true)) {
y--;
clip.point = {x:x,y:y};
parent.localToGlobal(clip.point);
};
while(!barrier.hitTest(clip.point.x,clip.point.y + height + 1,true)) {
y++;
clip.point = {x:x,y:y};
parent.localToGlobal(clip.point);
};
clip._y = y;
onEnterFrame for the character:
// Make it fall
if(jumpSpeed < maxGravity) {
jumpSpeed += gravityAmount;
};
y += jumpSpeed;
clip.point = {x:x,y:y};
parent.localToGlobal(clip.point);
// Check for ground below
if(barrier.hitTest(clip.point.x,clip.point.y + height + 1,true) || barrier.hitTest(clip.point.x - width,clip.point.y + height + 1,true) || barrier.hitTest(clip.point.x + width,clip.point.y + height + 1,true)) {
if(barrier.hitTest(clip.point.x - width,clip.point.y,true) || barrier.hitTest(clip.point.x + width,clip.point.y,true)) {
if(!move(0,false,false,true)) {
sendHitToAI();
};
};
while(barrier.hitTest(clip.point.x,clip.point.y + height + 1,true) || barrier.hitTest(clip.point.x - width,clip.point.y + height + 1,true) || barrier.hitTest(clip.point.x + width,clip.point.y + height + 1,true)) {
y--;
clip.point = {x:x,y:y};
parent.localToGlobal(clip.point);
};
jumpSpeed = 0;
jumping = false;
} else {
jumping = true;
};
// Check for ceiling above
if(barrier.hitTest(clip.point.x,clip.point.y - height,true) || barrier.hitTest(clip.point.x - width,clip.point.y - height,true) || barrier.hitTest(clip.point.x + width,clip.point.y - height,true)) {
while(barrier.hitTest(clip.point.x,clip.point.y - height,true) || barrier.hitTest(clip.point.x - width,clip.point.y - height,true) || barrier.hitTest(clip.point.x + width,clip.point.y - height,true)) {
y++;
clip.point = {x:x,y:y};
parent.localToGlobal(clip.point);
};
jumpSpeed = 0;
};
// Check for platform below
if(jumpSpeed > 0 && (platforms.hitTest(clip.point.x,clip.point.y + height + 1,true) || platforms.hitTest(clip.point.x - width,clip.point.y + height + 1,true) || platforms.hitTest(clip.point.x + width,clip.point.y + height + 1,true))) {
while(platforms.hitTest(clip.point.x,clip.point.y + height + 1,true) || platforms.hitTest(clip.point.x - width,clip.point.y + height + 1,true) || platforms.hitTest(clip.point.x + width,clip.point.y + height + 1,true)) {
y--;
clip.point = {x:x,y:y};
parent.localToGlobal(clip.point);
};
jumpSpeed = 0;
jumping = false;
};
// Move background or character
if(mcsToMove[0] != undefined && (clip.point.y < vcamBoundsY && (clip._y - clip.point.y) >= 0 || clip.point.y > (Stage.height - vcamBoundsY - 50) && (clip._y - clip.point.y) <= 0)) {
// Move the background
for(var i = 0;i < mcsToMove.length;i++) {
if(typeof(mcsToMove[i]) == "movieclip") {
// Just a movieclip
mcsToMove[i]._y += (clip._y - clip.point.y);
} else if(mcsToMove[i][1] != undefined) {
// It's an array with a speed multiplier
mcsToMove[i][0]._y += (clip._y - clip.point.y) * mcsToMove[i][1];
} else if(mcsToMove[i].clip != undefined) {
// It's a character
mcsToMove[i].y += (clip._y - clip.point.y);
};
};
y = clip._y;
} else {
// Move the character
clip._y = y;
};
About mcsToMove: mcsToMove is an array that holds all the movieclips that need to be moved by the vcam. It includes the level_mc (nested inside the level_mc is the barrier).
I originally had the code for the character also being the code for the enemy, but when it didn't work I tried tweaking it to what you see now (which is easier to try and fix). My only guess as to why it's not working is that somehow the function in the enemy thinks that the barrier IS at the places it's putting the enemy.
I've been stuck on this for a week now, and any help would be very greatly appreciated.
I am a servant of the Most High God
The Hanging Collab || The Legend of Newgrounds (Game) || Crystal Rays (Song)
Also in the mcsToMove array is the enemy (whereupon the y value of the enemy, not the _y value, is changed).
I found something interesting (and incredibly aggravating) while looking for a solution.
When I put a "trace(y)" in various places in the enemy function, it never goes less than 209 (before you jump it's 209, and after you jump it ends up 209).
When I removed the enemy from mcsToMove and put instead at the beginning of the enemy onEnterFrame:
y -= _root.test.jumpSpeed;
I got the same result again.
I am a servant of the Most High God
The Hanging Collab || The Legend of Newgrounds (Game) || Crystal Rays (Song)
Could you post a swf file of the game so far? I'm not sure I know what's happening.
"Whoever said 'winners never quit' obviously never considered addicts." - Hoeloe
I just found out that removing the "y -= _root.test.jumpSpeed;" and not having the enemy in the mcsToMove still results the same--the enemy bounces. What could the problem POSSIBLY be?
I am a servant of the Most High God
The Hanging Collab || The Legend of Newgrounds (Game) || Crystal Rays (Song)
Here's an example:
http://spamtheweb.com/ul/upload/081208/4 1370_helpme.php
Hit space to jump. The blue is the character, the red is the enemy.
I am a servant of the Most High God
The Hanging Collab || The Legend of Newgrounds (Game) || Crystal Rays (Song)
Exactly what movieclips and why are you moving separately with mcsToMove if you could just move the movieclip containing them all?
The movieclip containing them all is _root. I don't want the character to move, just everything else. I want to be able to move some things at different speeds (i.e. backgrounds move at 1/4 speed).
All I'm moving in the example is the level_mc and the enemy.
I am a servant of the Most High God
The Hanging Collab || The Legend of Newgrounds (Game) || Crystal Rays (Song)
Attach enemies in the level movieclip. Everything works, no need for arrays.
I already tried that, however. I put the enemy in the level movieclip and still the enemy bounced.
I am a servant of the Most High God
The Hanging Collab || The Legend of Newgrounds (Game) || Crystal Rays (Song)
I tried it using localToGlobal for the hitTest and it bounced. When I don't use localToGlobal, it lands in the wrong place.
I am a servant of the Most High God
The Hanging Collab || The Legend of Newgrounds (Game) || Crystal Rays (Song)
If I set enemy.y to be, say, barrier._y+300, it works perfectly (except it's not using the barrier, obviously). It stays in place when you jump.
That leads me to believe that my while loops are flawed somehow (but I can't see how) or that the hitTest functions I am using are, for some reason, returning false when it should be returning true? Is there an alternative to hitTest I can use?
I am a servant of the Most High God
The Hanging Collab || The Legend of Newgrounds (Game) || Crystal Rays (Song)
It's fixed. It was a simple layering problem in the .fla file, caused by calling the character function before the enemy function. I switched them, and it's fixed.
I am a servant of the Most High God
The Hanging Collab || The Legend of Newgrounds (Game) || Crystal Rays (Song)