View Full Version : [AS3] Game help ...?
kingie94
09-28-2008, 06:33 PM
I have a character that can be moved with the arrow keys and i want it to collect coins, i have made it so that when it picks up the coin the score goes up by 100,
When the coin is collected i want it to move to a random place..
can anyone help?
Assuming the coin can be anywhere on the Stage:
If the coin is just being repositioned...
coin.x = Math.random()*stage.stageWidth;
coin.y = Math.random()*stage.stageHeight;
If a new coin is being instantiated...
var coin:Coin = new Coin();
coin.x = Math.random()*stage.stageWidth;
coin.y = Math.random()*stage.stageHeight;
If you want the coin to be confined to a specific area of the stage...
var leftLimit:Number = /*some number*/;
var rightLimit:Number = /*some number*/;
var topLimit:Number = /*some number*/;
var bottomLimit:Number = /*some number*/;
coin.x = (Math.random()*(stage.stageWidth-rightLimit))+leftLimit;
coin.y = (Math.random()*(stage.stageHeight-bottomLimit))+topLimit;
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.