I got this code here:
var player = {
ATK: 30
}
function start(place) {
if (place == 'goldMine') {
canvas = document.getElementById('canvas');
ctx = canvas.getContext('2d');
var player = {
x: 0,
y: 197.5
};
var slope = {
x: 159,
y: 198.5,
up: false
};
var gold = {
x: 240,
y: 188,
mined: false,
x1: 200,
y1: 188,
mined1: false
};
ctx.font = '15px Monospace';
var move = setInterval(function(){player.x += 7;},50)
var draw = setInterval(function() {
ctx.clearRect(0, 0, canvas.width, canvas.height)
ctx.fillText('\\o/',player.x,player.y);
ctx.fillText("__________________",0,195.5);
ctx.fillText("/",slope.x,slope.y);
ctx.fillText("______________________________________________________",165.5,184.5);
ctx.fillText("/0\\",gold.x,gold.y);
ctx.fillText("/0\\",gold.x1,gold.y1);
if (player.x >= slope.x - 23 && !slope.up) {
player.y -= 10;
slope.up = true;
}
if (player.x >= gold.x - 23 && gold.mined == false) {
clearInterval(move)
dam = setInterval(function(){gold.health -= player.ATK}, 1000)
}
if (gold.health <= 0) {
gold.mined = true; gold.y = 210; move = setInterval(function(){player.x += 7;},50)
}
if (player.x >= gold.x1 - 23.99 && gold.mined == false) {
gold.y1 = 250;
gold.mined1 = true;
}
}, 50)
}
}
start('goldMine')
<canvas id='canvas' width='985' height='200'></canvas>
player.x (which is the \o/) is bigger than gold.x - 23, the move interval should stop working and the dam interval should start running. The dam interval is suppose to decrease gold.health by player.ATK every second. And when the gold.health is smaller or equal to zero, it suppose to start the move interval again and the gold.y should be 210. But it won't work. Can someone help me please? Thanks!
Aucun commentaire:
Enregistrer un commentaire