Hi everyone,
I’ve got this game and I’m stuck with what I think it may be a very simple problem to solve. Yet, I haven’t been able to do it. I need a score counter for a shooter game: there are spaceships flying around the stage and, when i click them, they die and disappear. I need to count the ships that I kill. Seems simple but I can’t manage to do it. I’ll post the code of thw two classes.
MAIN--------------------------
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.ui.Mouse;
import flash.events.TimerEvent;
import flash.utils.Timer;
import flash.events.Event;
import flash.media.Sound;
import flash.net.*;
import flash.media.SoundChannel;
public class Main extends MovieClip
{
var total:int = 200;
var naves = new Array;
var tempo:Timer;
var tempo2:Timer;
var pontos:int = 0;
var tempojogo:Timer = new Timer(1000,1);
var musica_fundo:Sound = new Sound();
var tiro:Sound = new Sound();
function Main():void
{
play_btn.addEventListener(MouseEvent.CLICK, jogar);
function jogar(evt:MouseEvent):void
{
if (currentFrame == 1)
{
gotoAndStop(totalFrames);
}
else
Mouse.hide();
stage.addEventListener(MouseEvent.MOUSE_MOVE,mexe_mira);
stage.addEventListener(MouseEvent.CLICK,som);
init_naves();
tempo = new Timer(700,total);
tempo.addEventListener(TimerEvent.TIMER,voa);
tempo.start();
tempo2 = new Timer(900,total);
tempo2.addEventListener(TimerEvent.TIMER,voa2);
tempo2.start();
tempojogo.addEventListener(TimerEvent.TIMER,contador);
tempojogo.start();
tiro.load(new URLRequest("SFX/tiro4mp.mp3"));
}
}
function som(event:MouseEvent)
{
tiro.play(0);
}
function contador(event:TimerEvent)
{
contador_txt.text = String(tempojogo.currentCount);
}
private function voa(e:TimerEvent):void
{
var nave = naves.pop();
nave.voa();
}
private function voa2(e:TimerEvent):void
{
var nave = naves.pop();
nave.voa2();
}
private function init_naves():void
{
var nave1;
var nave2;
for (var i = 0; i < total; i++)
{
nave1 = new Nave ;
nave1.x = -30;
nave1.y = Math.floor(Math.random() * this.stage.stageHeight);
this.addChild(nave1);
naves.push(nave1);
}
musica_fundo.load(new URLRequest("Musica/Carmina.mp3"));
musica_fundo.play();
}
private function mexe_mira(event:MouseEvent)
{
Mouse.hide();
mira.x = mouseX;
mira.y = mouseY;
}
}
}
NAVE(spaceship)---------------------
package
{
import flash.display.MovieClip;
import flash.events.;
import flash.utils.Timer;
import flash.media.Sound;
import flash.net.;
import flash.media.SoundChannel;
public class Nave extends MovieClip
{
var speed_x:int = 10;
var speed_x2:int = 12;
var speed_y:int = 2;
var speed_y2:int = -2;
// var pontos:int = 0;
function Nave():void
{
this.addEventListener(MouseEvent.CLICK, contapontos);
}
function contapontos(e:MouseEvent):void
{
// pontos = pontos + 1;
// trace(pontos);
}
private function quandoClique(e:MouseEvent)
{
trace("Já foste!
");
parent.removeChild(this);
// pontos = pontos + 1 ;
// trace(pontos);
}
public function voa():void
{
this.addEventListener(Event.ENTER_FRAME, passa);
addEventListener(MouseEvent.CLICK,quandoClique);
}
public function voa2():void
{
this.addEventListener(Event.ENTER_FRAME, passa2);
addEventListener(MouseEvent.CLICK,quandoClique);
}
private function quandoFrame(e:Event)
{
x += speed_x;
y += speed_y;
}
private function passa(e:Event):void
{
this.x= (this.x)+speed_x;
this.y = (this.y)+speed_y;
}
private function passa2(e:Event):void
{
this.x= (this.x)+speed_x2;
this.y = (this.y)+speed_y2;
}
}
}
Can somebody PLEASE help?
Thanks