1 Replies - 5073 Views - Last Post: 23 February 2012 - 02:41 AM

#1 iJasonTATE  Icon User is offline

  • New D.I.C Head

Reputation: -10
  • View blog
  • Posts: 41
  • Joined: 14-August 11

Need help finding an solving a problem with my game.

Posted 09 February 2012 - 11:27 AM

I am developing a "Space Invaders" type game and am having some issues getting my bullet it fire. I will post all of my code. Thanks so much!

stop();
onEnterFrame = function(){ 
	if(Key.isDown(32)){//if the space bar is pressed
		var bulletID:Number = Math.random(); //create a variable that we'll use at the bullet's id
		//then attach a bullet to the stage
		_root.attachMovie('mcBullet', 'Bullet'+bulletID,_root.getNextHighestDepth());
		//setting the coordinates of the bullet to be the same as the main character
		_root['Bullet'+bulletID]._x = mcMain._x + mcMain._width/2 - _root['Bullet'+bulletID]._width/2;
		_root['Bullet'+bulletID]._y = mcMain._y;
		_root['Bullet'+bulletID].onEnterFrame = function(){
			//giving the bullet some actions
			this._y -= 10; //moving the bullet
			if(this._y < -1 * this._height){//if the bullet goes off stage
				//then destroy it
				this.removeMovieClip();
				
			}
		}
	}
}

var mainSpeed:Number = 6;//how fast the main guy can move
//ENEMY TIMING VARIABLES
//how much time before another enemy is made
var enemyTime:Number = 0;
//how much time needed to make an enemy
//it should be more than the shooting rate
//or else killing all of the enemies would
//be impossible :o/>
var enemyLimit:Number = 16;

onEnterFrame = function(){ 
	// this controls the mcMain
//this function will run every frame (needed for moving the character
	if(Key.isDown(37) || Key.isDown(65)){ //if the "A" key or Left Arrow Key is Down
		ship._x -= mainSpeed;//then the move the guy left
	}
	if (Key.isDown(38) || Key.isDown(87)){//if the "W" key or Up Arrow Key is Down
		ship._y -= mainSpeed; //then move the guy up
	}
	if(Key.isDown(39) || Key.isDown(68)){//if the "D" key or Right Arrow Key is Down
		ship._x += mainSpeed; //then move the guy to the right
	}
	if(Key.isDown(40) || Key.isDown(83)){//if the "S" key or Down Arrow Key is Down
		ship._y += mainSpeed; //then move the guy down
	}
	
 enemyTime ++;//incrementing time for enemy
	if(enemyTime == enemyLimit){//if enough time has elapsed
		var enID:Number = Math.random(); //create a variable that we'll use at the enemy's id
		_root.attachMovie('mcEnemy','en'+ enID,_root.getNextHighestDepth());//then add the enemy
		//setting it's coordinates
		_root['en'+enID]._x = int(Math.random()*Stage.width);//randomly within the boundaries
		_root['en'+enID]._y = -50; //sets this offstage at first
		_root['en'+enID].onEnterFrame = function(){//then give it some functions
			this._y += 5;
		}
		enemyTime = 0;//reset the time
	}
}


Everything works (moving the character with the keys and having the enemies fall down the screen) until I type in the bullet code.

Is This A Good Question/Topic? 0
  • +

Replies To: Need help finding an solving a problem with my game.

#2 lbfb  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 31
  • Joined: 23-February 12

Re: Need help finding an solving a problem with my game.

Posted 23 February 2012 - 02:41 AM

I know I might be stating the obvous and I apologise in advance if this is so, but have you tried putting a trace statement inside that loop that creates the bullet? If you trace the bulletID or even the x- or y- co-ordinates that are being generated (or even if they are being generated) it might help track down the problem.

Are you getting any error messages when you test the movie clip?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1