2,321 Forum Posts by "Musician"
At 8/18/05 05:17 PM, MusicianEXE wrote:At 8/18/05 04:59 PM, RiftMaster wrote:But I dont think mEXE really wanted to fight he's just defending his position as a far more informed programmer than Chicken will ever be.
O.O your the guy who programmed carious weltling
lol but I already knew that. u don't post alot on the BBS tho.
At 8/18/05 04:59 PM, RiftMaster wrote:
But I dont think mEXE really wanted to fight he's just defending his position as a far more informed programmer than Chicken will ever be.
O.O your the guy who programmed carious weltling...
At 8/16/05 10:05 PM, HeywoodJablowmee wrote: what i mean by walkin off the screen is: i want the character to be able to explore more than just the opening frame, but at the same time i want the screen to follow him so that the person playing has to guess where the character is
We all know what your talking about. It's called scrolling and the secret is to move the ground in the opposite direction that you would move a character. U really should check out the AS: Main thread, it has alot to offer to someone new to flash.
what you mean the source could've been better? is anyone even fucking reading it. I posted the source from a backup file thats been dismantled and explain. A BACKUP FILE. why the hell would I give out my real source in a way that any n00b could come along and copy and paste... GOD DAMMIT, I know I've said this like fucking twice already.
rubber chicken - All I would need to do to create some extra code to put in a platform that would use a percentage equation to make the ground variavle higher depending on how close you were to the center. I'm also not 100% sure of what the hell you said in your post :\, So why don't you actually read the tutorial and try and figure out the theory behind it rather than automatically assuming that your way is better. kk kootchie?
Hahaha WTF? this cracks me up because it's so ironically true. There are n00bs everwhere calling other n00bs, n00bs. tis the the circle of newgrounds.
At 8/18/05 06:29 AM, -liam- wrote:At 8/18/05 06:27 AM, MusicianEXE wrote: yeah I sorta said that in my last post. its old demo...old enough anyhow. the wall collisions weren't even programmed at that point. read the ladt thing I posted the one more thing before I go to bed thing only I didn't go to bed.Yeah I saw that, just thought I'd say it anyway.
Any chance someone could post what the tutorial makes?
tommorow Ill take a my current fla and cut out all the stuff that shouldn't be there and create a swf that shows what what the tutorial makes. btw Im sure that you know this but the actual amount of text that is source code could make up like 1 post. So I REALLY put alot of notation on it. The idea is not to copy and paste. It's to learn how it works so that you can do it in a way that fits your FLA (I have a really uniques style which puts most of the code for a game in one frame. Since little to no people code this way, my code is even more anti- copy and paste.)
pardon my typos
the whole tute looks alot more intimidating than it is. the reason it's size is so beefy is because of all the extra detail I use in explaining this crap (The tute assumes you are a n00b). So if you really new to actionscript you'll need to read all of it. otherwise feel free to skim through till you reach something you dont know. Or just use it as a reference while making a game. I just wanted it to be used. I don't wanna have replies like.
"Thats alot of text and despite the fact I didn't read it I am thoroughly convinced that you are an expert"
best just to learn it all at once then read 20 small crappy tutorials that are so indescriptive that all it's good for is copy and paste. No offence to the people that made them it's just the truth.
At 8/18/05 06:11 AM, -liam- wrote: Heh, on the demo thing you posted you can got through the walls.. thought I'd mention that.
And that was a lot of writing.
yeah I sorta said that in my last post. its old demo...old enough anyhow. the wall collisions weren't even programmed at that point. read the ladt thing I posted the one more thing before I go to bed thing only I didn't go to bed.
At 8/18/05 05:51 AM, Gothbmx wrote: cheers its working now :)
seeing ur tute, do u no how to get a button to activate when another object, like the player on my game, touches it?
iv had a go at it for ages and found what i thought it would be but it doesnt work. i put in:
onClipEvent (enterFrame) {
if (this.hitTest(_root.player)) {
nextFrame();
}
}
O wait.... you just forgot to put _root. in front of nextFrame()
onClipEvent (enterFrame) {
if (this.hitTest(_root.player)) {
_root.nextFrame();
}
}
onClipEvent (enterFrame) {
if (this.hitTest(_root.player)) {
this.nextFrame();
}
}
I'm not positive man, I've always found the timeline controls to be kinda fickle. or atleast nextframe and prevframe. good luck, and still read my tutorial dammit
you see the reason you should read my one big tutorial instead of a bunch of small crappy ones that have the same info but more poorly explained is because... well thats the reason, lol. But one thing I repeat constantly is the fact that hitTest Sucks. Its really fickle altough it does have the impressive ability to detect every contour of an object which makes it usefull for stuff like what you wanna do.
First of all I wouldn't suggest using a button it should be a movie clip
Secondly you'd probably just use an if statement like...
if(_root.man.hitTest(_root.MC, true)){
<put whatever you want to happen here>
}
Thirdly take the fucking time out of the day to read my tutorial, it explains all of the basic stuff that you need to know and how to do it the right way (new people shouldn't program sloppy because its easy, simply because it makes it that much harder to get out of the habbit).
Fourthly bump my tute thread with a post with your praise and OMG's so I can feel slight better about wasting a day on it.
heres a link that has my tute in one post if you want to print it out
yes it is and I shall rip the testicles off the first man to insult it.
btw if ur new to actionscript then heres a linky to my tute
http://www.newground../topic.php?id=327971
I am rather proud of it :)
HAHAHAHA this is comic. maybe you should put the line of code that starts the sound in the if statement that ur using to initiate the jump. you get a treat if you guess which line starts the sound.
I dislike buttons. being the optimization freak that I am i'll state that with like 5 minutes extra effort you can program a movie clip to work just like a button only it can't be tabbed and isn't as taxing on ram.
At 8/17/05 09:29 PM, RiftMaster wrote: Oh and BITER. If I wanted shitty clock games and movies I would have titled this thread:
"SHITFAG CLOCK MOVIES AND CRAP MADE BY 14 YEAR OLD COCKSMOKERS WANTED OMG LOLZ"
)
heh makes me wonder what kind of posts that thread would get. And it looks like you only have games on the front page so you dont accept movies at all do you ?(lol et"games" is sorta a givaway but I want to be sure)
just one more thing before bed to prevent any confusion. the swf I linked to is not the result of the source code in the tutorial. it is the result of a source thats even older than this one. since this code thats been posted is practically useless now that it's covered with notes and the original backup file that used the source I've lost (the one I posted was being saved in a word document, I have alot of backup files...)not to mention im really to lazy to get one of the older files up to date with this one, you'll have to deal with that SWF as an example for now (I am using this in a game and although I have no techniques I care to hide the new one has all sorts of new moves that use techniques that im not going to share just yet...)
NOW THAT THIS TUTORIAL IS POSTED THERE IS NOT EXCUSE FOR A N00B TO SUBMIT A CRAPPILY PROGRAMMED GAME AND HAVE IT SURVIVE
(I've seen several make the front page...scary)
G'night
At 8/18/05 03:27 AM, dieEVILsanta wrote: nice, that is a lot of writing.
hahaha funny to hear someone say that.
W00t! hahaha I really should go to bed.
wallStop();
I call once again on my wallStop function again since it also has code to turn jump speed to zero along with run speed. (My wallStop function PWNS XD).
if (velocity>maxVelocity) {
velocity -= 10;
}
it will subtract a certain amount from the velocity. Some people like to have a variable called gravity which is subtracted from velocity at this point, but I think that’s sort of pointless since I’d only be using it once and I have like, 20 variables already…wait, do I have 20 variables…I know I have a lot but I’m too lazy to count them.
if (velocity>=0) {
man.gotoAndStop("jump");
} else if (velocity<0) {
man.gotoAndStop("fall");
}
}
And at the end a small bit of code to determine whether to play the jump or fall animation based on the velocity. You don’t have to have a fall animation (you can get away with only having one for jump). But I think it makes it look better for some reason.
if (man._y>ground && groundy.hitTest(man._x, man._y, true) && jump == true) {
man._y = ground;
jump = false;
if (runspeed != 0) {
man.gotoAndStop("walk");
} else {
man.gotoAndStop("stand");
}
}
This bit of code governs the landing sequence (the sequence that lets the movie clip that it’s landed and can stop falling but hopefully you already got that). Again I use hitTest as a backup because you can land if you’re not hitting anything. And lastly I put some animation control code to set it to walk or run depending on the jump speed upon landing because the animations were glitching quite a lot while the man movie clip was landing for reasons unknown.
if (dash == false && jump == false && walking == true && Key.isDown(AttackKey) && (runspeed>=maxrunspeed || runspeed<=-maxrunspeed)) {
This is like the initial jump and fall sequences only for the dash attack. Take note that you must be at full speed to use the attack.
dash = true;
dashspeed = runspeed;
walking = false;
tells the game that you are using the dash attack, that dashspeed is equal to runspeed, and that since obviously since you need to be at full speed to use the attack you are most likely walking.
} else if (dash == true) {
the dash sequence
man.gotoAndStop("dash");
play the dash animation
if (dashspeed<0) {
dashspeed += 2;
} else if (dashspeed>0) {
dashspeed -= 2;
}
this is basically the same as the other if statement waaaaaaay up at the top that lowers the runspeed if you’re not running. Also if you look at that if statement you will see that one of its conditions is not if dash == false. That is simply so that while this attack is occurring, your runspeed will be reset to 0. This makes perfect sense seeing as you will be exiting the attack with a dashspeed of zero and it would look stupid if you went from standing still to running full speed 26 pixels a frame. When making a game always look for ways of changing your old if statements or variables to fit the need of the program before creating new ones (admittedly I didn’t follow that rule very well with this game but do as I say not as I do!).
groundy._x -= dashspeed;
sorta like every other thing we’ve done you’re moving the character in some direction at some speed. Or I guess the ground this time since, I’m doing scrolling
if (dashspeed<3 && dashspeed>-3) {
dashspeed = 0;
dash = false;
}
Like that if statement at the beginning that sets the runspeed to zero if its in between 2 numbers, this if statement ends the dash attack.
} else if (attacking == false && timer<=0 && Key.isDown(AttackKey) && jump == false) {
if (runspeed<maxrunspeed || runspeed>-maxrunspeed) {
attacking = true;
walking = false;
man.gotoAndPlay("slash");
attackcounter = 0;
}
}
another initial sequence only this time for the normal ground attack…BUT WAIT! Whats this? It requires the variable timer to be less than or equal to 0 (really it just has to be 0 but I set it like that as a precaution if for some extremely complicated and technical reason it jumps over 0 and into the negatives).Why have I done this? Simple! To delay the character from attacking at hyper fast rate. Making him wait for a split second or 2 so that the speed of the characters swings don’t look
if (attacking == true) {
attackcounter++;
if (attackcounter>=5) {
attacking = false;
timer = 5;
}
}
the attack sequence uses a counter to count up to 5 (5 being the number of frames in the attack animation) and then ending the attack sequence while setting the variable timer to 5 so that the if statement I showed you earlier will take effect and start subtracting from it. When the timer reaches 0 you’ll be able to attack again. This way the loop of attacking not attacking will be delayed and won’t look like attacking, attacking, still attacking, I must have some violent media influence, attacking, and attacking.
};
if a braces is followed by a semi-colon then it usually means that you’re ending a clip event function like the onEnterFrame function that I stated at the waaaaay beginning. Why do braces that end clip events have semi-colons after them….nobody knows…well actually its more like nobody cares. Below are the two functions that you saw me use before in the code. Before some n00b asks, let me say than “No” these functions are not programmed into flash like hitTest(). These are custom made functions that I programmed for my convenience. What’s this you ask? I can make my own functions. Why yes! You can and let me tell you how…
function wallCheck() {
declaring a function is similar to declaring an if statement. Only instead of being constantly looped through, they happen when you call upon them. This way I don’t have to continuously rewrite the same code over and over again. This is the way I use functions anyways, I we were programming outside of flash this kind of function would be called a void. However if you were to use the command return it would be something else. Void is the title a function gets when it does not return a value. If it returns a number value its an integer, if it returns true or false it’s a boolean, if it returns something that is in the decimals it’s a float, and if it returns a word value like “stuff”, “wordhere”, or “something” then it’s a character.
Page 4 of 6
if (Key.isDown(LeftKey) && jump == false && dash == false && attacking == false && !lefthit == true) {
This is an “if” statement. An if statement is the most essential piece of coding in every logic based code that I know. Simply enough when you are using an if statement you are saying “if this is happening then do this.” An example would be if a bullet hit a man the thing that would happen would be…the bullet would disappear, maybe a blood movie clip would be displayed, his health would be subtracted from, and if his health was below zero (you can have “if” statements inside of “if” statements) then maybe a bool named dead would be given a value of true or the mans movie clip would gotoAndPlay(death animation). Once again “if” statements are crucial if you don’t understand what they are for then please read this again or find some other tutorial to teach you.
Sorry bout this but before we move on I have some more stuff to explain. If you look above to the if statement, then you can see inside the parenthesis (incase you didn’t know this is where the condition for the if statement goes.). All of those are the conditions (if the left arrow key is down and you’re not jumping and your not doing a dash attack and the is not collision detected with the current value of leftwall).Notice the double ampersand between each condition. This is the operator that represents “and”. Other operators that can be used to separate if statement conditions are…
> - greater than
< - less than
== - check to see if is equal to
>= - greater then or equal to
<= - less than or equal to
!= - is not equal to
=== - strictly equal (sorta complex to explain but essentially the same as “==” only the thing its being compared to has to be the same type of variable)
!== - strictly unequal (same as “!=” only it checks the variables type for equality there are booleans, integers, floats, and a lot of other types I really don’t care to know since flash sets the type for you.)
! – not
|| - or
Since all of these can be used in if statements they are also crucial to know (although a lot of them you should have learned in your math class if you were listening)
In this “if” statement, you’ll see everything that’s happening when the character is walking to the left
groundy._x -= runspeed;
I’m moving the ground instead of the man movie clip this way we the land scrolls and we don’t have to worry about the character going off screen.
walking = true;
Walking is true… because you are walking.
if (lefthit == true) {
walking = false;
wallStop();
}
This is the collision system for when you’re walking. It calls on another function that I’ve written called wallStop(). wallStop() is just like the Landing if statement further down only it works for walls (aduh). If the man reaches or passes the walls x then his speed is set to 0 and his x is backed up to where the x started. This way he’s still colliding with the wall and can’t continue in that directs but can back out of it seeing as righthit’s value is still false. This is why it’s crucial that I have right counterpart for every left-based variable.
if (runspeed<=0) {
man.gotoAndStop("walk");
} else if (runspeed>0) {
man.gotoAndStop("skid");
if (righthit == true) {
wallStop();
walking = false;
}
runspeed -= 2;
}
if your skidding you subtract an extra 2 from runspeed. This is also where I put the collision check for skidding so that you cannot skid through walls.
You see here for the first time an else if statement. Just like an if statement only it will only occur if all of its conditions are met and the if statement’s it’s attached to conditions are not met. However since the first if statement in this case condition is runspeed is less than or equal to 0 and the else if statement’s conditions are if runspeed is greater than 0. there should never be a time when the if’s and the else if’s conditions are met at the same time.
if (runspeed>-maxrunspeed) {
runspeed -= 2;
}
This decreases the variable runspeed’s value by 2 so long as runspeed is greater than negative max runspeed. maxrunspeed has to be negative because the man is heading, left and if he was going by being less than positive maxrunspeed like when the man is heading right then there technically wouldn’t be a maxrunspeed because it would always be less.
if (man._xscale>0) {
man._xscale = man._xscale*-1;
}
a new property of movie clips is introduced. _xscale is like the width of an object only put into a percent like form. _xscale always starts at 100 and at -100 the object is completely flipped (facing the opposite direction). This is perfect for making an opposite direction for every animation you’ve made, however maybe it’s a personal glitch of mine or something that happens to everyone using flash but when I try to do this with more than one object then the width of at least one of them goes crazy. So you have to improvise. Since the original direction you are facing when you’re spawned is “right” then the negative version of whatever your _xscale is must be a perfectly flipped version of you movie clip. Therefore when you turning left you first check to see if your movie clips _xscale is not already what you want it somehow using an if statement (I always check if its positive or negative by asking if the xscale is greater or less than 0). And then you multiply it by negative one, swapping it from positive to negative or vice versa.
} else if (Key.isDown(RightKey) && jump == false && dash == false && attacking == false && !righthit == true) {
Same as I did for walking left only with some changes to make it work for moving right and its an else if statement so that you cant walk right and left at the same time.
groundy._x -= runspeed;
Remember that if the man would move to the right if there was not scrolling, then the platform would move to the left if there was. If the ground is moving instead of the movieclip then it moves in the opposite direction.
walking = true;
walking = true if your walking aduh(again)
if (righthit == true) {
walking = false;
wallStop();
}
Page 3 of 6
THIS CODE IS ON THE MAIN TIMELINE IN THE FIRST FRAME
behold my large list of unorganized variables. These are the reason my sources are not for the weak hearted.
if you already know what variables are then move on. If you don’t let me explain. Variables are basically just holders of values. There are several different kinds of variables all of which are determined by the value that the variable has. If the variable’s value is a number then its an int (integer), if it holds quoted material (i.e. myVariable = 20) then it’s a char (character), if the value is a decimal number then its declared a float (float), and finally if it’s a value of true or false then it’s considered a bool (boolean), wait I forgot one if its value is undefined then it’s a void till it’s given a real value (I don’t know if its called a void or an undeclared but there’s a function type called void that isn’t a variable type so I’m just assuming). I’m also not positive of this, but should a variable be declared something at one point in the code and can be declared a value later that is not of the same type as before it will be declared a multiple (I dunno the real name I just call them multiples). A multiple in theory is caused when flash realizes that it can have it’s type changed twice within a reoccurring code. I assume that constantly changing the value type of a variable is taxing on the computers ram (“not noticeably though”) and also many times requires the “===” and “!==” instead of “==” and “!=” to work in if statements correctly (its fickle so I don’t suggest this unless you have a good reason which I have yet to find one). Phew….did I forget anything? Probably, I always do but lets move on. Ooh I just remembered I think since flash 6 both floats and ints are in the number class, they combined em.
maxrunspeed = 26;
the fastest you can run
runspeed = 0;
im using a drift engine so my run speed starts at 0 but if you character only has on speed it should just be the number of how fast your character goes.
jumpHeight = 40;
your initial jump velocity
velocity = 0;
same idea as runspeed
maxVelocity = -20;
same idea as max runspeed
jump = true;
jump is the bool to determine if he’s in the air or not.
man = _root.man;
this is optional, I do this so I don’t have to worry about typing _root before something everytime I want to refer to something on the main timeline. Now I only have to put down man instead of _root man.
LeftKey = Key.LEFT;
RightKey = Key.RIGHT;
JumpKey = Key.UP;
AttackKey = Key.SPACE;
Same idea as man, only if I decide halfway through I don’t like the keys I used for the controls halfway through the production of the game then I can just change these
walking = false;
Sorta self explanatory
dash = false;
I have an attack that I refer to as a dash and need a bool to keep track of whether its happening or not.
attackcounter = 0;
attackcounter is my way of telling the game when the player is done attacking or the attack animation is over. I reset the counter to 0 at the start of every attack. Then in the attacks if statement I have it add 1 to the attackcounter when its value = the number of frames in that attack animation then I declare that the attack is over
white._alpha = 0;
On the stage I have a movie clip called white and im setting its alpha to 0 so everything isn’t white.
man._y = ground;
part of the collision system you saw earlier it just sets his y coordinate to the value of ground.
attacking = false;
attacking tells me whether the character is attacking or not…god you’re dumb;
timer = 5;
a variable that I use to keep track of my delays (more on this later)
groundy = _root.groundy;
I named it groundy because the name ground was already taken by the ground collision variable
groundframe = 1;
lastframe = 3;
these two variables are part of a very effective form of scrolling optimization. All you need to know about these right now is that lastframe is the number of frames inside of the movieclip groundy and that groundframe is the current frame that groundy is set to
rightactive = false;
leftactive = false;
this shows if your within range of any walls
rightwall = undefined;
leftwall = undefined;
these are the wall equivalent of the ground variable I made. They show the x coordinate of the nearest right and left wall or atleast the last one that was active (the last one you were close to).
righthit = false;
lefthit = false;
These are determined by the wallCheck function that I’ve written waaaaay down there. They show whether you are colliding with a wall or not.
widthholder = _root.man._width/2-10;
this variable is equal to half of the man’s width subtract ten.
I’ll get more organized…someday. If I feel like it…moving on
_root.onEnterFrame = function() {
yeah…you know…its like onClipEvent(enterFrame) only different because this code is in a frame and not a movieclip. Because coding in movieclip doesn’t exist outside of flash and I wanna do C++ someday…when I feel like it…
before we move on notice the braces that comes after the string “_root.onEnterFrame.function()” (these are braces {}). Those braces show the beginning and end of statements, loops and so on. So way down at the bottom where you can see the last brace before I state the wallCheck function, that’s where this onEnterFrame function ends. Is this confusing you yet? Too bad because I don’t know how to better explain it.
wallCheck();
a wonderful little function that I made that works just like hitTest…only it detects detects walls and nothing else…and it doesn’t suck.. (btw for those of you who don’t know what hitTest is, it is the built in function to flash that detects a collision between 2 objects. It however is very bad for things like wall collisions and is very taxing on a computers ram. The only good thing about hitTest is that it can detect all of the contours of a shape, but if you want basic box collision you’re better off making your own.)
Page 2 of 6
PLATFORMERS FROM THE GROUND UP
A LITTL…CAUGHT MYSELF THERE, A FRICKIN HUGE TUTORIAL
BY THE MUSICIAN
I dunno why everything that isn’t actionscript is in notation…I just started doing it this way and kept at it.
IF YOU READ ANYTHING READ THIS FIRST
If you have finished algebra 1 then actionscript will be soooooo much easier to get. And if you have finished trigonometry well then the sine cosine and atan commands will be easier to learn (but im not gonna be covering any trig this time)
I had an idea for a tutorial, and was bored enough to do it. I centers on a rather advanced FLA file that I wrote. Or at least a glitchy one from a backup file. I’ve taken the liberty of using the glitchy one from the backup file simply because I’d rather not have someone try (keyword being try) to copy and paste this into the flash action script window. A lot of this code has been modified in word rather than in flash and it’s been broken apart many times so I don’t know if it will work anymore at all in flash. But just because it can’t be read by a computer doesn’t mean it can’t be read by humans (I can’t believe I typed this up). The idea is that I would type notes around the source code that were so dumbed down a n00b could understand it. And when I say n00b I mean n00b to actionscript not flash. If you don’t know how to do the visual bits of flash then it will be difficult to understand what I’m talking about even with a coding background. That all typed, if you don’t know the basic timeline control commands then the following content explains them. Otherwise you should skip it or have your intelligence insulted. ONCE AGAIN this code is fricked up from being edited outside of flash. If you find an error whoop dee frickin doo you can post it but don’t be surprised if I reply by repeating this to you unless of course you solve a real glitch that I havn’t found yet in the collision code that makes it so that hits to a wall to the left of you are not detected. Also I may typo once or twice during this…freaking large tutorial, please understand that you’d be brain-dead too if you’d been typing this all day.
If anyone learns anything from this please say so, it would be nice to know I didn’t waste a day of my life for nothing.
ESSENTIAL ACTIONSCRIPT FOR THE COMPLETE N00B
Not everything I’ve listed here is relevant to this tutorial but you might as well learn it now.
stop(); – what do you think it does…CMON!...it pauses whichever timeline you specify (i.e. _root. stop(); to stop the main timeline. I f you don’t specify which timeline then it assumes you are referring to the timeline of the frame or movie clip it’s posted in.
play(); - just like stop only the opposite…did that make sense?
gotoAndStop(); - like stop() only it goes somewhere first…infact it’s pretty self explanatory doncha think.
gotoAndPlay(); - like play() only goes somewhere first… ALSO very self explanatory.
nextFrame(); - move to the next frame
nextScene(); - move to the next scene
prevFrame(); - move to the previous frame
prevScene(); - If I need to explain this then you have no business reading this tutorial…or being alive.
_root. - putting this in front of an instance will tell the game to look for it on the main timeline as opposed to some timeline inside of a movieclip. You don’t have to this all the time if you create a variable for you mc like MC = _root.MC.
._x - the x coordinate of an MC or a button (I dunno about graphics)
._y – ditto only for going up and down rather than left and right. Also not that the greater the y coordinate the lower you go and the lower the y coordinate the higher you go.
._alpha – how see-through an object is for lack of a better term. Its also refered to as opacity in photoshop if that rings a bell. Will return a value and value can be set to between 1 and 100 (if its over 100 then its auto set to one hundred and vice versa for less than 0)
THIS CODE IS IN THE PLATFORMS
I would like to note that this can be used for a tile based system as well with a little tweaking and ingenuity. However im too lazy to do that for you and I still don’t fully understand everything about TBG’s.
onClipEvent (enterFrame) {
leeway = 10;
leeway2 = 30;
leeway3 = 10;
leeway is different for each platform it shows it’s detect ranges. In the if statements below the conditions depend on these variables to make a radar range. (Just try and understand that this is crucial for my form of ground collision).
grip = false;
you can’t grab on to the top of this platform. The code to allow you to grip onto a platform (like if you fall off you can catch yourself) was uncomplete at this time.
walljump = true;
you can jump off the side of this. The wall jump code wasn’t complete at this time
sideA = this._x+_root.groundy._x;
sideB = this._x+this._width+_root.groundy._x;
groundTop = this._y+_root.groundy._y;
measures the coordinates and values of the platform it’s in
if (_root.man._x>sideA && _root.man._x<sideB && _root.man._y<groundTop+leeway && _root.man._y>groundTop-leeway/2) {
_root.ground = groundTop;
}
This is the code for ground collision, if the man is within the platforms detect range then the y coordinate of the top of this platform becomes the value of the variable ground which is in the code on the main timeline. In the main timeline there is a line of code defining landing as if the character’s y is greater than the ground’s value (y coordinates are the reverse of x coordinates, if you raise an object y coordinate it goes down instead of up.), then it will set the mans y to ground’s value. The detect range for the ground collision is determined by the variable “leeway 1”
if (_root.man._x+_root.widthholder>sideA-leew
ay2/2 && _root.man._x+_root.widthholder<sideA+leewa
y2 && _root.man._y>groundTop+leeway3) {
rightactive = true;
_root.rightwall = sideA;
} else {
rightactive = false;
}
if (_root.man._x-_root.widthholder<sideB+leew
ay2/2 && _root.man._x-_root.widthholder>sideB-leewa
y2 && _root.man._y>groundTop+leeway3) {
leftactive = true;
_root.leftwall = sideB;
} else {
leftactive = false;
}
}
This code is for wall collision. In concept it’s as simple as doing y axis collisions. However since there are 2 directions, things get complicated quickly.
I'm reposting so that I can remove the constant // do not post until all 6 pages are posted
wallStop();
//I call once again on my wallStop function again since it also has code to turn jump speed to zero along //with run speed. (My wallStop function PWNS XD).
if (velocity>maxVelocity) {
velocity -= 10;
}
//it will subtract a certain amount from the velocity. Some people like to have a variable called gravity //which is subtracted from velocity at this point, but I think that’s sort of pointless since I’d only be using it //once and I have like, 20 variables already…wait, do I have 20 variables…I know I have a lot but I’m too //lazy to count them.
if (velocity>=0) {
man.gotoAndStop("jump");
} else if (velocity<0) {
man.gotoAndStop("fall");
}
}
//And at the end a small bit of code to determine whether to play the jump or fall animation based on the //velocity. You don’t have to have a fall animation (you can get away with only having one for jump). But //I think it makes it look better for some reason.
if (man._y>ground && groundy.hitTest(man._x, man._y, true) && jump == true) {
man._y = ground;
jump = false;
if (runspeed != 0) {
man.gotoAndStop("walk");
} else {
man.gotoAndStop("stand");
}
}
//This bit of code governs the landing sequence (the sequence that lets the movie clip that it’s landed and //can stop falling but hopefully you already got that). Again I use hitTest as a backup because you can land //if you’re not hitting anything. And lastly I put some animation control code to set it to walk or run //depending on the jump speed upon landing because the animations were glitching quite a lot while the //man movie clip was landing for reasons unknown.
if (dash == false && jump == false && walking == true && Key.isDown(AttackKey) && (runspeed>=maxrunspeed || runspeed<=-maxrunspeed)) {
//This is like the initial jump and fall sequences only for the dash attack. Take note that you must be at full //speed to use the attack.
dash = true;
dashspeed = runspeed;
walking = false;
//tells the game that you are using the dash attack, that dashspeed is equal to runspeed, and that since //obviously since you need to be at full speed to use the attack you are most likely walking.
} else if (dash == true) {
//the dash sequence
man.gotoAndStop("dash");
//play the dash animation
if (dashspeed<0) {
dashspeed += 2;
} else if (dashspeed>0) {
dashspeed -= 2;
}
//this is basically the same as the other if statement waaaaaaay up at the top that lowers the runspeed if //you’re not running. Also if you look at that if statement you will see that one of its conditions is not if //dash == false. That is simply so that while this attack is occurring, your runspeed will be reset to 0. This //makes perfect sense seeing as you will be exiting the attack with a dashspeed of zero and it would look //stupid if you went from standing still to running full speed 26 pixels a frame. When making a game //always look for ways of changing your old if statements or variables to fit the need of the program before //creating new ones (admittedly I didn’t follow that rule very well with this game but do as I say not as I //do!).
groundy._x -= dashspeed;
//sorta like every other thing we’ve done you’re moving the character in some direction at some speed. Or //I guess the ground this time since, I’m doing scrolling
if (dashspeed<3 && dashspeed>-3) {
dashspeed = 0;
dash = false;
}
//Like that if statement at the beginning that sets the runspeed to zero if its in between 2 numbers, this if //statement ends the dash attack.
} else if (attacking == false && timer<=0 && Key.isDown(AttackKey) && jump == false) {
if (runspeed<maxrunspeed || runspeed>-maxrunspeed) {
attacking = true;
walking = false;
man.gotoAndPlay("slash");
attackcounter = 0;
}
}
//another initial sequence only this time for the normal ground attack…BUT WAIT! Whats this? It requires //the variable timer to be less than or equal to 0 (really it just has to be 0 but I set it like that as a precaution //if for some extremely complicated and technical reason it jumps over 0 and into the negatives).Why have //I done this? Simple! To delay the character from attacking at hyper fast rate. Making him wait for a split //second or 2 so that the speed of the characters swings don’t look
if (attacking == true) {
attackcounter++;
if (attackcounter>=5) {
attacking = false;
timer = 5;
}
}
//the attack sequence uses a counter to count up to 5 (5 being the number of frames in the attack animation) //and then ending the attack sequence while setting the variable timer to 5 so that the if statement I showed //you earlier will take effect and start subtracting from it. When the timer reaches 0 you’ll be able to attack //again. This way the loop of attacking not attacking will be delayed and won’t look like attacking, //attacking, still attacking, I must have some violent media influence, attacking, and attacking.
};
//if a braces is followed by a semi-colon then it usually means that you’re ending a clip event function like //the onEnterFrame function that I stated at the waaaaay beginning. Why do braces that end clip events //have semi-colons after them….nobody knows…well actually its more like nobody cares. Below are the //two functions that you saw me use before in the code. Before some n00b asks, let me say than “No” these //functions are not programmed into flash like hitTest(). These are custom made functions that I //programmed for my convenience. What’s this you ask? I can make my own functions. Why yes! You //can and let me tell you how…
function wallCheck() {
declaring a function is similar to declaring an if statement. Only instead of being constantly looped //through, they happen when you call upon them. This way I don’t have to continuously rewrite the same code over and over again. This is the way I use functions anyways, I we were programming outside of //flash this kind of function would be called a void. However if you were to use the command return it would be something else. Void is the title a function gets when it does not return a value. If it returns a //number value its an integer, if it returns true or false it’s a boolean, if it returns something that is in the //decimals it’s a float, and if it returns a word value like “stuff”, “wordhere”, or “something” then it’s a character. (still more to come)
if (Key.isDown(LeftKey) && jump == false && dash == false && attacking == false && !lefthit == true) {
//This is an “if” statement. An if statement is the most essential piece of coding in every logic based code //that I know. Simply enough when you are using an if statement you are saying “if this is happening then //do this.” An example would be if a bullet hit a man the thing that would happen would be…the bullet //would disappear, maybe a blood movie clip would be displayed, his health would be subtracted from, and //if his health was below zero (you can have “if” statements inside of “if” statements) then maybe a bool //named dead would be given a value of true or the mans movie clip would gotoAndPlay(death animation). //Once again “if” statements are crucial if you don’t understand what they are for then please read this //again or find some other tutorial to teach you.
//Sorry bout this but before we move on I have some more stuff to explain. If you look above to the if //statement, then you can see inside the parenthesis (incase you didn’t know this is where the condition for //the if statement goes.). All of those are the conditions (if the left arrow key is down and you’re not //jumping and your not doing a dash attack and the is not collision detected with the current value of //leftwall).Notice the double ampersand between each condition. This is the operator that represents “and”. //Other operators that can be used to separate if statement conditions are…
//> - greater than
//< - less than
//== - check to see if is equal to
//>= - greater then or equal to
//<= - less than or equal to
//!= - is not equal to
//=== - strictly equal (sorta complex to explain but essentially the same as “==” only the thing its being //compared to has to be the same type of variable)
//!== - strictly unequal (same as “!=” only it checks the variables type for equality there are booleans, //integers, floats, and a lot of other types I really don’t care to know since flash sets the type for you.)
//! – not
//|| - or
//Since all of these can be used in if statements they are also crucial to know (although a lot of them you //should have learned in your math class if you were listening)
//In this “if” statement, you’ll see everything that’s happening when the character is walking to the left
groundy._x -= runspeed;
//I’m moving the ground instead of the man movie clip this way we the land scrolls and we don’t have to //worry about the character going off screen.
walking = true;
//Walking is true… because you are walking.
if (lefthit == true) {
walking = false;
wallStop();
}
//This is the collision system for when you’re walking. It calls on another function that I’ve written called //wallStop(). wallStop() is just like the Landing if statement further down only it works for walls (aduh). If //the man reaches or passes the walls x then his speed is set to 0 and his x is backed up to where the x //started. This way he’s still colliding with the wall and can’t continue in that directs but can back out of it //seeing as righthit’s value is still false. This is why it’s crucial that I have right counterpart for every left-//based variable.
if (runspeed<=0) {
man.gotoAndStop("walk");
} else if (runspeed>0) {
man.gotoAndStop("skid");
if (righthit == true) {
wallStop();
walking = false;
}
runspeed -= 2;
}
//if your skidding you subtract an extra 2 from runspeed. This is also where I put the collision check for //skidding so that you cannot skid through walls.
//You see here for the first time an else if statement. Just like an if statement only it will only occur if all of //its conditions are met and the if statement’s it’s attached to conditions are not met. However since the first //if statement in this case condition is runspeed is less than or equal to 0 and the else if statement’s //conditions are if runspeed is greater than 0. there should never be a time when the if’s and the else if’s //conditions are met at the same time.
if (runspeed>-maxrunspeed) {
runspeed -= 2;
}
//This decreases the variable runspeed’s value by 2 so long as runspeed is greater than negative max //runspeed. maxrunspeed has to be negative because the man is heading, left and if he was going by being //less than positive maxrunspeed like when the man is heading right then there technically wouldn’t be a //maxrunspeed because it would always be less.
if (man._xscale>0) {
man._xscale = man._xscale*-1;
}
//a new property of movie clips is introduced. _xscale is like the width of an object only put into a percent //like form. _xscale always starts at 100 and at -100 the object is completely flipped (facing the opposite //direction). This is perfect for making an opposite direction for every animation you’ve made, however //maybe it’s a personal glitch of mine or something that happens to everyone using flash but when I try to //do this with more than one object then the width of at least one of them goes crazy. So you have to //improvise. Since the original direction you are facing when you’re spawned is “right” then the negative //version of whatever your _xscale is must be a perfectly flipped version of you movie clip. Therefore //when you turning left you first check to see if your movie clips _xscale is not already what you want it //somehow using an if statement (I always check if its positive or negative by asking if the xscale is greater //or less than 0). And then you multiply it by negative one, swapping it from positive to negative or vice //versa.
} else if (Key.isDown(RightKey) && jump == false && dash == false && attacking == false && !righthit == true) {
//Same as I did for walking left only with some changes to make it work for moving right and its an else if //statement so that you cant walk right and left at the same time.
groundy._x -= runspeed;
//Remember that if the man would move to the right if there was not scrolling, then the platform would //move to the left if there was. If the ground is moving instead of the movieclip then it moves in the //opposite direction.
walking = true;
//walking = true if your walking aduh(again)
if (righthit == true) {
walking = false;
wallStop();
}
PLEASE DONT POST ANYMORE THIS WHOLE FRICKING THING IS 15 PAGES LONG IN WORD WHEN SET TO THE FONT SIZE OF 10
THIS CODE IS ON THE MAIN TIMELINE IN THE FIRST FRAME
behold my large list of unorganized variables. These are the reason my sources are not for the weak hearted.
if you already know what variables are then move on. If you don’t let me explain. Variables are //basically just holders of values. There are several different kinds of variables all of which are determined //by the value that the variable has. If the variable’s value is a number then its an int (integer), if it holds //quoted material (i.e. myVariable = 20) then it’s a char (character), if the value is a decimal number then //its declared a float (float), and finally if it’s a value of true or false then it’s considered a bool (boolean), //wait I forgot one if its value is undefined then it’s a void till it’s given a real value (I don’t know if its //called a void or an undeclared but there’s a function type called void that isn’t a variable type so I’m just //assuming). I’m also not positive of this, but should a variable be declared something at one point in the //code and can be declared a value later that is not of the same type as before it will be declared a multiple //(I dunno the real name I just call them multiples). A multiple in theory is caused when flash realizes that it //can have it’s type changed twice within a reoccurring code. I assume that constantly changing the value //type of a variable is taxing on the computers ram (“not noticeably though”) and also many times requires //the “===” and “!==” instead of “==” and “!=” to work in if statements correctly (its fickle so I don’t //suggest this unless you have a good reason which I have yet to find one). Phew….did I forget anything? //Probably, I always do but lets move on. Ooh I just remembered I think since flash 6 both floats and ints //are in the number class, they combined em.
maxrunspeed = 26;
the fastest you can run
runspeed = 0;
im using a drift engine so my run speed starts at 0 but if you character only has on speed it should just be the number of how fast your character goes.
jumpHeight = 40;
your initial jump velocity
velocity = 0;
same idea as runspeed
maxVelocity = -20;
same idea as max runspeed
jump = true;
jump is the bool to determine if he’s in the air or not.
man = _root.man;
this is optional, I do this so I don’t have to worry about typing _root before something everytime I want //to refer to something on the main timeline. Now I only have to put down man instead of _root man.
LeftKey = Key.LEFT;
RightKey = Key.RIGHT;
JumpKey = Key.UP;
AttackKey = Key.SPACE;
Same idea as man, only if I decide halfway through I don’t like the keys I used for the controls halfway //through the production of the game then I can just change these
walking = false;
Sorta self explanatory
dash = false;
I have an attack that I refer to as a dash and need a bool to keep track of whether its happening or not.
attackcounter = 0;
attackcounter is my way of telling the game when the player is done attacking or the attack animation is over. I reset the counter to 0 at the start of every attack. Then in the attacks if statement I have it add 1 to the attackcounter when its value = the number of frames in that attack animation then I declare that the attack is over
white._alpha = 0;
On the stage I have a movie clip called white and im setting its alpha to 0 so everything isn’t white.
man._y = ground;
part of the collision system you saw earlier it just sets his y coordinate to the value of ground.
attacking = false;
attacking tells me whether the character is attacking or not…god you’re dumb;
timer = 5;
a variable that I use to keep track of my delays (more on this later)
groundy = _root.groundy;
I named it groundy because the name ground was already taken by the ground collision variable
groundframe = 1;
lastframe = 3;
these two variables are part of a very effective form of scrolling optimization. All you need to know about these right now is that lastframe is the number of frames inside of the movieclip groundy and that groundframe is the current frame that groundy is set to
rightactive = false;
leftactive = false;
this shows if your within range of any walls
rightwall = undefined;
leftwall = undefined;
these are the wall equivalent of the ground variable I made. They show the x coordinate of the nearest //right and left wall or atleast the last one that was active (the last one you were close to).
righthit = false;
lefthit = false;
//These are determined by the wallCheck function that I’ve written waaaaay down there. They show //whether you are colliding with a wall or not.
widthholder = _root.man._width/2-10;
//this variable is equal to half of the man’s width subtract ten.
//I’ll get more organized…someday. If I feel like it…moving on
_root.onEnterFrame = function() {
yeah…you know…its like onClipEvent(enterFrame) only different because this code is in a frame and not //a movieclip. Because coding in movieclip doesn’t exist outside of flash and I wanna do C++ someday…when I feel like it…
//before we move on notice the braces that comes after the string “_root.onEnterFrame.function()” (these are braces {}). Those braces show the beginning and end of statements, loops and so on. So way down at the bottom where you can see the last brace before I state the wallCheck function, that’s where this onEnterFrame function ends. Is this confusing you yet? Too bad because I don’t know how to better explain it.
wallCheck();
a wonderful little function that I made that works just like hitTest…only it detects detects walls and nothing else…and it doesn’t suck.. (btw for those of you who don’t know what hitTest is, it is the built in function to flash that detects a collision between 2 objects. It however is very bad for things like wall collisions and is very taxing on a computers ram. The only good thing about hitTest is that it can detect all of the contours of a shape, but if you want basic box collision you’re better off making your own.)
//PLATFORMERS FROM THE GROUND UP
//A LITTL…CAUGHT MYSELF THERE, A FRICKIN HUGE TUTORIAL
//BY THE MUSICIAN
//I dunno why everything that isn’t actionscript is in notation…I just started doing it this way and kept at it.
//IF YOU READ ANYTHING READ THIS FIRST
//If you have finished algebra 1 then actionscript will be soooooo much easier to get. And if you have //finished trigonometry well then the sine cosine and atan commands will be easier to learn (but im not gonna be //covering any trig this time)
//I had an idea for a tutorial, and was bored enough to do it. I centers on a rather advanced FLA file that I //wrote. Or at least a glitchy one from a backup file. I’ve taken the liberty of using the glitchy one from the //backup file simply because I’d rather not have someone try (keyword being try) to copy and paste this //into the flash action script window. A lot of this code has been modified in word rather than in flash and //it’s been broken apart many times so I don’t know if it will work anymore at all in flash. But just because //it can’t be read by a computer doesn’t mean it can’t be read by humans (I can’t believe I typed this up). //The idea is that I would type notes around the source code that were so dumbed down a n00b could //understand it. And when I say n00b I mean n00b to actionscript not flash. If you don’t know how to do //the visual bits of flash then it will be difficult to understand what I’m talking about even with a coding //background. That all typed, if you don’t know the basic timeline control commands then the following //content explains them. Otherwise you should skip it or have your intelligence insulted. ONCE AGAIN //this code is fricked up from being edited outside of flash. If you find an error whoop dee frickin doo you //can post it but don’t be surprised if I reply by repeating this to you unless of course you solve a real glitch //that I havn’t found yet in the collision code that makes it so that hits to a wall to the left of you are not //detected. Also I may typo once or twice during this…freaking large tutorial, please understand that you’d //be brain-dead too if you’d been typing this all day.
//If anyone learns anything from this please say so, it would be nice to know I didn’t waste a day of my life //for nothing.
//ESSENTIAL ACTIONSCRIPT FOR THE COMPLETE N00B
//Not everything I’ve listed here is relevant to this tutorial but you might as well learn it now.
//stop(); – what do you think it does…CMON!...it pauses whichever timeline you specify (i.e. _root. stop(); //to stop the main timeline. I f you don’t specify which timeline then it assumes you are referring to the //timeline of the frame or movie clip it’s posted in.
//play(); - just like stop only the opposite…did that make sense?
//gotoAndStop(); - like stop() only it goes somewhere first…infact it’s pretty self explanatory doncha think.
//gotoAndPlay(); - like play() only goes somewhere first… ALSO very self explanatory.
//nextFrame(); - move to the next frame
//nextScene(); - move to the next scene
//prevFrame(); - move to the previous frame
//prevScene(); - If I need to explain this then you have no business reading this tutorial…or being alive.
//_root. - putting this in front of an instance will tell the game to look for it on the main timeline as opposed to some timeline inside of a movieclip. You don’t have to this all the time if you create a variable for you mc like MC = _root.MC.
//._x - the x coordinate of an MC or a button (I dunno about graphics)
//._y – ditto only for going up and down rather than left and right. Also not that the greater the y coordinate the lower you go and the lower the y coordinate the higher you go.
//._alpha – how see-through an object is for lack of a better term. Its also refered to as opacity in photoshop if that rings a bell. Will return a value and value can be set to between 1 and 100 (if its over 100 then its auto set to one hundred and vice versa for less than 0)
//THIS CODE IS IN THE PLATFORMS
//I would like to note that this can be used for a tile based system as well with a little tweaking and //ingenuity. However im too lazy to do that for you and I still don’t fully understand everything about //TBG’s.
onClipEvent (enterFrame) {
leeway = 10;
leeway2 = 30;
leeway3 = 10;
//leeway is different for each platform it shows it’s detect ranges. In the if statements below the conditions //depend on these variables to make a radar range. (Just try and understand that this is crucial for my form of ground collision).
grip = false;
//you can’t grab on to the top of this platform. The code to allow you to grip onto a platform (like if you fall //off you can catch yourself) was uncomplete at this time.
walljump = true;
//you can jump off the side of this. The wall jump code wasn’t complete at this time
sideA = this._x+_root.groundy._x;
sideB = this._x+this._width+_root.groundy._x;
groundTop = this._y+_root.groundy._y;
//measures the coordinates and values of the platform it’s in
if (_root.man._x>sideA && _root.man._x<sideB && _root.man._y<groundTop+leeway && _root.man._y>groundTop-leeway/2) {
_root.ground = groundTop;
}
//This is the code for ground collision, if the man is within the platforms detect range then the y coordinate //of the top of this platform becomes the value of the variable ground which is in the code on the main //timeline. In the main timeline there is a line of code defining landing as if the character’s y is greater than //the ground’s value (y coordinates are the reverse of x coordinates, if you raise an object y coordinate it //goes down instead of up.), then it will set the mans y to ground’s value. The detect range for the ground //collision is determined by the variable “leeway 1”
if (_root.man._x+_root.widthholder>sideA-leew
ay2/2 && _root.man._x+_root.widthholder<sideA+leewa
y2 && _root.man._y>groundTop+leeway3) {
rightactive = true;
_root.rightwall = sideA;
} else {
rightactive = false;
}
if (_root.man._x-_root.widthholder<sideB+leew
ay2/2 && _root.man._x-_root.widthholder>sideB-leewa
y2 && _root.man._y>groundTop+leeway3) {
leftactive = true;
_root.leftwall = sideB;
} else {
leftactive = false;
}
}
This code is for wall collision. In concept it’s as simple as doing y axis collisions. However since there are 2 directions, things get complicated quickly.
At 8/17/05 09:20 PM, PillowBiter wrote: Buddy... "might offer cash prizes"? You're going to need a better draw than that if you want to attract real submissions. I, among many other artists, submit to Newgrounds for the exposure to a huge community. Why would I submit my hard work to create traffic for a tiny site bogged down with uncomfortable advertisments? There is no gain for me. If there was cash invovled, I'm sure you would get some submissions but I would hope that nobody gives tehir hard work up for nothing.
hey you never know, if enough people submit games to a small site then it picks up traffic then your games are going to get alot more exposure then before. so its sorta like an investment I guess. the stock market work similarly and it's in the toilet right now... Alright bad example. Anyways, on a personal note I'm surprised half your submissions even made it through the portal (they dont look like they had alot of "hard work" in them).
use the equation 100/z then have the scale, speed and coordinate of the object depend on that. naturally you have to do with statements for every 3d object with a z coordinate. Theres more than that but I can't remember (I havn't tried it yet).
I've been working on this wierd drift platform engine for a day or 2 now. Since its only an engine right now it does not have alot of art (only basics). it currently lacks length, several moves, a background, enemies and so on. I want to know if I finish this will it make it through the portal atleast.
arrow keys to move and jump and space to attack
if youre running at full speed you can dash attack which along with being a good attack can get you across gaps too large to jump.
The controls take some time to get used to.
k then I guess I'll make it into a game if its good then.
I tried alot of framerates but im gonna stick with this speed. it doesn't look too riduculous

