I don't mind if people decompile my stuff.
I freely share everything I make.
(good luck reading decompiled code anyway)I also like talking to people, but most seem to be too worried about "bothering" me.
Now, about that pipe problem...
I suppose it would be simple enough to have an invisible hitbox within the pipe's movieClip.
When you press the masturbate button, Peach can loop through all of the sprites that are able to prevent masturbation, and for each one have peach hitTest() against its "noMasturbate" movieClip. If even one of those hitTests is true, then ignore the masturbation effect.
The trick here is that you're not doing a hitTest against the movieClips themselves, you're doing a hitTest against invisible hitBoxes
inside of those movieClips. So these boxes can be larger than the pipes, allowing you to detect when Peach is standing on top of a pipe instead of overlapping it.
In this case, these invisible hitBoxes would all be named "noMasturbate"
To make this more efficient, you can store a list containing only the movieClips that are able to prevent masturbation. To do this, each pipe can contain code that adds that pipe to the list.
To make the masturbation check even more efficient, the check would only happen at the instant you press the masturbate button.
To make this check more efficient, you can use a
break command to prematurely stop looping as soon as you find a hitTest() that's true, so that you don't bother checking any more objects.
To make this even more efficient, you can also make it so that this masturbation check only occurs when you
press the button, but not while holding it.
The way I detect button presses is to have a second variable with a name like last_mastButton which stores the state of the button from the previous frame. So a button check would be something like this:
- Code: Select All Code
loop = function(){
var mastButton = Key.isDown( Key.SHIFT );
if(mastButton && !last_mastButton){
// button has just been pressed
}// if: mastButton pressed
last_mastButton = mastButton;
}// loop()
The loop function can be onEnterFrame if you want.
The reason this code works is because "last_mastButton" will still exist the next time the loop() function runs, so it remembers whether or not the button was held down the last time.
"mastButton" is temporary because it starts with "var", but "last_mastButton" does not have the word "var" in front of it, so it gets stored within the movieClip and will still be there on the next frame.
The IF statement checks to see if the button is current held, but was not pressed during the previous frame.
To make a pipe store itself in a list, you could put code like this inside of the pipe:
- Code: Select All Code
if(_parent.noMast_list == undefined){
_parent.noMast_list = {};
}// if: a noMast_list doesn't exist
_parent.noMast_list[_name] = this;
This creates an empty object named noMast_list, just outside of the pipe.
Then it creates a variable inside of that list, giving the variable the exact same name as the pipe's instance name.
Inside of that variable it stores a reference to itself.
A "reference" is basically a shortcut to a movieClip or an object.
When you access that variable, you actually end up accessing this movieClip directly.
You see, when you type something like this:
- Code: Select All Code
myVariable = myMovieClip;
This will not copy the movieClip. Instead it will make the variable behave as if
IS that movieClip, and you end up having 2 ways to access the same movieClip.
So these two lines will do exactly the same thing:
- Code: Select All Code
myMovieClip._x = 32;
myVariable._x = 32;
And you can later reassign this variable to access a different movieClip like so:
- Code: Select All Code
myVariable = myMovieClip2;
This is a VERY useful trick in Flash that a lot of people who are new to programming don't know about.
Upon pressing the masturbation button, you can have Peach search through this list for the pipe she's colliding near like so:
- Code: Select All Code
playerCanMast = true;
for(var clipName in _parent.noMast_list){
var thisSprite = _parent.noMast_list[clipName];
if(thisSprite.noMasturbate != undefined){
var playerHitNoMast = this.hitBox.hitTest( thisSprite.noMasturbate );
if(playerHitNoMast){
playerCanMast = false;
break; // stop checking sprites
}// if: player is near an object that forbids masturbation
}// if: something called "noMasturbate" exists inside of this sprite
}// for: each movieClip shortcut stored within noMast_list
The code starts off assuming that Peach is allowed to masturbate.
Then it uses a FOR...IN loop to look at every variable inside of "noMast_list"
It access the movieClip stored in that variable and checks whether or not that movieClip contains anything named "noMasturbate"
If it does contain something by that name, this assumes that "noMasturbate" is a movieClip and attempts to to a hitTest() against it.
If the hitTest turns out to be true, it sets the "playerCanMast" boolean variable to false, indicating that the player is not allowed to masturbate.
Then it
breaks out of the code, since there's no need to check the rest of the pipes.
After doing this check you can simply check whether or not "playerCanMast" is true or false, and perform the masturbation if it's true.