Skip to main content
Participant
October 6, 2014
Question

define quadrants on stage for conditional events (Total newbie)

  • October 6, 2014
  • 4 replies
  • 509 views

I have been wracking my brain for a week to get this and can't figure it out. I need to have an object appear at random points on the screen each time the code is run, the stage needs to be broken down into 4 quadrants and the angle of the object changes depending on which quadrant it appears in...the stage needs to be dynamic as well...I don't need an exact answer because this is an assignment and I don't want to cheat but it's due tomorrow and I've got nothing.

This topic has been closed for replies.

4 replies

Participant
October 6, 2014

Ok to prove I am doing this myself here's what I've got so far

package  {

  import flash.display.MovieClip;

  public class Main extends MovieClip

  {

  public function Main()

  {

  // constructor code

  var hero = new Hero();

  addChild(hero);

  hero.x = stage.stageWidth / 2;

  hero.y = stage.stageHeight / 2;

  var enemy = new Enemy();

  addChild(enemy);

  enemy.x = Math.random() * (stage.stageWidth - enemy.width) + enemy.width/2;

  enemy.y = Math.random() * (stage.stageHeight - enemy.height) + enemy.height/2;

}

       }

          }

And what I need to do next is:

Use the if-condition to check what quadrant each of

the enemies are in, if…

• Top right: rotate the enemy instance to 45 degrees

• Bottom right: rotate the enemy instance to 135 degrees

• Bottom left: rotate the enemy instance to 225 degrees

• Top left: rotate the enemy instance to 315 degrees

(issue is I can't find what code it is for checking the quadrant)

Inspiring
October 7, 2014

Top left quadrant is:

x < stage.stageWidth * .5  && y < stage.stageHeight * .5

Top right would then be:

x > stage.stageWidth * .5 && y < stage.stageHeight * .5

Make sense?

Participant
October 7, 2014

perfect I get it then I just change the >< around to get the bottoms thanks so much