View Full Version : rpg
bombsledder
March 8th, 2004, 09:04 PM
im creating an rpg game and im making it so if you hit the water or the house or anything else it will stop you but im having real difficulty and it is probobaly not that hard so do you think you could help me with this..
the script is
onClipEvent (load) {
speed = 5;
speed2 = 5
speed3 = 5;
speed4 = 5;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
_root.level1._x -= speed2;
}
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.DOWN)) {
_root.level1._y -= speed3;
}
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
_root.level1._x += speed4;
}
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.UP)) {
_root.level1._y += speed;
}
}
onClipEvent (enterFrame) {
if (this, hitTest(_level0.level1.sign)or(_level0.level1.wate r)) {
speed = 0;
} else {
speed = 5;
}
}
and there is an attachment if you can download it
:)
grinch
March 8th, 2004, 09:28 PM
Lol, nice background there... I see you spent a lot of time. :D
Just kidding.
I'm going to mess around with it and figure something out.
grinch:kir:
bombsledder
March 8th, 2004, 09:36 PM
hey those are some quality graphics especially when the ball hits the door and you press enter
bombsledder
March 8th, 2004, 09:36 PM
trying to make an input text where you type in what you want but im lost
BlueBoots
March 11th, 2004, 02:56 AM
this.hitTest, not this, hitTest
I think. Just from syntax point of view, I don't use hitTest very often.
And use your output window to full advantage, and trace(condition); as well.
If anything comes up undefined you have to re-check your paths and stuff.
Will d/l fla when I have time...
Johnny64
March 11th, 2004, 10:13 AM
Don't have Flash MX 2004 but i can see two things that your doing wrong and one style misstake :)
ok the syntax of hittest is wrong you had a , in stand of a . and you have to call the hittest function for every object you have to test. so this dosn't work
this.hitTest(_root.level1.sign) or (_root.level1.water))
//but this will
this.hitTest(_root.level1.sign) or this.hitTest(_root.level1.water)
the style misstake will not make the AS crash but it does make it a mess..you have like 5 onClipEvent (enterFrame) ! while one is more then enough. :)
onClipEvent (load) {
speed = 5;
speed2 = 5;
speed3 = 5;
speed4 = 5;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
_root.level1._x -= speed2;
}
if (Key.isDown(Key.DOWN)) {
_root.level1._y -= speed3;
}
if (Key.isDown(Key.LEFT)) {
_root.level1._x += speed4;
}
if (Key.isDown(Key.UP)) {
_root.level1._y += speed;
}
if (this.hitTest(_root.level1.sign) or this.hitTest(_root.level1.water)) {
speed = 0;
} else {
speed = 5;
}
}
And don't forget that the ActionScript Dictionary is you friend so use it ;)
bombsledder
March 11th, 2004, 06:21 PM
hey thanks alot..
yaa
(i will add you to my credits if i ever get it on the internet)
BlueBoots
March 11th, 2004, 07:23 PM
If anything ever doesn't work, and you're not sure why, do a trace.
Put the path name, or the piece you're not sure about, into this:
trace(this.is.the.thing.your.not.sure.works);
after the code where you want to use: this.is.the.thing.your.not.sure.works
If the output window, it'll trace and then display what flash evaluates that is.
If it comes back 'undefined' it means flash can't find what your looking for, the path is wrong. You need to re-check all of your instance names and re-write your paths.
There are other ways to use trace but this is the one I use most often. Example: (Actions on main timeline frame)
_level0.movie1.onEnterFrame = function() {
myNumber = _level0.movie1._currentframe;
if (myPlay = true){
_level0.movie1.movieNum.text = myNumber;
trace(myNumber);
}else{
(myPlay = false)
delete this.onEnterFrame;
}
}
(To make it work I have myPlay set to true when movie1 plays, and false when movie1 stops at 500 frames on the actual movie itself)
If my code works, the output window will display a huge, constantly adding list of numbers. If it doesn't, it'll keep saying 'undefined' because we're checking for my number each time you enter the frame, and if it's 12 frames persecond, (default) thats 12 checks a second.
_level0.movie1.onEnterFrame = function() {
myNumber = _level0.movie1._currentframe;
if (myPlay = true){
_level0.movie1.movieNum.text = myNumber;
}else{
(myPlay = false)
delete this.onEnterFrame;
}
trace(myNumber);
}
Now we've moved trace to after the else. Trace won't trace anything till else is called. If an 'undefined' appears in the output window, it's good because it shows my else has deleted the enterFrame function.
If the output shows undefined more than once, it's still checking on enterFrame but it's no longer finding myNumber. So the code is broken.
If it keeps displaying 500, then it's completely ignoring the "else."
Luckily, this code works!
Also, if you're not sure about something, select it in the actions window and click on the little book icon (the reference). It'll tell ya all about it and sometimes includes examples.
bombsledder
March 11th, 2004, 08:10 PM
hey thanks .but i have just one more question on this say that i want the house to be able to stop when hitting it from the right and from the bottom of the house.. and same with the water how would i do this because on the code that master showed me
well i played with that script for a while and added a few more codes
onClipEvent (load) {
speed = 5;
speed2 = 5;
speed3 = 5;
speed4 = 5;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
_root.level1._x -= speed2;
}
if (Key.isDown(Key.DOWN)) {
_root.level1._y -= speed3;
}
if (Key.isDown(Key.LEFT)) {
_root.level1._x += speed4;
}
if (Key.isDown(Key.UP)) {
_root.level1._y += speed;
}
if (this.hitTest(_root.level1.sign) or this.hitTest(_root.level1.water)) {
speed = 0;
speed2=0
} else {
speed = 5;
speed2=5
}
}
well that would work of the sign but completly screws up the house and other because each of the make it the right and the up
not work.. help
bombsledder
March 11th, 2004, 10:18 PM
hey master how come my like footer won't show up
Johnny64
March 12th, 2004, 11:04 AM
][/b]
you forgot a ] :)
bombsledder
March 12th, 2004, 11:48 AM
thanks
bombsledder
March 12th, 2004, 12:47 PM
yea does anyone think thet could help me with the hitTest problem
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.