(function() {"use strict";var __module = CC_EDITOR ? module : {exports:{}};var __filename = 'preview-scripts/assets/main.js';var __require = CC_EDITOR ? function (request) {return cc.require(request, require);} : function (request) {return cc.require(request, __filename);};function __define (exports, require, module) {"use strict";
cc._RF.push(module, '20d35cf0opDEIlkAnYBDiMX', 'main', __filename);
// main.js

'use strict';

var _cc$Class;

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

cc.Class((_cc$Class = {
    extends: cc.Component,

    properties: {
        isKeyDown: false,
        camera: cc.Camera,
        direction: 0,
        block: cc.Sprite
    },

    onLoad: function onLoad() {
        cc.director.getPhysicsManager().enabled = true;
        cc.director.getPhysicsManager().debugDrawFlags = cc.PhysicsManager.DrawBits.e_aabbBit | cc.PhysicsManager.DrawBits.e_pairBit | cc.PhysicsManager.DrawBits.e_centerOfMassBit | cc.PhysicsManager.DrawBits.e_jointBit | cc.PhysicsManager.DrawBits.e_shapeBit;
    },
    onKeyDown: function onKeyDown(event) {
        console.log('keydown');
        switch (event.keyCode) {
            case cc.macro.KEY.up:
                this.isKeyDown = true;
                this.direction = 1;
                break;
            case cc.macro.KEY.down:
                this.isKeyDown = true;
                this.direction = -1;
                break;
            case cc.macro.KEY.left:
                this.isKeyDown = true;
                this.direction = 2;
                break;
            case cc.macro.KEY.right:
                this.isKeyDown = true;
                this.direction = -2;
                break;
            default:
                this.isKeyDown = false;
                break;
        }
        this.moveCamera();
    },
    moveCamera: function moveCamera() {
        if (this.isKeyDown) {
            var p = void 0;
            switch (this.direction) {
                case 1:
                    p = cc.v2(0, 100);
                    break;
                case -1:
                    p = cc.v2(0, -100);
                    break;
                case 2:
                    p = cc.v2(-100, 0);
                    break;
                case -2:
                    p = cc.v2(100, 0);
                    break;
            }
            this.camera.getComponent(cc.RigidBody).linearVelocity = p;
        } else {
            this.camera.getComponent(cc.RigidBody).linearVelocity = cc.v2(0, 0);
        }
    }
}, _defineProperty(_cc$Class, 'onLoad', function onLoad() {
    cc.director.getPhysicsManager().enabled = true;
    cc.director.getPhysicsManager().debugDrawFlags = cc.PhysicsManager.DrawBits.e_aabbBit | cc.PhysicsManager.DrawBits.e_pairBit | cc.PhysicsManager.DrawBits.e_centerOfMassBit | cc.PhysicsManager.DrawBits.e_jointBit | cc.PhysicsManager.DrawBits.e_shapeBit;
}), _defineProperty(_cc$Class, 'onKeyUp', function onKeyUp() {
    this.isKeyDown = false;
}), _defineProperty(_cc$Class, 'start', function start() {
    cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, this.onKeyDown, this);
    cc.systemEvent.on(cc.SystemEvent.EventType.KEY_UP, this.onKeyUp, this);
}), _defineProperty(_cc$Class, 'updateRigidBody', function updateRigidBody() {
    var component = this.block.node.getComponent(cc.PhysicsBoxCollider);
    component.offset.y = -this.camera.node.y;
    component.apply();
}), _defineProperty(_cc$Class, 'update', function update(dt) {
    // this.updateRigidBody();
    console.log('块的坐标: [%s,%s], 摄像机:[%s,%s]', this.block.node.x, this.block.node.y, this.camera.node.x, this.camera.node.y);
}), _cc$Class));

cc._RF.pop();
        }
        if (CC_EDITOR) {
            __define(__module.exports, __require, __module);
        }
        else {
            cc.registerModuleFunc(__filename, function () {
                __define(__module.exports, __require, __module);
            });
        }
        })();
        //# sourceMappingURL=main.js.map
        