PDA

View Full Version : [AS2] help with adding score


geirke
09-12-2008, 01:14 AM
hi

i am currently making a flash game and i would like score to be added when i kill the enemy.


there is no hit test only co-ordinates, i want when the enemy is removed the score goes up by 1. :confused:

my code for the whole game is

score = 0;
Mouse.hide();
attachMovie("crosshair", "crosshair", 1);
attachMovie("tank", "tank", 2, {_x:530, _y:720});
fire_array = new Array();
fire_delay = 60;
just_fired = 0;
crosshair.onEnterFrame = function() {
this._x = _xmouse;
this._y = _ymouse;
};
tank.onEnterFrame = function() {
mousex = _xmouse-this._x;
mousey = (_ymouse-this._y)*-1;
angle = Math.atan(mousey/mousex)/(Math.PI/180);
if (mousex<0) {
angle += 180;
}
if (mousex>=0 && mousey<0) {
angle += 360;
}
if (angle>160) {
angle = 160;
}
if (angle<20) {
angle = 20;
}
firepower = Math.sqrt(mousex*mousex+mousey*mousey);
if (firepower>200) {
firepower = 200;
}
this.cannon._rotation = angle*-1;
};
function onMouseDown() {
if (just_fired>fire_delay) {
just_fired = 0;
angle = tank.cannon._rotation;
start_ball_x = tank._x+98*Math.cos(angle*Math.PI/180);
start_ball_y = tank._y+98*Math.sin(angle*Math.PI/180);
cannonball_fired = attachMovie("cannonball", "cannonball_"+_root.getNextHighestDepth(), _root.getNextHighestDepth(), {_x:start_ball_x, _y:start_ball_y});
cannonball_fired.dirx = Math.cos(angle*Math.PI/180)*firepower;
cannonball_fired.diry = Math.sin(angle*Math.PI/180)*firepower;
cannonball_fired.fire_coord_x = _root._xmouse;
cannonball_fired.fire_coord_y = _root._ymouse;
cannonball_fired.onEnterFrame = function() {
this._x += this.dirx/50;
this._y += this.diry/50;
dist_x = this._x-this.fire_coord_x;
dist_y = this._y-this.fire_coord_y;
dist = Math.sqrt(dist_x*dist_x+dist_y*dist_y);
if (dist<20) {
fire_array.push("explosion"+_root.getNextHighestDepth());
exp = attachMovie("explosion", "explosion"+_root.getNextHighestDepth(), _root.getNextHighestDepth(), {_x:this._x, _y:this._y});
exp.onEnterFrame = function() {
this._width += 2;
this._height += 2;
this._alpha -= 2;
if (this._alpha<0) {
for (x in fire_array) {
if (this.name == _root[fire_array[x]].name) {
fire_array.splice(x, 1);
}
}
this.removeMovieClip();
}
};
this.removeMovieClip();
}
};
}
}
_root.onEnterFrame = function() {
just_fired++;
new_enemy = Math.random()*500;
if (new_enemy<1) {
enemy = attachMovie("enemy", "enemy"+_root.getNextHighestDepth(), _root.getNextHighestDepth(), {_x:-40, _y:Math.random()*500});
enemy.speed = 1;
enemy.energy = 100;
enemy.onEnterFrame = function() {
this._x += this.speed;
if (this._x>800) {
this.removeMovieClip();
}
for (x in fire_array) {
dist_x = this._x-_root[fire_array[x]]._x;
dist_y = this._y-_root[fire_array[x]]._y;
dist = Math.sqrt(dist_x*dist_x+dist_y*dist_y);
if (dist<(this._width+_root[fire_array[x]]._width)/2) {
this.energy -= 2;
this.bar.gotoAndStop(25-(this.energy/4));
if (this.energy<0) {
this.removeMovieClip();
}
}
}
};
}
};



can you please help in and tell me what to do, i need help quick

thankyou,
geirke

Mazoonist
09-12-2008, 04:31 AM
You've posted in the Actionscript 3.0 forum, and your code is Actionscript 2.0. Also, you might want to consider AS tags instead of Quote tags. Your code is hard to read because it's not indented at all.

I don't understand your problem, can't you just increment your score like this?:
score++;

geirke
09-15-2008, 02:44 AM
i dont understand how to get my score working im really dumb, were do i put score++???

xdeath
09-15-2008, 02:56 AM
i don't understand what increments do exactly but can't you just say something like this:

// i don't know the name of your movieclip on your enemy so i will call it
// "enm" you can rename it later and see if it works i'm not going to read
// all that code. it's to much and it's not even as tags so it's even harder
// to read then it would be.
if (_root.enm.hitTest(bullet))
{
score+=1;
}

were you can see bullet just place the name of what ever is suppose to kill enemy. see not that hard. i don't know how your game works explaining it would be better say like creating movieclips of enemies so we know if we have to use a remove function to get rid of them ect...

geirke
09-15-2008, 11:57 AM
thanks....but u see my problem is it has no hit test....

what happens is...i shoot this bullet thing whicih explodes, and when the part that explodes is close to the enemy it hurts the enemy, the enemy has life and depending on how close the explosion is is how much damage the enemy gets.

i think its called an hit area...


i don't understand what increments do exactly but can't you just say something like this:

// i don't know the name of your movieclip on your enemy so i will call it
// "enm" you can rename it later and see if it works i'm not going to read
// all that code. it's to much and it's not even as tags so it's even harder
// to read then it would be.
if (_root.enm.hitTest(bullet))
{
score+=1;
}

were you can see bullet just place the name of what ever is suppose to kill enemy. see not that hard. i don't know how your game works explaining it would be better say like creating movieclips of enemies so we know if we have to use a remove function to get rid of them ect...