my first post here so bear with me :)
Im rediscovering my programing intrest with the "new" canvas elements and javascript and i tought i make a game for fun, pretty new to javascript tough.
The game is a hunting game and the problem i have is that when the animal comes into hearing range (a pixel representing the hunter and two circles around him represents his hearingrange and visionrange) he should say "i hear something" and in vision range he should shoot.
That all works fine but he spams the text and shooting every time the gameloop repeats and the animal is in range.
My tought was to use setInterval but i cant get it to work as i want :( Here is my code:
var Interval = setInterval(function(){hunterTimer()},1000);
if (hunter.x >= moose.x-hunter.d1/2 &&
hunter.x <= moose.x+hunter.d2+hunter.d1/2 &&
moose.y >= moose.y-hunter.d1/2 &&
hunter.y <= moose.y+hunter.d2+hunter.d1/2){
function hunterTimer() {
ctxtext.fillText("I hear something!",50,textbreak),
textbreak += 10;
}
hunterTimer();
}
Any help would be nice, sorry for the long post :D
Aucun commentaire:
Enregistrer un commentaire