# Deducting points from high score

**URL:** <https://forum.kirupa.com/t/deducting-points-from-high-score/301713>\
**Category:** Uncategorized\
**Created:** [December 14, 2009, 5:28pm UTC](https://forum.kirupa.com/t/deducting-points-from-high-score/301713 "2009-12-14T17:28:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mushi206](https://avatars.discourse-cdn.com/v4/letter/m/9dc877/32.png) [@mushi206](https://forum.kirupa.com/u/mushi206)\
**Post date:** [December 14, 2009, 5:28pm UTC](https://forum.kirupa.com/t/deducting-points-from-high-score/301713/1 "2009-12-14T17:28:37Z")

</div>

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(a_a+b_b));  
}  
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;  
}
