
cc.Class({
    extends: cc.Component,
    properties: {
    },
    
    flirtingAction: function() {
        // 1.把手放上去 3.过不定时时间，女生showMessage ‘老师，这里有人骚扰’
        return cc.moveTo(0.1, cc.p(-30, 70))
        // 2.加分
        // let intervalId = setInterval(()=> {
        //     // 加上跟老师的判断

        //     if(isFlirting && !teachers.isSwivel) {
        //         this.config.score = this.config.score + this.timer++
        //     } else {
        //         clearInterval(intervalId)
        //     }
        // }, 1000)
        // 3
        // femaleStudent.showMessage(messageList[0,1,2])
    },

    endFlirtingAction: function() {
        return cc.moveTo(0.1, cc.p(0, 0))
    },

    setTouchScreenControl: function() {
        var self = this
        // 添加屏幕点击事件监听
        // 当触碰到屏幕时，设置抚摸开关打开，并执行抚摸方法
        self.node.on(cc.Node.EventType.TOUCH_START, (event) => {
        // self.node.on(cc.Node.EventType.MOUSE_DOWN, (event) => {
            self.game.heartMusic.play()
            self.isFlirting = true
            self.node.runAction(self.flirtingAction)
        })

        // 停止触摸屏幕时，设置抚摸开关关闭，停止抚摸
        self.node.on(cc.Node.EventType.TOUCH_END, (event) => {
        // self.node.on(cc.Node.EventType.MOUSE_UP, (event) => {
            self.game.heartMusic.pause()
            self.isFlirting = false
            self.node.runAction(self.endFlirtingAction)
        })
    
        self.node.on(cc.Node.EventType.TOUCH_CANCEL, (event) => {
            // self.node.on(cc.Node.EventType.MOUSE_UP, (event) => {
            self.isFlirting = false
            self.node.runAction(self.endFlirtingAction)
        })
    },

    onLoad () {
        // 初始化抚摸的动作
        this.flirtingAction = this.flirtingAction()
        // 初始化停止抚摸的动作
        this.endFlirtingAction = this.endFlirtingAction()
        // this.node.runAction(this.flirtingAction)
        // 抚摸的开关
        this.isFlirting = false
        // 抚摸停留时常
        this.timer = 0
        // 初始化屏幕点击监听
        this.setTouchScreenControl()

    },

    update (dt) {
        if (this.isFlirting) {
            this.game.gainScore()
        }
    },
});
