Hi All i am trying a OOP way of making a simple clicking game. the rules are very simple: There will be balloons coming up from the bottom of the stage in a random way and the player has to pop them.
I have these classes for the game
Game_Manager.as= this manages the creation of balloons, players and collisions
Balloon.as= This is the balloon class
Player.as=This is the player class
The Game Manager class will pass stage to the balloon and player classes and create them. I add these two in the Game Manager class.In the balloon class i add all the balloons in an balloon array.
Now when i run the code i am unable to check for collisions as nothing happens when the player and balloon collides. and i get a child must be a caller of the display object when i ry to remove the balloons after they have crossed the stage.
I have been trying to make it work for a long time a the game is very very simple. Please help me in the Object Oriented way of designing this simple game as i think that is where my error might be.
I will post the code for these below
Game Manager.as
public class GameManager extends MovieClip{
public var backGround:BackGround;
public var player:Player;
public var balloon:Balloon;
public var scoreBoard:ScoreBoard;
public var trial:Number;
public var gameTimer:Timer;
//public var balloonArray:Array;
public function GameManager(){
//balloonArray=new Array();
gameTimer=new Timer(250);
backGround=new BackGround();
//scoreBoard=new ScoreBoard(stage);
addChild(backGround);
gameTimer.addEventListener(TimerEvent.TIMER,onGameTimer);
gameTimer.start();
player=new Player(stage);
backGround.addChild(player);
balloon=new Balloon(stage);
//balloon.y=435;
backGround.addChild(balloon);
//balloonArray.push(balloon);
}//end of game manager
public function onGameTimer(t:TimerEvent):void{
if(balloon.hitTestObject(player))
trace("hit");
}//end of game timer
Balloon.as
public class Balloon extends MovieClip{
public var stageRef:Stage;
public var balloonArray:Array;
public var player:Player;
public var gameManager:GameManager;
//public var player:Player;
public function Balloon(stageRef:Stage){
trace("inside balloon");
this.stageRef=stageRef;
addEventListener(Event.ENTER_FRAME,onBalloonStart);
//player=new Player(stage);
//trace("balloon");
balloonArray=new Array();
}//end of balloon
private function onBalloonStart(e:Event):void{
makeBalloons();
moveBalloons();
//testCollisions();
}//end of balloon start
private function makeBalloons():void{
trace("inside make balloons");
var trial=Math.floor(Math.random()*100);
if(trial<(3+Math.floor(Math.random()*5)+1)){
var temp:MovieClip;
temp=this;
temp.y=435;
temp.gotoAndStop(Math.floor(Math.random()*5)+1);
temp.x=Math.floor(Math.random()*514);
//stageRef.addChild(temp);
balloonArray.push(temp);
}
}//end of make balloons
private function moveBalloons():void{
//trace(player);
var tmp:MovieClip;
trace(balloonArray.length);
//trace(player);
for(var i:int=balloonArray.length-1;i>=0;i--){
trace("inside balloon array");
tmp=balloonArray*;
tmp.y-=1;
if(tmp.y<-25){
balloonArray.splice(i,1);
if(stageRef.contains(tmp))
stageRef.removeChild(tmp); //this is where i get the child must be a caller error
}
}
}//end of move balloons
Player.as
public class Player extends MovieClip{
//public var player:Player;
public var stageRef:Stage;
public var balloon:Balloon;
public var gameManager:GameManager;
public function Player(stageRef:Stage){
trace("inside player");
this.stageRef=stageRef;
startDrag(true,new Rectangle(0,0,550,400));
addEventListener(Event.ENTER_FRAME,onPlayerStart);
}//end of player
private function onPlayerStart(e:Event):void{
rotation+=15;
}//on player start