Forums

OverviewV-Play 1 SupportPath movement with dynamic input › Reply To: Path movement with dynamic input

OverviewV-Play 1 SupportPath movement with dynamic input › Reply To: Path movement with dynamic input
#6580

PanflamCutie

Dear Alex,

I tried to revite my code, so that it works with MovementAnimation (as you requested).

I’ve got two functions, which are responsible for calculating the next direction to take, but I don’t know where to invoke them (first).

Furthermore, is there a way to check if the entity has reached the “next field” without calculating the “goal field” to which the values of x and y of the entity must be compared to?

    function calculateTheGoal() {
        leftWay = true
        rightWay = true
        upWay = true
        downWay = true

        // checking for border
        if(column === 0) {
            leftWay = false
        }
        if (column === 12) {
            rightWay = false
        }
        if (row === 0) {
            upWay = false
        }
        if (row === 8) {
            downWay = false
        }
    }

    property bool done: false
    property int xPoint: 0
    property int yPoint: 0
//    property point nextWay
    function move() {
        calculateTheGoal()
        while (done === false) {
            randomNumber = utils.generateRandomValueBetween(1, 4)
            console.debug(randomNumber)
            switch (randomNumber) {
                case 1:
                    if (upWay) {
                        //nextWay = Qt.point(0, -1)
                        xPoint = 0
                        yPoint = -1
                        done = true
                    }
                    break;
                case 2:
                    if (rightWay) {
//                        nextWay = Qt.point(1, 0)
                        xPoint = 1
                        yPoint = 0
                        done = true;
                    }
                    break;
                case 3:
                    if (downWay) {
//                        nextWay = Qt.point(0, 1)
                        xPoint = 0
                        yPoint = 1
                        done = true;
                    }
                    break;
                case 4:
                    if (leftWay) {
//                        nextWay = Qt.point(-1, 0)
                        xPoint = -1
                        yPoint = 0
                        done = true;
                    }
                    break;
            }
        }
        movement.running = true
        done = false
    }

 

MovementAnimation {
//        1. calculate the goal
//        2. calculate the movement of one field in the grid towards the goal
//        3. pass this values to the MovementAnimation
//        4. start the MovementAnimation
//        5. when the animation finished, repeat these steps
id: movement
        target: parent
        property: "pos"

        velocity: Qt.point(xPoint, yPoint)
        running: true


        onRunningChanged: {

            move()

        }

    }

Thanks in advance and best regards,

PanflamCutie

Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support