janhung
04-18-2009, 02:27 PM
Hi. Hopefully this isn't too confusing and I really hope that someone could help!!!
I am trying to make a game where 2 types of images would drop from the sky at regular intervals. One type ("c" below) would add points and the other ("f" below) would deduct points if the player's character gets "hit" by the images. ("Player" moves left and right with cursor) And if either 'hits' the player, it would immediately disappear (as if it's dropped into the player's cart). If it is not 'caught' by the player, it would fall through the ground.
I put the following as the AS for a layer. Now, when the the first "c" reaches the horizontal level of the "player", the second "c", which would be on its way down, would disappear (instead of going all the way down) and when the third "c" reaches the horizontal level of the "player", it disappears no matter where the "player" is. After that, all images ("c" and "f") just fall through the "player" even if the "player" is right below them.
Also, only the first "c" gets counted towards "points". All "f" gets counted.
I would appreciate it if you could let me know what's wrong. Or if you have done something similar / have suggestions for a better scoring system... Thanks!!!
points = 0;
//variables for "c"
var delay_c = 1200;
var now_c = getTimer();
var tc = 1;
var ID_c = 1;
var cIN = 0;
//variables for "f"
var delay_f = 2000;
var now_f = getTimer();
var tf = 1;
var ID_f = 1;
var fIN = 0;
onEnterFrame = function(){
stop();
//score calculation
points = cIN*100 - fIN*50;
score.text = points;
//x-range of mouse cursor
if (_root._xmouse > (600-player._width)) {
target = 600-player._width;
} else if (_root._xmouse < 0) {
target = 0;
} else {
target = _root._xmouse;
};
//movement of player
player._x = player._x + (target-player._x)*0.3;
//duplicate falling "c" at random x
if ((getTimer()-now_c) >= delay_c) {
tc++;
duplicateMovieClip(c1,"c"+tc,tc);
_root["c"+tc]._x = random(565) + 25;
now_c = getTimer();
};
//when "c" falls into cart
if ((_root["c"+ID_c].cBegin._y + _root["c"+ID_c].cBegin._height) > 354) {
trace(ID_c);
if ((_root["c"+ID_c]._x >= _root.player._x) && ((_root["c"+ID_c]._x+_root["c"+ID_c]._width) <= (_root.player._x+_root.player._width))) {
trace(ID_c+"in");
cIN = cIN + 1;
trace(cIN);
_root["c"+ID_c]._alpha = 0;
}
ID_c = ID_c + 1;
trace(ID_c);
_root["c"+ID_c]._alpha = 100;
};
//duplicate falling "f" at random x
if ((getTimer()-now_f) >= delay_f) {
tf++;
duplicateMovieClip(f1,"f"+tf,tf);
_root["f"+tf]._x = random(565) + 25;
now_f = getTimer();
};
//when "f" falls into cart
if ((_root["f"+ID_f].fBegin._y + _root["f"+ID_f].fBegin._height) > 354) {
if (((_root["f"+ID_f]._x+_root["f"+ID_f]._width) > _root.player._x) && (_root["f"+ID_f]._x <= (_root.player._x+_root.player._width))) {
fIN++;
_root["f"+ID_f]._alpha = 0;
}
ID_f++;
_root["f"+ID_f]._alpha = 100;
};
//gameover
if (points < 0) {
nextScene();
};
};
I am trying to make a game where 2 types of images would drop from the sky at regular intervals. One type ("c" below) would add points and the other ("f" below) would deduct points if the player's character gets "hit" by the images. ("Player" moves left and right with cursor) And if either 'hits' the player, it would immediately disappear (as if it's dropped into the player's cart). If it is not 'caught' by the player, it would fall through the ground.
I put the following as the AS for a layer. Now, when the the first "c" reaches the horizontal level of the "player", the second "c", which would be on its way down, would disappear (instead of going all the way down) and when the third "c" reaches the horizontal level of the "player", it disappears no matter where the "player" is. After that, all images ("c" and "f") just fall through the "player" even if the "player" is right below them.
Also, only the first "c" gets counted towards "points". All "f" gets counted.
I would appreciate it if you could let me know what's wrong. Or if you have done something similar / have suggestions for a better scoring system... Thanks!!!
points = 0;
//variables for "c"
var delay_c = 1200;
var now_c = getTimer();
var tc = 1;
var ID_c = 1;
var cIN = 0;
//variables for "f"
var delay_f = 2000;
var now_f = getTimer();
var tf = 1;
var ID_f = 1;
var fIN = 0;
onEnterFrame = function(){
stop();
//score calculation
points = cIN*100 - fIN*50;
score.text = points;
//x-range of mouse cursor
if (_root._xmouse > (600-player._width)) {
target = 600-player._width;
} else if (_root._xmouse < 0) {
target = 0;
} else {
target = _root._xmouse;
};
//movement of player
player._x = player._x + (target-player._x)*0.3;
//duplicate falling "c" at random x
if ((getTimer()-now_c) >= delay_c) {
tc++;
duplicateMovieClip(c1,"c"+tc,tc);
_root["c"+tc]._x = random(565) + 25;
now_c = getTimer();
};
//when "c" falls into cart
if ((_root["c"+ID_c].cBegin._y + _root["c"+ID_c].cBegin._height) > 354) {
trace(ID_c);
if ((_root["c"+ID_c]._x >= _root.player._x) && ((_root["c"+ID_c]._x+_root["c"+ID_c]._width) <= (_root.player._x+_root.player._width))) {
trace(ID_c+"in");
cIN = cIN + 1;
trace(cIN);
_root["c"+ID_c]._alpha = 0;
}
ID_c = ID_c + 1;
trace(ID_c);
_root["c"+ID_c]._alpha = 100;
};
//duplicate falling "f" at random x
if ((getTimer()-now_f) >= delay_f) {
tf++;
duplicateMovieClip(f1,"f"+tf,tf);
_root["f"+tf]._x = random(565) + 25;
now_f = getTimer();
};
//when "f" falls into cart
if ((_root["f"+ID_f].fBegin._y + _root["f"+ID_f].fBegin._height) > 354) {
if (((_root["f"+ID_f]._x+_root["f"+ID_f]._width) > _root.player._x) && (_root["f"+ID_f]._x <= (_root.player._x+_root.player._width))) {
fIN++;
_root["f"+ID_f]._alpha = 0;
}
ID_f++;
_root["f"+ID_f]._alpha = 100;
};
//gameover
if (points < 0) {
nextScene();
};
};