FastBall Game



  • hello everyone,
    i am trying to implement the fastball game of iOS by Qt...
    i have created Sprite for the active game componenets..

    @Image {
    id: sprite
    source: image

    property int type : 0
    property string image : ""
    property int damage : 1
    property real velocity : 0
    
    property real topOffset : 0
    property real leftOffset : 0
    property real rightOffset : 0
    property real bottomOffset : 0
    

    }@

    @Sprite
    {
    id: ball
    property int life: 1
    property bool imune: false
    property int imunePhase: 0
    topOffset: 1
    rightOffset: 1
    bottomOffset: 1
    leftOffset: 1

      //objectName: "ball"
    

    Image {
    x: -8
    y: 18
    smooth: true

    source: "images/ball8.png"
    
     RotationAnimation on rotation {
        id:ballRotation
        from: 0
        to: 360
        direction: RotationAnimation.Clockwise
        duration: 1200
        loops: Animation.Infinite
    }
    

    }
    @

    Have the codes for the obstacles in a similar manner in Sprites with type = 1
    and the code for the @Star@ with type= 2 in Sprites

    How to implement the collision when Ball collides with the obstacles or the Ball collides with the stars to gain points...



  • One possibility, is every tick, call a JavaScript function which iterates over the balls, stars and obstacles to find intersections, and then cause the appropriate change (eg, remove stars, change direction of balls, etc). Not sure whether that would be too performant, however.



  • i tried this
    actually referredto code of Qtflying bus
    @function checkCollisions(){
    var imune = ball.imune

    var obj,collides,damage = 0;
    
    for(var i = 0; i < sprites.length; i++)
    {
        obj = sprites[i];
    
        //if(obj == null || obj.type == ENEMY_TYPE && imune)
          //  continue;
    
         collides = (ball.y + ball.height - ball.bottomOffset >= obj.y + obj.topOffset
                    && ball.y + ball.topOffset <= obj.y + obj.height - obj.bottomOffset
                    && ball.x + ball.width - ball.rightOffset >= obj.x + obj.leftOffset
                    && ball.x + ball.leftOffset <= obj.x + obj.width - obj.rightOffset);
    
        if(collides){
            if(obj.type == ENEMY_TYPE){
                imune = true;
                damage = obj.damage;
            }else if(obj.type == STAR_TYPE){
    
    
            }
    
        }
    
    }
    
    if(damage > 0){
        ball.imune = true;
        ball.life = Math.max(ball.life - 1, 0);
    
        if (ball.life == 0) {
            saveScoreToDisk();
            menu.setState("gameover", false);
            start.state = "";
        }
    }
    

    }@

    and called this function using a timer

    @Timer{

    id:timer
    repeat: true
    interval: 30
    running: false
    onTriggered: Engine.checkCollisions();
    

    }@

    but this isnt working :(


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.