Forum Topic: AS2 Birds eye view wall/restrictor

(79 views • 3 replies)

This topic is 1 page long.

<< < > >>
None

dasmitimsad

Reply To Post Reply & Quote

Posted at: 1/24/09 12:06 AM

dasmitimsad NEUTRAL LEVEL 02

Sign-Up: 01/21/09

Posts: 3

This is my first message here so hopefully this is how you post in NewGrounds. I am making a game (a bit like Hands of War) but I have tried all that I know to make a wall that the character cannot walk through but it hasn't worked. Can anyone help me with it please? Thankyou.

I can eat you.

BBS Signature

None

Woadraiders

Reply To Post Reply & Quote

Posted at: 1/24/09 06:10 AM

Woadraiders DARK LEVEL 11

Sign-Up: 11/11/07

Posts: 561

Enterframe + hittest?
If the hittest returns true, then place the character off the wall.
This should be simple enough to start out with...

Mibbygames.com
panterA

BBS Signature

None

Pyromaniac

Reply To Post Reply & Quote

Posted at: 1/24/09 01:30 PM

Pyromaniac EVIL LEVEL 18

Sign-Up: 01/14/05

Posts: 2,977

To effectively make a wall, you need to take the direction and speed the character is moving in, and reverse it.

Say the characters _x is going up by 10. To make a wall stop it, when it is touching it, the characters _x would be going down by 10.

This is best achieved through a speed variable. Say you make the character move right by the variable speed when right is pressed. ( _x+=speed; )To stop him from going through a ride-side wall, you say _x-=speed;

Change that as needed for whatever direction the character is moving in.


None

flailthefox

Reply To Post Reply & Quote

Posted at: 1/24/09 01:43 PM

flailthefox NEUTRAL LEVEL 05

Sign-Up: 08/30/07

Posts: 214

this is like a overhead game? such as a maze game?

in which you need to add a code along the lines of :

onClipEvent (load) {
power = 6;
radius = 14;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
_x -= power;
}
if (Key.isDown(Key.RIGHT)) {
_x += power;
}
if (Key.isDown(Key.UP)) {
_y -= power;
}
if (Key.isDown(Key.DOWN)) {
_y += power;
}
while (_root.wall.hitTest(_x, _y+radius, true)) {
_y--;
}
while (_root.wall.hitTest(_x, _y-radius, true)) {
_y++;
}
while (_root.wall.hitTest(_x-radius, _y, true)) {
_x++;
}
while (_root.wall.hitTest(_x+radius, _y, true)) {
_x--;
}
}

I'll explain each part for you.

The Power (line 2) it just to make the player move faster than it is said in the Key.down code lines. I put this in to make him run faster. So ignore that.

We skip along a bit blah blah blah.

ok here we are. If you make a movieclip of a square and name it wall, and give it an instance name of wall, then this code will work., here's why:

I check the hit test between the center of the player and the wall before moving him. If I "foresee" the player's center will hit the wall, I don't move him. Then I performed the same hit test as before but not relatively to the center. then I perform the test and move back the player of one pixel in a direction every time the hit test is detected in that direction. Since player's speed is 3, the while loop won't be executed more than 3 times, that is not CPU expensive.

Make sense? ;)

Destroyed.


All times are Eastern Standard Time (GMT -5) | Current Time: 08:27 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!