-
maze walls
iam tryin to make a maze game. my codes all right ( NOT REALY!!) but the
walls arnt good a hittest they just arnt . I tryed combineing two codes... total disaster!!
help on better maze with better colision plaese... thanks
PHP Code:
// combined sucky code
onClipEvent(load){
speed = 0;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.UP)) {
speed = 7;
}
else if (Key.isDown(Key.DOWN)) {
speed =- 7;
}
else gotoAndStop(1);
}
onClipEvent (enterFrame) {
if (Math.abs(speed)>0) {
speed *= .7;
}
if (Key.isDown(Key.LEFT)) {
_x -= 7;
}
if (Key.isDown(Key.RIGHT)) {
_x += 7;
}
speed *= .98;
x = Math.sin(_rotation*(Math.PI/20))*speed;
y = Math.cos(_rotation*(Math.PI/20))*speed*-1;
if (!_root.maze.hitTest(_x+x, _y+y, true)) {
_x += x;
_y += y;
} else {
speed *= -.6;
}
}
onClipEvent (enterFrame) {
if(_root.maze.hitTest(_x+(_width/2),_y,true)){
this._x -= 7;
}
if(_root.maze.hitTest(_x-(_width/2),_y,true)){
this._x += 7;
}
}
-
President
I didn't quite get what's going on in the code. Though here's a fla that was in the Flash MX samples that has that maze game. Hope it helps.
Last edited by PhobiK; 12-21-2008 at 09:55 PM.
This is MC. His _parents sent him to stop() by the super market to buy some _root beer if he wanted to gotoAndPlay() with his friends at the park later.
This is my Blog!... The gaming Process
Please check out my site: Giddel Creations
-
hard for me
thats to dificult is there somthing lil more easier??
-
Senior Member
the only difficult part is to find the code there
Code:
onClipEvent (enterFrame) {
if (_root.started && _root._currentframe==1) {
with (_root.square) {
//
// keyboard controls
if (Key.isDown(Key.DOWN)) {
_y += 1;
}
if (Key.isDown(Key.UP)) {
_y -= 1;
}
if (Key.isDown(Key.LEFT)) {
_x -= 1;
}
if (Key.isDown(Key.RIGHT)) {
_x += 1;
}
//
// detect if edges of the player square are colliding with the maze walls
if (walls.hitTest(getBounds(_root).xMax, _y, true)) {
_x -= 1;
}
if (walls.hitTest(getBounds(_root).xMin, _y, true)) {
_x += 1;
}
if (walls.hitTest(_x, getBounds(_root).yMax, true)) {
_y -= 1;
}
if (walls.hitTest(_x, getBounds(_root).yMin, true)) {
_y += 1;
}
//
// detect if maze is finished
if (_root.goal.hitTest(_x, getBounds(_root).yMax, true)) {
_root.gotoandstop(3);
}
}
}
}
-
President
Thanks for posting it Well it's not too difficult. getBounds is used to get the limits of the mc. It gives you the values xMin, xMax, yMin and yMax. So you check the hitTest like you were doing it but with those values. You can also keep it your way replacing the getBounds with _x + _width/2 for example. That works too.
This is MC. His _parents sent him to stop() by the super market to buy some _root beer if he wanted to gotoAndPlay() with his friends at the park later.
This is my Blog!... The gaming Process
Please check out my site: Giddel Creations
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|