Commit 3086c8db authored by Friends233's avatar Friends233

拖拽

parent 7cd7a7fe
This diff is collapsed.
export const CUSTOM_EVENT = {
/** 爪子动画结束的回调 */
CLIP_ANI_END: 'CLIP_ANI_END',
/** 爪子碰撞 */
CLIP_COLLISION: 'CLIP_COLLISION',
/** 游戏结束 */
GAME_OVER: 'GAME_OVER',
/** 下一关 */
......@@ -16,77 +12,10 @@ export const CUSTOM_EVENT = {
/** 销毁游戏场景 */
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 = {
/** 爪子能伸出去的长度 */
maxLong: 644,
/** 摇晃速度 */
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
]
]
/** 块矩阵最大行 */
maxRow: 10,
/** 块矩阵最大列 */
maxCol: 10
}
\ No newline at end of file
......@@ -9,9 +9,16 @@ const { ccclass, property } = cc._decorator;
@ccclass
export default class GameScene extends cc.Component {
/** 默认底色块 */
@property(cc.Prefab)
defaultBlock: cc.Prefab = null
/** 游戏配置 */
gameConfig = { ...Config }
/** 方块矩阵 */
blockMatrix: cc.Node = null
protected onLoad(): void {
......@@ -23,9 +30,23 @@ export default class GameScene extends cc.Component {
}
start() {
this.blockMatrix = cc.find('blockMatrix', this.node)
this.setDefaultBlock()
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() {
// cc.game.on(cc.game.EVENT_HIDE, () => {
......@@ -124,12 +145,12 @@ export default class GameScene extends cc.Component {
/** 下一关 */
nextLevel() {
}
/** 刷新舞台道具 */
refreshStageProps() {
}
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;
@ccclass
export default class BlockItem extends cc.Component {
export default class NewClass extends cc.Component {
isMove = false
viewWidth = 0
viewHeight = 0
/** 方块矩阵外层容器 */
blockMatrix: cc.Node = null
start() {
this.viewHeight = cc.view.getVisibleSize().height
this.viewWidth = cc.view.getVisibleSize().width
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 k = node.convertToWorldSpaceAR(node.getPosition())
console.log('start', k.x, k.y)
......@@ -31,16 +42,19 @@ export default class BlockItem extends cc.Component {
addNodeEvent() {
this.node.on(cc.Node.EventType.TOUCH_START, () => {
console.log('TOUCH_START')
this.isMove = true
this.node.scale = 1.57
}, this)
this.node.on(cc.Node.EventType.TOUCH_END, () => {
console.log('TOUCH_END')
this.setBlockMatrixAll(this.node.getPosition())
}, this)
this.node.on(cc.Node.EventType.TOUCH_MOVE, (e: cc.Event.EventTouch) => {
const allBlock = this.node.children
const matrix = cc.find('blockMatrix', this.node.parent)
const matrix = this.blockMatrix
const node = allBlock[0]
const blockPos = node.convertToWorldSpaceAR(node.getPosition())
......@@ -50,7 +64,7 @@ export default class BlockItem extends cc.Component {
if (this.isMove) {
const pos: cc.Vec2 = e.getPreviousLocation()
const viewW = this.viewWidth, viewH = this.viewHeight
this.node.setPosition(pos.x - (viewW / 2), pos.y - (812 - (1624 - viewH) / 2))
}
}, this)
......
{
"ver": "1.1.0",
"uuid": "d3a58978-56d5-45f1-b300-f7e269a2a93a",
"uuid": "005cb974-4dad-45ce-acb8-fb0f1da60d28",
"importer": "typescript",
"isPlugin": false,
"loadPluginInWeb": true,
......
......@@ -13,7 +13,7 @@
},
{
"__type__": "cc.Node",
"_name": "procItem",
"_name": "block",
"_objFlags": 0,
"_parent": null,
"_children": [],
......@@ -21,23 +21,26 @@
"_components": [
{
"__id__": 2
},
{
"__id__": 3
}
],
"_prefab": {
"__id__": 3
"__id__": 4
},
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 229,
"g": 123,
"b": 123,
"r": 143,
"g": 186,
"b": 186,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 39,
"height": 41
"width": 58,
"height": 58
},
"_anchorPoint": {
"__type__": "cc.Vec2",
......@@ -48,8 +51,8 @@
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
20.5,
0,
-270,
270,
0,
0,
0,
......@@ -105,6 +108,16 @@
"_atlas": null,
"_id": ""
},
{
"__type__": "b1207cbMWhNVLKTFVfAq/t2",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
},
"_enabled": true,
"_id": ""
},
{
"__type__": "cc.PrefabInfo",
"root": {
......
{
"ver": "1.3.2",
"uuid": "579f375a-1df7-440f-aded-3c14d59e021d",
"uuid": "00d2b9dc-0261-4f19-854e-b24e4a40a5a6",
"importer": "prefab",
"optimizationPolicy": "AUTO",
"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