Skip navigation
Currently Being Moderated

Adding obstacles and items in game

Jul 1, 2012 1:43 AM

Tags: #problem #air #code_snippets #ac3 #game

Hello everybody!

I'm makeing game for mobile devices. In the game you "drive" spaceship and try to collect as many stars as possible and avoid obstacles. The game is based on Starling framework. I have now made the background and the spaceship. Background is scrolling to opposite direction what give feeling that the spaceship is moving. And then I'm able to move spaceship with touchevents.

Next thing is that I should add obstacles. I have four types of obstacles. Before they spawn, I would like that watchout image would appears before the obstacles apperas from up. The obstacles should spawn randomly on X-axis and spaceship should avoid to crashing them.

 

After that I should add stars what the spaceship should collect.

 

Could somebody please give me some code snippets or ideas how should should I do this, I'm very newbie?

 

I have tried to follow "Starting with starling series, but the game is so different in certain things and now I'm stuck with adding these obstacles.

 
Replies
  • Currently Being Moderated
    Jul 1, 2012 4:57 AM   in reply to lekale

    If you want things to happen randomly, become familiar with using the Math.random() method.  Figure out how to randomly select an obtacle from an array of the four of them.  Figure out how to randoimly select an x value for placement of the different things using the width of the stage to determine your limits.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 3, 2012 4:43 AM   in reply to lekale

    Yes, you could sould probably use ENTER_FRAME to drive movingthe objects.  I do not know what "currentTime" involves... I would just increment the y property, as in: tempEnemy.y += 1;

     

    In your makeEnemies function you should be selecting one of the obstacle classes (you appear to only have one class named Obstacle).  Have an array with the different class names as String values and use something like the following to instantiate whichever one you select randomly...

     

    var ClassRef:Class = Class(getDefinitionByName(randomClassName));

    var classInstance:* = new ClassRef();

    addChild(classInstance);

     

     

    In the code above, randomClassName is whichever string you selected from the obstacle classes array.

     

    You should not be reinstantiating the obstacles array each time you make an enemy - you lose any you have i it that way.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points