Game com Timer
Exemplo Timer
by Alexandre Gomiero de Oliveira
HTML
<div id="game">
<div id="" style="z-index:1; background:rgb(50, 50, 255); opacity: 0.7; width:70px; height:20px;">
<p style="font-color:black; text-align:center;" id="display_tempo"></p>
</div>
<div id="square0"></div>
<div id="square1"></div>
<div id="notepad"></div>
<div id="pad"></div>
</div>
<script type="text/javascript">
var gameWidth = 400
var gameHeight = 400
var intervalOne, intervalTwo, timeoutOne, x
var angle = 2
var tempX = 0
var tempY = 0
var block = 1
var square = 0
var squareTop = 0
var squareLeft = 0
var squareMotion = 1
var speed = 80
var getPad = 0
var nextScore = 0
var score = 0
var count = 0
var collisionOne = 0
var collisionTwo = 0
var collisionThree = 0
// tempo
var tempo = 0;
var tempo_controle = 0;
var parado = 1;
document.body.style.margin = "0px"
document.body.style.padding = "0px"
// Atualiza o tempo
function atualiza_tempo()
{
if (parado)
return;
var tempo_segundos = Math.floor((+new Date() - tempo) / 1000);
var display = tempo_segundos.toString() + " seg";
document.getElementById("display_tempo").innerHTML = display;
return;
}
function setupGame() {
document.getElementById("game").style.borderRight = "1px solid #aaa"
document.getElementById("game").style.borderRight = "1px solid #aaa"
document.getElementById("game").style.borderBottom = "1px solid #aaa"
document.getElementById("game").style.width = gameWidth + "px"
document.getElementById("game").style.height = gameHeight + "px"
document.getElementById("square0").style.position = "absolute"
document.getElementById("square0").style.width = "40px"
document.getElementById("square0").style.height = "40px"
document.getElementById("square0").style.backgroundColor = "#444"
document.getElementById("square0").style.display = "none"
document.getElementById("square1").style.position = "absolute"
document.getElementById("square1").style.width =...