ed Mack ... that code you posted on the front page was EXACTLY!!!! What I've been trying to write all day long! I LOVE YOU! HEHEHEHEH!
Printable View
ed Mack ... that code you posted on the front page was EXACTLY!!!! What I've been trying to write all day long! I LOVE YOU! HEHEHEHEH!
I'm building an art based scrolling rpg and have had 2 versions of code so far.
I can scroll and collide with the perimiter ala shape flag but extra collisions with other mcs is really giving me a headache. The hit doesn't work and the sound just loops and loops, I tried onLoad function but this played sound once and hit test didn't work :*(
please can somebody take a look and see if they can solve this for me....
Code type 1 is:-
//on hero mc
onClipEvent (load) {
end=true;
move = 0;
lock = true;
}
onClipEvent (enterFrame) {
if (!_root.universe.world.hitTest(this._x-xstep, this._y-ystep, true)) {
_parent.universe._x += Xstep;
_parent.universe._y += Ystep;
Ystep = 0;
Xstep = 0;
hit=false
} else{hit=true;}
if (Key.isDown(Key.UP)) {
Ystep = 10;
Xstep = 0;
this.gotoAndStop("back");
} else if (Key.isDown(Key.DOWN)) {
Ystep = -10;
Xstep = 0;
this.gotoAndStop("front");
} else if (Key.isDown(Key.LEFT)) {
Xstep = 10;
Ystep = 0;
this.gotoAndStop("left");
} else if (Key.isDown(Key.RIGHT)) {
Xstep = -10;
Ystep = 0;
this.gotoAndStop("right");
}
if(xstep or ystep ){;hero.play();}
else{hero.gotoAndStop(1)}
if(hit){hero.gotoAndStop(1)}
//the bit I'm stuck on which on house1 collision plays yell frame 2 to play sound
onClipEvent (enterFrame) {
if (_root.hero.hitTest (_root.stage.house1) == true)
{
speed = 0;
_root.yell; gotoAndPlay ("3")
}
}
and code type 2:-
//on hero mc
onClipEvent (enterFrame) {
if (_root.hero.hitTest (_root.stage.bound1))
{
speed = 0;
_root.stage._y -=5
}
else if (_root.hero.hitTest (_root.stage.bound2))
{
speed = 0;
_root.stage._x -=5
}
else if (_root.hero.hitTest (_root.stage.bound3))
{
speed = 0;
_root.stage._y +=5
}
else if (_root.hero.hitTest (_root.stage.bound4))
{
speed = 0;
_root.stage._x +=5
}
else
{
}
if (Key.isDown(Key.RIGHT) == true){
GOTOANDSTOP (3);
}
else if (Key.isDown(Key.UP) == true){
GOTOANDSTOP (2);
}
else if (Key.isDown(Key.DOWN) == true){
GOTOANDSTOP (4);
}
else if (Key.isDown(Key.LEFT) == true){
GOTOANDSTOP (5);
}
else if (Key.isDown(Key.UP) == false){
GOTOANDSTOP (1);
}
}
//bit i'm stuck on
onClipEvent (enterFrame) {
if (_root.hero.hitTest (_root.stage.house1) == true)
{
speed = 0;
_root.yell; gotoAndPlay ("3")
}
}
AND on stage aka background code type 2...
//movement
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT) == true){
_x = _x - 5;
}
if (Key.isDown(Key.LEFT) == true){
_x = _x + 5;
}
if (Key.isDown(Key.DOWN) == true){
_y = _y - 5;
}
if (Key.isDown(Key.UP) == true){
_y = _y + 5;
}
}
----------------------------------------
What I really want to do is when hero mc collides with house I want to move to stage 2 i.e go inside a building. This is really buggin me though and it was hard enough figuring out 1 code type only to scrape another together only to have the self same problem.
Please could somebody put me out of my misery??
Thanks,
Gunny.
this has prooved too complex for me.
I'd like to understand at least one of the firs codes posted and I just ask any1 with a teacher's soul and a lot of patience, to explain it to me :D
the code is this
thanks, I really appreciate it... and if you dont want to explain, at least tell my how to adapt the code so that instead of moving the character, the map scrollsCode:onClipEvent(load){
s = 5;
b = this.getBounds(this);
function move(x,y){
if(!_root.hit.hitTest(_x+x+b.xmin+1, _y+y+b.ymin+1, true)){
if(!_root.hit.hitTest(_x+x+b.xmax-1, _y+y+b.ymin+1, true)){
if(!_root.hit.hitTest(_x+x+b.xmin+1, _y+y+b.ymax-1, true)){
if(!_root.hit.hitTest(_x+x+b.xmax-1, _y+y+b.ymax-1, true)){
_x += x;
_y += y;
}
}
}
}
}
}
onClipEvent(enterFrame){
if(Key.isDown(Key.UP)){
move(0,-s);
}
if(Key.isDown(Key.DOWN)){
move(0,s);
}
if(Key.isDown(Key.LEFT)){
move(-s,0);
}
if(Key.isDown(Key.RIGHT)){
move(s,0);
}
}
I make a paint engine, It always dublicates the same instance. Now by a push of a button the all start to fall how do I create interation(collision, hitTest) between each iduvidual dublicated instance??
This is the code I have for the Instance sofahr. Do I need to use an Array for this?
PHP Code:onClipEvent(enterFrame) {
if(keyPressed == true) {
if(i<10){
i++;
if (this.hitTest(_root.Vice_Brick+i)){
hit = true;
fall = true;
}
}
}
}
If you apply this to a box...
This establishes the speed and boundriesCode:onClipEvent(load){
s = 5;
b = this.getBounds(this);
top-right corner of the MCCode:
function move(x,y){
if(!_root.hit.hitTest(_x+x+b.xmin+1, _y+y+b.ymin+1, true)){
Bottom right corner of the MCCode:if(!_root.hit.hitTest(_x+x+b.xmax-1, _y+y+b.ymin+1, true)){
Top Left corner of the MCCode:if(!_root.hit.hitTest(_x+x+b.xmin+1, _y+y+b.ymax-1, true)){
Bottom left corner of the MCCode:if(!_root.hit.hitTest(_x+x+b.xmax-1, _y+y+b.ymax-1, true)){
that's the coding to make the "Hero" move.Code:onClipEvent(enterFrame){
if(Key.isDown(Key.UP)){
move(0,-s);
}
if(Key.isDown(Key.DOWN)){
move(0,s);
}
if(Key.isDown(Key.LEFT)){
move(-s,0);
}
if(Key.isDown(Key.RIGHT)){
move(s,0);
}
}
______________________________________________
MY QUESTION:
Is it possible to do a hittest through different MCs? I have an MC of my hero swinging a fish, in which a hit area comes up, and if a target inside a different MC is within the hit area of the hero MC, I want the MC of the target to go to frame 2...
And is it possible to have 2 different hitTests inside the same MC?
Does anyone know some simple coding that they are SURE will work for a maze-type game so that my hero wont keep walking through the maze walls...Please if you have a simple script for Flash 5 POST IT!!! I want to be able to make my own game with the script without screwing up...
see page one
I am trying to make a birds eye game where a little guy walks around a world that I am creating slowly. Maybe it will become multiplayer (that would be cool) if my friend/server allows me to host it from the site.
Anyways, There are rocks on the gorund and I want the little man to stop when her runs into one. I have figured out how to make him move, here is what I have:
onClipEvent (enterFrame) {
if (Key.isDown(key.Right)) {
this._x += 3;
this.gotoAndStop("WalkEast");
} else if (Key.isDown(key.Down)) {
this._y += 3;
this.gotoAndStop("WalkSouth");
} else if (Key.isDown(key.Left)) {
this._x -= 3;
this.gotoAndStop("WalkWest");
} else if (Key.isDown(key.Up)) {
this._y -= 3;
this.gotoAndStop("WalkNorth");
} else if (Key.isDown(key.Right) and key.isDown(66)) {
this._x += 6;
this.gotoAndStop("RunEast");
} else if (Key.isDown(65)) {
this._x += 0;
this.gotoAndStop("PickW");
} else {
this._y += 0;
this.gotoAndStop("StandS");
if (this.hitTest(BigRock)) {
this._y += 0;
this._x += 0;
this.gotoAndStop("StandS");
}
}
}
Note, the "else.if(key.isDown(key.Right) and key.isdown(b))" doesnt work If you know how to make it do something while pressing 2 keys at once plz help as well.
Anyways, my problem is the last IF funtion in that thread, it doesn't seem to want to work. I'll attach a zip to this forum if anyone needs me to, but later.:doughnut: :cow:
here is just a sample with 3 rocks and a little dude.
See page one, once again (Ed's post)
i wonder, why the the hittest always freeze when hit the wall/boundry?
http://darksquall.digitalrice.com/dungeon2.zip
key:
arrow to move
tab to take the blackbox, while on it
red area, the area to walk
I tried the thing on page one but nothing happened.
Hey everyone,
I was wondering the same thing that Thor mentioned a few posts before this one on July 13th. Ed Mack's hitTest Collision method only works for two MCs that are on the main stage. This causes a problem for me, since my "hero" and "hit" are within MCs.
When looking at Ed Mack's code:Code:_root.world.holder.hero; // Hero
_root.world.holder.wall; // the Wall the hero cannot pass through
I don't see a thing that would not permit it to work within any MC. I have tried using his code with my scenario (changing _root.hit to _root.world.holder.wall, for example), but the hero always passes through the wall, meaning something's just not registering in the hitTest department. The only thing that may be holding back its functionality is the use of xmax, xmin, ymin, and ymax, but I'm uncertain of that as well.Code:onClipEvent(load){
s = 5;
b = this.getBounds(this);
function move(x,y){
if(!_root.hit.hitTest(_x+x+b.xmin+1, _y+y+b.ymin+1, true)){
if(!_root.hit.hitTest(_x+x+b.xmax-1, _y+y+b.ymin+1, true)){
if(!_root.hit.hitTest(_x+x+b.xmin+1, _y+y+b.ymax-1, true)){
if(!_root.hit.hitTest(_x+x+b.xmax-1, _y+y+b.ymax-1, true)){
_x += x;
_y += y;
}
}
}
}
}
}
onClipEvent(enterFrame){
if(Key.isDown(Key.UP)){
move(0,-s);
}
if(Key.isDown(Key.DOWN)){
move(0,s);
}
if(Key.isDown(Key.LEFT)){
move(-s,0);
}
if(Key.isDown(Key.RIGHT)){
move(s,0);
}
}
If any of you can figure out a way to get around this problem, I'm sure many people would be grateful. I, for one, thank you in advance for any help you may provide.
Thanks!
- Bean
hi bean,
I've tried ed's and work on mine, you can see it in dongeon.zip, which i've sent be4.
the only problem now is my hero stuck / freeze ( like there is an ice trap outside the red area ^^) cant go back after hit the wall
use arrow key to move and tab to take the black box.
BTW my code is spooky so prepare your eye :p :p
I made some minor change to ed's code, so the map moving, instead the hero.
BUT i found that the script, which has no error, run not well
it still walk pass the wall for some pixel, and then stuck
it should be working , shouldn't it ??
since this is a discussion about hittest i thought this was the best place to post this:
if(_root.Symbol 16, hittest(_root.Symbol 4)){
_root.score +=1;
}
whenever i try to test the scene the output says:
')' expected
and i can't figure out where it wants me to put a ')'
help:confused:
well, that usually happens to me when I use If(Key.isDown)
Because I end up typing
Instead ofCode:if(Key.isDown(Key.Right)
Not sure if thats ur problem though.Code:if(Key.isDown(Key.Right))
no, i made sure i had enough but it wants more and i don't know where.
Maybe you could try giving Symbol 16 and Symbol 4 unique instance names. Just select the individual symbol, then in the properties window, under "Instance Name", give the symbol a name that kind of describes what it is. Then use this:
Assuming you change symbol 16 to "sixteen"
and assuming you change symbol 4 to "four"
Of course you shouldn't neccesarily use "sixteen" and "four". I just used those so they resemble their original counterparts.Code:if (_root.sixteen.hitTest("_root.four")){
_root.score += 1;
}
- Bean
thx that worked i dont know how, i had their instance names the same as their symbol names.