I'm making a little game for a school project and I'm stuck ...
I Have a player with a x and y position.
I want the arrow to start from player.x and reach monster.x.
The problem is that the arrow stays stuck in player.x because I drew it on player.x.
I want to take the player position only for one time , not during the whole animation , so if the player moves to another location , he can shoot another arrow from that position ...
The code
if (arrowShot) {
drawSprite(fleche, Arrow.width * Arrow.frameX, Arrow.height * Arrow.frameY, Arrow.width, Arrow.height, player.x, player.y, Arrow.width, Arrow.height);
if (monstre.health > 0) {
ctx.fillText("-1", monstre.x, monstre.y + 50);
monstre.health -= 1;
}
if (monstre.health == 0) {
ctx.fillText("dead", monstre.x, monstre.y + 50);
}
}
Yes I add the arrow.speed to it in this code
if (clickX > monstre.x - 400 && clickX < monstre.x - 368 && clickY > monstre.y - 250 && clickY < monstre.y - 202) {
arrowShot = 1;
var inter = setInterval(function() {
if (Arrow.y > monstre.y) {
Arrow.y -= Arrow.speed;
Arrow.moving = true;
}
if (Arrow.x < monstre.x) {
Arrow.x += Arrow.speed;
Arrow.moving = true;
} else {
Arrow.x = player.x - 30;
Arrow.speed = 10;
arrowShot = 0;
Arrow.moving == false;
clearInterval(inter);
}
}, 30);
}
question from:
https://stackoverflow.com/questions/65858492/this-arrow-just-cant-reach-the-monster 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…