A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: [Help] RPG Problem

  1. #1
    11 Years Old Boya
    Join Date
    Apr 2004
    Posts
    61

    [Help] RPG Problem

    Ok..I was making a game base on a tutorial called The Basic of RPG(role playing game) and tried to make a hitTest(so the player won't go through building) but it didn't work.

    I put the following code:

    ::The Wall::
    Code:
    onClipEvent (load) {
    	movespeed = 2;
    }
    onClipEvent (enterFrame) {
    	if (Key.isDown(Key.RIGHT)) {
    		_x -= movespeed;
    		if (_root.man.hitTest(this)) {
    			_x += movespeed;
    		}
    	}
    	if (Key.isDown(Key.LEFT)) {
    		_x += movespeed;
    		if (_root.man.hitTest(this)) {
    			_x -= movespeed;
    		}
    	}
    	if (Key.isDown(Key.UP)) {
    		_y += movespeed;
    		if (_root.man.hitTest(this)) {
    			_y -= movespeed;
    		}
    	}
    	if (Key.isDown(Key.DOWN)) {
    		_y -= movespeed;
    		if (_root.man.hitTest(this)) {
    			_y += movespeed;
    		}
    	}
    }
    ::Background:not the frame)
    Same as the Wall script but changed 'this' into '_root.wall'.

    ::Character::
    Code:
    onClipEvent (load) {
    	movespeed = 0;
    }
    onClipEvent (enterFrame) {
    	if (Key.isDown(Key.UP) or Key.isDown(Key.DOWN) or Key.isDown(Key.RIGHT) or Key.isDown(Key.LEFT)) {
    		energy -= .2;
    	}
    	if (Key.isDown(Key.RIGHT)) {
    		_rotation = 90;
    	}
    	if (Key.isDown(Key.LEFT)) {
    		_rotation = 270;
    	}
    	if (Key.isDown(Key.UP)) {
    		_rotation = 0;
    	}
    	if (Key.isDown(Key.DOWN)) {
    		_rotation = 180;
    	}
    	if (Key.isDown(Key.RIGHT) && Key.isDown(Key.UP)) {
    		_rotation = 45;
    	}
    	if (Key.isDown(Key.LEFT) && Key.isDown(Key.UP)) {
    		_rotation = 315;
    	}
    	if (Key.isDown(Key.RIGHT) && Key.isDown(Key.DOWN)) {
    		_rotation = 135;
    	}
    	if (Key.isDown(Key.LEFT) && Key.isDown(Key.DOWN)) {
    		_rotation = 225;
    	}
    }
    I'll give many thanks to the people who would help me.
    Checkout my site:
    Click HERE
    Checkout my games:
    Oops! No game for now!

  2. #2
    Lunatic Baukereg's Avatar
    Join Date
    Nov 2000
    Location
    Lowlands
    Posts
    853
    The walls are propably one MC. That way, hitTest is checked between the hero and the boundry box of the wall-MC.

    Check this thread: http://www.flashkit.com/board/showth...0&pagenumber=1

  3. #3
    11 Years Old Boya
    Join Date
    Apr 2004
    Posts
    61
    OMG!!! I just solve the problem myself.
    Checkout my site:
    Click HERE
    Checkout my games:
    Oops! No game for now!

  4. #4
    11 Years Old Boya
    Join Date
    Apr 2004
    Posts
    61
    OH CRAP!!! Another problem. This is what happen:

    Well I solve the last problem by putting the Background and the Wall MC into 1 MC I call it '1'. Then I created another MC in the '1' MC called 'step' with an instance name of 'casino1'.

    I want the man to go the next frame when he hit the 'casino1' MC BUT it didn't work.

    I put the following code in the '1' MC:
    Code:
    onClipEvent (load) {
    	movespeed = 2;
    }
    onClipEvent (enterFrame) {
    	//Moving Background
    	if (Key.isDown(Key.RIGHT)) {
    		_x -= movespeed;
    		if (_root.man.hitTest(this.wall)) {
    			_x += movespeed;
    		}
    	}
    	if (Key.isDown(Key.LEFT)) {
    		_x += movespeed;
    		if (_root.man.hitTest(this.wall)) {
    			_x -= movespeed;
    		}
    	}
    	if (Key.isDown(Key.UP)) {
    		_y += movespeed;
    		if (_root.man.hitTest(this.wall)) {
    			_y -= movespeed;
    		}
    	}
    	if (Key.isDown(Key.DOWN)) {
    		_y -= movespeed;
    		if (_root.man.hitTest(this.wall)) {
    			_y += movespeed;
    		}
    	}
    	//Casino 1
    	if (Key.isDown(Key.SPACE)) {
    		if (_root.man.hitTest(this.casino1)) {
    			gotoAndPlay(2);
    		} else {
    			//DO NOTHING
    		}
    	}
    }
    Checkout my site:
    Click HERE
    Checkout my games:
    Oops! No game for now!

  5. #5
    Senior Member TyroneWatt's Avatar
    Join Date
    Mar 2004
    Location
    Behind you
    Posts
    125
    code:

    //Casino 1
    if (Key.isDown(Key.SPACE)) {
    if (_root.man.hitTest(this.casino1)) {
    gotoAndPlay(2);
    } else {
    //DO NOTHING
    }
    }



    When the hit test is true you are going to the 2nd frame of your current MC (1). You probably want to go to _root.gotoAndPlay(2).
    if this is not what you want, put a trace in the 'if' statement and see if thats working at least.

  6. #6
    11 Years Old Boya
    Join Date
    Apr 2004
    Posts
    61
    Oh thanks alot!!!
    Checkout my site:
    Click HERE
    Checkout my games:
    Oops! No game for now!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center