PDA

View Full Version : [AS2] Spin the Bottle-App


khymera
02-17-2009, 07:47 PM
I am looking to do a simple spin the bottle game in flash. I would like to know if any anyone can point me in the right direction.

The object "AKA Bottle" spins there a 6 predetermined landing areas:

So far have the spin button

on(press){
object.spinning = true
object.spin = 17 + Math.random()*20
object._rotation = object._rotation = 0
}

and the bottle object spinning to the button.


onClipEvent(enterFrame){
if (spinning){
if (spin <= 0){
spinning = false
rot = (_rotation < 0) ? 180 + _rotation : _rotation
_root.youSpunA = Math.floor(16 * rot/180)+1
}else{
_rotation += spin -= .25
_parent.wheel._rotation = -_rotation
}
}
}


I would like to if I can traceback the 6 predetermined positions so if the bottle lands on one of them an action can be performed, EX(bottle lands on point 1 message says you have to kiss player a, bottle lands on point 2 message says you have to kiss player b) nothing more If anyone can point me in the direction would be appreciated, kind of lost here.

Thanks

PhatKitty
02-21-2009, 12:15 AM
Maybe you could make an array, then trace 0-5 depeding on what section they land on, I think it's something like:

var zone = new Array();
zone[0] = "Kiss player A"
zone[1] = "Kiss player B"
zone[2] = "Ect"
zone[3] = "Ect"
zone[4] = "Ect"
zone[5] = "Ect"

then you could use a Boolean variable with a hitTest like:

var zone0:Boolean = false
var zone1:Boolean = false
var zone2:Boolean = false
var zone3:Boolean = false
var zone4:Boolean = false
var zone5:Boolean = false

Replace the textbox below to whatever var name you gave your text box and the "bottle" bit to whatever you called your bottle/spinner:

if (hitTest(bottle)) {
zone0 = true
textbox=zone[0];
} else {
zone0 = false
}
if (hitTest(bottle)) {
zone1 = true
textbox=zone[1];
} else {
zone1 = false
}

EDIT: I only did this bit for zone 0 + 1 so don't forget to fill in 2-5.

This should make it so when the bottle is touching each zone, the diferent messages will appear in the text box.

Hope it helps, and works =P

neilmmm
02-21-2009, 01:23 AM
I would use the tween class

import mx.transitions.Tween;
import mx.transitions.easing.*;

btn_mc.onRelease=function () {
this.enabled=false;
var rotTime:Number=Math.ceil(Math.random()*12);
var rotAmount=(rotTime*60)+360
var outcome:Number=rotTime%6

var myTween:Tween = new Tween (bottle_mc,"_rotation",Strong.easeOut,this._rotation,rotAmount,rotTime,t rue);
myTween.onMotionFinished=function () {
trace("perform outcome "+outcome);
btn_mc.enabled=true;
}
}