在好例子网,分享、交流、成长!
您当前所在位置:首页CSS 开发实例Box Model → html5 一个“一笔画”小游戏源码(通关)

html5 一个“一笔画”小游戏源码(通关)

Box Model

下载此实例
  • 开发语言:CSS
  • 实例大小:0.78M
  • 下载次数:40
  • 浏览次数:1672
  • 发布时间:2018-06-29
  • 实例类别:Box Model
  • 发 布 人:lzyzjbs
  • 文件格式:.zip
  • 所需积分:2
 相关标签: 游戏 一笔画 小游戏

实例介绍

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

【实例截图】

【核心代码】

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<!DOCTYPE HTML>
<html lang="zh-CN">
<head>
  <meta charset="utf-8" />
  <title>H5小游戏100例: 一笔画</title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0, shrink-to-fit=no" />
  <link href="css/onstroke.css" rel="stylesheet">
</head>
 
<body>
    <div class="wrapper">
        <!-- 关卡列表 -->
        <ul class="levels" id="levels">
            <!-- <li class="level">
                <span class="level-no">001</span>
                <span class="level-name">第一关</span>
                <div class="level-arrow"></div>
            </li> -->
        </ul>
        <div class="game" id="game">
            <div class="game-back" id="gameBack"></div>
            <canvas id="easel" width="375" height="603" class="easel"></canvas>
            <div class="game-control">
                <div class="game-control-reset">重新开始</div>
                <div class="game-control-rollback">回退</div>
            </div>
        </div>
    </div>
</body>
<script type="text/javascript" src="script/lib/pixi.js"></script>
<script type="text/javascript" src="script/lib/gsap/TweenMax.js"></script>
<script type="text/javascript" src="script/onestroke.js"></script>
<script type="text/javascript">
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  = '<li class="level" onclick="enter('   index   ')">\
                <span class="level-no">'   (index   1)   '</span>\
                <span class="level-name">'   level.name   '</span>\
                <div class="level-arrow"></div>\
            </li>'
        }
    );
    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();
 
</script>
 
 
 
</html>

实例下载地址

html5 一个“一笔画”小游戏源码(通关)

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警