Commit 3086c8db authored by Friends233's avatar Friends233

拖拽

parent 7cd7a7fe
This diff is collapsed.
export const CUSTOM_EVENT = { export const CUSTOM_EVENT = {
/** 爪子动画结束的回调 */
CLIP_ANI_END: 'CLIP_ANI_END',
/** 爪子碰撞 */
CLIP_COLLISION: 'CLIP_COLLISION',
/** 游戏结束 */ /** 游戏结束 */
GAME_OVER: 'GAME_OVER', GAME_OVER: 'GAME_OVER',
/** 下一关 */ /** 下一关 */
...@@ -16,77 +12,10 @@ export const CUSTOM_EVENT = { ...@@ -16,77 +12,10 @@ export const CUSTOM_EVENT = {
/** 销毁游戏场景 */ /** 销毁游戏场景 */
GAME_DESTROY: 'GAME_DESTROY' GAME_DESTROY: 'GAME_DESTROY'
} }
/** 游戏进度颜色 */
export const GameColors = [
['#EC5F33', '#E52800', '#CA1D00'],
['#FF9400', '#FF6C00', '#EC5F33', '#E52800', '#CA1D00'],
['#FFD34A', '#FFC300', '#FFB637', '#FF9400', '#FF6C00', '#EC5F33', '#E52800', '#CA1D00']
]
export const Config = { export const Config = {
/** 爪子能伸出去的长度 */ /** 块矩阵最大行 */
maxLong: 644, maxRow: 10,
/** 块矩阵最大列 */
/** 摇晃速度 */ maxCol: 10
rotationSpeed: 1,
/** 爪子伸出去的速度 */
playSpeed: 350,
/** 普通道具移动速度 */
normalPropSpeed: 250,
/** 高级道具移动速度 */
bestPropSpeed: 500,
/** 每轮生成加分道具数量 */
bestPropsNum: 3,
/** 普通道具每种最多生成数量 */
propsNum: 2,
/** 每关的游戏时间 */
countDowns: [30, 30, 30],
/** 关卡信息 */
LevelInfo: [
{
level: 1,
/** 目标数量 */
num: 10,
/** 倒计时 */
cds: 30,
},
{
level: 1,
/** 目标数量 */
num: 5,
/** 倒计时 */
cds: 30,
},
{
level: 1,
/** 目标数量 */
num: 8,
/** 倒计时 */
cds: 30,
}
],
/** 进度默认颜色 */
defaultColor: "#FF6C00",
/** 道具分布图 4*3 */
propsMap: [
[
1, 0, 0, 1,
1, 1, 1, 0,
1, 1, 1, 1
],
[
1, 0, 0, 1,
1, 1, 1, 1,
1, 0, 1, 1
]
]
} }
\ No newline at end of file
...@@ -9,9 +9,16 @@ const { ccclass, property } = cc._decorator; ...@@ -9,9 +9,16 @@ const { ccclass, property } = cc._decorator;
@ccclass @ccclass
export default class GameScene extends cc.Component { export default class GameScene extends cc.Component {
/** 默认底色块 */
@property(cc.Prefab)
defaultBlock: cc.Prefab = null
/** 游戏配置 */ /** 游戏配置 */
gameConfig = { ...Config } gameConfig = { ...Config }
/** 方块矩阵 */
blockMatrix: cc.Node = null
protected onLoad(): void { protected onLoad(): void {
...@@ -23,9 +30,23 @@ export default class GameScene extends cc.Component { ...@@ -23,9 +30,23 @@ export default class GameScene extends cc.Component {
} }
start() { start() {
this.blockMatrix = cc.find('blockMatrix', this.node)
this.setDefaultBlock()
this.addNodeEvent() this.addNodeEvent()
} }
/** 设置默认方块底色块 */
setDefaultBlock() {
const { maxRow, maxCol } = this.gameConfig
const parent = this.blockMatrix
for (let i = 0; i < maxRow; i++) {
for (let j = 0; j < maxCol; j++) {
const block = cc.instantiate(this.defaultBlock)
block.setParent(parent)
}
}
}
/** 添加节点的事件 */ /** 添加节点的事件 */
addNodeEvent() { addNodeEvent() {
// cc.game.on(cc.game.EVENT_HIDE, () => { // cc.game.on(cc.game.EVENT_HIDE, () => {
...@@ -124,12 +145,12 @@ export default class GameScene extends cc.Component { ...@@ -124,12 +145,12 @@ export default class GameScene extends cc.Component {
/** 下一关 */ /** 下一关 */
nextLevel() { nextLevel() {
} }
/** 刷新舞台道具 */ /** 刷新舞台道具 */
refreshStageProps() { refreshStageProps() {
} }
update(dt: number): void { update(dt: number): void {
......
// Learn TypeScript:
// - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
// - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html
const { ccclass, property } = cc._decorator; const { ccclass, property } = cc._decorator;
@ccclass @ccclass
export default class BlockItem extends cc.Component { export default class NewClass extends cc.Component {
isMove = false isMove = false
viewWidth = 0 viewWidth = 0
viewHeight = 0 viewHeight = 0
/** 方块矩阵外层容器 */
blockMatrix: cc.Node = null
start() { start() {
this.viewHeight = cc.view.getVisibleSize().height this.viewHeight = cc.view.getVisibleSize().height
this.viewWidth = cc.view.getVisibleSize().width this.viewWidth = cc.view.getVisibleSize().width
this.addNodeEvent() this.addNodeEvent()
const matrix = cc.find('blockMatrix', this.node.parent) const matrix = this.blockMatrix = cc.find('blockMatrix', this.node.parent)
const node = matrix.children[0] const node = matrix.children[0]
const k = node.convertToWorldSpaceAR(node.getPosition()) const k = node.convertToWorldSpaceAR(node.getPosition())
console.log('start', k.x, k.y) console.log('start', k.x, k.y)
...@@ -31,16 +42,19 @@ export default class BlockItem extends cc.Component { ...@@ -31,16 +42,19 @@ export default class BlockItem extends cc.Component {
addNodeEvent() { addNodeEvent() {
this.node.on(cc.Node.EventType.TOUCH_START, () => { this.node.on(cc.Node.EventType.TOUCH_START, () => {
console.log('TOUCH_START')
this.isMove = true this.isMove = true
this.node.scale = 1.57
}, this) }, this)
this.node.on(cc.Node.EventType.TOUCH_END, () => { this.node.on(cc.Node.EventType.TOUCH_END, () => {
console.log('TOUCH_END')
this.setBlockMatrixAll(this.node.getPosition()) this.setBlockMatrixAll(this.node.getPosition())
}, this) }, this)
this.node.on(cc.Node.EventType.TOUCH_MOVE, (e: cc.Event.EventTouch) => { this.node.on(cc.Node.EventType.TOUCH_MOVE, (e: cc.Event.EventTouch) => {
const allBlock = this.node.children const allBlock = this.node.children
const matrix = cc.find('blockMatrix', this.node.parent) const matrix = this.blockMatrix
const node = allBlock[0] const node = allBlock[0]
const blockPos = node.convertToWorldSpaceAR(node.getPosition()) const blockPos = node.convertToWorldSpaceAR(node.getPosition())
...@@ -50,7 +64,7 @@ export default class BlockItem extends cc.Component { ...@@ -50,7 +64,7 @@ export default class BlockItem extends cc.Component {
if (this.isMove) { if (this.isMove) {
const pos: cc.Vec2 = e.getPreviousLocation() const pos: cc.Vec2 = e.getPreviousLocation()
const viewW = this.viewWidth, viewH = this.viewHeight const viewW = this.viewWidth, viewH = this.viewHeight
this.node.setPosition(pos.x - (viewW / 2), pos.y - (812 - (1624 - viewH) / 2)) this.node.setPosition(pos.x - (viewW / 2), pos.y - (812 - (1624 - viewH) / 2))
} }
}, this) }, this)
......
{ {
"ver": "1.1.0", "ver": "1.1.0",
"uuid": "d3a58978-56d5-45f1-b300-f7e269a2a93a", "uuid": "005cb974-4dad-45ce-acb8-fb0f1da60d28",
"importer": "typescript", "importer": "typescript",
"isPlugin": false, "isPlugin": false,
"loadPluginInWeb": true, "loadPluginInWeb": true,
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
}, },
{ {
"__type__": "cc.Node", "__type__": "cc.Node",
"_name": "procItem", "_name": "block",
"_objFlags": 0, "_objFlags": 0,
"_parent": null, "_parent": null,
"_children": [], "_children": [],
...@@ -21,23 +21,26 @@ ...@@ -21,23 +21,26 @@
"_components": [ "_components": [
{ {
"__id__": 2 "__id__": 2
},
{
"__id__": 3
} }
], ],
"_prefab": { "_prefab": {
"__id__": 3 "__id__": 4
}, },
"_opacity": 255, "_opacity": 255,
"_color": { "_color": {
"__type__": "cc.Color", "__type__": "cc.Color",
"r": 229, "r": 143,
"g": 123, "g": 186,
"b": 123, "b": 186,
"a": 255 "a": 255
}, },
"_contentSize": { "_contentSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
"width": 39, "width": 58,
"height": 41 "height": 58
}, },
"_anchorPoint": { "_anchorPoint": {
"__type__": "cc.Vec2", "__type__": "cc.Vec2",
...@@ -48,8 +51,8 @@ ...@@ -48,8 +51,8 @@
"__type__": "TypedArray", "__type__": "TypedArray",
"ctor": "Float64Array", "ctor": "Float64Array",
"array": [ "array": [
20.5, -270,
0, 270,
0, 0,
0, 0,
0, 0,
...@@ -105,6 +108,16 @@ ...@@ -105,6 +108,16 @@
"_atlas": null, "_atlas": null,
"_id": "" "_id": ""
}, },
{
"__type__": "b1207cbMWhNVLKTFVfAq/t2",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
},
"_enabled": true,
"_id": ""
},
{ {
"__type__": "cc.PrefabInfo", "__type__": "cc.PrefabInfo",
"root": { "root": {
......
{ {
"ver": "1.3.2", "ver": "1.3.2",
"uuid": "579f375a-1df7-440f-aded-3c14d59e021d", "uuid": "00d2b9dc-0261-4f19-854e-b24e4a40a5a6",
"importer": "prefab", "importer": "prefab",
"optimizationPolicy": "AUTO", "optimizationPolicy": "AUTO",
"asyncLoadAssets": false, "asyncLoadAssets": false,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment