View Full Version : Zelda Game HitTest help
amps7
August 9th, 2005, 09:45 AM
Hi,im experimenting with making a zelda game (not tile-based) and am in need of a code for when the hero hits a wall. I know this has been asked so many times before but i just cant seem to get a suitable code.
Templarian
August 9th, 2005, 11:00 AM
to make it simple you are doing it on when the key is pressed right?
if(Key.isDown(Key.LEFT)){
character._x -= 4
if(hittest){
character._y += 4.
}
}
something basic like that but not in psuedo.
amps7
August 9th, 2005, 01:19 PM
Thanks Templarian, i'll need to try it out when i get home. In the meantime,could you please help me with another confusing problem? What is wrong with this code:
if (Key.isDown(Key.UP) && Key.isDown(Key.RIGHT)){
this.gotoAndStop(3);
}
}
It looks perfect to me but doesnt seem to work at all. :(
TheCanadian
August 9th, 2005, 01:23 PM
One of the brackets was facing the wrong way, try this:
onClipEvent (enterFrame) {
if (Key.isDown(Key.UP) && Key.isDown(Key.RIGHT)) {
this.gotoAndStop(3);
}
}
amps7
August 9th, 2005, 01:30 PM
Sorry that was a manual error when i was typing it! Its Fixed now.
TheCanadian
August 9th, 2005, 01:46 PM
So does the code work for you now?
amps7
August 9th, 2005, 03:16 PM
No it doesnt seem to be working,i've made up a .fla of main character. Could you (or anyone else) please examine it to see what's wrong?
Heres the .fla.
http://www.amps.ecwhost.com/files/MovementProblem.fla
amps7
August 10th, 2005, 04:31 PM
Anyone? I can't seem to work it out :puzzled:
Insane Knux
August 10th, 2005, 04:46 PM
Ah, don't feel bummed out! I'll give a go at it! ;)
So what exactly is your problem? He moves fine for me!
amps7
August 10th, 2005, 04:58 PM
Thanks,I need you to examine the code for him diagonally right.
if (Key.isDown(Key.UP) && Key.isDown(Key.RIGHT)) {
this.gotoAndStop(3);
}
}
I just need you to see whats wrong with it and why he dosent seem to carry out the actions.
Insane Knux
August 10th, 2005, 05:19 PM
Aight, I'm on it.
//EDIT
WEWT! 170th post! :thumb:
//EDIT
Currently it works, just the animation doesnt. Easy fix, brb.
Insane Knux
August 10th, 2005, 05:39 PM
Alright man... I couldn't get it working... but tomorrow I'll take another swing at it...
Lord Rahl
August 10th, 2005, 06:55 PM
Hmm, this is odd. I'm working on it now and I'll let you know with what I come up with.
Lord Rahl
August 10th, 2005, 07:07 PM
Well I have to admit. I can't figure it out. I have seen it before and it still annoys me. Anyways, I worked up something similar for you to look at that does work. I'm still working on it and may possibly figure it out. Untill then, check out the posted fla.
Aggrix
August 10th, 2005, 07:28 PM
Do this instead:
if (Key.isDown(Key.DOWN)) {
this.gotoAndStop(2);
}
else if (Key.isDown(Key.UP)) {
this.gotoAndStop(3);
}
else if (Key.isDown(Key.LEFT)) {
this.gotoAndStop(4);
}
else if (Key.isDown(Key.RIGHT)) {
this.gotoAndStop(6);
}
The other way was first checking for the right key and if it was down it would play frame 6. Then right after that it would play frame 3 for the up key. This was causing it to keep switching from frame 6 to 3 and not play out the walking animation on frame 3.
Lord Rahl
August 10th, 2005, 07:33 PM
The other way was first checking for the right key and if it was down it would play frame 6. Then right after that it would play frame 3 for the up key. This was causing it to keep switching from frame 6 to 3 and not play out the walking animation on frame 3.
Bravo Aggrix. ;) And to think it was so simple. Though, I should have noticed that right off.... or at least tried the same thing. :look:
amps7
August 11th, 2005, 07:30 AM
Thanks Aggrix,Lord Rahl,InsaneKnux and The Canadian for your help.
It was very simple but things like that can really throw you off.
amps7
August 11th, 2005, 09:38 AM
Ok,one more question (i think...). Is there a more effective way of doing a hittest for circular objects or more complicated objects?
Lord Rahl
August 11th, 2005, 12:18 PM
You can do it multiple ways, but this script works with round objects better than most. Just place it in your goodguy MC and replace object with wall or whatever.
onClipEvent(enterFrame){
if (_root.object.hitTest(getBounds(_root).xMax, _y, true)) {
//place script to back track speed here
//example: _root.object._x -= _root.speed;
}
if (_root.floor.map.hitTest(getBounds(_root).xMin, _y, true)) {
//place script to back track speed here
}
if (_root.floor.map.hitTest(_x, getBounds(_root).yMax, true)) {
//place script to back track speed here
}
if (_root.floor.map.hitTest(_x, getBounds(_root).yMin, true)) {
//place script to back track speed here
}
}
amps7
August 11th, 2005, 02:29 PM
Thanks,now this is what i've got so far:
The .fla is 104kb zipped so i've hosted that.
Fla: Here (http://www.amps.ecwhost.com/files/ZeldaEngine.zip)
Swf: Below
Lord Rahl
August 11th, 2005, 03:03 PM
Its great so far. Is there a talk key or way of entering house yet?
Edit: Also, is the fairy part of the main character MC? If it is, your main character will stop when it hits the wall too.
Insane Knux
August 11th, 2005, 03:39 PM
Heh, very nice game.
Oh, and bravo Aggrix! You obviously pay more attention to detail!
Also: YAY! I was thanked :) lol.
TheCanadian
August 11th, 2005, 03:41 PM
Talk with space.
amps7
August 11th, 2005, 04:06 PM
Thanx guys.
Lord Rahl, i haven't added the ability to enter the house yet. Talk is with Space (as the canadian mentioned). The fairy isnt part of the main characters MC and it has just got a simple co-ordinate code on it for staying slightly behind the hero.
amps7
August 11th, 2005, 04:16 PM
Sorry for asking another question but i'm learning ALOT here. What would be the most effective way of playing an animation when the hero hits a wall or a tree. If you know Zelda games then you will know that whenever link moves into a wall that he cannot get by he plays his "pushing" animation.
TheCanadian
August 11th, 2005, 04:20 PM
Put this on Link.
onClipEvent (enterFrame) {
if (this.hitTest(_root.tree)) {
gotoAndPlay("treeHitAnimation");
}
}
"treeHitAnimation" is the lable of the frame you would like to play.
amps7
August 11th, 2005, 05:46 PM
ok,thanx
amps7
August 15th, 2005, 09:13 AM
Ok,ive been experimenting tryin to achieve a Zelda style scrolling and its harder than i thought. So far ive got a code on the Hero's MC that states when the hero reaches a certain X or Y value (the end of the screen) the view switches to a different frame.This works ok except for the respawning nd positioning of the Hero on the different frames. Can anyone help me out?
nathan99
August 18th, 2005, 04:00 AM
ok, i dont like your hitTest too much. :) you should use a if not hitting when button is pessed then move for eg
if(Key.isDown(Key.LEFT)){
_xscale=-100;
if(!_root.leftwalls(this)){
//if the left walls are NOT hitting
_x-=speed;
//move left
}
}
get me? this way seems a lot smoother, heres how i have used it in a game im doing now
nathan99
August 18th, 2005, 04:03 AM
add i_eat_lots_of_food@hotmail.com to ur msn if u have it and i can help
amps7
August 18th, 2005, 10:47 AM
ok,thanx
jonathanOber
August 18th, 2005, 04:39 PM
Thanks,now this is what i've got so far:
The .fla is 104kb zipped so i've hosted that.
Fla: Here (http://www.amps.ecwhost.com/files/ZeldaEngine.zip)
Swf: Below
are you creating your graphics in photoshop, imageready, illustrator?? i want to do something like this, but i want to create my own characters, i just wanted to know what program works the easiest, i was thinking of making a character pixel-like just like link.
- Thanks
smack_boom
August 18th, 2005, 11:23 PM
Hey amps! If you want to take this game furthur maybe i can help. I've made an Zelda engine in the past.
nathan99
August 19th, 2005, 10:09 AM
ok i have accepted
amps7
August 19th, 2005, 12:37 PM
jonathanOber- The graphics used are just sprites ripped from the original SNES game.
SmackBoom- Any help i get is appreciated!
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.