~cmiller/+junk/kenvandine-maze-plus-level-compiler

« back to all changes in this revision

Viewing changes to Hole.qml

  • Committer: Ken VanDine
  • Date: 2014-10-22 21:53:14 UTC
  • Revision ID: ken.vandine@canonical.com-20141022215314-op96fhzc9epfs2qh
init

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import QtQuick 2.2
 
2
import Bacon2D 1.0
 
3
 
 
4
Entity {
 
5
    id: hole
 
6
    bodyType: Entity.Static
 
7
 
 
8
    fixtures: Circle {
 
9
        id: circle
 
10
        sensor: true
 
11
        radius: 15
 
12
        x: radius
 
13
        y: radius
 
14
 
 
15
        onContactChanged: {
 
16
            if (other.parent != ball || ball.state == "gone")
 
17
                return;
 
18
 
 
19
            var distX = Math.abs(ball.x - hole.x - circle.x)
 
20
            var distY = Math.abs(ball.y - hole.y - circle.y)
 
21
            var dist = Math.sqrt(distX * distX + distY * distY)
 
22
 
 
23
            if (Math.abs(dist < circle.radius)) {
 
24
                ball.disappearTo(ball.parent.mapFromItem(hole,
 
25
                                                         circle.x,
 
26
                                                         circle.y))
 
27
            }
 
28
        }
 
29
 
 
30
        Image {
 
31
            anchors.centerIn: parent
 
32
            source: "hole.png"
 
33
        }
 
34
    }
 
35
}