saalek110
Well-Known Member
صفحه ۲
معرفی قالب دوم:
معرفی قالب دوم:
JavaScript:
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<style>
canvas {
border:1px solid #d3d3d3;
background-color: #f1f1f1;
}
</style>
</head>
<body onload="startGame()">
<script>
function startGame() {
myGameArea.start();
}
var myGameArea = {
canvas : document.createElement("canvas"),
start : function() {
document.getElementById("p2").innerHTML+="myGameArea start" ;
this.canvas.width = 480;
this.canvas.height = 270;
this.context = this.canvas.getContext("2d");
document.body.insertBefore(this.canvas, document.body.childNodes[0]);
this.frameNo = 0;
this.interval = setInterval(updateGameArea, 20);
},
clear : function() {
this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
}
}
function updateGameArea() {
//document.getElementById("p3").innerHTML+= "updategamearea" ;
myGameArea.clear();
myGameArea.frameNo += 1;
document.getElementById("p4").innerHTML= "frameno= " + JSON.stringify(myGameArea.frameNo) ;
if (myGameArea.frameNo == 1 || everyinterval(150)) {
document.getElementById("p5").innerHTML= "frameno= " + JSON.stringify(myGameArea.frameNo) ;
}
}
function everyinterval(n) {
if ((myGameArea.frameNo / n) % 1 == 0) {return true;}
return false;
}
</script>
<br>
<p id="p1"></p>
<p id="p2"></p>
<p id="p3"></p>
<p id="p4"></p>
<p id="p5"></p>
<button onmousedown="accelerate(-0.2)" onmouseup="accelerate(0.05)">ACCELERATE</button>
<p>Use the ACCELERATE button to stay in the air</p>
<p>How long can you stay alive?</p>
</body>
</html>
آخرین ویرایش: