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 :confused:
Any advice appreciated. Thanks.
- Steve
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 :eek: