├── .gitignore ├── README.md ├── assets ├── Scene.meta ├── Scene │ ├── main.fire │ └── main.fire.meta ├── Script.meta ├── Script │ ├── Body.js │ ├── Body.js.meta │ ├── Food.js │ ├── Food.js.meta │ ├── Grobal.js │ ├── Grobal.js.meta │ ├── Head.js │ ├── Head.js.meta │ ├── Main.js │ └── Main.js.meta ├── Texture.meta ├── Texture │ ├── HelloWorld.png │ ├── HelloWorld.png.meta │ ├── back.png │ ├── back.png.meta │ ├── control.png │ ├── control.png.meta │ ├── control_b.png │ ├── control_b.png.meta │ ├── head.png │ ├── head.png.meta │ ├── reddot.png │ ├── reddot.png.meta │ ├── singleColor.png │ ├── singleColor.png.meta │ ├── speet.png │ └── speet.png.meta ├── body.prefab ├── body.prefab.meta ├── food.prefab ├── food.prefab.meta ├── head.prefab └── head.prefab.meta ├── creator.d.ts ├── jsconfig.json ├── project.json ├── settings ├── builder.json ├── builder.panel.json └── project.json ├── snake.png ├── template-banner.png └── template.json /.gitignore: -------------------------------------------------------------------------------- 1 | #///////////////////////////////////////////////////////////////////////////// 2 | # Fireball Projects 3 | #///////////////////////////////////////////////////////////////////////////// 4 | 5 | library/ 6 | temp/ 7 | local/ 8 | build/ 9 | 10 | #///////////////////////////////////////////////////////////////////////////// 11 | # Logs and databases 12 | #///////////////////////////////////////////////////////////////////////////// 13 | 14 | *.log 15 | *.sql 16 | *.sqlite 17 | 18 | #///////////////////////////////////////////////////////////////////////////// 19 | # files for debugger 20 | #///////////////////////////////////////////////////////////////////////////// 21 | 22 | *.sln 23 | *.csproj 24 | *.pidb 25 | *.unityproj 26 | *.suo 27 | 28 | #///////////////////////////////////////////////////////////////////////////// 29 | # OS generated files 30 | #///////////////////////////////////////////////////////////////////////////// 31 | 32 | .DS_Store 33 | ehthumbs.db 34 | Thumbs.db 35 | 36 | #///////////////////////////////////////////////////////////////////////////// 37 | # exvim files 38 | #///////////////////////////////////////////////////////////////////////////// 39 | 40 | *UnityVS.meta 41 | *.err 42 | *.err.meta 43 | *.exvim 44 | *.exvim.meta 45 | *.vimentry 46 | *.vimentry.meta 47 | *.vimproject 48 | *.vimproject.meta 49 | .vimfiles.*/ 50 | .exvim.*/ 51 | quick_gen_project_*_autogen.bat 52 | quick_gen_project_*_autogen.bat.meta 53 | quick_gen_project_*_autogen.sh 54 | quick_gen_project_*_autogen.sh.meta 55 | .exvim.app 56 | 57 | #///////////////////////////////////////////////////////////////////////////// 58 | # webstorm files 59 | #///////////////////////////////////////////////////////////////////////////// 60 | 61 | .idea/ 62 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 贪吃蛇 2 | 3 | 4 | ## 开发工具: Cocos Creator V1.5 5 | > 使用了1.5才有的camera摄像机 6 | 7 | ## 已实现功能: 8 | 9 | 1. 蛇头+蛇身 蛇平移 10 | 11 | 2. 添加向量,移动向量 12 | 13 | 3. 添加方向控制 14 | 15 | 4. 加速 16 | 17 | 5. 使用camera跟踪角色移动 18 | 19 | 6. 随机生成食物 20 | 21 | 7. 吃了食物之后变长 22 | 23 | 8. 多人联机(未实现) 24 | 25 | ## 遗留或待优化问题: 26 | 27 | 1. 小蛇转弯移动会偏移一点点路线,跟节点移动的策略有关,可以优化,或用其他移动策略解决。 28 | 2. 小蛇加速节点之间距离会变短。 29 | 3. 小蛇可以180度掉头。 30 | 4. 联机游戏 31 | 32 | 33 | ## 截图: 34 | ![image](https://github.com/dixonzhang/ccc_snake/blob/master/snake.png) 35 | -------------------------------------------------------------------------------- /assets/Scene.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.0.1", 3 | "uuid": "29f52784-2fca-467b-92e7-8fd9ef8c57b7", 4 | "isGroup": false, 5 | "subMetas": {} 6 | } -------------------------------------------------------------------------------- /assets/Scene/main.fire: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "__type__": "cc.SceneAsset", 4 | "_name": "", 5 | "_objFlags": 0, 6 | "_rawFiles": null, 7 | "scene": { 8 | "__id__": 1 9 | } 10 | }, 11 | { 12 | "__type__": "cc.Scene", 13 | "_objFlags": 0, 14 | "_parent": null, 15 | "_children": [ 16 | { 17 | "__id__": 2 18 | }, 19 | { 20 | "__id__": 13 21 | } 22 | ], 23 | "_tag": -1, 24 | "_active": true, 25 | "_components": [], 26 | "_prefab": null, 27 | "_id": "2d2f792f-a40c-49bb-a189-ed176a246e49", 28 | "_opacity": 255, 29 | "_color": { 30 | "__type__": "cc.Color", 31 | "r": 255, 32 | "g": 255, 33 | "b": 255, 34 | "a": 255 35 | }, 36 | "_cascadeOpacityEnabled": true, 37 | "_anchorPoint": { 38 | "__type__": "cc.Vec2", 39 | "x": 0, 40 | "y": 0 41 | }, 42 | "_contentSize": { 43 | "__type__": "cc.Size", 44 | "width": 0, 45 | "height": 0 46 | }, 47 | "_localZOrder": 0, 48 | "_globalZOrder": 0, 49 | "_opacityModifyRGB": false, 50 | "groupIndex": 0, 51 | "autoReleaseAssets": false 52 | }, 53 | { 54 | "__type__": "cc.Node", 55 | "_name": "Canvas", 56 | "_objFlags": 0, 57 | "_parent": { 58 | "__id__": 1 59 | }, 60 | "_children": [ 61 | { 62 | "__id__": 3 63 | }, 64 | { 65 | "__id__": 5 66 | }, 67 | { 68 | "__id__": 9 69 | } 70 | ], 71 | "_tag": -1, 72 | "_active": true, 73 | "_components": [ 74 | { 75 | "__id__": 11 76 | }, 77 | { 78 | "__id__": 12 79 | } 80 | ], 81 | "_prefab": null, 82 | "_id": "a286bbGknJLZpRpxROV6M94", 83 | "_opacity": 255, 84 | "_color": { 85 | "__type__": "cc.Color", 86 | "r": 252, 87 | "g": 252, 88 | "b": 252, 89 | "a": 255 90 | }, 91 | "_cascadeOpacityEnabled": true, 92 | "_anchorPoint": { 93 | "__type__": "cc.Vec2", 94 | "x": 0.5, 95 | "y": 0.5 96 | }, 97 | "_contentSize": { 98 | "__type__": "cc.Size", 99 | "width": 960, 100 | "height": 640 101 | }, 102 | "_rotationX": 0, 103 | "_rotationY": 0, 104 | "_scaleX": 1, 105 | "_scaleY": 1, 106 | "_position": { 107 | "__type__": "cc.Vec2", 108 | "x": 480, 109 | "y": 320 110 | }, 111 | "_skewX": 0, 112 | "_skewY": 0, 113 | "_localZOrder": 0, 114 | "_globalZOrder": 0, 115 | "_opacityModifyRGB": false, 116 | "groupIndex": 0 117 | }, 118 | { 119 | "__type__": "cc.Node", 120 | "_name": "back", 121 | "_objFlags": 0, 122 | "_parent": { 123 | "__id__": 2 124 | }, 125 | "_children": [], 126 | "_tag": -1, 127 | "_active": true, 128 | "_components": [ 129 | { 130 | "__id__": 4 131 | } 132 | ], 133 | "_prefab": null, 134 | "_id": "4b80ewcfylCAaRrtpUplUyM", 135 | "_opacity": 255, 136 | "_color": { 137 | "__type__": "cc.Color", 138 | "r": 255, 139 | "g": 255, 140 | "b": 255, 141 | "a": 255 142 | }, 143 | "_cascadeOpacityEnabled": true, 144 | "_anchorPoint": { 145 | "__type__": "cc.Vec2", 146 | "x": 0.5, 147 | "y": 0.5 148 | }, 149 | "_contentSize": { 150 | "__type__": "cc.Size", 151 | "width": 2800, 152 | "height": 1800 153 | }, 154 | "_rotationX": 0, 155 | "_rotationY": 0, 156 | "_scaleX": 1, 157 | "_scaleY": 1, 158 | "_position": { 159 | "__type__": "cc.Vec2", 160 | "x": 0, 161 | "y": 0 162 | }, 163 | "_skewX": 0, 164 | "_skewY": 0, 165 | "_localZOrder": 0, 166 | "_globalZOrder": 0, 167 | "_opacityModifyRGB": false, 168 | "groupIndex": 0 169 | }, 170 | { 171 | "__type__": "cc.Sprite", 172 | "_name": "", 173 | "_objFlags": 0, 174 | "node": { 175 | "__id__": 3 176 | }, 177 | "_enabled": true, 178 | "_spriteFrame": { 179 | "__uuid__": "b16daaa0-8309-4ee9-be30-a5c4e2b6b875" 180 | }, 181 | "_type": 0, 182 | "_sizeMode": 0, 183 | "_fillType": 0, 184 | "_fillCenter": { 185 | "__type__": "cc.Vec2", 186 | "x": 0, 187 | "y": 0 188 | }, 189 | "_fillStart": 0, 190 | "_fillRange": 0, 191 | "_isTrimmedMode": true, 192 | "_srcBlendFactor": 770, 193 | "_dstBlendFactor": 771, 194 | "_atlas": null 195 | }, 196 | { 197 | "__type__": "cc.Node", 198 | "_name": "control Node", 199 | "_objFlags": 0, 200 | "_parent": { 201 | "__id__": 2 202 | }, 203 | "_children": [ 204 | { 205 | "__id__": 6 206 | } 207 | ], 208 | "_tag": -1, 209 | "_active": true, 210 | "_components": [ 211 | { 212 | "__id__": 8 213 | } 214 | ], 215 | "_prefab": null, 216 | "_id": "90f84nU/GhBjIo24+gbUVBk", 217 | "_opacity": 255, 218 | "_color": { 219 | "__type__": "cc.Color", 220 | "r": 255, 221 | "g": 255, 222 | "b": 255, 223 | "a": 255 224 | }, 225 | "_cascadeOpacityEnabled": true, 226 | "_anchorPoint": { 227 | "__type__": "cc.Vec2", 228 | "x": 0, 229 | "y": 0 230 | }, 231 | "_contentSize": { 232 | "__type__": "cc.Size", 233 | "width": 200, 234 | "height": 200 235 | }, 236 | "_rotationX": 0, 237 | "_rotationY": 0, 238 | "_scaleX": 1, 239 | "_scaleY": 1, 240 | "_position": { 241 | "__type__": "cc.Vec2", 242 | "x": -449, 243 | "y": -280 244 | }, 245 | "_skewX": 0, 246 | "_skewY": 0, 247 | "_localZOrder": 0, 248 | "_globalZOrder": 0, 249 | "_opacityModifyRGB": false, 250 | "groupIndex": 0 251 | }, 252 | { 253 | "__type__": "cc.Node", 254 | "_name": "control_f", 255 | "_objFlags": 0, 256 | "_parent": { 257 | "__id__": 5 258 | }, 259 | "_children": [], 260 | "_tag": -1, 261 | "_active": true, 262 | "_components": [ 263 | { 264 | "__id__": 7 265 | } 266 | ], 267 | "_prefab": null, 268 | "_id": "65781dloftCoaVGrF9mXp3H", 269 | "_opacity": 255, 270 | "_color": { 271 | "__type__": "cc.Color", 272 | "r": 255, 273 | "g": 255, 274 | "b": 255, 275 | "a": 255 276 | }, 277 | "_cascadeOpacityEnabled": true, 278 | "_anchorPoint": { 279 | "__type__": "cc.Vec2", 280 | "x": 0.5, 281 | "y": 0.5 282 | }, 283 | "_contentSize": { 284 | "__type__": "cc.Size", 285 | "width": 80, 286 | "height": 80 287 | }, 288 | "_rotationX": 0, 289 | "_rotationY": 0, 290 | "_scaleX": 1, 291 | "_scaleY": 1, 292 | "_position": { 293 | "__type__": "cc.Vec2", 294 | "x": 100, 295 | "y": 100 296 | }, 297 | "_skewX": 0, 298 | "_skewY": 0, 299 | "_localZOrder": 0, 300 | "_globalZOrder": 0, 301 | "_opacityModifyRGB": false, 302 | "groupIndex": 0 303 | }, 304 | { 305 | "__type__": "cc.Sprite", 306 | "_name": "", 307 | "_objFlags": 0, 308 | "node": { 309 | "__id__": 6 310 | }, 311 | "_enabled": true, 312 | "_spriteFrame": { 313 | "__uuid__": "a39ea543-d649-4efd-a301-c11623937946" 314 | }, 315 | "_type": 0, 316 | "_sizeMode": 1, 317 | "_fillType": 0, 318 | "_fillCenter": { 319 | "__type__": "cc.Vec2", 320 | "x": 0, 321 | "y": 0 322 | }, 323 | "_fillStart": 0, 324 | "_fillRange": 0, 325 | "_isTrimmedMode": true, 326 | "_srcBlendFactor": 770, 327 | "_dstBlendFactor": 771, 328 | "_atlas": null 329 | }, 330 | { 331 | "__type__": "cc.Sprite", 332 | "_name": "", 333 | "_objFlags": 0, 334 | "node": { 335 | "__id__": 5 336 | }, 337 | "_enabled": true, 338 | "_spriteFrame": { 339 | "__uuid__": "7443bbc3-fffe-42b0-a883-4b94e4d3931e" 340 | }, 341 | "_type": 0, 342 | "_sizeMode": 0, 343 | "_fillType": 0, 344 | "_fillCenter": { 345 | "__type__": "cc.Vec2", 346 | "x": 0, 347 | "y": 0 348 | }, 349 | "_fillStart": 0, 350 | "_fillRange": 0, 351 | "_isTrimmedMode": true, 352 | "_srcBlendFactor": 770, 353 | "_dstBlendFactor": 771, 354 | "_atlas": null 355 | }, 356 | { 357 | "__type__": "cc.Node", 358 | "_name": "speet Node", 359 | "_objFlags": 0, 360 | "_parent": { 361 | "__id__": 2 362 | }, 363 | "_children": [], 364 | "_tag": -1, 365 | "_active": true, 366 | "_components": [ 367 | { 368 | "__id__": 10 369 | } 370 | ], 371 | "_prefab": null, 372 | "_id": "ef302NCe0lBoYBy8cUKqj1k", 373 | "_opacity": 255, 374 | "_color": { 375 | "__type__": "cc.Color", 376 | "r": 255, 377 | "g": 255, 378 | "b": 255, 379 | "a": 255 380 | }, 381 | "_cascadeOpacityEnabled": true, 382 | "_anchorPoint": { 383 | "__type__": "cc.Vec2", 384 | "x": 0.5, 385 | "y": 0.5 386 | }, 387 | "_contentSize": { 388 | "__type__": "cc.Size", 389 | "width": 80, 390 | "height": 80 391 | }, 392 | "_rotationX": 0, 393 | "_rotationY": 0, 394 | "_scaleX": 1, 395 | "_scaleY": 1, 396 | "_position": { 397 | "__type__": "cc.Vec2", 398 | "x": 373, 399 | "y": -178 400 | }, 401 | "_skewX": 0, 402 | "_skewY": 0, 403 | "_localZOrder": 0, 404 | "_globalZOrder": 0, 405 | "_opacityModifyRGB": false, 406 | "groupIndex": 0 407 | }, 408 | { 409 | "__type__": "cc.Sprite", 410 | "_name": "", 411 | "_objFlags": 0, 412 | "node": { 413 | "__id__": 9 414 | }, 415 | "_enabled": true, 416 | "_spriteFrame": { 417 | "__uuid__": "8f4ab48f-7d58-47b3-8eec-8bdcb559b252" 418 | }, 419 | "_type": 0, 420 | "_sizeMode": 1, 421 | "_fillType": 0, 422 | "_fillCenter": { 423 | "__type__": "cc.Vec2", 424 | "x": 0, 425 | "y": 0 426 | }, 427 | "_fillStart": 0, 428 | "_fillRange": 0, 429 | "_isTrimmedMode": true, 430 | "_srcBlendFactor": 770, 431 | "_dstBlendFactor": 771, 432 | "_atlas": null 433 | }, 434 | { 435 | "__type__": "cc.Canvas", 436 | "_name": "", 437 | "_objFlags": 0, 438 | "node": { 439 | "__id__": 2 440 | }, 441 | "_enabled": true, 442 | "_designResolution": { 443 | "__type__": "cc.Size", 444 | "width": 960, 445 | "height": 640 446 | }, 447 | "_fitWidth": false, 448 | "_fitHeight": true 449 | }, 450 | { 451 | "__type__": "0cf5dZQ+M1O8bocE7QPX4YK", 452 | "_name": "", 453 | "_objFlags": 0, 454 | "node": { 455 | "__id__": 2 456 | }, 457 | "_enabled": true, 458 | "headPrefab": { 459 | "__uuid__": "ddda61e4-5287-412b-a51b-d9eb570b802d" 460 | }, 461 | "bodyPrefab": { 462 | "__uuid__": "085cf3ee-4683-4cd5-acf3-bf5097fe6691" 463 | }, 464 | "controlNode": { 465 | "__id__": 5 466 | }, 467 | "controlSprite": { 468 | "__id__": 6 469 | }, 470 | "speetNode": { 471 | "__id__": 9 472 | }, 473 | "cameraNode": { 474 | "__id__": 13 475 | }, 476 | "foodPrefab": { 477 | "__uuid__": "566e3f62-6970-4d3d-ad2d-145242044ea7" 478 | }, 479 | "backNode": { 480 | "__id__": 3 481 | }, 482 | "controlCenterVec": null, 483 | "speet": 0.12, 484 | "speetUp": 0.06 485 | }, 486 | { 487 | "__type__": "cc.Node", 488 | "_name": "camera Node", 489 | "_objFlags": 0, 490 | "_parent": { 491 | "__id__": 1 492 | }, 493 | "_children": [], 494 | "_tag": -1, 495 | "_active": true, 496 | "_components": [ 497 | { 498 | "__id__": 14 499 | } 500 | ], 501 | "_prefab": null, 502 | "_id": "3863843YBBHJaF9ClLe4fC/", 503 | "_opacity": 255, 504 | "_color": { 505 | "__type__": "cc.Color", 506 | "r": 255, 507 | "g": 255, 508 | "b": 255, 509 | "a": 255 510 | }, 511 | "_cascadeOpacityEnabled": true, 512 | "_anchorPoint": { 513 | "__type__": "cc.Vec2", 514 | "x": 0.5, 515 | "y": 0.5 516 | }, 517 | "_contentSize": { 518 | "__type__": "cc.Size", 519 | "width": 0, 520 | "height": 0 521 | }, 522 | "_rotationX": 0, 523 | "_rotationY": 0, 524 | "_scaleX": 1, 525 | "_scaleY": 1, 526 | "_position": { 527 | "__type__": "cc.Vec2", 528 | "x": 480, 529 | "y": 320 530 | }, 531 | "_skewX": 0, 532 | "_skewY": 0, 533 | "_localZOrder": 0, 534 | "_globalZOrder": 0, 535 | "_opacityModifyRGB": false, 536 | "groupIndex": 0 537 | }, 538 | { 539 | "__type__": "cc.Camera", 540 | "_name": "", 541 | "_objFlags": 0, 542 | "node": { 543 | "__id__": 13 544 | }, 545 | "_enabled": true, 546 | "_targets": [ 547 | { 548 | "__id__": 3 549 | } 550 | ], 551 | "zoomRatio": 1 552 | } 553 | ] -------------------------------------------------------------------------------- /assets/Scene/main.fire.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.0.0", 3 | "uuid": "2d2f792f-a40c-49bb-a189-ed176a246e49", 4 | "asyncLoadAssets": false, 5 | "autoReleaseAssets": false, 6 | "subMetas": {} 7 | } -------------------------------------------------------------------------------- /assets/Script.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.0.1", 3 | "uuid": "4734c20c-0db8-4eb2-92ea-e692f4d70934", 4 | "isGroup": false, 5 | "subMetas": {} 6 | } -------------------------------------------------------------------------------- /assets/Script/Body.js: -------------------------------------------------------------------------------- 1 | cc.Class({ 2 | extends: cc.Component, 3 | 4 | properties: { 5 | snakeName: null, 6 | snakeIndex: 0, 7 | isDead: false, 8 | speet: 0, 9 | prePointSnapshot: null,// 上一点的快照 10 | startPointSnapshot: null,// 当前点的快照 11 | distanceSnapshot: 0, // 上一点与当前点快照的距离 12 | 13 | bodyOutColliderNode: { 14 | default: null, 15 | type: cc.Node 16 | } 17 | }, 18 | 19 | // use this for initialization 20 | onLoad: function () { 21 | // body用了两个碰撞组件, 外层的碰撞组件为了让机器蛇自动躲避其他蛇 22 | var bodyInCollider = this.getComponent(cc.CircleCollider); 23 | var bodyOutCollider = this.bodyOutColliderNode.getComponent(cc.CircleCollider); 24 | bodyOutCollider.radius = 3* bodyInCollider.radius; 25 | }, 26 | init: function(name, index){ 27 | this.snakeName = name; 28 | this.snakeIndex = index; 29 | }, 30 | 31 | // called every frame, uncomment this function to activate update callback 32 | update: function (dt) { 33 | if(!this.isDead){ 34 | var speet = Grobal.snakeSpeetMap[this.snakeName]; 35 | if(!speet){ 36 | speet = this.speet; 37 | Grobal.snakeSpeetMap[this.snakeName] = speet; 38 | } 39 | 40 | // 将位置往上一个蛇身位置移动 41 | var snakeArray = Grobal.snakeMap[this.snakeName]; 42 | if(snakeArray){ 43 | 44 | 45 | 46 | if(!this.prePointSnapshot){//第一次为空时初始化 47 | var prePoint = snakeArray[this.snakeIndex-1].getPosition(); 48 | this.prePointSnapshot = prePoint; 49 | this.startPointSnapshot = this.node.getPosition(); 50 | this.distanceSnapshot = cc.pDistance(this.startPointSnapshot, this.prePointSnapshot); 51 | } 52 | 53 | // 累计移动的轨迹长度是否大于快照的长度是则重新初始化 54 | var totalDist = cc.pDistance(this.node.getPosition(), this.startPointSnapshot); 55 | // console.log('dist:', totalDist) 56 | if(totalDist >= this.distanceSnapshot - 0.1){ 57 | var prePoint = snakeArray[this.snakeIndex-1].getPosition(); 58 | this.prePointSnapshot = prePoint; 59 | this.startPointSnapshot = this.node.getPosition(); 60 | this.distanceSnapshot = cc.pDistance(this.startPointSnapshot, this.prePointSnapshot); 61 | } 62 | 63 | 64 | // var subVec = cc.pSub(this.prePointSnapshot, this.node.getPosition()); 65 | // var nomalVec = cc.pNormalize(subVec); 66 | var subVec = cc.pSub(this.prePointSnapshot, this.startPointSnapshot); 67 | 68 | this.node.x += subVec.x/speet * dt; 69 | this.node.y += subVec.y/speet * dt; 70 | } 71 | } 72 | }, 73 | }); 74 | -------------------------------------------------------------------------------- /assets/Script/Body.js.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.0.3", 3 | "uuid": "f9e808e4-f5ca-4f62-922c-3aa5dc25baed", 4 | "isPlugin": false, 5 | "loadPluginInWeb": true, 6 | "loadPluginInNative": true, 7 | "loadPluginInEditor": false, 8 | "subMetas": {} 9 | } -------------------------------------------------------------------------------- /assets/Script/Food.js: -------------------------------------------------------------------------------- 1 | cc.Class({ 2 | extends: cc.Component, 3 | 4 | properties: { 5 | weight: 0 6 | }, 7 | 8 | // use this for initialization 9 | onLoad: function () { 10 | this.init(); 11 | }, 12 | 13 | init: function(){ 14 | this.weight = cc.random0To1() * 20; 15 | this.node.width = this.weight; 16 | this.node.height = this.weight; 17 | 18 | this.node.setPosition(cc.randomMinus1To1()*Grobal.backWidth/2, cc.randomMinus1To1()*Grobal.backHeight/2); 19 | // console.log('init..', this.node.width, 'point:', this.node.getPosition()); 20 | 21 | var circleCollider = this.getComponent(cc.CircleCollider); 22 | circleCollider.radius = this.weight;//碰撞组件的半径大小 23 | }, 24 | 25 | setWidth: function(weight){ 26 | this.weight = weight; 27 | this.node.width = this.weight; 28 | this.node.height = this.weight; 29 | }, 30 | 31 | unuse: function () { 32 | 33 | }, 34 | 35 | reuse: function () { 36 | this.init(); 37 | } 38 | 39 | // called every frame, uncomment this function to activate update callback 40 | // update: function (dt) { 41 | 42 | // }, 43 | }); 44 | -------------------------------------------------------------------------------- /assets/Script/Food.js.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.0.3", 3 | "uuid": "5dd824f7-1bc7-4c87-aaba-f9d754780913", 4 | "isPlugin": false, 5 | "loadPluginInWeb": true, 6 | "loadPluginInNative": true, 7 | "loadPluginInEditor": false, 8 | "subMetas": {} 9 | } -------------------------------------------------------------------------------- /assets/Script/Grobal.js: -------------------------------------------------------------------------------- 1 | window.Grobal = { 2 | gameMain: null, 3 | snakeMap: null, 4 | snakeSpeetMap: null, 5 | foodPool: null, 6 | bodyPool: null, 7 | headPool: null, 8 | backWidth: 0, 9 | backHeight: 0, 10 | } -------------------------------------------------------------------------------- /assets/Script/Grobal.js.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.0.3", 3 | "uuid": "d50fe72b-fc8d-4a05-8eee-f8a6f77e3ac9", 4 | "isPlugin": false, 5 | "loadPluginInWeb": true, 6 | "loadPluginInNative": true, 7 | "loadPluginInEditor": false, 8 | "subMetas": {} 9 | } -------------------------------------------------------------------------------- /assets/Script/Head.js: -------------------------------------------------------------------------------- 1 | cc.Class({ 2 | extends: cc.Component, 3 | 4 | properties: { 5 | bodyPrefab: { 6 | default: null, 7 | type: cc.Prefab 8 | }, 9 | canControl: false, 10 | snakeName: null, 11 | vec: null, 12 | isDead: false, 13 | speet: 0, 14 | growingWeight: 0, // 增长的体重满10则增加一个节点 15 | }, 16 | 17 | // use this for initialization 18 | onLoad: function () { 19 | //碰撞检测 20 | var manager = cc.director.getCollisionManager(); 21 | manager.enabled = true; 22 | manager.enabledDrawBoundingBox = true; 23 | }, 24 | init: function(name){ 25 | this.snakeName = name; 26 | }, 27 | setVec: function(vec){ 28 | this.vec = vec; 29 | }, 30 | 31 | setCanControl: function(canControl){ 32 | this.canControl = canControl; 33 | }, 34 | 35 | //碰撞事件监听 36 | onCollisionEnter: function (other) { 37 | var group = cc.game.groupList[other.node.groupIndex]; 38 | 39 | if(group === 'food'){ 40 | var foodScript = other.node.getComponent('Food'); 41 | this.growingWeight += foodScript.weight; 42 | 43 | Grobal.foodPool.put(other.node); 44 | if(this.growingWeight/10 > 0){ 45 | var size = this.growingWeight / 10; 46 | for(var i = 0; i < Math.floor(size); i++){ 47 | var body = cc.instantiate(this.bodyPrefab);//生成身体 48 | 49 | //根据最后两个节点的向量的确定新增节点的坐标 50 | var arr = Grobal.snakeMap[this.snakeName]; 51 | var lastp = arr[arr.length-1].getPosition(); 52 | var lastp2 = arr[arr.length-2].getPosition(); 53 | 54 | body.getComponent('Body').init(this.snakeName, arr.length); 55 | 56 | var subVec = cc.pSub(lastp, lastp2); 57 | 58 | 59 | var currp = cc.pAdd(lastp, subVec); 60 | 61 | body.setPosition(currp); 62 | Grobal.gameMain.addBody(body); 63 | 64 | arr.push(body); 65 | } 66 | 67 | this.growingWeight = this.growingWeight % 10;//增加节点后,修改重量为余数 68 | } 69 | } 70 | if(group === 'body out'){//遇到其他蛇则躲闪 71 | // 是自己则不处理 72 | var bodyScript = other.node.parent.getComponent('Body'); 73 | if(bodyScript){ 74 | if(this.snakeName == bodyScript.snakeName) 75 | return; 76 | } 77 | 78 | var arr = Grobal.snakeMap[this.snakeName]; 79 | if(arr){ 80 | var p1 = arr[0].getPosition(); 81 | var p2 = arr[1].getPosition(); 82 | 83 | var subVec = cc.pSub(p1, p2); 84 | // var prepVec = cc.pPerp(subVec);//逆时针90度 85 | 86 | var x = -subVec.x; 87 | var y = cc.randomMinus1To1()*subVec.y; 88 | 89 | var v = cc.v2(x, y); 90 | this.vec = v; 91 | } 92 | } 93 | if(group === 'body'){ 94 | // 是自己则不处理 95 | var bodyScript = other.node.getComponent('Body'); 96 | if(bodyScript){ 97 | if(this.snakeName == bodyScript.snakeName) 98 | return; 99 | } 100 | 101 | this.isDead = true; 102 | 103 | var arr = Grobal.snakeMap[this.snakeName]; 104 | if(arr){ 105 | for(var i = 0; i < arr.length; i++){ 106 | var prefab = arr[i]; 107 | var bodyScript = prefab.getComponent('Body'); 108 | if(bodyScript){ 109 | bodyScript.isDead = true; 110 | } 111 | 112 | //死蛇变成食物 113 | Grobal.gameMain.addFood(prefab.getPosition(), 10); 114 | 115 | //回收蛇 116 | if(i == 0) 117 | Grobal.headPool.put(prefab); 118 | else 119 | Grobal.bodyPool.put(prefab); 120 | } 121 | Grobal.snakeMap[this.snakeName] = null; 122 | } 123 | } 124 | }, 125 | 126 | // called every frame, uncomment this function to activate update callback 127 | update: function (dt) { 128 | if(!this.isDead){ 129 | var speet = Grobal.snakeSpeetMap[this.snakeName]; 130 | if(!speet){ 131 | speet = this.speet; 132 | Grobal.snakeSpeetMap[this.snakeName] = speet; 133 | } 134 | 135 | var vvv = cc.pNormalize(this.vec); 136 | 137 | // console.log(vvv.x, ',', vvv.y); 138 | this.node.x += vvv.x*this.node.width/speet *dt; 139 | this.node.y += vvv.y*this.node.width/speet *dt; 140 | 141 | if(Math.abs(this.node.x) >= Grobal.backWidth/2){ 142 | this.vec.x = -this.vec.x; 143 | } 144 | if(Math.abs(this.node.y) >= Grobal.backHeight/2){ 145 | this.vec.y = - this.vec.y; 146 | } 147 | } 148 | }, 149 | }); 150 | -------------------------------------------------------------------------------- /assets/Script/Head.js.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.0.3", 3 | "uuid": "2d12960d-fd4a-46bc-9312-f8a474086e82", 4 | "isPlugin": false, 5 | "loadPluginInWeb": true, 6 | "loadPluginInNative": true, 7 | "loadPluginInEditor": false, 8 | "subMetas": {} 9 | } -------------------------------------------------------------------------------- /assets/Script/Main.js: -------------------------------------------------------------------------------- 1 | cc.Class({ 2 | extends: cc.Component, 3 | 4 | properties: { 5 | headPrefab: { 6 | default: null, 7 | type: cc.Prefab 8 | }, 9 | bodyPrefab: { 10 | default: null, 11 | type: cc.Prefab 12 | }, 13 | controlNode: { 14 | default: null, 15 | type: cc.Node 16 | }, 17 | controlSprite: { 18 | default: null, 19 | type: cc.Node 20 | }, 21 | speetNode: { 22 | default: null, 23 | type: cc.Node 24 | }, 25 | cameraNode: { 26 | default: null, 27 | type: cc.Node 28 | }, 29 | foodPrefab: { 30 | default: null, 31 | type: cc.Prefab 32 | }, 33 | backNode: { 34 | default: null, 35 | type: cc.Node 36 | }, 37 | controlCenterVec: null, 38 | speet: 0.12, 39 | speetUp: 0.06 40 | }, 41 | 42 | // use this for initialization 43 | onLoad: function () { 44 | 45 | this.node.on(cc.Node.EventType.TOUCH_MOVE, this.controlMoveCallBack, this); 46 | this.node.on(cc.Node.EventType.TOUCH_END, this.controlEndCallBack, this); 47 | 48 | this.speetNode.on(cc.Node.EventType.TOUCH_START, this.speetStartCallBack, this); 49 | this.speetNode.on(cc.Node.EventType.TOUCH_END, this.speetEndCallBack, this); 50 | 51 | this.controlCenterVec = new cc.Vec2(this.controlNode.width/2, this.controlNode.height/2); 52 | 53 | Grobal.gameMain = this; 54 | Grobal.snakeMap = {}; 55 | Grobal.snakeSpeetMap = {}; 56 | Grobal.foodPool = new cc.NodePool('Food');//创建食物的对象池并指定脚本、这样会调用 unuse reuse方法 57 | Grobal.bodyPool = new cc.NodePool(); 58 | Grobal.headPool = new cc.NodePool(); 59 | Grobal.backWidth = this.backNode.width; 60 | Grobal.backHeight = this.backNode.height; 61 | 62 | //摄像机,跟随小蛇移动 63 | var camera = this.cameraNode.getComponent(cc.Camera); 64 | 65 | 66 | this.initFood(camera); 67 | 68 | for(var i = 0; i < 10; i++){ 69 | this.createSnake('snake' + i, camera); 70 | } 71 | 72 | this.createSnake('player', camera);//可控制的小蛇 73 | }, 74 | /** 75 | * 控制按钮 76 | */ 77 | controlMoveCallBack: function(event){ 78 | var touches = event.getTouches(); 79 | var touchLoc = touches[0].getLocation(); 80 | var touchPoint = this.controlNode.convertToNodeSpace(touchLoc); 81 | 82 | // 设置控制点 限制超出父节点 83 | var subVec = cc.pSub(touchPoint, this.controlCenterVec); 84 | if(cc.pDistance(touchPoint, this.controlCenterVec) > this.controlNode.width/2){ 85 | var nv = cc.pNormalize(subVec); 86 | this.controlSprite.x = this.controlCenterVec.x + nv.x * this.controlNode.width/2; 87 | this.controlSprite.y = this.controlCenterVec.y + nv.y * this.controlNode.width/2; 88 | }else{ 89 | this.controlSprite.setPosition(touchPoint); 90 | } 91 | 92 | 93 | var playerSnakeArr = Grobal.snakeMap['player']; 94 | if(playerSnakeArr && playerSnakeArr[0]){ 95 | var headScript = playerSnakeArr[0].getComponent('Head'); 96 | if(headScript){ 97 | headScript.setVec(subVec); 98 | } 99 | } 100 | }, 101 | /** 102 | * 松开时回复控制点到中点 103 | */ 104 | controlEndCallBack: function(event){ 105 | // 恢复控制点位置控制点 106 | this.controlSprite.setPosition(this.controlCenterVec); 107 | }, 108 | 109 | speetStartCallBack: function(){ 110 | var speet = Grobal.snakeSpeetMap['player']; 111 | if(speet) 112 | Grobal.snakeSpeetMap['player'] = this.speetUp; 113 | }, 114 | speetEndCallBack: function(){ 115 | var speet = Grobal.snakeSpeetMap['player']; 116 | if(speet) 117 | Grobal.snakeSpeetMap['player'] = this.speet; 118 | }, 119 | 120 | createSnake: function(name, camera){ 121 | var x = 960/2 * cc.randomMinus1To1(); 122 | var y = 640/2 * cc.randomMinus1To1(); 123 | 124 | var snakeArr = new Array(); 125 | 126 | // 蛇头 127 | var headPrefab = cc.instantiate(this.headPrefab); 128 | var headScript = headPrefab.getComponent('Head'); 129 | headScript.init(name); 130 | headScript.setVec(new cc.Vec2(100*cc.randomMinus1To1(), 100*cc.randomMinus1To1())); 131 | 132 | snakeArr.push(headPrefab); 133 | 134 | // 蛇身 135 | for(var i = 0; i < 5; i++){ 136 | var bodyPrefab = cc.instantiate(this.bodyPrefab); 137 | bodyPrefab.getComponent('Body').init(name, i+1); 138 | snakeArr.push(bodyPrefab); 139 | } 140 | 141 | for(var i = 0; i < snakeArr.length; i++){ 142 | var bodyPrefab = snakeArr[i]; 143 | 144 | this.node.addChild(bodyPrefab); 145 | bodyPrefab.setPosition(cc.p(i*bodyPrefab.width + x, 0 + y)); 146 | 147 | camera.addTarget(bodyPrefab); 148 | } 149 | 150 | Grobal.snakeMap[name] = snakeArr; 151 | }, 152 | initFood: function(camera){ 153 | for(var i = 0; i < 100; i++){ 154 | var food = cc.instantiate(this.foodPrefab); 155 | 156 | this.node.addChild(food); 157 | camera.addTarget(food); 158 | } 159 | }, 160 | addFood: function(position, weight){ 161 | var food; 162 | if(Grobal.foodPool.size()>0) 163 | food = Grobal.foodPool.get(); 164 | else 165 | food = cc.instantiate(this.foodPrefab); 166 | 167 | this.node.addChild(food); 168 | food.setPosition(position); 169 | food.getComponent('Food').setWidth(weight); 170 | 171 | var camera = this.cameraNode.getComponent(cc.Camera); 172 | camera.addTarget(food); 173 | }, 174 | addBody: function(body){ 175 | this.node.addChild(body); 176 | var camera = this.cameraNode.getComponent(cc.Camera); 177 | camera.addTarget(body); 178 | }, 179 | 180 | // called every frame, uncomment this function to activate update callback 181 | // update: function (dt) { 182 | 183 | // }, 184 | lateUpdate: function (dt) { 185 | 186 | if(Grobal.snakeMap['player']){ 187 | // camera跟踪蛇头 关键代码!!! 188 | let targetPos = Grobal.snakeMap['player'][0].convertToWorldSpaceAR(cc.Vec2.ZERO); 189 | this.cameraNode.position = this.cameraNode.parent.convertToNodeSpaceAR(targetPos); 190 | 191 | // let ratio = targetPos.y / cc.winSize.height; 192 | // this.camera.zoomRatio = 1 + (0.5 - ratio) * 0.5; 193 | } 194 | }, 195 | }); 196 | -------------------------------------------------------------------------------- /assets/Script/Main.js.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.0.3", 3 | "uuid": "0cf5d650-f8cd-4ef1-ba1c-13b40f5f860a", 4 | "isPlugin": false, 5 | "loadPluginInWeb": true, 6 | "loadPluginInNative": true, 7 | "loadPluginInEditor": false, 8 | "subMetas": {} 9 | } -------------------------------------------------------------------------------- /assets/Texture.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.0.1", 3 | "uuid": "7b81d4e8-ec84-4716-968d-500ac1d78a54", 4 | "isGroup": false, 5 | "subMetas": {} 6 | } -------------------------------------------------------------------------------- /assets/Texture/HelloWorld.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dixonzhang/ccc_snake/0feb9d91a721703592ba8972c408eb6c1f60f4c1/assets/Texture/HelloWorld.png -------------------------------------------------------------------------------- /assets/Texture/HelloWorld.png.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.0.0", 3 | "uuid": "6aa0aa6a-ebee-4155-a088-a687a6aadec4", 4 | "type": "sprite", 5 | "wrapMode": "clamp", 6 | "filterMode": "bilinear", 7 | "subMetas": { 8 | "HelloWorld": { 9 | "ver": "1.0.3", 10 | "uuid": "31bc895a-c003-4566-a9f3-2e54ae1c17dc", 11 | "rawTextureUuid": "6aa0aa6a-ebee-4155-a088-a687a6aadec4", 12 | "trimType": "auto", 13 | "trimThreshold": 1, 14 | "rotated": false, 15 | "offsetX": 0, 16 | "offsetY": 0, 17 | "trimX": 0, 18 | "trimY": 0, 19 | "width": 195, 20 | "height": 270, 21 | "rawWidth": 195, 22 | "rawHeight": 270, 23 | "borderTop": 0, 24 | "borderBottom": 0, 25 | "borderLeft": 0, 26 | "borderRight": 0, 27 | "subMetas": {} 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /assets/Texture/back.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dixonzhang/ccc_snake/0feb9d91a721703592ba8972c408eb6c1f60f4c1/assets/Texture/back.png -------------------------------------------------------------------------------- /assets/Texture/back.png.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.0.0", 3 | "uuid": "c070fb21-971c-472a-8946-33b8793639c9", 4 | "type": "sprite", 5 | "wrapMode": "clamp", 6 | "filterMode": "bilinear", 7 | "subMetas": { 8 | "back": { 9 | "ver": "1.0.3", 10 | "uuid": "b16daaa0-8309-4ee9-be30-a5c4e2b6b875", 11 | "rawTextureUuid": "c070fb21-971c-472a-8946-33b8793639c9", 12 | "trimType": "auto", 13 | "trimThreshold": 1, 14 | "rotated": false, 15 | "offsetX": 0, 16 | "offsetY": 0, 17 | "trimX": 0, 18 | "trimY": 0, 19 | "width": 2800, 20 | "height": 1800, 21 | "rawWidth": 2800, 22 | "rawHeight": 1800, 23 | "borderTop": 0, 24 | "borderBottom": 0, 25 | "borderLeft": 0, 26 | "borderRight": 0, 27 | "subMetas": {} 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /assets/Texture/control.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dixonzhang/ccc_snake/0feb9d91a721703592ba8972c408eb6c1f60f4c1/assets/Texture/control.png -------------------------------------------------------------------------------- /assets/Texture/control.png.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.0.0", 3 | "uuid": "7ce82941-8d8a-4508-bd21-e08d58f6df3a", 4 | "type": "sprite", 5 | "wrapMode": "clamp", 6 | "filterMode": "bilinear", 7 | "subMetas": { 8 | "control": { 9 | "ver": "1.0.3", 10 | "uuid": "7443bbc3-fffe-42b0-a883-4b94e4d3931e", 11 | "rawTextureUuid": "7ce82941-8d8a-4508-bd21-e08d58f6df3a", 12 | "trimType": "auto", 13 | "trimThreshold": 1, 14 | "rotated": false, 15 | "offsetX": 0, 16 | "offsetY": 0, 17 | "trimX": 0, 18 | "trimY": 0, 19 | "width": 200, 20 | "height": 200, 21 | "rawWidth": 200, 22 | "rawHeight": 200, 23 | "borderTop": 0, 24 | "borderBottom": 0, 25 | "borderLeft": 0, 26 | "borderRight": 0, 27 | "subMetas": {} 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /assets/Texture/control_b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dixonzhang/ccc_snake/0feb9d91a721703592ba8972c408eb6c1f60f4c1/assets/Texture/control_b.png -------------------------------------------------------------------------------- /assets/Texture/control_b.png.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.0.0", 3 | "uuid": "447fc375-60f0-49c8-93b7-6c35a423edda", 4 | "type": "sprite", 5 | "wrapMode": "clamp", 6 | "filterMode": "bilinear", 7 | "subMetas": { 8 | "control_b": { 9 | "ver": "1.0.3", 10 | "uuid": "a39ea543-d649-4efd-a301-c11623937946", 11 | "rawTextureUuid": "447fc375-60f0-49c8-93b7-6c35a423edda", 12 | "trimType": "auto", 13 | "trimThreshold": 1, 14 | "rotated": false, 15 | "offsetX": 0, 16 | "offsetY": 0, 17 | "trimX": 0, 18 | "trimY": 0, 19 | "width": 80, 20 | "height": 80, 21 | "rawWidth": 80, 22 | "rawHeight": 80, 23 | "borderTop": 0, 24 | "borderBottom": 0, 25 | "borderLeft": 0, 26 | "borderRight": 0, 27 | "subMetas": {} 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /assets/Texture/head.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dixonzhang/ccc_snake/0feb9d91a721703592ba8972c408eb6c1f60f4c1/assets/Texture/head.png -------------------------------------------------------------------------------- /assets/Texture/head.png.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.0.0", 3 | "uuid": "14c11a2f-7277-4186-8858-981c4667afbd", 4 | "type": "sprite", 5 | "wrapMode": "clamp", 6 | "filterMode": "bilinear", 7 | "subMetas": { 8 | "head": { 9 | "ver": "1.0.3", 10 | "uuid": "649885cd-c0c2-44ec-a1c5-538701452a98", 11 | "rawTextureUuid": "14c11a2f-7277-4186-8858-981c4667afbd", 12 | "trimType": "auto", 13 | "trimThreshold": 1, 14 | "rotated": false, 15 | "offsetX": 0, 16 | "offsetY": 0, 17 | "trimX": 0, 18 | "trimY": 0, 19 | "width": 30, 20 | "height": 30, 21 | "rawWidth": 30, 22 | "rawHeight": 30, 23 | "borderTop": 0, 24 | "borderBottom": 0, 25 | "borderLeft": 0, 26 | "borderRight": 0, 27 | "subMetas": {} 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /assets/Texture/reddot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dixonzhang/ccc_snake/0feb9d91a721703592ba8972c408eb6c1f60f4c1/assets/Texture/reddot.png -------------------------------------------------------------------------------- /assets/Texture/reddot.png.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.0.0", 3 | "uuid": "ecc24b98-24b3-463d-a179-3c14f292c696", 4 | "type": "sprite", 5 | "wrapMode": "clamp", 6 | "filterMode": "bilinear", 7 | "subMetas": { 8 | "reddot": { 9 | "ver": "1.0.3", 10 | "uuid": "4f401f22-69b2-40d0-8118-c263fec5310e", 11 | "rawTextureUuid": "ecc24b98-24b3-463d-a179-3c14f292c696", 12 | "trimType": "auto", 13 | "trimThreshold": 1, 14 | "rotated": false, 15 | "offsetX": 0, 16 | "offsetY": 0, 17 | "trimX": 0, 18 | "trimY": 0, 19 | "width": 30, 20 | "height": 30, 21 | "rawWidth": 30, 22 | "rawHeight": 30, 23 | "borderTop": 0, 24 | "borderBottom": 0, 25 | "borderLeft": 0, 26 | "borderRight": 0, 27 | "subMetas": {} 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /assets/Texture/singleColor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dixonzhang/ccc_snake/0feb9d91a721703592ba8972c408eb6c1f60f4c1/assets/Texture/singleColor.png -------------------------------------------------------------------------------- /assets/Texture/singleColor.png.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.0.0", 3 | "uuid": "a8027877-d8d6-4645-97a0-52d4a0123dba", 4 | "type": "sprite", 5 | "wrapMode": "clamp", 6 | "filterMode": "bilinear", 7 | "subMetas": { 8 | "singleColor": { 9 | "ver": "1.0.3", 10 | "uuid": "410fb916-8721-4663-bab8-34397391ace7", 11 | "rawTextureUuid": "a8027877-d8d6-4645-97a0-52d4a0123dba", 12 | "trimType": "auto", 13 | "trimThreshold": 1, 14 | "rotated": false, 15 | "offsetX": 0, 16 | "offsetY": 0, 17 | "trimX": 0, 18 | "trimY": 0, 19 | "width": 2, 20 | "height": 2, 21 | "rawWidth": 2, 22 | "rawHeight": 2, 23 | "borderTop": 0, 24 | "borderBottom": 0, 25 | "borderLeft": 0, 26 | "borderRight": 0, 27 | "subMetas": {} 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /assets/Texture/speet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dixonzhang/ccc_snake/0feb9d91a721703592ba8972c408eb6c1f60f4c1/assets/Texture/speet.png -------------------------------------------------------------------------------- /assets/Texture/speet.png.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.0.0", 3 | "uuid": "bf9f9f2a-865b-4b31-9fac-128f654ccd33", 4 | "type": "sprite", 5 | "wrapMode": "clamp", 6 | "filterMode": "bilinear", 7 | "subMetas": { 8 | "speet": { 9 | "ver": "1.0.3", 10 | "uuid": "8f4ab48f-7d58-47b3-8eec-8bdcb559b252", 11 | "rawTextureUuid": "bf9f9f2a-865b-4b31-9fac-128f654ccd33", 12 | "trimType": "auto", 13 | "trimThreshold": 1, 14 | "rotated": false, 15 | "offsetX": 0, 16 | "offsetY": 0, 17 | "trimX": 0, 18 | "trimY": 0, 19 | "width": 80, 20 | "height": 80, 21 | "rawWidth": 80, 22 | "rawHeight": 80, 23 | "borderTop": 0, 24 | "borderBottom": 0, 25 | "borderLeft": 0, 26 | "borderRight": 0, 27 | "subMetas": {} 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /assets/body.prefab: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "__type__": "cc.Prefab", 4 | "_name": "", 5 | "_objFlags": 0, 6 | "_rawFiles": null, 7 | "data": { 8 | "__id__": 1 9 | } 10 | }, 11 | { 12 | "__type__": "cc.Node", 13 | "_name": "body", 14 | "_objFlags": 0, 15 | "_parent": null, 16 | "_children": [ 17 | { 18 | "__id__": 2 19 | } 20 | ], 21 | "_tag": -1, 22 | "_active": true, 23 | "_components": [ 24 | { 25 | "__id__": 5 26 | }, 27 | { 28 | "__id__": 6 29 | }, 30 | { 31 | "__id__": 7 32 | } 33 | ], 34 | "_prefab": { 35 | "__id__": 8 36 | }, 37 | "_id": "", 38 | "_opacity": 255, 39 | "_color": { 40 | "__type__": "cc.Color", 41 | "r": 255, 42 | "g": 255, 43 | "b": 255, 44 | "a": 255 45 | }, 46 | "_cascadeOpacityEnabled": true, 47 | "_anchorPoint": { 48 | "__type__": "cc.Vec2", 49 | "x": 0.5, 50 | "y": 0.5 51 | }, 52 | "_contentSize": { 53 | "__type__": "cc.Size", 54 | "width": 10, 55 | "height": 10 56 | }, 57 | "_rotationX": 0, 58 | "_rotationY": 0, 59 | "_scaleX": 1, 60 | "_scaleY": 1, 61 | "_position": { 62 | "__type__": "cc.Vec2", 63 | "x": 0, 64 | "y": 0 65 | }, 66 | "_skewX": 0, 67 | "_skewY": 0, 68 | "_localZOrder": 0, 69 | "_globalZOrder": 0, 70 | "_opacityModifyRGB": false, 71 | "groupIndex": 2 72 | }, 73 | { 74 | "__type__": "cc.Node", 75 | "_name": "collideNode", 76 | "_objFlags": 0, 77 | "_parent": { 78 | "__id__": 1 79 | }, 80 | "_children": [], 81 | "_tag": -1, 82 | "_active": true, 83 | "_components": [ 84 | { 85 | "__id__": 3 86 | } 87 | ], 88 | "_prefab": { 89 | "__id__": 4 90 | }, 91 | "_id": "", 92 | "_opacity": 255, 93 | "_color": { 94 | "__type__": "cc.Color", 95 | "r": 255, 96 | "g": 255, 97 | "b": 255, 98 | "a": 255 99 | }, 100 | "_cascadeOpacityEnabled": true, 101 | "_anchorPoint": { 102 | "__type__": "cc.Vec2", 103 | "x": 0.5, 104 | "y": 0.5 105 | }, 106 | "_contentSize": { 107 | "__type__": "cc.Size", 108 | "width": 0, 109 | "height": 0 110 | }, 111 | "_rotationX": 0, 112 | "_rotationY": 0, 113 | "_scaleX": 1, 114 | "_scaleY": 1, 115 | "_position": { 116 | "__type__": "cc.Vec2", 117 | "x": 0, 118 | "y": 0 119 | }, 120 | "_skewX": 0, 121 | "_skewY": 0, 122 | "_localZOrder": 0, 123 | "_globalZOrder": 0, 124 | "_opacityModifyRGB": false, 125 | "groupIndex": 4 126 | }, 127 | { 128 | "__type__": "cc.CircleCollider", 129 | "_name": "", 130 | "_objFlags": 0, 131 | "node": { 132 | "__id__": 2 133 | }, 134 | "_enabled": true, 135 | "tag": 0, 136 | "_offset": { 137 | "__type__": "cc.Vec2", 138 | "x": 0, 139 | "y": 0 140 | }, 141 | "_radius": 50 142 | }, 143 | { 144 | "__type__": "cc.PrefabInfo", 145 | "root": { 146 | "__id__": 1 147 | }, 148 | "asset": { 149 | "__id__": 0 150 | }, 151 | "fileId": "db175pMvLVB7YIen+4dD2pu", 152 | "sync": false 153 | }, 154 | { 155 | "__type__": "cc.Sprite", 156 | "_name": "", 157 | "_objFlags": 0, 158 | "node": { 159 | "__id__": 1 160 | }, 161 | "_enabled": true, 162 | "_spriteFrame": { 163 | "__uuid__": "4f401f22-69b2-40d0-8118-c263fec5310e" 164 | }, 165 | "_type": 0, 166 | "_sizeMode": 0, 167 | "_fillType": 0, 168 | "_fillCenter": { 169 | "__type__": "cc.Vec2", 170 | "x": 0, 171 | "y": 0 172 | }, 173 | "_fillStart": 0, 174 | "_fillRange": 0, 175 | "_isTrimmedMode": true, 176 | "_srcBlendFactor": 770, 177 | "_dstBlendFactor": 771, 178 | "_atlas": null 179 | }, 180 | { 181 | "__type__": "cc.CircleCollider", 182 | "_name": "", 183 | "_objFlags": 0, 184 | "node": { 185 | "__id__": 1 186 | }, 187 | "_enabled": true, 188 | "tag": 0, 189 | "_offset": { 190 | "__type__": "cc.Vec2", 191 | "x": 0, 192 | "y": 0 193 | }, 194 | "_radius": 5 195 | }, 196 | { 197 | "__type__": "f9e80jk9cpPYpIsOqXcJbrt", 198 | "_name": "", 199 | "_objFlags": 0, 200 | "node": { 201 | "__id__": 1 202 | }, 203 | "_enabled": true, 204 | "snakeName": null, 205 | "snakeIndex": 0, 206 | "isDead": false, 207 | "speet": 0.12, 208 | "prePointSnapshot": null, 209 | "startPointSnapshot": null, 210 | "distanceSnapshot": 0, 211 | "bodyOutColliderNode": { 212 | "__id__": 2 213 | } 214 | }, 215 | { 216 | "__type__": "cc.PrefabInfo", 217 | "root": { 218 | "__id__": 1 219 | }, 220 | "asset": { 221 | "__id__": 0 222 | }, 223 | "fileId": "c7d8aPOV7lObqG+/X6UF+Wl", 224 | "sync": false 225 | } 226 | ] -------------------------------------------------------------------------------- /assets/body.prefab.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.0.0", 3 | "uuid": "085cf3ee-4683-4cd5-acf3-bf5097fe6691", 4 | "asyncLoadAssets": false, 5 | "subMetas": {} 6 | } -------------------------------------------------------------------------------- /assets/food.prefab: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "__type__": "cc.Prefab", 4 | "_name": "", 5 | "_objFlags": 0, 6 | "_rawFiles": null, 7 | "data": { 8 | "__id__": 1 9 | } 10 | }, 11 | { 12 | "__type__": "cc.Node", 13 | "_name": "food", 14 | "_objFlags": 0, 15 | "_parent": null, 16 | "_children": [], 17 | "_tag": -1, 18 | "_active": true, 19 | "_components": [ 20 | { 21 | "__id__": 2 22 | }, 23 | { 24 | "__id__": 3 25 | }, 26 | { 27 | "__id__": 4 28 | } 29 | ], 30 | "_prefab": { 31 | "__id__": 5 32 | }, 33 | "_id": "", 34 | "_opacity": 255, 35 | "_color": { 36 | "__type__": "cc.Color", 37 | "r": 255, 38 | "g": 255, 39 | "b": 255, 40 | "a": 255 41 | }, 42 | "_cascadeOpacityEnabled": true, 43 | "_anchorPoint": { 44 | "__type__": "cc.Vec2", 45 | "x": 0.5, 46 | "y": 0.5 47 | }, 48 | "_contentSize": { 49 | "__type__": "cc.Size", 50 | "width": 30, 51 | "height": 30 52 | }, 53 | "_rotationX": 0, 54 | "_rotationY": 0, 55 | "_scaleX": 1, 56 | "_scaleY": 1, 57 | "_position": { 58 | "__type__": "cc.Vec2", 59 | "x": 0, 60 | "y": 0 61 | }, 62 | "_skewX": 0, 63 | "_skewY": 0, 64 | "_localZOrder": 0, 65 | "_globalZOrder": 0, 66 | "_opacityModifyRGB": false, 67 | "groupIndex": 3 68 | }, 69 | { 70 | "__type__": "cc.Sprite", 71 | "_name": "", 72 | "_objFlags": 0, 73 | "node": { 74 | "__id__": 1 75 | }, 76 | "_enabled": true, 77 | "_spriteFrame": { 78 | "__uuid__": "4f401f22-69b2-40d0-8118-c263fec5310e" 79 | }, 80 | "_type": 0, 81 | "_sizeMode": 1, 82 | "_fillType": 0, 83 | "_fillCenter": { 84 | "__type__": "cc.Vec2", 85 | "x": 0, 86 | "y": 0 87 | }, 88 | "_fillStart": 0, 89 | "_fillRange": 0, 90 | "_isTrimmedMode": true, 91 | "_srcBlendFactor": 770, 92 | "_dstBlendFactor": 771, 93 | "_atlas": null 94 | }, 95 | { 96 | "__type__": "5dd82T3G8dMh6q6+ddUeAkT", 97 | "_name": "", 98 | "_objFlags": 0, 99 | "node": { 100 | "__id__": 1 101 | }, 102 | "_enabled": true, 103 | "weight": 0 104 | }, 105 | { 106 | "__type__": "cc.CircleCollider", 107 | "_name": "", 108 | "_objFlags": 0, 109 | "node": { 110 | "__id__": 1 111 | }, 112 | "_enabled": true, 113 | "tag": 0, 114 | "_offset": { 115 | "__type__": "cc.Vec2", 116 | "x": 0, 117 | "y": 0 118 | }, 119 | "_radius": 30 120 | }, 121 | { 122 | "__type__": "cc.PrefabInfo", 123 | "root": { 124 | "__id__": 1 125 | }, 126 | "asset": { 127 | "__id__": 0 128 | }, 129 | "fileId": "16acdMtheRHkq6d0ECEucnL", 130 | "sync": false 131 | } 132 | ] -------------------------------------------------------------------------------- /assets/food.prefab.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.0.0", 3 | "uuid": "566e3f62-6970-4d3d-ad2d-145242044ea7", 4 | "asyncLoadAssets": false, 5 | "subMetas": {} 6 | } -------------------------------------------------------------------------------- /assets/head.prefab: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "__type__": "cc.Prefab", 4 | "_name": "", 5 | "_objFlags": 0, 6 | "_rawFiles": null, 7 | "data": { 8 | "__id__": 1 9 | } 10 | }, 11 | { 12 | "__type__": "cc.Node", 13 | "_name": "head", 14 | "_objFlags": 0, 15 | "_parent": null, 16 | "_children": [], 17 | "_tag": -1, 18 | "_active": true, 19 | "_components": [ 20 | { 21 | "__id__": 2 22 | }, 23 | { 24 | "__id__": 3 25 | }, 26 | { 27 | "__id__": 4 28 | } 29 | ], 30 | "_prefab": { 31 | "__id__": 5 32 | }, 33 | "_id": "", 34 | "_opacity": 255, 35 | "_color": { 36 | "__type__": "cc.Color", 37 | "r": 255, 38 | "g": 255, 39 | "b": 255, 40 | "a": 255 41 | }, 42 | "_cascadeOpacityEnabled": true, 43 | "_anchorPoint": { 44 | "__type__": "cc.Vec2", 45 | "x": 0.5, 46 | "y": 0.5 47 | }, 48 | "_contentSize": { 49 | "__type__": "cc.Size", 50 | "width": 13, 51 | "height": 13 52 | }, 53 | "_rotationX": 0, 54 | "_rotationY": 0, 55 | "_scaleX": 1, 56 | "_scaleY": 1, 57 | "_position": { 58 | "__type__": "cc.Vec2", 59 | "x": 0, 60 | "y": 0 61 | }, 62 | "_skewX": 0, 63 | "_skewY": 0, 64 | "_localZOrder": 0, 65 | "_globalZOrder": 0, 66 | "_opacityModifyRGB": false, 67 | "groupIndex": 1 68 | }, 69 | { 70 | "__type__": "cc.Sprite", 71 | "_name": "", 72 | "_objFlags": 0, 73 | "node": { 74 | "__id__": 1 75 | }, 76 | "_enabled": true, 77 | "_spriteFrame": { 78 | "__uuid__": "649885cd-c0c2-44ec-a1c5-538701452a98" 79 | }, 80 | "_type": 0, 81 | "_sizeMode": 0, 82 | "_fillType": 0, 83 | "_fillCenter": { 84 | "__type__": "cc.Vec2", 85 | "x": 0, 86 | "y": 0 87 | }, 88 | "_fillStart": 0, 89 | "_fillRange": 0, 90 | "_isTrimmedMode": true, 91 | "_srcBlendFactor": 770, 92 | "_dstBlendFactor": 771, 93 | "_atlas": null 94 | }, 95 | { 96 | "__type__": "cc.CircleCollider", 97 | "_name": "", 98 | "_objFlags": 0, 99 | "node": { 100 | "__id__": 1 101 | }, 102 | "_enabled": true, 103 | "tag": 0, 104 | "_offset": { 105 | "__type__": "cc.Vec2", 106 | "x": 0, 107 | "y": 0 108 | }, 109 | "_radius": 7 110 | }, 111 | { 112 | "__type__": "2d129YN/UpGvJMS+KR0CG6C", 113 | "_name": "", 114 | "_objFlags": 0, 115 | "node": { 116 | "__id__": 1 117 | }, 118 | "_enabled": true, 119 | "bodyPrefab": { 120 | "__uuid__": "085cf3ee-4683-4cd5-acf3-bf5097fe6691" 121 | }, 122 | "canControl": false, 123 | "snakeName": null, 124 | "vec": null, 125 | "isDead": false, 126 | "speet": 0.12, 127 | "growingWeight": 0 128 | }, 129 | { 130 | "__type__": "cc.PrefabInfo", 131 | "root": { 132 | "__id__": 1 133 | }, 134 | "asset": { 135 | "__id__": 0 136 | }, 137 | "fileId": "95f22zv5oNDT40RWg8FfCiA", 138 | "sync": false 139 | } 140 | ] -------------------------------------------------------------------------------- /assets/head.prefab.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.0.0", 3 | "uuid": "ddda61e4-5287-412b-a51b-d9eb570b802d", 4 | "asyncLoadAssets": false, 5 | "subMetas": {} 6 | } -------------------------------------------------------------------------------- /jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es6", 4 | "module": "commonjs" 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "library", 9 | "local", 10 | "settings", 11 | "temp" 12 | ] 13 | } -------------------------------------------------------------------------------- /project.json: -------------------------------------------------------------------------------- 1 | { 2 | "engine": "cocos2d-html5", 3 | "packages": "packages" 4 | } -------------------------------------------------------------------------------- /settings/builder.json: -------------------------------------------------------------------------------- 1 | { 2 | "excludeScenes": [], 3 | "orientation": { 4 | "landscapeLeft": true, 5 | "landscapeRight": true, 6 | "portrait": false, 7 | "upsideDown": false 8 | }, 9 | "packageName": "org.cocos2d.helloworld", 10 | "startScene": "2d2f792f-a40c-49bb-a189-ed176a246e49", 11 | "title": "hello_world", 12 | "webOrientation": "auto" 13 | } -------------------------------------------------------------------------------- /settings/builder.panel.json: -------------------------------------------------------------------------------- 1 | { 2 | "excludeScenes": [], 3 | "packageName": "org.cocos2d.helloworld", 4 | "platform": "web-mobile", 5 | "startScene": "2d2f792f-a40c-49bb-a189-ed176a246e49", 6 | "title": "HelloWorld" 7 | } -------------------------------------------------------------------------------- /settings/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "collision-matrix": [ 3 | [ 4 | false, 5 | false, 6 | false, 7 | false, 8 | false 9 | ], 10 | [ 11 | false, 12 | false, 13 | true, 14 | true, 15 | true 16 | ], 17 | [ 18 | false, 19 | true, 20 | false, 21 | false, 22 | false 23 | ], 24 | [ 25 | false, 26 | true, 27 | false, 28 | false, 29 | false 30 | ], 31 | [ 32 | false, 33 | true, 34 | false, 35 | false, 36 | false 37 | ] 38 | ], 39 | "design-resolution-height": 640, 40 | "design-resolution-width": 960, 41 | "excluded-modules": [], 42 | "fit-height": true, 43 | "fit-width": false, 44 | "group-list": [ 45 | "default", 46 | "head", 47 | "body", 48 | "food", 49 | "body out" 50 | ], 51 | "simulator-orientation": false, 52 | "simulator-resolution": { 53 | "height": 640, 54 | "width": 960 55 | }, 56 | "start-scene": "current", 57 | "use-customize-simulator": false, 58 | "use-project-simulator-setting": false 59 | } -------------------------------------------------------------------------------- /snake.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dixonzhang/ccc_snake/0feb9d91a721703592ba8972c408eb6c1f60f4c1/snake.png -------------------------------------------------------------------------------- /template-banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dixonzhang/ccc_snake/0feb9d91a721703592ba8972c408eb6c1f60f4c1/template-banner.png -------------------------------------------------------------------------------- /template.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "TEMPLATES.helloworld.name", 3 | "desc": "TEMPLATES.helloworld.desc", 4 | "banner": "template-banner.png" 5 | } --------------------------------------------------------------------------------