js>>>>范围之内随机数。
2016-12-17 19:17
253 查看
var 随机变量 = randFn(20,30);:产生20-30之间的随机数;;
键盘监听:用上下左右键 控制物体上下左右移动移动
//键盘监听事件
document.onkeydown = function(e){
switch(e.keyCode){
case 37:
//左
hero.left = true;
hero.right = false;
hero.top = false;
hero.bottom = false;
break;
case 38:
// 上
hero.left = false;
hero.right = false;
hero.top = true;
hero.bottom = false;
break;
case 39:
//右
hero.left = false;
hero.right = true;
hero.top = false;
hero.bottom = false;
break;
case 40:
//下
hero.left = false;
hero.right = false;
hero.top = false;
hero.bottom = true;
break;
default:
break;
}
}
document.onkeyup = function(){
hero.left = false;
hero.right = false;
hero.top = false;
hero.bottom = false;
}用在:
move: function() {
// onkeydown
//左
if(this.left) {
this.x -= this.speed;
}
//右
if(this.right) {
this.x += this.speed;
}
// 上
if(this.top) {
this.y -= this.speed;
}
//xia
if(this.bottom) {
this.y += this.speed;
}
}
};
创建游戏等需要的图片方法:
//C创建游戏所用的到所有图片对象
var background1Img = new Image();
background1Img.src = "img/background.png";
var background2Img = new Image();
background2Img.src = "img/background.png";
var heroImg = new Image();
heroImg.src = "img/herofly.png";
var enemy1 = new Image();
enemy1.src = "img/enemy1.png";
var enemy2 = new Image();
enemy2.src = "img/enemy2.png";
var enemy3 = new Image();
enemy3.src = "img/enemy3.png";
var bullet1 = new Image();
bullet1.src = "img/bullet1.png";
var bullet2 = new Image();
bullet2.src = "img/bullet2.png";
var prop = new Image();
prop.src = "img/prop.png";
键盘监听:用上下左右键 控制物体上下左右移动移动
//键盘监听事件
document.onkeydown = function(e){
switch(e.keyCode){
case 37:
//左
hero.left = true;
hero.right = false;
hero.top = false;
hero.bottom = false;
break;
case 38:
// 上
hero.left = false;
hero.right = false;
hero.top = true;
hero.bottom = false;
break;
case 39:
//右
hero.left = false;
hero.right = true;
hero.top = false;
hero.bottom = false;
break;
case 40:
//下
hero.left = false;
hero.right = false;
hero.top = false;
hero.bottom = true;
break;
default:
break;
}
}
document.onkeyup = function(){
hero.left = false;
hero.right = false;
hero.top = false;
hero.bottom = false;
}用在:
move: function() {
// onkeydown
//左
if(this.left) {
this.x -= this.speed;
}
//右
if(this.right) {
this.x += this.speed;
}
// 上
if(this.top) {
this.y -= this.speed;
}
//xia
if(this.bottom) {
this.y += this.speed;
}
}
};
创建游戏等需要的图片方法:
//C创建游戏所用的到所有图片对象
var background1Img = new Image();
background1Img.src = "img/background.png";
var background2Img = new Image();
background2Img.src = "img/background.png";
var heroImg = new Image();
heroImg.src = "img/herofly.png";
var enemy1 = new Image();
enemy1.src = "img/enemy1.png";
var enemy2 = new Image();
enemy2.src = "img/enemy2.png";
var enemy3 = new Image();
enemy3.src = "img/enemy3.png";
var bullet1 = new Image();
bullet1.src = "img/bullet1.png";
var bullet2 = new Image();
bullet2.src = "img/bullet2.png";
var prop = new Image();
prop.src = "img/prop.png";
相关文章推荐
- js 获取指定范围的随机数
- JS获取自定义范围随机数
- js中Math.random()生成指定范围数值的随机数
- js取随机范围内随机数
- JS math.random随机数,产生指定范围内的随机整数的代码
- 产生JS指定范围随机数(包含上限数和下限数)
- js中Math.random()生成指定范围数值的随机数
- 用js编写生成指定范围内的随机数
- js 获取范围内的随机数实例代码
- JS生成某个范围的随机数
- [js][技巧]生成指定范围指定个数的不重复随机数
- JS生成某个范围的随机数(四种情况)
- js 获取范围内的随机数
- 利用js中的Math生成范围随机数
- JS生成某个范围的随机数(四种情况)
- 利用js得到某个范围内的整数随机数
- js 获取范围内的随机数
- JS生成某个范围的随机数【四种情况详解】
- js生成指定范围内的随机数
- js 产生规定范围里的随机数