Hi
I’ve got most of this game im making working
The only problem now is I want a point deducted for every time the person_mc makes contact with items_mc and items_mc2
The code i added in dosnt deduct i but i have left it in to show where i added the code
Thanks
//The code below is to set the score to 0 to begin with
var scoreCount:Number = 0;
score.text = scoreCount;
//code to allow person_mc to move randomely
function getdistance(x, y, x1, y1) {
var run, rise;
run = x1-x;
rise = y1-y;
return (_root.hyp(run, rise));
}
function hyp(a, b) {
return (Math.sqrt(aa+bb));
}
MovieClip.prototype.reset = function() {
//Width and height of the movie
width = 500;
height = 350;
//distance and speed
var dist, norm;
this.x = this._x;
this.y = this._y;
this.speed = Math.random()*4+2;
this.targx = Math.random()*width;
this.targy = Math.random()*height;
dist = _root.getdistance(this.x, this.y, this.targx, this.targy);
norm = this.speed/dist;
this.diffx = (this.targx-this.x)*norm;
this.diffy = (this.targy-this.y)*norm;
};
//moves movie clip
MovieClip.prototype.move = function() {
if (_root.getdistance(this.x, this.y, this.targx, this.targy)>this.speed) {
this.x += this.diffx;
this.y += this.diffy;
} else {
this.x = this.targx;
this.y = this.targy;
if (!this.t) {
this.t = getTimer();
}
if (getTimer()-this.t>1000) {
this.reset();
this.t = 0;
}
}
this._x = this.x;
this._y = this.y;
};
//This code is to allow the items_mc and items_mc2 to appear randomely
randomX = Math.floor(Math.random() * 500)
randomY = Math.floor(Math.random() * 350)
items_mc._x = randomX;
items_mc._y = randomY;
randomX = Math.floor(Math.random() * 550)
randomY = Math.floor(Math.random() * 400)
items_mc2._x = randomX;
items_mc2._y = randomY;
//The code below is for moving the grinder using the arrow keys
var KeyListener:Object = new Object();
KeyListener.onKeyDown = function():Void {
//Allows grinder to move left
if (Key.isDown(Key.LEFT)) {
if (grinder_mc._x>29) {
grinder_mc._x -= 5;
}
}
//Allows grinder to move right
if (Key.isDown(Key.RIGHT)) {
if (grinder_mc._x<499) {
grinder_mc._x += 5;
}
}
//Allows grinder to move up
if (Key.isDown(Key.UP)) {
if (grinder_mc._y>-58.2) {
grinder_mc._y -= 5;
}
}
//Allows grinder to move down
if (Key.isDown(Key.DOWN)) {
if (grinder_mc._y<490) {
grinder_mc._y += 5;
}
}
//This causes the spacebar button to remove items_mc on press
if (Key.isDown(Key.SPACE)) {
hitRemove(grinder_mc,items_mc);
hitRemove(grinder_mc,items_mc2);
}
};
Key.addListener(KeyListener);
//This function detects whether the objects have collided.
function hitRemove(moveObject:MovieClip, hitObject:MovieClip) {
if (moveObject.hitTest(hitObject)) {
//displayscore
if(hitObject._visible == true) {
scoreCount++;
score.text = scoreCount;
}
hitObject._visible = false;
}
}
//displayscore
if(hitObject._visible == true) {
scoreCount–;
score.text = scoreCount;
}