00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 import QtQuick 1.0
00041 import com.nokia.symbian 1.0
00042 import QtMobility.sensors 1.1
00043
00044 Window {
00045 id:win
00046 width: 360
00047 height: 640
00048
00049
00050 property int score: 0
00051
00052
00053 property int count: 0
00054
00055
00056 property string lightReading: ""
00057
00058
00059 property string rotationReading: ""
00060
00061
00062 property string proximityReading: "far"
00063
00064
00065 property alias xposition: smiley.x
00066 property alias yposition: smiley.y
00067
00068
00069 function countPoints()
00070 {
00071
00072 bomb1.countPoints();
00073 bomb2.countPoints();
00074 bomb3.countPoints();
00075 bomb4.countPoints();
00076 bomb5.countPoints();
00077 bomb6.countPoints();
00078
00079 heart1.countPoints();
00080 heart2.countPoints();
00081 heart3.countPoints();
00082 heart4.countPoints();
00083 heart5.countPoints();
00084 heart6.countPoints();
00085 }
00086
00087
00088 Accelerometer{
00089 id: myAcceleroSensor
00090 onReadingChanged: {
00091 count++;
00092
00093
00094 if( (count)%8 == 0 ){
00095 smiley.x = (reading.x)*100;
00096 smiley.y = (reading.y)*100;
00097
00098
00099 if( smiley.y > 310){
00100 smiley.y = 310;
00101 }
00102 if( smiley.x < 0){
00103 smiley.x = 0;
00104 }
00105 if( smiley.x > 330){
00106 smiley.x = 330;
00107 }
00108 countPoints();
00109 }
00110 }
00111 }
00112
00113
00114 ProximitySensor{
00115 id: myProxiSensor
00116 onReadingChanged: {
00117 if( reading.close == true){
00118 proximityReading = "close";
00119 }
00120 else{
00121 proximityReading = "far";
00122 }
00123 }
00124 }
00125
00126
00127 function lightCondition()
00128 {
00129 if( myLightSensor.reading.lightLevel == AmbientLightReading.Bright){
00130 lightReading = "Bright"
00131 }
00132 else if( myLightSensor.reading.lightLevel == AmbientLightReading.Dark){
00133 lightReading = "Dark"
00134 }
00135 else if( myLightSensor.reading.lightLevel == AmbientLightReading.Light){
00136 lightReading = "Light"
00137 }
00138 else if( myLightSensor.reading.lightLevel == AmbientLightReading.Sunny){
00139 lightReading = "Sunny"
00140 }
00141 else if( myLightSensor.reading.lightLevel == AmbientLightReading.Twilight){
00142 lightReading = "Twilight"
00143 }
00144 else{
00145 lightReading = "Undefined"
00146 }
00147 }
00148
00149
00150 AmbientLightSensor{
00151 id: myLightSensor
00152 onReadingChanged: {
00153 lightCondition();
00154 }
00155
00156 }
00157
00158
00159 RotationSensor{
00160 id: myRotationSensor
00161 property int x: 0
00162 property int y: 0
00163 property int z: 0
00164 onReadingChanged: {
00165 x = reading.x
00166 y = reading.y
00167 z = reading.z
00168 rotationReading = "x: " + x + " y: " + y + " z: " + z
00169 }
00170
00171 }
00172
00173
00174 Image{
00175 id:exitButton
00176 anchors.right: parent.right
00177 anchors.top: parent.top
00178 source: "exit.png"
00179 MouseArea {
00180 anchors.fill: parent
00181 onPressed: { Qt.quit() }
00182 }
00183 }
00184
00185
00186 Bomb{ id:bomb1; visible: false }
00187 Bomb{ id:bomb2; visible: false }
00188 Bomb{ id:bomb3; visible: false }
00189 Bomb{ id:bomb4; visible: false }
00190 Bomb{ id:bomb5; visible: false }
00191 Bomb{ id:bomb6; visible: false }
00192
00193 Heart{ id:heart1; visible: false }
00194 Heart{ id:heart2; visible: false }
00195 Heart{ id:heart3; visible: false }
00196 Heart{ id:heart4; visible: false }
00197 Heart{ id:heart5; visible: false }
00198 Heart{ id:heart6; visible: false }
00199
00200
00201
00202 Image {id: smiley; source: "smile.png"; x: 5; y: 310; width: 30; height: 30 }
00203
00204
00205 function randomArrangement()
00206 {
00207 bomb1.x = 5; bomb1.y = 5; bomb1.visible = true;
00208 heart1.x = 75; heart1.y = 5; heart1.visible = true
00209 heart2.x = 150; heart2.y = 5; heart2.visible = true
00210
00211 heart3.x = 225; heart3.y = 5; heart3.visible = true
00212 bomb2.x = 5; bomb2.y = 75; bomb2.visible = true
00213 bomb3.x = 75; bomb3.y = 75; bomb3.visible = true
00214
00215 heart4.x = 150; heart4.y = 75; heart4.visible = true
00216 bomb4.x = 225; bomb4.y = 75; bomb4.visible = true
00217
00218 bomb5.x = 5; bomb5.y = 150; bomb5.visible = true
00219
00220 heart5.x = 75; heart5.y = 150; heart5.visible = true
00221 heart6.x = 150; heart6.y = 150; heart6.visible = true
00222
00223 bomb6.x = 225; bomb6.y = 150; bomb6.visible = true
00224 }
00225
00226
00227 Button{
00228 id:startButton
00229 text:"Start Game"
00230 width: 300
00231 height: 50
00232 anchors.centerIn: parent
00233
00234 onClicked:{
00235
00236
00237 myAcceleroSensor.connectToBackend();
00238 myProxiSensor.connectToBackend();
00239 myLightSensor.connectToBackend();
00240 myRotationSensor.connectToBackend();
00241
00242 myLightSensor.active = true;
00243 myRotationSensor.active = true;
00244 myProxiSensor.active = true;
00245 myAcceleroSensor.active = true;
00246
00247 startButton.visible = false;
00248 resetButton.visible = true;
00249 lightCondition();
00250 randomArrangement();
00251 }
00252 }
00253
00254
00255 Button{
00256 id:resetButton
00257 text:"Reset"
00258 width: 150
00259 height: 50
00260 anchors.left: scorecard.right
00261 anchors.bottom:parent.bottom
00262 anchors.bottomMargin: 10
00263 visible: false;
00264 onClicked:{
00265 score = 0;
00266 randomArrangement();
00267 }
00268 }
00269
00270
00271 Text{
00272 id: helpText
00273 anchors.bottom: scorecard.bottom
00274 anchors.bottomMargin: 15
00275 anchors.left: parent.left
00276 anchors.leftMargin: 15
00277 width: 300
00278 height: 250
00279 wrapMode: Text.WrapAnywhere
00280 color: "white"
00281 font.italic: true
00282 font.pointSize: 6
00283 text: {
00284 "Note: Supported in portrait mode only." + "\n" + "\n" +
00285 "Smiley moves, with the help of accelerometer reading." + "\n" +
00286 "You collect 100 points for touching heart." + "\n" +
00287 "You loose 100 points for touching bomb." + "\n" + "\n" +
00288 "Proximity sensor reading :- " + proximityReading + "\n" +
00289 "Light sensor reading :- " + lightReading + "\n" +
00290 "Rotation sensor reading:- " + rotationReading
00291 }
00292 }
00293
00294
00295 Text{
00296 id:scorecard
00297 text: "Score : " + score
00298 color: "white"
00299 width: 200
00300 height: 50
00301 anchors.bottom: parent.bottom
00302 anchors.bottomMargin: 10
00303 anchors.left: parent.left
00304 anchors.leftMargin: 15
00305 }
00306
00307 }