View Full Version : Platformer physics - hitTests + Gravity
Sammo
December 7th, 2004, 01:55 PM
Hey, I figured this would be a popular subject, so i did search the forums, but didn't find anything relevent to my point. Whether I can search correctly, I'm sure i'll be corrected on :P
Anyway, I'm a novice at AS, but I want to create a platformer (don't worry! I'm not going to ask you lot to do it!), just for fun + practice. It'll be Mario-esque, just for the lack of creativity needed to create it. :P
I can handle all the controls and DuplicateMovieClip() etc. It's the hitTest + gravity i'm worried about. Here is an example of my hitTests:
onClipEvent (load) {
speed = 5;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
_x -= speed;
}
if (this.hitTest(_root.wall_left)) {
_x += speed;
}
if (Key.isDown(Key.RIGHT)) {
_x += speed;
}
if (this.hitTest(_root.wall_right)) {
_x -= speed;
}
if (Key.isDown(Key.UP)) {
_y -= speed;
}
if (this.hitTest(_root.wall_up)) {
_y += speed;
}
if (Key.isDown(Key.DOWN)) {
_y += speed;
}
if (this.hitTest(_root.wall_down)) {
_y -= speed;
}
}
/*wall_up,down,left,right are instance names of a
movieclip called wall which is on the stage 4 times.
Boundries, wall_up at the top of the stage, etc.*/
Which is all very simple, but it works, so it's been fine for me.
When I introduce gravity (which I need help with, but will get onto in a moment), The character won't fall with an even pace, so i wont be able to counter the speed as I have done in the code above.
Is there a more technical way of using hitTests to stop a character?
And how would I implement gravity (I have searched and read the forums, and read Poms tutorial but im still not sure) into a game, such as a 2D platformer?
JoMan
December 7th, 2004, 02:05 PM
I taught some people how to make a platform game a while back:
http://www.kirupaforum.com/forums/showthread.php?t=69442
It's outdated (cause I no longer use onClipEvents handlers), but it might help. Also, I use this ActionScript for the proper ground setting:
function collision() {
with (hero) {
if (limits.hitTest(_x-8, _y-30, true)) {
_x+=3;
} else if (limits.hitTest(_x+8, _y-30, true)) {
_x-=3;
}
if (limits.hitTest(_x-6, _y+5, true) and (jumpPower<=1)) {
_y-= jumpPower;
}
}
}
I hope that I have helped you :).
P.S. You should go to www.gotoAndPlay.it, and look at some of the hitTest articles that they have there.
peace
Sammo
December 8th, 2004, 04:31 PM
Thanks JoMan I'm reading some articles now. But I still don't get the whole hitTest thing.
I mean, for all the hitTest examples I've seen they are countering the speed for eg:
if (Key.isDown (Key.UP)) {
this._y -= 5;
}
if (hitTest(whatever_mc)) {
this._y += 5;
}
Right?
But when gravity is involved his falling speed is always raising. So how do you stop him when you can't be sure on his final impact speed?
JoMan
December 8th, 2004, 06:22 PM
Oh, here is the ground ActionScript that I forgot to put with the other code:
for (i=1; i<=50; i++) {
if (!limits.hitTest(_x, _y-i, true) and (jumpPower<=1)) {
_y -= i-3;
break;
} else if (limits.hitTest(_x, _y-i, true) and (jumpPower<=1)) {
jumping = 0;
}
}
It will set the movieClip at the propper ground position once he makes contact with the limits. Also, the basic code:
if (limits.hitTest(_x, _y, true)) {
// resistance
}
can determine the x or y collision depending on the x or y property that you state, and it can also be determined by resistance, whether its x resistance, or y resistance. I hope I'm not confusing you; If so, tell me.
peace
Sammo
December 9th, 2004, 12:57 PM
Sorry, can you explain what that code actually means?
JoMan
December 9th, 2004, 01:52 PM
Ok, sure :). First, what we have, is the:
for (i=1; i<=50; i++) {
The 'i' will become our resistance and propper ground setting. Now, when we add:
if (!limits.hitTest(_x, _y-i, true) and (jumpPower<=1)) {
_y -= i-3;
break;
This simply states that if the ground is not being touched (the '!' declares a negotive response), then the movieClip will slowly fall. The falling will not be a part of the gravity, but it is needed for the propper ground collision (instead of the movieClip landing above or in the ground :crazy: ). Please reply for the next part.
peace
Sammo
December 9th, 2004, 02:02 PM
Yup got that, is limits a variable you defined in some other place?
Inferno
December 9th, 2004, 02:18 PM
cool new avatar joman :)
JoMan
December 9th, 2004, 03:12 PM
cool new avatar joman :)
thanks :).
JoMan
December 9th, 2004, 03:13 PM
Yup got that, is limits a variable you defined in some other place?
No, 'limis' is the name of my terrain (ground) movieClip.
Sammo
December 9th, 2004, 06:22 PM
Okay, thanks for this joMan. :)
Think you could go on with the code?
JoMan
December 9th, 2004, 07:42 PM
Okay, thanks for this joMan. :)
Think you could go on with the code?
Sure, but it will have to wait until 10:00 tonight, because I have a fencing class... ENGARDE! Seeya then!
peace
JoMan
December 9th, 2004, 11:55 PM
Ok, I'm back! Sorry for the delay. Ok, so now to declare the actual collision:
} else if (limits.hitTest(_x, _y-i, true) and (jumpPower<=1)) {
jumpPower = 0;
fallSpeed = 0;
}
}
}
}
Now, for my game, the jumpPower is the ammount of -well- jump power and the fallSpeed is the ammount of falling speed, so I declared -in this code- that both speeds will be set back to zero. Pretty basic stuff. Reply when you read this.
peace
Sammo
December 10th, 2004, 12:42 PM
Yo, that's ok...I think...
So would I do:
onClipEvent (enterFrame) {
if (Key.isDown (Key.UP)) {
jumpPower = 10;
}
}
If yes, how and why?
If no, how would I do it?
JoMan
December 10th, 2004, 01:39 PM
Well, the jumping code will go like this:
function mcJump() { // or an onClipEvent handler, depending on type of programming
if (Key.isDown(Key.UP) and (!jumping)) { // if the UP key is being pressed, and jumping is false
jumpPower = 15;
jumping = true;
}
if (jumping) { // if jumping is true
jumpPower--;
if (jumpPower>=15) { // if jumpPower is more than 15
jumpPower = -15;
}
mc._y -= jumpPower;
}
}
And in the ground collision code, just state that jumping is 'false', and jumpPower is set to '0'. Please reply when you read this.
peace
Danko
December 10th, 2004, 05:34 PM
Check this out! Excellent tutorial:
http://www.tonypa.pri.ee/tbw/index.html
JoMan
December 10th, 2004, 05:59 PM
Check this out! Excellent tutorial:
http://www.tonypa.pri.ee/tbw/index.html
Yes, I have seen that, but it's tilebased, and tilebased is outdated. (although, that site has definitely got some good tutorials :)).
Sammo
December 10th, 2004, 06:18 PM
Okay
so we have a ground, and a jump. What about a platform that you can stand on, and can also jump from underneath it to land on top?
You don't have to do this joMan, but I really appreciate it :)
JoMan
December 10th, 2004, 09:10 PM
It's no problem at all :). Okay, to make a platform like the one that you described, can be done simply by removing a former code of ours, so the one we remove, is the upper limit code, or 'cieling' code:
if (limits.hitTest(_x, _y+5, true) and (jumpPower<=1)) {
_y-= jumpPower;
}
Now the platform should do as you wanted it to do. Please reply when you read this.
P.S. I can also send you my fla if you want.
peace
Sammo
December 11th, 2004, 04:21 AM
It's no problem at all :). Okay, to make a platform like the one that you described, can be done simply by removing a former code of ours, so the one we remove, is the upper limit code, or 'cieling' code: Ok...
I'm a little confuddled by that last post...sorry http://kirupaforum.com/forums/images/smilies/depressed.gif
JoMan
December 11th, 2004, 03:51 PM
Hi,
Oh, that's ok, I kinda thought that you would. Ok, originally we had the wall and upper limits(or cieling) code:
function collision() {
with (hero) {
if (limits.hitTest(_x-8, _y-30, true)) { // right wall code
_x+=3;
} else if (limits.hitTest(_x+8, _y-30, true)) { // left wall code
_x-=3;
}
if (limits.hitTest(_x, _y+5, true)) { // upper limit code
jumpPower = 0;
}
}
}
Right? Well, all you need to do is remove the upper limit code, which will create the platform that you want.
P.S. Maybe I should teach you how to make a platform game from scratch?
peace
Sammo
December 11th, 2004, 06:16 PM
P.S. Maybe I should teach you how to make a platform game from scratch?
joMan that would be great, but you really don't have to...
JoMan
December 11th, 2004, 06:47 PM
It's ok, I love teaching :D! Later(about 5:00), I will start teaching you the how to make a Platform game, Ok?
Sammo
December 11th, 2004, 07:46 PM
Thank you so much!
JoMan
December 11th, 2004, 08:07 PM
Your welcome :). One minute, post coming..
JoMan
December 11th, 2004, 08:24 PM
Ok, let's start, shall we? First, add four layers to the timeline so that you will have a total of five layers, and name them -top to bottom- in this order: ACTIONS, SOUND, hero, limits, bg(or backGround). Now we need to create two movieClips. The first should be your character, which will contain the walking and jumping animations; name it 'hero' and place it in the 'hero' layer. The second, should be the limits for the ground collision which should be named 'limits' and should be placed in the 'limits' layer.
P.S. I will need your email so I can send you the fla for this section of the lesson.
Sammo
December 11th, 2004, 08:57 PM
Okay, I'm sorry, it's 1 am in England, so i'm going to bed, I'll start it tomorrow
email is cannedlaughter@gmail.com
and by limits do you mean a mc of the ground?
JoMan
December 11th, 2004, 09:00 PM
Okay, I'm sorry, it's 1 am in England, so i'm going to bed, I'll start it tomorrow
Wow, it's 7:07 p.m. here! Goddnight!
and by limits do you mean a mc of the ground?
Yes, the limits movieClip will be the ground and walls.
Sammo
December 12th, 2004, 05:28 AM
Okay I'm done. Just on your fla, how did you get the limits to not show up...
I can't work it out.
To anyone who's reading this, I will upload the .fla's from each lesson
first one: here (http://kesou.com/lesson1.zip)
JoMan
December 12th, 2004, 09:59 AM
Oh, sorry about that. Okay, select the limits and open it's properties. There should be a dropdown menu inside; open it and select alpha and change the alpha to 0%. That should make the limits invisible. Please reply when you read this.
Sammo
December 12th, 2004, 11:07 AM
Okay joMan, I'm at your fla's stage now :)
I'm usng Mario sprites, kay?
JoMan
December 12th, 2004, 02:41 PM
Ok, good :D. Now, that is what we need to program this little game, so now select the frame in the SCRIPT layer, open the actions panel, and type the following:
startGame(); // this declares the startGame function
stop(); // this stops the frames from playing unnecessarely
function startGame() {
_quality = "low"; // this sets the game quality at low (for a super nintedo look)
started = true; // started variable is declared 'true'
walking = true; // walking variable is declared 'true'
key.onKeyUp = keyRelease; // this declares a key release function
Key.addListener(key);
fscommand("allowscale", true); // this will set the game at a full screen
_root.onEnterFrame = moveHero; // this declares the movement function
}
Not too difficult, right? let's see...
The:
started = true;
walking = true;
Are very important, and will be used in the moveHero function. The:
key.onKeyUp = keyRelease;
Key.addListener(key);
Will set the stage for a key release function for when the 'RIGHT' and 'LEFT' keys are released. And finally, the:
_root.onEnterFrame = moveHero;
Will declare the 'moveHero' function. Please reply when you read this.
peace
Sammo
December 12th, 2004, 02:57 PM
Yup, I''ve got that
JoMan
December 12th, 2004, 04:40 PM
Yup, I''ve got that
Ok good :). One second, post coming...
JoMan
December 12th, 2004, 05:02 PM
Ok, now we need some movement script, so now we type the following code:
function moveHero() {
with (hero) { // this is a setting that is not much used, but is very useful at times
if (started) { // this is needed for the hero's movement to be stopped once it is declared false
if (Key.isDown(Key.RIGHT)) { // this states if the 'RIGHT' key is being pressed
_x += 2; // this will move the hero to the right
_xscale = 100; // this declares that the hero is now facing right
if (walking) { // this declares if the animation will play or not. It will also come in handy for the jumping code as well
nextFrame(); // this plays the movieClips walking sequence
}
Now to break it down for you. When we use:
if (started) {
That will determine if the hero can move or not; If I declare 'started = false', then he cannot walk or move at all. If I declare 'started = true', then the hero can move and walk. Also, the reason that the following code:
if (walking) {
nextFrame();
Comes after the following code:
if (Key.isDown(Key.RIGHT)) {
_x+=2;
_xscale = 100;
Is so that if I declare that the walking is false (lets say for the jumping), then the animation for the walking will not play, but the hero can still move around. Now for the other movement:
} else if (Key.isDown(Key.LEFT)) { // this states if the 'LEFT' key is being pressed
_x -= 2; // this will move the hero to the left
_xscale = -100; // this declares that the hero is now facing left
if (walking) { // this declares if the animation will play or not. It will also come in handy for the jumping code as well
nextFrame(); // this plays the movieClips walking sequence
}
}
}
That is mostly the same stuff as the 'RIGHT' key script, only it is set off by an 'else if' statement. Please reply when you read this.
P.S. You are my first -should I say student?- to understand things really well :hugegrin:
peace
Sammo
December 12th, 2004, 05:19 PM
On your moveHero code, you need 2 (I think) more close curly brackets at the end. :)
P.S. You are my first -should I say student?- to understand things really well :hugegrin:
Or your first to just keep saying yup :P
Nah just kidding,
EDIT: except, the nextFrame() bit, why do we want it to do that (and what is it doing?)?
Other than that I'm following so far. Can you go on?
JoMan
December 12th, 2004, 08:05 PM
EDIT: except, the nextFrame() bit, why do we want it to do that (and what is it doing?)
Oh, did you see the hero that I made in the lesson 1 fla? Just view the inside of him by double clicking him. The nextFrame() is making him play the walking animation.
P.S. The reason I didn't have the other bracket, is because I am not done with the movement.
JoMan
December 12th, 2004, 08:33 PM
All right, in the final part of the moveHero function (not the end of the game), we will need some jumping script, right? Well the way we do that is the following:
if (Key.isDown(Key.UP) and (!jumping)) {
if (groundHit) {
walking = false; // walking is false, therefore the hero will not play the walking animation
jumpPower = 10; // this is the -well- jump power for the hero's jumping
jumping = true; // jumping variable is true, therefore you cannot set the jumpPower at 10 again (remembering the 'SPACE' key 'if' statement
jumpSound.start(); // this will be used later in the game
}
}
Now let's break it down. The following code:
if (Key.isDown(Key.UP) and (!jumping)) {
if (groundHit) {
States that if the 'SPACE' key is being pressed, the 'jumping' variable is false, and the 'groundHit' variable is true, then the hero will be allowed to jump. Now, the following code:
jumpSound.start();
will be used later on, once we add sound to our game. Ok, the next thing we need is the actual jumpPower settings, so write the following code:
if (jumping) { // if the jumping variable is true
jumpPower--; // the jumpPower will count up one by one
gotoAndStop("jump"); // hero will play the jump animation
if (jumpPower>=10) { // if jumpPower is more than 10
jumpPower = -10; // the jumpPower will be set to -10
}
_y -= jumpPower; // the hero's y position will change; following the jumpPower number
}
}
collision(); // this declares the collision function
checkFall(); // this declares the checkFall function
}
So far so good, right? Well then, let me break it down. First of all, we have the following code:
if (jumping) {
jumpPower--;
gotoAndStop("jump");
This states that if the 'jumping' variable is declared true, then the hero will play the jump animation, and the jumpPower variable will count up one by one. Now, the following code:
if (jumpPower>=10) {
jumpPower = -10;
}
_y -= jumpPower;
}
This states that if the jumpPower variable is more than 10, then it will be set to
-10. Please reply when you read this.
peace
Sammo
December 13th, 2004, 01:14 PM
Ok, it's just this bit:
This states that if the jumpPower variable is more than 10, then it will be set to
-10. What would jumpPower = -10 do (and to help the situation)?
Am I right in thinking that the hero in lesson2.fla doesnt jump becasue you have set the groundHit variable/function?
oh and lesson 2.fla is here (http://kesou.com/lesson2.zip)
Sammo
December 13th, 2004, 01:21 PM
oh and lesson 2.fla is here (http://kesou.com/lesson2.zip)
JoMan
December 13th, 2004, 05:52 PM
Am I right in thinking that the hero in lesson2.fla doesnt jump becasue you have set the groundHit variable
Yes, the 'groundHit' variable stops the hero from jumping if he is not touching the ground. So, if he is touching the ground, then the 'groundHit' variable will declare itself true, therefore the hero will be able to jump. But if he is not touching the ground, the 'groundHit' variable will declare itself false and he cannot jump.
Sammo
December 14th, 2004, 12:43 PM
ok :)
Can you continue?
This is excellent joMan thanks so much!
JoMan
December 14th, 2004, 02:40 PM
Next, we need to make an onKeyRelease function, so we write the following:
function keyRelease() {
with (hero) {
if (started) {
if (Key.getCode() == Key.RIGHT && walking) { // this states if the 'RIGHT' key is being released
gotoAndStop(1); // this says that the hero will play the standing animation
} else if (Key.getCode() == Key.LEFT && walking) { // this states if the 'LEFT' key is being released
gotoAndStop(1); // this says that the hero will play the standing animation
}
}
}
}
No, this code is pretty much self explainitory, but let's break it down. The following code:
if (Key.getCode() == Key.RIGHT && walking) {
gotoAndStop(1);
That states that if the 'RIGHT' key is being released, then the hero will go and stop on the first frame, or 'standing' animation. The following code:
if (Key.getCode() == Key.LEFT && walking) {
gotoAndStop(1);
That states that if the 'LEFT' key is being released, then the hero will go and stop on the first frame, or 'standing' animation. Please reply when you read this.
Sammo
December 14th, 2004, 04:41 PM
Why do we want that? Won't that stop his walking animation?
JoMan
December 14th, 2004, 04:56 PM
Why do we want that? Won't that stop his walking animation?
Yes, once the key is released, the hero will go back to the standing posision.
Sammo
December 14th, 2004, 05:23 PM
Ok....
When do we say in that function that, that happens when the key is lifted?
EDIT: Nevermind, I understand now. With this code at the start:
Key.onKeyUp = keyRelease;
Whats next? ground testing?
JoMan
December 14th, 2004, 06:22 PM
Ok....
When do we say in that function that, that happens when the key is lifted?
EDIT: Nevermind, I understand now. With this code at the start:
Key.onKeyUp = keyRelease;
Whats next? ground testing?
Yup :), ground collision! Now, by this part of the tute, you only need the collision and the gravity, right? Well, let's start with the collision! Okay, now we need a 'collision' function, so type the following code:
function collision() {
with (hero) {
if (limits.hitTest(_x+3, _y-15, true)) { // this states if the hero is touching the 'right' wall
_x-=2; // this is the resistance that pushes the hero to the left, creating the allusion of a wall
} else if (limits.hitTest(_x-3, _y-15, true)) { // this states if the hero is touching the 'left' wall
_x+=2;// this is the resistance that pushes the hero to the right, creating the allusion of a wall
}
This is the script for the walls. Now, when we look at the following code:
if (limits.hitTest(_x+3, _y-15, true)) {
Notice the highlighted part, that is so that the wall collision will work if the hero is in the proper y properties when he hits the wall. Now, we need the ground code, so we type the following code:
for (i=1; i<=50; i++) { // this creates a variable, and gives it a property
if (!limits.hitTest(_x, _y-i, true) and (jumpPower<=1)) { // this states that if the hero is not hitting the wall
_y -= i-3; // this is where the variable is used
break;
} else if (limits.hitTest(_x, _y-i, true) and (jumpPower<=1)) { // this states that if the hero is hitting the ground
jumping = false; // this declares that the jumping variable is false
jumpPower = 0; // this sets the jumpPower to 0
fallSpeed = 0; // this sets the fallSpeed to 0 (later in coding)
walking = true; // this declares that the walking variable true
groundHit = true; // this declares that the groundHit variable true
hero.jump.gotoAndStop(2); // the jump animation will set the hero to the standing posision (see the hero's jumping animation in the lesson flas)
}
}
}
}
Now let's break it down. The following code:
for (i=1; i<=50; i++) {
That is the most important part of the proper ground collision setting. What this does, is create a variable, and gives it a property, which -in this case- is the variable 'i'. Now, what 'i' does, is it counts up from one to 50, and it checks where it is so that if it is less that 50, then it will continue to count. Now, with that in mind, the following code:
if (!limits.hitTest(_x, _y-i, true) and (jumpPower<=1)) {
_y -= i-3;
break;
This states that if the hero is not hitting the ground, then he will move down slowly.
} else if (limits.hitTest(_x, _y-i, true) and (jumpPower<=1)) {
jumping = false;
jumpPower = 0;
fallSpeed = 0;
walking = true;
groundHit = true;
hero.jump.gotoAndStop(2);
}
}
}
}
That states that if the hero is hitting the ground, then he will stop, and the variables will be reset. Please reply when you read this.
Sammo
December 15th, 2004, 01:46 PM
Sorry, I'm not sure I fully understood that :(
if (limits.hitTest(_x+3, _y-15, true)) {
Notice the highlighted part, that is so that the wall collision will work if the hero is in the proper y properties when he hits the wall.
??? why -15 and why +3?
JoMan
December 15th, 2004, 04:39 PM
Sorry, I'm not sure I fully understood that :(
??? why -15 and why +3?
Oh, that depends on the game's limits (the size), the '_y-15' has to do with how far up the wall colision detection will work, and the '_x+3' says that the hero can only move so far into the wall until it pushes him back.
Sammo
December 16th, 2004, 12:52 PM
so the stage is 15 pixels high, and the hero can walk 3 pixels into the edge of the stage before he gets stopped?
Sorry, if I'm wrong :(
JoMan
December 16th, 2004, 02:13 PM
Sorry, if I'm wrong :(
It's ok, your learning.
so the stage is 15 pixels high?
No, the stage is as high as you make (draw) it, but the _y-15 is an optional thing that may help the wall hitTest in some occasions.
and the hero can walk 3 pixels into the edge of the stage before he gets stopped?
Yes, correct :D! It's also an optional thing that may help in some occasions.
Sammo
December 16th, 2004, 02:47 PM
Ok I'm think I'm understanding it :)
hitTests and me don't mix :P
I still don't understand why you've set the -15, what does that actually do?
And you think you could continue with the tute? Side-Scrolling maybe?
Thanks for everything joMan :D
JoMan
December 16th, 2004, 03:35 PM
I still don't understand why you've set the -15, what does that actually do?Yeah, it's a bit hard to explain. Side scrolling (as you requested) will have to come a little later; for now, we should get the gravity in first. Now we need gravity, so let's type the following code:
function checkFall() {
with (hero) {
if (started) {
if (!limits.hitTest(_x, _y+i, true)) {
gotoAndStop("jump");
groundHit = false;
if (!jumping) {
fallSpeed += 1;
if (fallSpeed>15) {
fallSpeed = 15;
}
_y += fallSpeed;
}
}
}
}
}
This may look like a heap of trouble, but really, it isn't that complex. Now let's break it down. As you have probably already noticed, this code is very much like the jumping code; Well, it is, which will make this alot easier for you :). Ok, let's start. First, the following code:
if (!limits.hitTest(_x, _y+i, true)) {
gotoAndStop("jump");
groundHit = false;
That states that if the limits are not being touched, then the hero will play the 'jump' animation and the groundHit variable will be declared 'true'. The following code:
if (!jumping) {
fallSpeed += 1;
That states that if the jumping variable is 'false', then the fallSpeed variable will be set to one. Finally, the following code:
if (fallSpeed>15) {
fallSpeed = 15;
}
That states that if the fallSpeed variable is less than 15, then it will be set to 15. The:
_y += fallSpeed;
That simply moves the hero's y position (makes him fall). Please reply after you read this.
peace
JoMan
December 16th, 2004, 03:37 PM
fasd;
sdafafdsadfs
Sammo
December 16th, 2004, 04:22 PM
wow! I understood that!!! :D
Hate to go back the the hitTesting, but on your fla (and my file) the character cant walk left becasue he hits the limits for the platform above him.
Can this be stopped?
EDIT: could we just take the _x off the hitTest for limits?
JoMan
December 16th, 2004, 04:42 PM
wow! I understood that!!! :D
Hate to go back the the hitTesting, but on your fla (and my file) the character cant walk left becasue he hits the limits for the platform above him.
Can this be stopped?
EDIT: could we just take the _x off the hitTest for limits?
Hmm, take away the _y-15, and see if that works.
Sammo
December 16th, 2004, 07:02 PM
Yes, that worked!
How did you get the hero to be able to jump through the platforms, and not the blocks?
And also, not sure if this will get fixed with more code, later on. But when you walk off an edge, the character does fall, but at an even pace and he is still walking
Walking a diagonal line downwards. which means he can jump while "falling"
How can we fix that?
JoMan
December 16th, 2004, 08:14 PM
Yes, that worked!
How did you get the hero to be able to jump through the platforms, and not the blocks?
Well, I constructed a seperate set of limits named 'ice'(actually, just one block of limits), and gave it cieling limit code.
And also, not sure if this will get fixed with more code, later on. But when you walk off an edge, the character does fall, but at an even pace and he is still walking
Walking a diagonal line downwards. which means he can jump while "falling"
How can we fix that?
Hmm, do you have the groundHit variable in the jumping?
mixedtrigeno
December 16th, 2004, 11:41 PM
wow someone thats that willing to help newb's is almost hard to believe...
thanks for helping this guy out you are helping me in the process.
the thing is i am a lil more ahead.
for some reason when my guys jumps and hits the ceiling he goes straight through the ceiling and also the scrolling doesnt work the way it is suppose to when the guy jumps and stands on a higher level the camera doesnt move with him. heres my fla oh and dont mind that the scrolling moves slow thats cuse of course the game is no where near finish is just begining. so in other words lol dont mind the art work thanks in advance joman.
JoMan
December 17th, 2004, 12:40 AM
wow someone thats that willing to help newb's is almost hard to believe...
thanks for helping this guy out you are helping me in the process.
the thing is i am a lil more ahead.
for some reason when my guys jumps and hits the ceiling he goes straight through the ceiling and also the scrolling doesnt work the way it is suppose to when the guy jumps and stands on a higher level the camera doesnt move with him. heres my fla oh and dont mind that the scrolling moves slow thats cuse of course the game is no where near finish is just begining. so in other words lol dont mind the art work thanks in advance joman.
I'll try my best to help out in the morning, cause I am getting sleepy :z:
JoMan
December 17th, 2004, 11:35 AM
wow someone thats that willing to help newb's is almost hard to believe...
thanks for helping this guy out you are helping me in the process.
the thing is i am a lil more ahead.
for some reason when my guys jumps and hits the ceiling he goes straight through the ceiling and also the scrolling doesnt work the way it is suppose to when the guy jumps and stands on a higher level the camera doesnt move with him. heres my fla oh and dont mind that the scrolling moves slow thats cuse of course the game is no where near finish is just begining. so in other words lol dont mind the art work thanks in advance joman.
Ok, let me take a look at it..
EDIT: Ummm, Either you're Leight, the programer, or that ActionScipt is a direct copy from one of the fla sources I saw.
JoMan
December 17th, 2004, 11:42 AM
Wow, I don't think that I can help you because the code is jumbled all over the place and it makes me dizzy :crazy:.
EDIT: Here is something I made last night that may help:
Sammo
December 17th, 2004, 11:49 AM
I added the checkFall code to your prototype and it worked fine.
Looking back over the code, we havn't done groundHit function, although this doesnt seem to matter atm, are we doing that next?
Lesson 3 here (http://kesou.com/lesson3.zip)
JoMan
December 17th, 2004, 12:50 PM
I added the checkFall code to your prototype and it worked fine.
Looking back over the code, we havn't done groundHit function, although this doesnt seem to matter atm, are we doing that next?
Lesson 3 here (http://kesou.com/lesson3.zip)
Yes, for the groundHit variable(not function), just set it in the jumping code, the collision code, and the falling code:
jumping code
// previous code
if (groundHit) { // just add that
if (Key.isDown(Key.SPACE) and (!jumping)) {
walking = false;
jumping = true;
jumpPower = 20;
}
} // and add that bracket
collision code
// previous code
for (i=1; i<50; i++) {
if (!limits.hitTest(_x, _y-i, true)) {
_y -= i-3;
break;
} else if (limits.hitTest(_x, _y-i, true)) {
jumpPower = 0;
fallSpeed = 0;
jumping = false;
walking = true;
groundHit = true; // just add that
hero.jump.gotoAndStop(3);
}
}
falling code
if (!limits.hitTest(_x, _y+i, true)) {
gotoAndStop("jump");
groundHit = false; // just add that
if (!jumping) {
fallSpeed++;
hero.jump.gotoAndStop(2);
if (fallSpeed>20) {
fallSpeed = 20;
}
_y += fallSpeed;
}
}
And that should fix it :).
Sammo
December 17th, 2004, 02:40 PM
oh sorry
I have them, I thought the groundHit was a function you had yet to define.
Okok :D Thanks again for this :)
Whats next?
JoMan
December 17th, 2004, 02:45 PM
oh sorry
I have them, I thought the groundHit was a function you had yet to define.
Okok :D Thanks again for this :)
Whats next?
Scrolling :D! Although, it may affect the rest of the former game (cause I didn't expect you to want to know scrolling). Post coming...
Sammo
December 17th, 2004, 03:07 PM
Ok Thanks :)
JoMan
December 17th, 2004, 03:32 PM
Ok, since we are now doing the scrolling, then we will need to change a few things from the other code. So, in the startGame function, we need to add a variable named 'heroSpeed', and a variable named 'scrollSpeed'. Example:
function startGame() {
heroSpeed = 3;
scrollSpeed = 3;
_quality = "low";
started = true;
walking = true;
key.onKeyUp = keyRelease;
Key.addListener(key);
fscommand("allowscale", true);
_root.onEnterFrame = moveHero;
}
Now we need to add the heroSpeed variable in the heroMove function. Example:
if (Key.isDown(Key.RIGHT)) {
_x += heroSpeed; // instead of '_x += 3'
if (walking) {
nextFrame();
}
} else if (Key.isDown(Key.LEFT)) {
_x -= heroSpeed; // instead of '_x -= 3'
if (walking) {
nextFrame();
}
}
We also need to declare the scrolling function, so we need to add
'scrolling()' to the list of functions. Example:
// at the end of the heroMove function:
}
collision();
checkFall();
scrolling();
}
Now we need the scrolling function, so we type the following code for the first part:
function scrolling() {
with (hero) {
if (started) {
if (Key.isDown(Key.RIGHT)) {
if (_x>=350 && limits._x>=-50) { // this states that if the limits and the hero are at a certain x position
_x = 350; // the hero will be set to this position
scrollSpeed = 3; // the scrollSpeed variable will be set to 3
heroSpeed = 0; // the heroSpeed variable will be set to 0
limits._x -= scrollSpeed; // this states that the limits will move to the left
} else {
heroSpeed = 3; // this states that the heroSpeed will be set to 3
}
Now, let's break it down. By the way, the x positions of the hero and the limits will vary depending on what your game's x positions are like. Ok, The following code:
if (Key.isDown(Key.RIGHT)) {
if (_x>=350 && limits._x>=-50) {
_x = 350;
scrollSpeed = 3;
heroSpeed = 0;
limits._x -= scrollSpeed;
That states that if the 'RIGHT' key is being pressed; the hero's x position is more than 350; and the limit's x position is more than 50, then the hero's x position will be set to 350, the scrollSpeed will be set to 3, the heroSpeed will be set to 0, and the limits will move to the left depending on the scrollSpeed. Now for the other part:
} else if (Key.isDown(Key.LEFT)) {
if (_x<=200 && limits._x<=559) { // this states that if the limits and the hero are at a certain x position
_x = 200; // the hero will be set to this position
scrollSpeed = 3; // the scrollSpeed variable will be set to 3
heroSpeed = 0; // the heroSpeed variable will be set to 0
limits._x += scrollSpeed; // this states that the limits will move to the right
} else {
heroSpeed = 3;
}
}
}
}
}
Now let's break it down. The following code:
} else if (Key.isDown(Key.LEFT)) {
if (_x<=200 && limits._x<=559) {
_x = 200;
scrollSpeed = 3;
heroSpeed = 0;
limits._x += scrollSpeed;
That states that if the 'LEFT' key is being pressed; the hero's x position is less than 200; and the limit's x position is less than 559, then the hero's x position will be set to 200, the scrollSpeed will be set to 3, the heroSpeed will be set to 0, and the limits will move to the right depending on the scrollSpeed. Please reply after you read this.
peace
mixedtrigeno
December 17th, 2004, 04:48 PM
no am not leight the programmer i wish i was lol i did some lil changes to his fla to make it fit mine and yes i know the thin is messy but hey it works fine so far lmao scept for the scrolling lmao but thanks
JoMan
December 17th, 2004, 05:14 PM
no am not leight the programmer i wish i was lol i did some lil changes to his fla to make it fit mine and yes i know the thin is messy but hey it works fine so far lmao scept for the scrolling lmao but thanks
You might want to consider placing the code in seperate clean functions so that it will be easier to locate stuff and add things to your code (it's also easier for us
-here at Kirupa- to help you).
Sammo
December 17th, 2004, 07:22 PM
Right, for the scrolling, would I want a really long bg, that goes far off the edge of the stage?
And how can you stop him going off the edge of the map? both ends...
Thanks :)
JoMan
December 17th, 2004, 11:08 PM
Right, for the scrolling, would I want a really long bg, that goes far off the edge of the stage?
And how can you stop him going off the edge of the map? both ends...
Thanks :)
Edge of map? I don't think I know what you're talking about. But, as for the long bg, yes (but not too teribly long, like out of zoom view @_@. See The Test that I posted for details).
Sammo
December 18th, 2004, 05:10 AM
Edge of map? I don't think I know what you're talking about.
Sorry, I'll try and explain better...
On a mario platformer (2D) and start at the left and travel to the right.
When you're at the starting point, if you go left you go go a little way, but then you stop. Say a wall.
Would I just make another limits and include the _y-15 on the code for that?
JoMan
December 18th, 2004, 11:00 AM
Sorry, I'll try and explain better...
On a mario platformer (2D) and start at the left and travel to the right.
When you're at the starting point, if you go left you go go a little way, but then you stop. Say a wall.
Would I just make another limits and include the _y-15 on the code for that?
Oh, ok! Yeah, that's not too hard. All you need to do is create some boundaries (let's say the maps default). Just type the following:
if (_x>=550) {
_x = 550;
} else if (_x<=0) {
_x = 0;
}
Basic boundaries that should keep the hero inside the map.
Sammo
December 18th, 2004, 02:14 PM
Just type the following...where?
in the heroMove function?
JoMan
December 18th, 2004, 04:29 PM
Just type the following...where?
Oh, sorry, I didn't specify (that's my biggest problem :crazy:).
in the heroMove function?
No, the boundary code goes into the 'collision' function.
Sammo
December 18th, 2004, 07:51 PM
Okay cool
I've been working on a gameover ani for my character. Now an enemy (that kills, and can be killed), and a hitTest, to play the death animation when you fall off the bottom of the screen (into water?)
Is that ok?
JoMan
December 18th, 2004, 08:33 PM
Okay cool
I've been working on a gameover ani for my character. Now an enemy (that kills, and can be killed), and a hitTest, to play the death animation when you fall off the bottom of the screen (into water?)
Is that ok?
Si, es facil!. Which one should I start with first?
RyxiaN
December 19th, 2004, 05:11 AM
that sounds cool
Sammo
December 19th, 2004, 06:05 AM
Any!!! :D
Ok, start with enemies.
RyxiaN
December 19th, 2004, 06:38 AM
what sort of game is it you are doing? It sounds cool
Sammo
December 19th, 2004, 08:38 AM
It's a mario-esque platformer, with my own artwork.
Just for fun and learning.
Couldn'd've even started it without joMan :)
RyxiaN
December 19th, 2004, 03:06 PM
okay... but JoMan can you answear in the forum "Help with mario-like game"
JoMan
December 19th, 2004, 03:20 PM
Ok, first, we will start with the enemies, so create an enemy (with a walk and die animation) and place it somewhere on screen; mind you, we will require a die animation for the hero also. Now we need to declare a new function named 'mayhem', so type the following code
// at the end of the heroMove code
}
collision();
checkFall();
scrolling();
mayhem();
}
Now, we need to create the function, so type the following code:
function mayhem() {
with (hero) {
if (enemy.hitTest(_x+5, _y, true)) {
gotoAndStop("die");
started = false;
} else if (enemy.hitTest(_x-5, _y, true)) {
gotoAndStop("die");
started = false;
}
}
So far, all we have is the code that states that if the enemy touches the hero's sides, then the hero will die. Now we need some enemy movement, so we type as followed:
with (enemy) {
if (!enemyDead) {
if (_xscale = 100) {
_x+=2;
} else if (_xscale = -100) {
_x-=2;
}
}
This states that if the enemy is facing right, then he will move to the right, and if he is facing left, then he will move to the left. Now let's move on to the enemy's collision, so we type as followed:
if (limits.hitTest(_x+20, _y, true)) {
_xscale = -100;
} else if (limits.hitTest(_x-20, _y, true)) {
_xscale = 100;
}
This one is pretty much self explanitory; it states that if the enemy touches the sides of the limits, then he will turn around and move in the opposite direction. Finally, we need to make a kill code, right? So, we type as followed:
if (hero.hitTest(_x, _y-70, true) and (jumpPower<=1)) {
gotoAndStop("enemy_die");
jumping = true;
Now, this states that if the hero is jumping/falling on the enemy's head, then the enemy will play the enemy_die animation. After that, we type the other half:
if (!enemyDead) {
jumpPower = 15;
enemyDead = true;
}
}
}
}
That states that if the enemyDead variable is false, then the jumpPower variable will be set to 15, and the enemyDead variable will be declared true. Please reply after you read this.
JoMan
December 19th, 2004, 04:41 PM
okay... but JoMan can you answear in the forum "Help with mario-like game"
I just did :beer:.
Sammo
December 19th, 2004, 06:06 PM
Cool!
Thanks joMan!!!!!
Am I right in saying that the enemy is 10 pixels wide. And the mayhem function states:
if (enemy.hitTest(_x+5, _y, true)) {
gotoAndStop("die");
started = false;
} else if (enemy.hitTest(_x-5,_y, true)) {
gotoAndStop("die");
started = false;
}
thats that if you touch the edge on the left (which will be 5 pixels from the center, and vice versa. So 10 pixels in width....right?
JoMan
December 19th, 2004, 09:06 PM
Cool!
Thanks joMan!!!!!
Am I right in saying that the enemy is 10 pixels wide. And the mayhem function states:
if (enemy.hitTest(_x+5, _y, true)) {
gotoAndStop("die");
started = false;
} else if (enemy.hitTest(_x-5,_y, true)) {
gotoAndStop("die");
started = false;
}
thats that if you touch the edge on the left (which will be 5 pixels from the center, and vice versa. So 10 pixels in width....right?
Oh, did you get the .fla file that I sent you?
Sammo
December 20th, 2004, 07:44 AM
Yes....was I wrong with that asumption? If so, what are the +5 and -5 for?
Dr Warm
December 20th, 2004, 08:37 AM
Sorry to butt in.......
because the registration is in the centre, 5 pixels to the right (+5) will hitTest the right edge of the movieclip. And 5 pixels to the left (-5) will hitTest for the left edge.
Comprehenday? <-- think you spell it like this!!
Sammo
December 20th, 2004, 08:58 AM
Ah, thanks Dr. Warm... I was right then :)
@joMan: Unless you've got anything else planned, can we do placment of coins + enemies over a map?
JoMan
December 20th, 2004, 11:59 AM
Ah, thanks Dr. Warm... I was right then :)
@joMan: Unless you've got anything else planned, can we do placment of coins + enemies over a map?
Woops! Sorry that I couldn't help earlier, I was at church. Okay, coins and enemies? sure, but it will have to be later, beacause I have a busy day today.
P.S. Hey, good to see you again, dr warm! Also, 'Comprende': Ese es como escribes entiende. Es espanol :P.
RyxiaN
December 20th, 2004, 12:21 PM
I really don't understand how you make AI on the enemies so they follow. It's superhard, right?
Sammo
December 20th, 2004, 02:28 PM
Why do you think it's superhard when you said you didnt know who to do it :P
if you got that from this forum then you're misreading joMans posts. He hasn't set the enemies to follow. He has just made them walk in one direction and turn around if they hit a wall
JoMan
December 20th, 2004, 06:15 PM
Ah, thanks Dr. Warm... I was right then :)
@joMan: Unless you've got anything else planned, can we do placment of coins + enemies over a map?
Well, just place the enemy on the map (preferably on the ground), and in the scrolling function, we type the following highlighted areas:
function scrolling() {
with (hero) {
if (started) {
if (Key.isDown(Key.RIGHT)) {
if (_x>=350 && limits._x>=-50) {
_x = 350;
scrollSpeed = 3;
heroSpeed = 0;
limits._x -= scrollSpeed;
enemy._x -= scrollSpeed;
} else {
heroSpeed = 3;
}
} else if (Key.isDown(Key.LEFT)) {
if (_x<=200 && limits._x<=559) {
_x = 200;
scrollSpeed = 3;
heroSpeed = 0;
limits._x += scrollSpeed;
enemy._x += scrollSpeed;
} else {
heroSpeed = 3;
}
}
}
}
}
Please reply after you read this.
peace
mixedtrigeno
December 21st, 2004, 12:59 AM
can you make a function in one frame and then call that function from within a movie clip?
for example on frame 1
function mayhem() {
with (hero) {
if (enemy.hitTest(_x+5, _y, true)) {
gotoAndStop("die");
started = false;
} else if (enemy.hitTest(_x-5, _y, true)) {
gotoAndStop("die");
started = false;
}
}
and then on a mc on frame 10 do this
onClipEvent (enterFrame) {
mayhem();
}
Sammo
December 21st, 2004, 08:07 AM
Hey joMan, okay I get that. Would you just make one enemy then put him on the stage several times. with different instance names?
Same for coins, yeah?
function coin() {
with (hero) {
if (coin.hitTest (_x, _y, true)) {
_root.score += 10;
removeMovieClip (coin);
}
}
}
With a dynamic text field called score. And in the startGame function:
score = 0;
Would that be okay?
RyxiaN
December 21st, 2004, 09:55 AM
So if you write:
with(hero){
i dont have to write
if (coin.hitTest(hero))
?
JoMan
December 21st, 2004, 11:16 AM
can you make a function in one frame and then call that function from within a movie clip?
for example on frame 1
function mayhem() {
with (hero) {
if (enemy.hitTest(_x+5, _y, true)) {
gotoAndStop("die");
started = false;
} else if (enemy.hitTest(_x-5, _y, true)) {
gotoAndStop("die");
started = false;
}
}
and then on a mc on frame 10 do this
onClipEvent (enterFrame) {
mayhem();
}
Yeah, that sould work.
JoMan
December 21st, 2004, 11:21 AM
Hey joMan, okay I get that. Would you just make one enemy then put him on the stage several times. with different instance names?
Same for coins, yeah?
function coin() {
with (hero) {
if (coin.hitTest (_x, _y, true)) {
_root.score += 10;
removeMovieClip (coin);
}
}
}
Would that be okay?
Something that I've learned in programming, is never to copy an enemy multiple times with different instances; it gets really messed up! As for coins, let me give it a shot. One minute..
JoMan
December 21st, 2004, 11:37 AM
Well, the removeMovieClip(coin) doesn't work, and you don't want to use this:
if (coin,hitTest(_x, _y, true)) {
You want to use this:
if (coin.hitTest(hero)) {
That is what I found so far.
JoMan
December 21st, 2004, 11:43 AM
So if you write:
with(hero){
i dont have to write
if (coin.hitTest(hero))
?
Well, you have the basic idea. But for that kind of hitTest, you need the 'hero' in there.
RyxiaN
December 21st, 2004, 11:47 AM
Yeah, i know. It's just to put in the MC and name it to "hero", right?
JoMan
December 21st, 2004, 11:57 AM
Yeah, i know. It's just to put in the MC and name it to "hero", right?
Yup :).
Wraithman
December 21st, 2004, 03:10 PM
Wow, this place looks like war of the programmers, lol :P
Sammo
December 21st, 2004, 04:40 PM
Ok, cool joMan. Coins + score are next on the list :)
JoMan
December 21st, 2004, 05:08 PM
Ok, cool joMan. Coins + score are next on the list :)
Ok, we'll get the score out of the way (because it's the easiest thing). So, now we need a function for the items on the game, so let's create the 'objects' function. By this time you probably already know where to declare the fuction, but I will still write it down anyway:
// at the end of the moveHero function
}
collision();
checkFall();
scrolling();
mayhem();
objects();
}
Ok, now we need to create the score, so select the text tool, and create a dynamic text box with a variable name(not an instance name) of '_root.score'.
Now open the actions panel, and under the startGame function, type the highlited area:
function startGame() {
heroSpeed = 3;
scrollSpeed = 3;
score = 0;
started = true;
walking = true;
_root.onEnterFrame = heroMove;
}
That's all that you need for the score. Please reply after you read this.
peace
Sammo
December 21st, 2004, 07:24 PM
*replies*
RyxiaN
December 22nd, 2004, 08:21 AM
joMan, why doesn't the removeMovieClip(); work?
JoMan
December 22nd, 2004, 12:26 PM
joMan, why doesn't the removeMovieClip(); work?
I don't know; I haven't taken the time to study it thoroughly.
RyxiaN
December 22nd, 2004, 02:10 PM
Okay. So if i want a object to be removed when you walk over it I shall make a Empty Frame in the end of the MC and name the frame "dead" or "picked" and i write:
onClipEvent(enterFrame){
if (_root.yoshi.hitTest(_root.coin)){
gotoAndStop("picked");
money = money+1;
}
}
JoMan
December 22nd, 2004, 04:06 PM
Okay. So if i want a object to be removed when you walk over it I shall make a Empty Frame in the end of the MC and name the frame "dead" or "picked" and i write:
onClipEvent(enterFrame){
if (_root.yoshi.hitTest(_root.coin)){
gotoAndStop("picked");
money = money+1;
}
}
Yes, although instead of putting 'money = money+1', just put 'money++'
RyxiaN
December 22nd, 2004, 08:30 PM
like this:
[CODE]onClipEvent(enterFrame){
if (_root.yoshi.hitTest(_root.coin)){
gotoAndStop("picked");
money = money++;
}
}
JoMan
December 22nd, 2004, 09:27 PM
like this:
[CODE]onClipEvent(enterFrame){
if (_root.yoshi.hitTest(_root.coin)){
gotoAndStop("picked");
money = money++;
}
}
actually, like this:
onClipEvent(enterFrame){
if (_root.yoshi.hitTest(_root.coin)){
gotoAndStop("picked");
money++;
}
Kafeenejunkie
December 23rd, 2004, 02:02 AM
For the coins in my game...
Would I drag out a certain number of them, giving each a different instance name. and on each one have this code:
coinscore ();
function coinscore () {
if (hero.hitTest(*instance name*)) {
_root.score += 10;
removeMovieClip();
}
}
If not what would I do for that?
Sammo
December 23rd, 2004, 02:04 AM
For the coins in my game...
Would I drag out a certain number of them, giving each a different instance name. and on each one have this code:
coinscore ();
function coinscore () {
if (hero.hitTest(*instance name*)) {
_root.score += 10;
removeMovieClip();
}
}
If not what would I do for that?
I have exactly the same thoughts + question
Plus, that objects function you mentioned.
RyxiaN
December 23rd, 2004, 07:26 AM
But joMan? How do you separate the colours in the Sprite?
Sammo
December 23rd, 2004, 01:59 PM
Dude! Can't you shut up and just read for a while?
You're posting in a thread with an excellent tutorial for a platformer in the making. There is no way joMan should redo it all again just for you because your game is slightly different... It's the same engine! And you shouldn't be making a game when you don't know who to animate a character. I'm doing this to learn. When this is over I'm going to use this as a reference for future times. This is what you should be doing. Instead of getting all impatient because someone doesn't fix your problem as soon as you've posted it.
If you'd've bothered to read the previous posts joMan has said he's working on the placement of enemies and coins. Just wait. Go do a tutorial from Actionscript.org or one of Kirupas Tutorials. Play a game. Just....don't live here trying to make the forum's all dedicated to you and your problems, you have a horrible habit of posting your problem is loads of places because someone didnt reply within the hour, don't expect others to help you over all their other priorities.
JoMan
December 23rd, 2004, 11:35 PM
For the coins in my game...
Would I drag out a certain number of them, giving each a different instance name. and on each one have this code:
coinscore ();
function coinscore () {
if (hero.hitTest(*instance name*)) {
_root.score += 10;
removeMovieClip();
}
}
If not what would I do for that?
Well, I don't know, I think it would work ( it worked on the multiple doors in one of my maze games).
JoMan
December 23rd, 2004, 11:41 PM
Hey Halikidiki, sorry that I haven't been on in a while, I have been REALLY busy, what with the Christmas season and all (off topic: Tomorow is Christmas eve @_@... that came right up under my nose!). So about those coins, let me do a little expiramenting, and I'll get back to you as soon as possible :D.
peace
JoMan
December 24th, 2004, 03:45 AM
Aha! Eureka! By further expiramenting, and observing other work, I have discovered the key to the coins! Instead of duplicating them through actionScript(my old outdated style), we can just use one mc(coin), duplicate it on screen, and give each of the copies different instance names(as Kafeenejunkie suggested)! Ok, lets start. First of all, create a coin movieClip, copy it (lets say three times), andgive them each different instance names. Example: 'coin1', 'coin2', 'coin3', etc. Now we need some code, so in the objects function, we type the following:
function objects() {
for (i = 1; i<=3; i++) {
if (hero.hitTest(_root["coin"+i])) {
_root["coin"+i].play();
score++;
}
}
}
Now lets break it down. When I wrote:
for (i = 1; i<=3; i++) {
What that is doing, is creating a variable, that will detect how many of the coins(on screen)that can be used (I don't quite fully understand the variable yet). Now, the following code:
if (hero.hitTest(_root["coin"+i])) {
_root["coin"+i].play();
score++;
}
This states that if the hero is touching one of the coins three coins, then that coin that he touched will play the obtained animation, and the score will be added to by one. See fla:
Sammo
December 24th, 2004, 07:43 AM
Ok thats great joMan!
in the Sounds layer I have put:
coinSound = new Sound();
coinSound.attachSound ("coinSound");
and
function objects() {
for (i = 1; 1 <= 20; i++) {
if (hero.hitTest (_root["coin"+i])) {
_root["coin"+i].play();
score += 10;
coinSound.start();
}
}
}
Is that all ok?
Also, is the placement of enemies the same?
JoMan
December 24th, 2004, 11:13 AM
Ok thats great joMan!
in the Sounds layer I have put:
coinSound = new Sound();
coinSound.attachSound ("coinSound");
and
function objects() {
for (i = 1; 1 <= 20; i++) {
if (hero.hitTest (_root["coin"+i])) {
_root["coin"+i].play();
score += 10;
coinSound.start();
}
}
}
Is that all ok?That's great! That's ecactly how I do it :) (it's good to see you working ahead and trying new things).
Also, is the placement of enemies the same?
Yes, it works :).
JoMan
December 24th, 2004, 11:25 AM
The only problem is that the code gets extra long. Original code with modifications:
function mayhem() {
for (var i = 1; i<8; i++) {
if (!_root["enemy"+i].enemyDead) {
if (_root["enemy"+i]._xscale == 100) {
_root["enemy"+i]._x+=2;
} else if (_root["enemy"+i]._xscale = -100) {
_root["enemy"+i]._x-=2;
}
if (limits.hitTest(_root["enemy"+i]._x+20, _root["enemy"+i]._y, true)) {
_root["enemy"+i]._xscale = -100;
} else if (limits.hitTest(_root["enemy"+i]._x-20, _root["enemy"+i]._y, true)) {
_root["enemy"+i]._xscale = 100;
}
if (hero.hitTest(_root["enemy"+i]._x, _root["enemy"+i]._y-70, true) and (jumpPower<=1)) {
_root["enemy"+i].gotoAndStop("enemy_die");
jumping = true;
if (!_root["enemy"+i].enemyDead) {
jumpPower = 15;
_root["enemy"+i].enemyDead = true;
removeMovieClip(_root["enemy"+i]);
}
}
}
}
}
Sammo
December 24th, 2004, 02:56 PM
can't you set the mayhem function inside the enemy movieclip
then it would only have to be one loop per type of enemy, right?
JoMan
December 24th, 2004, 04:31 PM
can't you set the mayhem function inside the enemy movieclip
then it would only have to be one loop per type of enemy, right?
Well, you can't put this type of programming into a movieClip, it needs to be in a frame. Also, it's nice to have all of the ActionScript in one spot, so that you don't have to go through everything looking for the code that you want to tweak (that's what I did when I first started programming! believe me, it was a mess :crazy: ).
peace on earth
Sammo
December 24th, 2004, 05:00 PM
ok :)
*thinks*
Is there anything else needed in a basic platformer?
JoMan
December 25th, 2004, 01:02 AM
ok :)
*thinks*
Is there anything else needed in a basic platformer?
Hmm, dunno.
*thinks as sits on a log*
Narrator: And pooh thought very hard.
Me: think, thinkthink think, think.
RyxiaN
December 25th, 2004, 07:26 AM
what means:
_root["enemy"+i]._x-=2;
JoMan
December 25th, 2004, 01:32 PM
what means:
_root["enemy"+i]._x-=2;
Haven't you read anything that I have written?!
RyxiaN
December 25th, 2004, 02:58 PM
No, i have just been at this forum once. And i saw that code up there at page 9.
Sammo
December 25th, 2004, 04:11 PM
Hey joMan, I have just got three more things:
Death when walling off ledge.
Hitting a box and a coin/power-up comes out
tranforming when touching a power-up
PS: For Xmas I got this book: Flash MX Game Design Demystified (http://www.amazon.co.uk/exec/obidos/ASIN/0201770210/qid=1104005429/ref=sr_8_xs_ap_i1_xgl/202-8094858-1361436) :D
RyxiaN
December 25th, 2004, 04:34 PM
JoMan: I have send you a PM! :P
Halikidiki (http://www.kirupaforum.com/forums/member.php?u=19473): Is the book good? I am about to buy one.
JoMan
December 25th, 2004, 05:21 PM
Hey joMan, I have just got three more things:
Death when walling off ledge.
Hitting a box and a coin/power-up comes out
tranforming when touching a power-up
PS: For Xmas I got this book: Flash MX Game Design Demystified (http://www.amazon.co.uk/exec/obidos/ASIN/0201770210/qid=1104005429/ref=sr_8_xs_ap_i1_xgl/202-8094858-1361436) :D
Ok then, I will start with #1 as soon as I can, but for now I have to go.
peace
Sammo
December 25th, 2004, 05:22 PM
ok thanks :)
PS you really should publish this as a tutorial on kirupa. It's awesome! :)
EDIT: Ryxian: It's very good. But it's big. 600+ pages.
JoMan
December 25th, 2004, 11:20 PM
ok thanks :)
Your welcome.
PS you really should publish this as a tutorial on kirupa. It's awesome! :).
Thankyou, but I don't think I'm that qualified ;).
P.S. I shall now start on the rest of the tutorial.
peace
JoMan
December 26th, 2004, 02:35 PM
Ok, this is a very simple, but criticle part of the tutorial. So, lets get started. First of all, the death code for the hero will be placed in the 'mayhem' function, so write the following code in the mayhem function:
if (hero.hitTest(_x, _y-70, true) and (jumpPower<=1)) {
gotoAndStop("enemy_die");
jumping = true;
if (!enemyDead) {
jumpPower = 15;
enemyDead = true;
}
}
if (_y>=600) {
jumpPower = 0;
fallSpeed = 0;
started = false;
}
}
}
Now, what this states, is that if the hero's y position is more than 600, then the jumpPower variable will be set to 0, the fallSpeed variable will be set to 0, and the started variable will be declared 'false'. Please reply after you read this.
peace
Sammo
December 26th, 2004, 06:04 PM
the 600 is 600 pixels from the top of the stage?
JoMan
December 26th, 2004, 07:56 PM
the 600 is 600 pixels from the top of the stage?
Yes, that is correct.
Sammo
December 27th, 2004, 11:59 AM
:D
Hitting box to get coin now?
oh and number 4: Pause Screen
JoMan
December 27th, 2004, 01:01 PM
:D
Hitting box to get coin now?
oh and number 4: Pause Screen
Ok, post coming...
P.S. I wont be here to help you later because I have a 5 hour fencing lesson.
JoMan
December 27th, 2004, 01:51 PM
First, create a box movieClip with the instance name of 'box'. Now we need to add a little code in the 'collision' function for the ceiling collision, so type the following highlighted area:
function collision() {
with (hero) {
if (limits.hitTest(_x+20, _y-20, true)) {
_x-=3;
} else if (limits.hitTest(_x-20, _y-20, true)) {
_x+=3;
}
if (limits.hitTest(_x, _y-75, true) and (jumpPower>=1)) {
jumpPower = 1;
}
Then we need to add the box (with its animations) inside of the limits movieClip. Now, in the 'objects' function under the coins code, type the following:
box = limits.box;
if (!boxHit) {
if (box.hitTest(_x, _y-75, true) and (jumpPower>=1)) {
box.play();
boxHit = true;
jumpPower = 1;
}
}
}
}
Let's break it down. the:
box = limits.box;
That is a variable that shortens the code; it declares that the variable 'box', will stand for the box in the limits movieClip. The following code:
if (!boxHit) {
if (box.hitTest(_x, _y-75, true) and (jumpPower>=1)) {
box.play();
boxHit = true;
jumpPower = 1;
}
}
That states that if the boxHit variable is 'false' and the hero is hitting the box from underneath, then the box will play its animation, the boxHit variable will be declared 'true', and the jumpPower variable will be set to 1. Please reply after you read this.
P.S. I have to go. Seeya later!
peace
JoMan
December 28th, 2004, 12:55 PM
This is just a test for my game:
width=550 height=400
Hey, is worked :P.
Sammo
December 28th, 2004, 05:34 PM
Doesn't load for me, neither does your footer actually...
JoMan
December 28th, 2004, 11:50 PM
Doesn't load for me, neither does your footer actually...
Does my footer work now?
Sammo
December 29th, 2004, 05:01 AM
nope, if you email me the swf, i'll upload it onto my site and you can link it from there. It's currently linked from your C drive so only you can view it I think....
JoMan
December 29th, 2004, 10:19 AM
nope, if you email me the swf, i'll upload it onto my site and you can link it from there. It's currently linked from your C drive so only you can view it I think....
Oh ok, I know almost nothing about how to let others view my work on the internet.
peace
radioxromance
January 6th, 2005, 09:02 PM
Hey jo - I remembered you saying something about tilebased games being not as good as your method - I was just wondering why you say that? I want to go read the tutorial over at gotoandplay by tonypa (it says it'supdated, and I never understood it too well anyway :P), but, aside from the edcational values presented in this plan, would this still be a good route to take for making a game? As in, is it much slower, or what are the pros or cons, if you know of them?
Thanks man, you've become quite an impresive help on this site!
Sammo
January 7th, 2005, 04:34 PM
Whoa! joMan! I forgot all about this thread!
So sorry!
Just wondering. To finish this off, do you think you could go a lil code for a pause screen?
JoMan
January 7th, 2005, 04:36 PM
Whoa! joMan! I forgot all about this thread!
So sorry!
Just wondering. To finish this off, do you think you could go a lil code for a pause screen?
Aye Aye Aye! I too forgot to finish this thread! Sorry for the delay, and I shall get started on the rest of the tutorial right away!
peace
JoMan
January 7th, 2005, 04:46 PM
Hey jo - I remembered you saying something about tilebased games being not as good as your method - I was just wondering why you say that? I want to go read the tutorial over at gotoandplay by tonypa (it says it'supdated, and I never understood it too well anyway :P), but, aside from the edcational values presented in this plan, would this still be a good route to take for making a game? As in, is it much slower, or what are the pros or cons, if you know of them?
Thanks man, you've become quite an impresive help on this site!
I didn't say that it wasn't as good as my method, but it is outdated unless you do a very old style, like the old mario, megaman, or zelda series for the original nintendo. The reason that tile based is outdated, is because it mainly consists of large ammounts of code skattered(not that skattered code is always a bad thing) and it is dependent upon one tile with multiple frames of graphics that you attach, which can get very tidious and confusing. My advise would be to use art based methods of graphics and programming. But thats just my opinion; do as you wish, because it is your game, not mine :). Also, you asked about the pros and cons? I'm not sure what you mean by your question. Do you mean good and bad parts of the styles?
peace
radioxromance
January 7th, 2005, 04:54 PM
Yes, that's what I meant, ie, is tilebased quicker/slower, more difficult than art style... you've basically already answered it. Thanks joMan!
JoMan
January 7th, 2005, 05:05 PM
Yes, that's what I meant, ie, is tilebased quicker/slower, more difficult than art style... you've basically already answered it. Thanks joMan!
Yes it is more dificult.
P.S. Your Welcome :).
peace
Sammo
January 8th, 2005, 07:24 AM
More difficult, but quicker and easier graphically.
netrix
January 8th, 2005, 07:20 PM
hey joMan on your example of the hitbox if u jump over the hitbox the "hero" will jump again is a little glitch... maybe am wrong but check it out...
Sammo
January 9th, 2005, 05:16 AM
Can a mod rename this to A Platform Tutorial?
JoMan
January 9th, 2005, 10:25 AM
hey joMan on your example of the hitbox if u jump over the hitbox the "hero" will jump again is a little glitch... maybe am wrong but check it out...
Actually, what I think that you are seeing, is him quick-landing onto the box, and then jumping again. This happens when the hero lands on a higher platform and the jump key is still being pressed.
peace
JoMan
January 9th, 2005, 10:27 AM
Can a mod rename this to A Platform Tutorial?
Probably. But, I wouldn't know where to find/ask them.
Off Topic: By the way, I wont be able to help later because I have a fencing tournamant to go to.
peace
Sammo
January 9th, 2005, 11:48 AM
ok, good luck!
JoMan
January 9th, 2005, 05:01 PM
Ugh. I just got back from the tournament, and man did I do horribly :bored: (bad day I guess). Anyway, what do you need me to help you make? (sorry, I forgot :P)
peace
netrix
January 9th, 2005, 06:11 PM
Actually, what I think that you are seeing, is him quick-landing onto the box, and then jumping again. This happens when the hero lands on a higher platform and the jump key is still being pressed.
peace
hey man ur right!! i checked again and it was like u said...
:link:
JoMan
January 9th, 2005, 06:14 PM
hey man ur right!! i checked again and it was like u said...
:link:
It seems alot like a glich though, I know :D.
peace
netrix
January 10th, 2005, 12:45 PM
Hey joMan... can u tell me how to make the "hero" kill the enemy jumping over him (i know this part) and get killed if he touches de enemy any other way?? please let me know if its not clear enough!!
JoMan
January 10th, 2005, 03:41 PM
Hey joMan... can u tell me how to make the "hero" kill the enemy jumping over him (i know this part) and get killed if he touches de enemy any other way?? please let me know if its not clear enough!!
Actually, I did write that part ( if you were reading the whole enemy tutorial).
peace
von_dragon
January 11th, 2005, 11:01 PM
joMan, excellent tutorial(s). Keep up the good work. Thanks for all the time and effort you put into these. I follow every one of them.
JoMan
January 13th, 2005, 07:29 PM
Hmm, I don't know why, but the game that I made (for the tutorial) will not let me insert my pause code, or it will have errors.
peace
JoMan
January 16th, 2005, 01:05 AM
I just need to test something, and I didn't feel like posting a new thread just to try it out:
width=550 height=400
P.S. Can anyone see my footer now?
peace
radioxromance
January 16th, 2005, 05:04 AM
Yep, I see it. But why the game? And I can't even play it... :(
JoMan
January 16th, 2005, 10:14 AM
Yep, I see it. But why the game? And I can't even play it... :(
It was just a test.
peace
Sammo
January 16th, 2005, 04:58 PM
joMan, why is your footer flash and not a gif/jpg?
Or does it do something flasy I'm not seeing?
Inferno
January 17th, 2005, 02:37 PM
maybe joman is good drawing in flash, like i am :)
radioxromance
January 17th, 2005, 02:55 PM
Well it could still be exported to a gif or jpeg, right? Although I don't know if that would change filesize much or advantages.
JoMan
January 18th, 2005, 02:47 PM
maybe joman is good drawing in flash, like i am :)
Guilty as charged :). Though, I cannot deny it, I have been drawing manga on paper more than I have on flash lately.
peace
JoMan
January 18th, 2005, 02:49 PM
joMan, why is your footer flash and not a gif/jpg?
Or does it do something flasy I'm not seeing?
Oh, I believe that the flash projecter leaves a sharper image. But, I don't know if you are seeing the propper(spelling?) font. Is the font you're seeing FFF Manager Bold?
peace
mixedtrigeno
January 20th, 2005, 04:54 PM
joMan, why doesn't the removeMovieClip(); work?removeMovieClip only works when you use duplicate or attach an mc to the stage, if you want to remove an mc that is on the stage without it been attach or duplicated use this
item.unloadMovie();
the bad thing is that i believe unload is slower then remove. please correct me if i am wrong
Shouri
January 20th, 2005, 11:18 PM
I'm sorry to post such a stupid question but, I've been trying to find the code to the movement of the sprite and... I can't do it anymore... could you please any of you point it out for me? I'm working on a platform based game, and I want the sprite to move like this one: http://www.gotoandplay.it/_articles/2003/12/scrolling_upd.php (the titles scroll with the sprite). I have the animations for all the actions, but I don't know how to put them up.
Preview:
http://www.webpost.net/sh/shourispics/ugine_stand_yes.gif http://www.webpost.net/sh/shourispics/ugine_walk_cape.gif http://www.webpost.net/sh/shourispics/ugine_jumpstick.gif http://www.webpost.net/sh/shourispics/ugine_jumpsstick.gif http://www.webpost.net/sh/shourispics/ugine_jumps.gif http://www.webpost.net/sh/shourispics/ugine_attackfull.gif
http://www.webpost.net/sh/shourispics/ugine_hurted.gif http://www.webpost.net/sh/shourispics/ugine_holdsstick.gif http://www.webpost.net/sh/shourispics/ugine_fly.gif http://www.webpost.net/sh/shourispics/ugine_falls.gif http://www.webpost.net/sh/shourispics/ugine_dead.gif http://www.webpost.net/sh/shourispics/coin.gif
http://www.webpost.net/sh/shourispics/fondo.gif
Please be easy on me since I had an awful day... >_<
Lukus
January 24th, 2005, 03:59 PM
Cheers joMan, this is great :) Should definately be made into a proper tutorial :)
[uber]
March 6th, 2005, 03:31 AM
hey JoMan.. i pm'd you really sick tute.. i kinda got lost after the scrolling thing.. my character went all funny.. probably because the lessons weren't for the scrolling.. anyway... i'll be back to ask some more questions once i have teh basics sorted out...
squishy
March 7th, 2005, 02:07 PM
maybe joman is good drawing in flash, like i am :)
same here :beer:
pl_031
March 12th, 2005, 12:25 AM
hi ! i read all your great tutorial but I got one problem. Maybe it is stupid but when i press the right button or left button the hero walking animation doesn't start, it stucks at the first frame and it's not the first time I got this problem. I don't know what i"m doing wrong but any help will be appreciated. I will attach the fla tomorrow because I am not on my computer.
(-:
edit: nvm, it works now even if I don't know why
yhack
March 16th, 2005, 02:56 PM
Wow this tutorial is great. I was just trying to make something like this. I'd like to see the finished thing, <thread maker(sorry i forgot your name)>
Joppe
March 22nd, 2005, 12:48 PM
How would i do if i want it to scroll upwards too?
netrix
April 7th, 2005, 09:47 AM
hi, has anyone made a full level yet??? I will try to start all over again soon and hopefully I will complete at least a level!!
:link:
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.