Snakes and ladders - moving a movie clip using random value from dice
A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: Snakes and ladders - moving a movie clip using random value from dice

  1. #1
    Junior Member
    Join Date
    Dec 2008
    Posts
    14

    Snakes and ladders - moving a movie clip using random value from dice

    Hi there, im fairly new to Flash so this is a basic question...

    Ok, i am creating a snakes and ladders game and have so far produced the board, the counter and the dice.

    Once the dice is rolled it returns a value called 'rollValue'

    The counter is a movie clip with the instance name 'counter' and is set up on the timeline with position 1 on the timeline being the first place on the board, position 2 on the timeline being the second place, 3 on the timeline being 3rd position on board etc etc.

    What i need to do is move the counter to the position on the timeline (hence moving it on the board) that is returned by the dice value.

    I was thinking something like this:

    counter.gotoAndStop(rollValue);

    or maybe this on the actual counter which would move it the amount of places determined by rollValue:

    on (press) {
    gotoAndStop(rollValue);
    }

    Although im not receiving any errors when testing both of these, the counter isn't moving

    Any advice appreciated. Thanks.

    - Steve

  2. #2
    Junior Member
    Join Date
    Dec 2008
    Posts
    14
    Here is the game board i am working on http://www.collinscreative.co.uk/Int...0rollover.html

    I simply need the snake to progress along the board each time the dice is rolled rather than go back to the beginning. I am using the getProperty action like this to get the current frame the snake is on on the timeline:

    var currentPos = getProperty ( "_root.button1", _currentframe );

    but the currentPos doesnt update in the variable:

    on (press) {gotoAndStop(_root.currentPos + _root.result);

    result is the variable returned from the dice.

    Hope this makes sense.


    Thanks.

    - Ste
    Last edited by stec74; 02-03-2009 at 07:52 PM.

  3. #3
    Junior Member
    Join Date
    Dec 2008
    Posts
    14

    Snakes and ladders game: Disabling dice roll until next move

    Hi i have nearly complete this game which has taken a bit longer than anticipated due to time constraints!
    http://www.collinscreative.co.uk/Int...ndladders6.swf

    The problem i now have is disabling the dice onRelease after each roll. Is there a way this can be achieved?

    The code on the timeline is as follows:

    // showResult is called when the dice has finished moving
    function showResult(de_instance){

    // result represents the text field variable that will receive the value of rollValue
    _root.result = de_instance.rollValue;
    }

    The code on the dice movie clip (one level down) is:

    #initclip

    function Diceclass() {
    this.state = false;
    this.rollValue = 0;
    this.randrotate = 0;
    if (this.rollOnClick == true) {
    this.onPress = function() {
    clearInterval(this.int1);
    clearInterval(this.int2);
    this.roll();
    };
    }
    }
    Diceclass.prototype = new MovieClip();
    Object.registerClass("dice_MC", Diceclass);

    Diceclass.prototype.roll = function() {
    clearInterval(this.int1);
    clearInterval(this.int2);
    this.rollValue = Math.floor(Math.random()*6)+1;
    this.dice_normal._visible = false;
    this.dice_blurred._visible = true;
    this.int1 = setInterval(getRandom, 20, this);
    this.int2 = setInterval(clearRandom, this.rollDuration, this);

    function getRandom(MC) {
    MC.state = true;
    MC.randFrame = Math.floor(Math.random()*6)+1;
    MC.randrotate = Math.floor(Math.random()*360);
    MC.dice_blurred.gotoAndStop(MC.randFrame+1);
    MC.dice_blurred._rotation += MC.randrotate;
    updateAfterEvent();

    }
    function clearRandom(MC) {
    clearInterval(MC.int1);
    clearInterval(MC.int2);
    MC.state = false;
    MC.dice_blurred._visible = false;
    MC.dice_normal._visible = true;
    MC.dice_normal.gotoAndStop(MC.rollValue+1);
    MC.dice_normal._rotation += MC.randrotate;
    MC.myFunction = eval(MC.rollFunction);
    MC.myFunction.apply(null,[MC]);
    }
    };

    #endinitclip

    I have achieved this with the counter (represented as a mouse on the game) by using a variable called diceroll:

    on (release) {
    if (this.diceroll == "no") {
    loadText = new LoadVars();
    loadText.load("data.txt");
    loadText.onLoad = function() {
    rollthedice.text = this.rollthedice;
    };
    } else if (this.diceroll == "yes") {
    {gotoAndStop(_root.result+_currentFrame);
    }
    }
    }

    ...but when i try to do this with the dice, it just wont disable the dice therefore the dice can be rolled as many times as you want. I just need the dice to be rolled once then disabled until the counter has been clicked and ready for the next move.

    I hope this makes sense.

    ps. the dice was a free component i got from http://www.flashvalley.co.uk

    Any help greatly appreciated as i have a tight deadline on this one now
    Last edited by stec74; 02-03-2009 at 07:54 PM.

  4. #4
    Senior Member vinayak.kadam's Avatar
    Join Date
    Oct 2006
    Location
    gotoAndPlay("Pune");
    Posts
    830
    Can u upload ur FLA so that we can check at our end.....what ur are rying to do is quite correct but if still u r not getting any results then we need FLA for debugging the probs!!!!!
    As ever,
    Vinayak Kadam

  5. #5
    Junior Member
    Join Date
    Dec 2008
    Posts
    14
    I have sent you a pm with the fla attached. Thanks.

  6. #6
    Junior Member
    Join Date
    Dec 2008
    Posts
    14
    The code i need for the dice initclip is as follows but enabling it again on the button is the problem now. I think its a target issue as the dice code is one level down.

    To disable the dice ad the following code:

    if (this.rollOnClick == true) {
    this.onPress = function() {
    clearInterval(this.int1);
    clearInterval(this.int2);
    this.roll();
    this.enabled = false;
    };
    }

  7. #7
    Senior Member vinayak.kadam's Avatar
    Join Date
    Oct 2006
    Location
    gotoAndPlay("Pune");
    Posts
    830
    Is ur problem solved ??
    As ever,
    Vinayak Kadam

  8. #8
    Junior Member
    Join Date
    Feb 2009
    Location
    Perth, Australia
    Posts
    10
    hey how do you start a thread on this site i want to ask people about a AI i'm making at the moment the i need help with but i can't post anything
    Can any one help?????

  9. #9
    Junior Member
    Join Date
    Dec 2008
    Posts
    14
    Hi, just thoght ide check back on this thread. version 1 of my game is now complete, thanks for everyones help. I plan to integrate a database with high score chart at some point so may return to this thread.

  10. #10
    Registered User
    Join Date
    Jul 2013
    Posts
    2
    can someone send me the fla copy of this game please? im really new into flash and want to learn from you. thanks!

  11. #11
    Senior Member realMakc's Avatar
    Join Date
    Oct 2002
    Posts
    661
    Quote Originally Posted by stec74 View Post
    Hi i have nearly complete this game which has taken a bit longer than anticipated due to time constraints!
    http://www.collinscreative.co.uk/Int...ndladders6.swf
    I think this game was moved here, and you could easily get the fla using some decompiler. But it's pointless, as it does not work (see "undefined"-s everywhere ?). And, even if it did, you should look for as3 games, if you want to learn flash at this point of time.

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

Poll by Flashkit.com