Forum Topic: Map Coding Help

(256 views • 14 replies)

This topic is 1 page long.

<< < > >>
Expressionless

Pelemus-McSoy

Reply To Post Reply & Quote

Posted at: 4/26/09 10:45 PM

Pelemus-McSoy NEUTRAL LEVEL 16

Sign-Up: 02/16/06

Posts: 340

Hey Newgrounds, how are you this fine evening?

I need help coming up with a more efficient coding method for map movement.

The image below shows what one portion of the map will look like. I can't use hitTest to block the user from going outside of the tan areas, and I do not have the energy/time/will power to make tiny lines to make a hitTest work.

Is there a way to keep the player from going into the black areas, or will the map have to be redrawn?

Thanks for the help, and have a good one.

~Pelo

Map Coding Help

Coming soon: Bill's Quest

About goddamned time!


None

DawnOfDusk

Reply To Post Reply & Quote

Posted at: 4/26/09 11:22 PM

DawnOfDusk EVIL LEVEL 14

Sign-Up: 02/22/08

Posts: 1,488

Yeah, read up on shapeflag hitTesting. If you don't have the will to code, then don't.

:: AS2: Main :: AS3: Main :: C++: Main :: I speak German =3

BBS Signature

None

Pelemus-McSoy

Reply To Post Reply & Quote

Posted at: 4/26/09 11:26 PM

Pelemus-McSoy NEUTRAL LEVEL 16

Sign-Up: 02/16/06

Posts: 340

I'll give the shapeflag a try.

Thanks.

Coming soon: Bill's Quest

About goddamned time!


Expressionless

Pelemus-McSoy

Reply To Post Reply & Quote

Posted at: 4/27/09 01:46 PM

Pelemus-McSoy NEUTRAL LEVEL 16

Sign-Up: 02/16/06

Posts: 340

I've tried using the shapeflag, but it still doesn't seem to work.

This is what I have:

/*Frame-----Dude is the square, and block is the blue area*/
onEnterFrame = function()
{
if(_root.dude.hitTest(_root.block._x, _root.block._y, true))
{
speed = 0;
}
else
{
speed = 5;
}
}

/*on square*/
on(keyPress "<Left>")
{
this._x -= _root.speed;
}
on(keyPress "<Right>")
{
this._x += _root.speed;
}
on(keyPress "<Up>")
{
this._y -= _root.speed;
}
on(keyPress "<Down>")
{
this._y += _root.speed;
}

I have the understanding that shapeFlag is meant for one point only...will that render this code above as useless?

Map Coding Help

Coming soon: Bill's Quest

About goddamned time!


None

kiwi-kiwi

Reply To Post Reply & Quote

Posted at: 4/27/09 02:41 PM

kiwi-kiwi LIGHT LEVEL 08

Sign-Up: 03/06/09

Posts: 630

You could look over here


None

Pelemus-McSoy

Reply To Post Reply & Quote

Posted at: 4/27/09 06:25 PM

Pelemus-McSoy NEUTRAL LEVEL 16

Sign-Up: 02/16/06

Posts: 340

Thanks, but unfortunately I'm working with AS2...or will that code work too?

Coming soon: Bill's Quest

About goddamned time!


Resigned

Kwing

Reply To Post Reply & Quote

Posted at: 4/27/09 07:07 PM

Kwing DARK LEVEL 24

Sign-Up: 07/24/07

Posts: 1,916

Mouse maze or arrow keys?


None

Pelemus-McSoy

Reply To Post Reply & Quote

Posted at: 4/27/09 07:18 PM

Pelemus-McSoy NEUTRAL LEVEL 16

Sign-Up: 02/16/06

Posts: 340

Arrow keys.

/*movement code*/
onClipEvent(enterFrame)
{
if(Key.isDown(Key.LEFT))
{
this._x += _root.leftSpeed;
}
if(Key.isDown(Key.RIGHT))
{
this._x -= _root.rightSpeed;
}
if(Key.isDown(Key.UP))
{
this._y += _root.upSpeed;
}
}

Coming soon: Bill's Quest

About goddamned time!


None

dragonjet

Reply To Post Reply & Quote

Posted at: 4/27/09 08:16 PM

dragonjet LIGHT LEVEL 20

Sign-Up: 12/02/05

Posts: 673

onEnterFrame = function()
{
   if(_root.block.hitTest(_root.dude._x, _root.dude._y, true)){
	   speed = 0;
   }else{ speed = 5; }
   
   if(Key.isDown(Key.LEFT)){ dude._x-=speed; }
   if(Key.isDown(Key.RIGHT)){ dude._x+=speed; }
   if(Key.isDown(Key.UP)){ dude._y-=speed; }
   if(Key.isDown(Key.DOWN)){ dude._y+=speed; }
}

and remove the code on the dude MC

Sig


Happy

Kart-Man

Reply To Post Reply & Quote

Posted at: 4/27/09 08:32 PM

Kart-Man NEUTRAL LEVEL 27

Sign-Up: 01/07/07

Posts: 3,715

Hey, Pelemus!

You'll want to look up shapeFlag hitTesting for this one. Assuming that the yellow pathways in your post are a movieclip, you can simply use shapeFlag to move the player back by its speed whenever a side of it is not touching the pathway:

speed = 6;
onEnterFrame = function () {
//if path is not hitTesting the _x of the player PLUS half of the player's width (RIGHT SIDE)
	if (!path.hitTest(player._x+player._width/2, player._y, true)) {
		player._x -=speed;
	}
//if path is not hitTesting the _x of the player MINUS half of the player's width (LEFT SIDE)
	if (!path.hitTest(player._x-player._width/2, player._y, true)) {
		player._x +=speed;
	}
//if path is not hitTesting the _y of the player MINUS half of the player's height (TOP SIDE)
	if (!path.hitTest(player._x, player._y-player._height/2, true)) {
		player._y +=speed;
	}
//if path is not hitTesting the _y of the player PLUS half of the player's height (BOTTOM SIDE)
	if (!path.hitTest(player._x, player._y+player._height/2, true)) {
		player._y -=speed;
	}
};

Elated

Pelemus-McSoy

Reply To Post Reply & Quote

Posted at: 4/27/09 08:34 PM

Pelemus-McSoy NEUTRAL LEVEL 16

Sign-Up: 02/16/06

Posts: 340

Thanks. This should be very helpful for me. Thank you very much!

Coming soon: Bill's Quest

About goddamned time!


None

dragonjet

Reply To Post Reply & Quote

Posted at: 4/27/09 08:48 PM

dragonjet LIGHT LEVEL 20

Sign-Up: 12/02/05

Posts: 673


Happy

Pelemus-McSoy

Reply To Post Reply & Quote

Posted at: 4/27/09 10:58 PM

Pelemus-McSoy NEUTRAL LEVEL 16

Sign-Up: 02/16/06

Posts: 340

Oh, thank you! I'll be sure to play around with it, see if I can tweak it some for my game...

I owe you guys one!

Coming soon: Bill's Quest

About goddamned time!


None

El-Presidente

Reply To Post Reply & Quote

Posted at: 4/27/09 11:38 PM

El-Presidente LIGHT LEVEL 27

Sign-Up: 06/02/05

Posts: 5,163

Use a shapeflag hitTest:
object.hitTest(x, y, Boolean)
In your case, the object is the whole ground / walls movieclip in one. Boolean is true for you. The x and y are coordinates that you use when checking the hitTest to see if the graphic itself touches those points. So use your player's points. Look more about it on AS: Main or anywhere.

MY E-PENIS IS BIGGER THAN YOURS
8=================================>
...and this is my fag...

BBS Signature

None

El-Presidente

Reply To Post Reply & Quote

Posted at: 4/28/09 05:27 PM

El-Presidente LIGHT LEVEL 27

Sign-Up: 06/02/05

Posts: 5,163

Wow, I hate those moments when I forget to scroll down and see if anyone responded. Sorry about that :/

MY E-PENIS IS BIGGER THAN YOURS
8=================================>
...and this is my fag...

BBS Signature

All times are Eastern Standard Time (GMT -5) | Current Time: 07:10 AM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!