Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. FastBall Game
Forum Updated to NodeBB v4.3 + New Features

FastBall Game

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 1.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mikealfa
    wrote on last edited by
    #1

    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...

    1 Reply Last reply
    0
    • C Offline
      C Offline
      chriadam
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mikealfa
        wrote on last edited by
        #3

        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 :(

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved