Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to random create objects from specific 5 points?
    primarykey
    data
    text
    <p>Halo, I am developing a mini flash game.</p> <p>Gameplay: Player control character and move left and right to collect money coin. There are 5 points that money and bomb release and move from top to bottom. When character collide with money then increase money else hit bomb age increase by 1. Once the age is 99, the game is over and the money is the final scores</p> <p>Here is my code:</p> <pre><code>package Class { import flash.events.Event; import flash.events.KeyboardEvent; import flash.events.MouseEvent; import flash.media.Sound; import flash.media.SoundChannel; import flash.text.TextField; import flash.ui.Keyboard; import flash.display.MovieClip; public class Game extends MovieClip { private var bgi:BGI; private var character:Character; private var money:Money; private var bomb:Bomb; private var moneysource : MoneySource; private var moneytext:TextField; private var agetext:TextField; private var characterspeed:int; private var objectspeed:int; private var age:int; private var moneyscore:int; private var moneyinscreen:int; private var moneyVector:Vector.&lt;MovieClip &gt; = new Vector.&lt;MovieClip &gt;; private var noofmoney:int; private var noofbomb:int; private var bombVector:Vector.&lt;MovieClip &gt; = new Vector.&lt;MovieClip &gt;; public function Game() { bgi = null; character = null; money = null; bomb = null; moneysource = null; Initialize(); } private function Initialize() { age = 0; moneyscore = 0; noofmoney = 15; noofbomb = 10; bgi = new BGI ; bgi.x = 0; bgi.y = 0; character = new Character ; character.x = 335; character.y = 400; bomb = new Bomb ; bomb.x = 40; bomb.y = 0; moneytext = new TextField ; moneytext.x = 450; moneytext.y = 0; moneytext.defaultTextFormat = Config.TxtFormat; moneytext.text = "Money : 0"; moneytext.width = 200; agetext = new TextField ; agetext.x = 700; agetext.y = 0; agetext.defaultTextFormat = Config.TxtFormat; agetext.text = "Age : 0"; agetext.width = 100; Config.CurrentStage.addChild(bgi); Config.CurrentStage.addChild(character); Config.CurrentStage.addChild(agetext); Config.CurrentStage.addChild(moneytext); moneysource = new MoneySource; moneysource.x = 61; moneysource.y = 50; Config.CurrentStage.addChild(moneysource); moneysource = new MoneySource; moneysource.x = 211; moneysource.y = 50; Config.CurrentStage.addChild(moneysource); moneysource = new MoneySource; moneysource.x = 371; moneysource.y = 50; Config.CurrentStage.addChild(moneysource); moneysource = new MoneySource; moneysource.x = 531; moneysource.y = 50; Config.CurrentStage.addChild(moneysource); moneysource = new MoneySource; moneysource.x = 691; moneysource.y = 50; Config.CurrentStage.addChild(moneysource); for (var i:int = 0; i &lt; noofmoney; i++) { money = new Money ; money.vel = RandomRange(6,7); money.x = RandomRange(0,750); money.y = RandomRange(0,100); Config.CurrentStage.addChild(money); moneyVector.push(money); } for (var j:int = 0; j &lt; noofbomb; j++) { bomb = new Bomb ; bomb.vel = RandomRange(6,7); bomb.x = RandomRange(0,750); bomb.y = RandomRange(0,100); Config.CurrentStage.addChild(bomb); bombVector.push(bomb); }*/ Config.CurrentStage.addEventListener(Event.ENTER_FRAME,Update); Config.CurrentStage.addEventListener(KeyboardEvent.KEY_DOWN,Control); } private function Update(evt:Event) { for (var i:int = 0; i &lt; moneyVector.length; i++) { if (moneyVector[i].hitTestObject(character)) { Config.CurrentStage.removeChild(moneyVector[i]); moneyVector.splice(i, 1); moneyscore += 400; moneytext.text = "Money : " + moneyscore.toString(); money = new Money ; //money.vel = RandomRange(6,7); money.x = RandomRange(0,750); money.y = RandomRange(0,100); Config.CurrentStage.addChild(money); moneyVector.push(money); } if (moneyVector[i].y &gt; Config.ScreenHeight) { moneyVector[i].x = RandomRange(0,750); moneyVector[i].y = - moneyVector[i].height; } } for (var j:int = 0; j &lt; bombVector.length; j++) { if (bombVector[j].hitTestObject(character)) { Config.CurrentStage.removeChild(bombVector[j]); bombVector.splice(j, 1); age++; agetext.text = "Age : " + age.toString(); bomb = new Bomb ; bomb.vel = RandomRange(6,7); bomb.x = RandomRange(0,750); bomb.y = RandomRange(0,100); Config.CurrentStage.addChild(bomb); bombVector.push(money); } if (bombVector[j].y &gt; Config.ScreenHeight) { bombVector[j].x = RandomRange(0,750); bombVector[j].y = - bombVector[j].height; } } } private function Control(evt:KeyboardEvent) { characterspeed = 15; if (evt.keyCode == Keyboard.LEFT) { character.x -= characterspeed; if (character.x &lt;= 0) { character.x = 0; } } if (evt.keyCode == Keyboard.RIGHT) { character.x += characterspeed; if (character.x &gt;= 670) { character.x = 670; } } } private function RandomRange(min:Number,max:Number):Number { return Math.random() * max - min + min; } } } </code></pre> <p>This is my Game: Currently, the bomb and money random appear X, 100 with 15 money and 10 bombs in a screen. What I want is, how to amend it become money and bomb appear from specific point, after that the money and bomb when hit the wall will bounce back. Anyone can provide me some code? Thanks</p> <p>An example similar game play with my game is <a href="http://www.youtube.com/watch?v=zzQ8PP5-TVE" rel="nofollow">http://www.youtube.com/watch?v=zzQ8PP5-TVE</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload