Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How do i make the program stop when there is no bullets?

Guest
May 12, 2014 May 12, 2014

package  {

  import flash.display.MovieClip;

  import flash.ui.Mouse;

  import flash.events.MouseEvent;

  import flash.events.TimerEvent;

  import flash.utils.Timer;

  import flash.events.Event;

  import flash.net.URLLoader;

  import flash.net.URLRequest;

  public class main extends MovieClip {

  var req:URLRequest;

  var loader:URLLoader;

  var cursor:Cursor = new Cursor();

  var gameTimer:Timer = new Timer(1200);

  var score:Number;

  var bullet:Number;

  public function main() {

  stop();

  instructionBtn.addEventListener(MouseEvent.CLICK,doIntro);

  Mouse.hide();

  cursor.mouseEnabled = false;

  stage.addEventListener(MouseEvent.MOUSE_MOVE,moveMouse);

  startBtn.addEventListener(MouseEvent.CLICK,duckGame);

  stage.addEventListener(MouseEvent.CLICK,setBullet);

  addChild(cursor);

  }

  function moveMouse(evt:MouseEvent):void

  {

  cursor.x = this.mouseX;

  cursor.y = this.mouseY;

  }

  function doIntro(evt:MouseEvent):void

  {

  gotoAndStop(2);

  doDisplay1();

  backBtn.addEventListener(MouseEvent.CLICK,doBack);

  addChild(cursor);

  }

  function doBack(evt:MouseEvent):void

  {

  gotoAndStop(1);

  instructionBtn.addEventListener(MouseEvent.CLICK,doIntro);

  startBtn.addEventListener(MouseEvent.CLICK,duckGame);

  }

  function doDisplay1():void

  {

  req = new URLRequest("introduction.txt");

  loader = new URLLoader();

  loader.addEventListener(Event.COMPLETE,fileLoaded);

  loader.load(req);

  addChild(cursor);

  }

  function fileLoaded(evt:Event):void

  {

  txtToload.text = loader.data;

  }

  function duckGame(evt:MouseEvent):void

  {

  gotoAndStop(3);

  gameTimer.addEventListener(TimerEvent.TIMER,startGame);

  gameTimer.start();

  score = 0;

  scoreTxt.text = score.toString();

  gameOverTxt.visible = false;

  bullet = 21;

  bulletsTxt.text = bullet.toString();

  addChild(cursor);

 

  }

  function gameOver(evt:TimerEvent):void

  {

  gameOverTxt.visible = true;

  gameOverTxt.text = "Game Over!";

  }

  function startGame(evt:TimerEvent):void

  {

  var duck:Duck = new Duck();

  duck.x +=  stage.stageWidth;

  duck.y = Math.random() * stage.stageHeight;

  addChild(duck);

  addChild(cursor);

  }

  function setScore():void

  {

  score++;   // score = score + 1

  scoreTxt.text = score.toString();

  }

  function setBullet(evt:MouseEvent):void

  {

  bullet--;

  bulletsTxt.text = bullet.toString();

  }

  }

}

TOPICS
ActionScript
390
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 12, 2014 May 12, 2014

Do this in setBullet after it takes away 1 bullet: if(bullet <= 0) {gameOver();}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 12, 2014 May 12, 2014

function setBullet(evt:MouseEvent):void

  {

  bullet--;

  bulletsTxt.text = bullet.toString();

  if(bullet <= 0);

  gameOverTxt.visible = true;}

  }

like this?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 12, 2014 May 12, 2014

Exactly, hope I helped.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 12, 2014 May 12, 2014

is not working though

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 12, 2014 May 12, 2014

function setBullet(evt:MouseEvent):void

  {

  bullet--;

  bulletsTxt.text = bullet.toString();

  if(bullet == 0)

  {

  gameTimer.addEventListener(TimerEvent.TIMER_COMPLETE,gameOver);

  }}

wuds wrong with this

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 13, 2014 May 13, 2014
LATEST

How is it not working? Is gameover still not happening? If so, then make sure that gameTimer is turned on ( gameTimer.start() )

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines