int0xitive
02-23-2008, 12:41 AM
So I've been working on this game all day and it almost works, I'm just having 2 major problems:
1. The collision detection isn't working. Your ship fires two distinct missiles, missile_mc+m and missile_mc+m+m. Each one also has their own hitTest to see if they hit an enemy, labeled as _root["enemy_mc"+e], but it doesn't work and I don't know why.
2. I also have an ammo counter going. It starts at 100 and successfully reduces your ammo count by 2 every time you shoot. However, it keeps going after 0. There is no "reload" function as I am going to put in ammo pickups that will immediately allow you to start shooting again. But for now, I just want nothing to happen.
Here's my code so far. Take a look and let me know if you've got any ideas.
// Attach the Player's Ship
attachMovie("triwing_mc", "triwing_mc", _root.getNextHighestDepth())
triwing_mc._x = 330;
triwing_mc._y = 450;
// Ship Movement
triwing_mc.onEnterFrame = function() {
if (Key.isDown(Key.RIGHT)) {
this._x += 15;
}
if (Key.isDown(Key.LEFT)){
this._x -= 15;
}
if (Key.isDown(Key.UP)){
this._y -= 15;
}
// Movement Limits
if (Key.isDown(Key.DOWN)){
this._y += 15;
}
if (this._x < -15){
this._x = -15;
}
if (this._x > 649){
this._x = 649;
}
if (this._y < -15){
this._y = -15;
}
if (this._y > 485){
this._y = 485;
}
};
// Missile Firing Code
var m:Number = 100;
var ammo:Number = 100;
var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
// Assigns missile function to Space Bar
if (Key.isDown(Key.SPACE)) {
// Subtracts 2 ammo every time a missile is fired
ammo -= 2;
// Fire two DISTINCT missiles
_root.attachMovie("missile_mc", "missile_mc"+m, m, {_x:triwing_mc._x+20, _y:triwing_mc._y+40});
_root.attachMovie("missile_mc", "missile_mc"+m+m, m+m, {_x:triwing_mc._x+130, _y:triwing_mc._y+20});
// Missile 1
_root["missile_mc"+m].onEnterFrame = function() {
if (this._y > -50) {
this._y -= 20;
if (this.hitTest(_root["enemy_mc."+e])) {
_root["enemy_mc"+e].removeMovieClip();
}
}else{
this.removeMovieClip();
}
// Missile 2
_root["missile_mc"+m+m].onEnterFrame = function() {
if (this._y > 0) {
this._y -= 20;
if (this.hitTest(_root["enemy_mc"+e])) {
_root["enemy_mc"+e].removeMovieClip();
}
}else{
this.removeMovieClip();
}
m += 1;
}
}
};
};
Key.addListener(keyListener);
var initialTimerValue:Number = 180;
var e:Number = 1000
// Timer limits level time to 3 minutes, spawns an enemy ever second
function checkTimer() {
var elapsedSeconds:Number = int(getTimer() / 1000)
if (initialTimerValue - elapsedSeconds > 0){
enemyIn(e);
e += 1;
}else{
clearInterval(intervalID);
}
}
var intervalID:Number = setInterval(checkTimer, 1000);
// Spawn enemies
function enemyIn(e) {
attachMovie("enemy_mc", "enemy_mc"+e, _root.getNextHighestDepth())
_root["enemy_mc"+e]._x = Math.round(Math.random() * 500);
_root["enemy_mc"+e]._y = -48;
_root["enemy_mc"+e].onEnterFrame = function(){
if (this._y < 650){
this._y += 15;
}else{
this.removeMovieClip();
}
}
}
1. The collision detection isn't working. Your ship fires two distinct missiles, missile_mc+m and missile_mc+m+m. Each one also has their own hitTest to see if they hit an enemy, labeled as _root["enemy_mc"+e], but it doesn't work and I don't know why.
2. I also have an ammo counter going. It starts at 100 and successfully reduces your ammo count by 2 every time you shoot. However, it keeps going after 0. There is no "reload" function as I am going to put in ammo pickups that will immediately allow you to start shooting again. But for now, I just want nothing to happen.
Here's my code so far. Take a look and let me know if you've got any ideas.
// Attach the Player's Ship
attachMovie("triwing_mc", "triwing_mc", _root.getNextHighestDepth())
triwing_mc._x = 330;
triwing_mc._y = 450;
// Ship Movement
triwing_mc.onEnterFrame = function() {
if (Key.isDown(Key.RIGHT)) {
this._x += 15;
}
if (Key.isDown(Key.LEFT)){
this._x -= 15;
}
if (Key.isDown(Key.UP)){
this._y -= 15;
}
// Movement Limits
if (Key.isDown(Key.DOWN)){
this._y += 15;
}
if (this._x < -15){
this._x = -15;
}
if (this._x > 649){
this._x = 649;
}
if (this._y < -15){
this._y = -15;
}
if (this._y > 485){
this._y = 485;
}
};
// Missile Firing Code
var m:Number = 100;
var ammo:Number = 100;
var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
// Assigns missile function to Space Bar
if (Key.isDown(Key.SPACE)) {
// Subtracts 2 ammo every time a missile is fired
ammo -= 2;
// Fire two DISTINCT missiles
_root.attachMovie("missile_mc", "missile_mc"+m, m, {_x:triwing_mc._x+20, _y:triwing_mc._y+40});
_root.attachMovie("missile_mc", "missile_mc"+m+m, m+m, {_x:triwing_mc._x+130, _y:triwing_mc._y+20});
// Missile 1
_root["missile_mc"+m].onEnterFrame = function() {
if (this._y > -50) {
this._y -= 20;
if (this.hitTest(_root["enemy_mc."+e])) {
_root["enemy_mc"+e].removeMovieClip();
}
}else{
this.removeMovieClip();
}
// Missile 2
_root["missile_mc"+m+m].onEnterFrame = function() {
if (this._y > 0) {
this._y -= 20;
if (this.hitTest(_root["enemy_mc"+e])) {
_root["enemy_mc"+e].removeMovieClip();
}
}else{
this.removeMovieClip();
}
m += 1;
}
}
};
};
Key.addListener(keyListener);
var initialTimerValue:Number = 180;
var e:Number = 1000
// Timer limits level time to 3 minutes, spawns an enemy ever second
function checkTimer() {
var elapsedSeconds:Number = int(getTimer() / 1000)
if (initialTimerValue - elapsedSeconds > 0){
enemyIn(e);
e += 1;
}else{
clearInterval(intervalID);
}
}
var intervalID:Number = setInterval(checkTimer, 1000);
// Spawn enemies
function enemyIn(e) {
attachMovie("enemy_mc", "enemy_mc"+e, _root.getNextHighestDepth())
_root["enemy_mc"+e]._x = Math.round(Math.random() * 500);
_root["enemy_mc"+e]._y = -48;
_root["enemy_mc"+e].onEnterFrame = function(){
if (this._y < 650){
this._y += 15;
}else{
this.removeMovieClip();
}
}
}