欢迎光临
我们一直在努力

html5初学者小游戏源代码,html5 一个“一笔画”小游戏源码(通关)

【实例简介】一个基于html5设计的小游戏

【实例截图】

html5初学者小游戏源代码,html5 一个“一笔画”小游戏源码(通关)

【核心代码】

H5小游戏100例: 一笔画

重新开始

回退

let onestroke = new OneStroke(

{

// 默认的线段颜色与端点颜色

lineColor: 0xe2e2e2,

vertexColor: 0x6dc6c0,

strokeColor: 0x416275,

activeVertexColor: 0x6dc6c0,

levels: [

{

name: "第一关",

lineColor: 0xe2e2e2,

vertexColor: 0x90b34f,

strokeColor: 0x445624,

activeVertexColor: 0x90b34f,

lines: [

{"x1": 375, "y1": 366, "x2": 200, "y2": 916},

{"x1": 200, "y1": 916, "x2": 664, "y2": 576},

{"x1": 664, "y1": 576, "x2": 88, "y2": 576},

{"x1": 88, "y1": 576, "x2": 556, "y2": 916},

{"x1": 556, "y1": 916, "x2": 375, "y2": 366}

]

},

{

name: "第二关",

lineColor: 0xe2e2e2,

vertexColor: 0x6dc6c0,

strokeColor: 0x416275,

activeVertexColor: 0x6dc6c0,

lines: [

{"x1": 240, "y1": 460, "x2": 654, "y2": 875},

{"x1": 654, "y1": 875, "x2": 100, "y2": 740},

{"x1": 100, "y1": 740, "x2": 240, "y2": 460},

{"x1": 240, "y1": 460, "x2": 515, "y2": 460},

{"x1": 515, "y1": 460, "x2": 654, "y2": 740},

{"x1": 654, "y1": 740, "x2": 100, "y2": 875},

{"x1": 100, "y1": 875, "x2": 515, "y2": 460}

]

},

{

name: "第三关",

lineColor: 0xe2e2e2,

vertexColor: 0xec6a74,

strokeColor: 0x914748,

activeVertexColor: 0xec6a74,

lines: [

{"x1": 177, "y1": 367, "x2": 177, "y2": 961},

{"x1": 177, "y1": 961, "x2": 673, "y2": 861},

{"x1": 673, "y1": 861, "x2": 177, "y2": 367},

{"x1": 177, "y1": 367, "x2": 572, "y2": 367},

{"x1": 572, "y1": 367, "x2": 78, "y2": 861},

{"x1": 78, "y1": 861, "x2": 572, "y2": 961},

{"x1": 572, "y1": 961, "x2": 572, "y2": 367}

]

},

{

name: "第四关",

src: "images/049.jpeg"

},

{

name: "第五关",

src: "images/053.jpeg"

},

{

name: "第六关",

src: "images/059.jpeg"

},

{

name: "第七关",

src: "images/401.jpeg"

}

]

}

);

// 兼容大屏幕适配

function fitEaselInfo() {

onestroke.viewLeft = document.querySelector(".wrapper").getBoundingClientRect().left;

onestroke.ratio = 375 / Math.min(document.body.clientWidth, 540);

}

window.addEventListener("resize", fitEaselInfo);

fitEaselInfo();

// 通关

onestroke.event.on("pass", function() {

console.log("通关");

// 进入下一关

onestroke.next();

});

// 进入新的一关

onestroke.event.on("start", function(curLevel) {

gameBack.innerHTML = curLevel.name;

});

// gameover

onestroke.event.on("gameover", function() {

alert("GAMEOVER");

});

// 关卡加载中

onestroke.event.on("level-loading", function() {

console.log("关卡" onestroke.curLevel " 加载中...")

});

onestroke.event.on("level-loaded", function() {

console.log("关卡" onestroke.curLevel " 加载成功")

});

// showOneStroke

let showOneStroke = function() {

levels.style.transform = game.style.transform = "translate(-100%, 0)";

}

// hideOneStroke

let hideOneStroke = function() {

levels.style.transform = game.style.transform = "translate(0, 0)";

}

// 进入对应的关卡

let enter = function(index) {

showOneStroke();

onestroke.enter(index);

}

// 关卡列表初始化

let initLevels = function() {

let str = '';

onestroke.config.levels.forEach(

function(level, index) {

str = '

' (index 1) '\

' level.name '\

'

}

);

levels.innerHTML = str;

// 返回事件

gameBack.addEventListener("click", function() {hideOneStroke()});

// 重新开始

document.querySelector(".game-control-reset").addEventListener("click", function() {onestroke.restart()});

// 回退

document.querySelector(".game-control-rollback").addEventListener("click", function() { onestroke.rollback()});

}

// 调用初始化列表

initLevels();

  • 海报
海报图正在生成中...
赞(0) 打赏
声明:
1、本博客不从事任何主机及服务器租赁业务,不参与任何交易,也绝非中介。博客内容仅记录博主个人感兴趣的服务器测评结果及一些服务器相关的优惠活动,信息均摘自网络或来自服务商主动提供;所以对本博客提及的内容不作直接、间接、法定、约定的保证,博客内容也不具备任何参考价值及引导作用,访问者需自行甄别。
2、访问本博客请务必遵守有关互联网的相关法律、规定与规则;不能利用本博客所提及的内容从事任何违法、违规操作;否则造成的一切后果由访问者自行承担。
3、未成年人及不能独立承担法律责任的个人及群体请勿访问本博客。
4、一旦您访问本博客,即表示您已经知晓并接受了以上声明通告。
文章名称:《html5初学者小游戏源代码,html5 一个“一笔画”小游戏源码(通关)》
文章链接:https://www.456zj.com/36884.html
本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址