Как добавить в жалкое подобие игры на JS объект, который будет рандомно по полю появляться, далее моргать и пропадать? Как сделать так?
var Wp, Hp;
var dL = dU = dR = dB = 0;
var L = 123,
T = 234,
S = 8,
nL = false,
nT = false;
onload = function ()
{
var CW = document.body.clientWidth;
Wp = .8 * CW, Hp = .75 * Wp;
document.getElementById ('pole').style.width = Wp + 'px';
document.getElementById ('pole').style.height = Hp + 'px';
document.body.onkeydown = function (ev)
{
var e = window.event || ev, K = e.keyCode;
if (K == 37) dL = -S;
else if (K == 38) dU = -S;
else if (K == 39) dR = S;
else if (K == 40) dB = S;
}
document.body.onkeyup = function (ev)
{
var e = window.event || ev, K = e.keyCode;
if (K == 37) dL = 0;
else if (K == 38) dU = 0;
else if (K == 39) dR = 0;
else if (K == 40) dB = 0;
}
function move1 ()
{
var p = 'px', O = document.getElementById ('img').style;
L += dL + dR, T += dU + dB;
if (L < 0) L = 0;
if (L > (Wp - 60)) L = Wp - 60;
if (T < 0) T = 0;
if (T > (Hp - 60)) T = Hp - 60;
O.left = L + p; O.top = T + p;
setTimeout (move1, 100);
}
function coin()
{
var B = document.getElementById('coin').style;
var Lk, Tk;
B.left = Lk+'px';
B.top = Tk+'px';
B.visibility = 'visible';
setTimeout (B.visibility = 'hidden', 15000);
setTimeout (coin, 20000);
}
coin ();
move1 ();
}
<div id="pole" style="width: 400px; height: 300px; position: relative; background: #e5e5e5; border : 5px solid #000;">
<div id="img" style="position: absolute; z-index: 999; left: 123px; top: 234px; border-radius : 50%; width : 60px; height : 60px; background : #000;"></div>
<div id="coin" style="position: absolute; z-index: 99; left: 123px; top: 234px; visibility : hidden; border-radisu : 10%; width : 20px; height : 20px; background : #000;"></div>
</div>