ãã®æçš¿ã¯ãã³ã³ãã¹ãã
Smart Posts for Smart Posts ãã«åå ããŠããŸã
çŸæç¹ã§ã¯ãå€ãã®ããã°ã©ããŒãã¢ããªã±ãŒã·ã§ã³ãã²ãŒã ã®éçºãQt Quickãã©ãã¯ã«ç§»è¡ããããšãæ¥ãããšã¯ãããŸãããããã¯ãããžãŒèªäœãåãå·»ãã€ã³ãã©ã¹ãã©ã¯ãã£ã¯æ¥ã
æé·ããçºå±ããã ãã§ãã
ãã®ããã2次å
空éã§ã®ç©çåŠã®ã·ãã¥ã¬ãŒã·ã§ã³ãããã«ãªããŸããã ããããQMLãã©ã°ã€ã³ã®ç»å Žåã åºæã®Qt Quickã«ãããBox2Dç©çãšã³ãžã³ãã¢ããªã±ãŒã·ã§ã³ã«ç°¡åã«çµ±åã§ããŸãã ä»æ¥ã¯ããã«ã€ããŠã話ããŸãã ããæ£ç¢ºã«ã¯ãåçŽãªã¢ã«ã«ãã€ãã®å®è£
ãåçŽãªã²ãŒã ãã©ãã ãçŽ æ©ãäœæã§ããããç©çãšã³ãžã³ãã»ãšãã©ãªãã¿ã®ãªãçšèªã§äœæ¥ããåã«åæããŠã¿ãŸãããã
QMLãšBox2dããã€ã³ããã
ãŸãããã©ã°ã€ã³ã®ãœãŒã¹ã³ãŒããååŸããå¿
èŠããããŸãã ãããè¡ãã«ã¯ããªã³ã¯
gitorious.org/qml-box2d/qml-box2d/trees/masterãã¯ãªãã¯ããå³ã®ãã¿ã³ããã¹ã¿ãŒãtar.gzãšããŠããŠã³ããŒãããã¯ãªãã¯ããŸãã ã¢ãŒã«ã€ããèã«çœ®ããQt Creatorã«ç§»åããŸãã
ããã§ããQt Qucik Applicationããªã©ã®æ°ãããããžã§ã¯ããäœæããŸãã ãŠã£ã¶ãŒãã§ãååããã¡ã€ã«ã·ã¹ãã å
ã®å Žæãå
¥åããQtãããã¡ã€ã«ãéžæããŠãå®äºããŸãã
ãããŠä»ãæãéèŠãªéšåã®1ã€ãå§ãŸããŸãã ãããŠéåžžãä»ã®èšèªãæè¡ã§æãé£ãããã®ã®1ã€ã§ãã å®éã«ãæ°ããäœæããã¢ããªã±ãŒã·ã§ã³ã«ãã©ã°ã€ã³ãæ¥ç¶ããå¿
èŠããããŸãã ãããè¡ãã«ã¯ãäœæãããã¢ãŒã«ã€ããã¢ããªã±ãŒã·ã§ã³ã®ã«ãŒããã£ã¬ã¯ããªã«è§£åããäœæããããã£ã¬ã¯ããªã®ååãqml-box2d-qml-box2dããqml-box2dã«å€æŽããŸãã Bã¢ããªã±ãŒã·ã§ã³ã®.proãã¡ã€ã«ã«æ°ããè¡ã1è¡è¿œå ããŸãã
include(qml-box2d/box2d-static.pri)
ãããŠãmain.cppã次ã®åœ¢åŒã«ããŸãã
#include <QtGui/QApplication> #include "qmlapplicationviewer.h" #include "box2dplugin.h" Q_DECL_EXPORT int main(int argc, char *argv[]) { QScopedPointer<QApplication> app(createApplication(argc, argv)); Box2DPlugin plugin; plugin.registerTypes("Box2D"); QScopedPointer<QmlApplicationViewer> viewer(QmlApplicationViewer::create()); viewer->setOrientation(QmlApplicationViewer::ScreenOrientationLockLandscape); viewer->setMainQmlFile(QLatin1String("qml/Quickanoid/main.qml")); viewer->showExpanded(); return app->exec(); }
ããã§ã¯ãïŒinclude "box2dplugin.h"ãšããè¡ã«ãã©ã°ã€ã³ããããŒãå«ãŸããŠããã
Box2DPlugin plugin; plugin.registerTypes("Box2D");
QMLã§å°æ¥å©çšå¯èœã«ãªãå¿
èŠãšãªãQt / Box2Dã®ã¿ã€ããã¢ããªã±ãŒã·ã§ã³ã«ç»é²ããŸãã
以äžã§ãã ããã¯ããã©ã°ã€ã³ãéçã«ãªã³ã¯ãããã©ã€ãã©ãªãšããŠæ¥ç¶ããã®ã«ååã§ãã ãã¡ããããã©ã°ã€ã³ã¯ç¬ç«ãããŠããããšããŠçµã¿ç«ãŠãããã·ã¹ãã å
ã®ãã¹ãŠã®QMLãã©ã°ã€ã³ã®å
±éãã£ã¬ã¯ããªã«é
眮ã§ããŸãã ããããæåã®ãªãã·ã§ã³ã¯ç§ãã¡ã®ç®çã«ãé©ããŠããŸãã çµæã®ãããžã§ã¯ãã®å€èŠ³ã¯ãããã次ã®ãšããã§ãã
ããã§ã¢ããªã±ãŒã·ã§ã³ãã³ã³ãã€ã«ããããšãããšãæšæºã®Hello Worldã衚瀺ãããŸããããã¯ãQt Quickã®ããã©ã«ããããžã§ã¯ãã®ãã³ãã¬ãŒãã§ãã ããããããã¯é¢çœããããŸããã ç©çåŠã®äœ¿çšã«èå³ããããŸãã
ã²ãŒã ã®èª¬æã圢åŒåãã
ããã§ãã¢ã«ã«ãã€ããã©ããããã決ããŸããã ãã®ãã©ã³ã®ããã¡ãã«å¿
èŠãªãã®ããªã¹ãããŸãã
- ããã©ã«ãã®ãŠã£ã³ããŠã¯360x640ã§ã-å°æ¥ã®ã¢ãã€ã«ããã€ã¹ãžã®ç§»æ€ã容æã«ããããã ãããŠãã¡ããã暪é·ã¢ãŒãã§ä¿®æ£ããŸãã
- ã¢ããªã±ãŒã·ã§ã³ã®èæ¯ã¯åçŽãªå³ã§ãããããã«å¯ŸããŠåçãããšäŸ¿å©ã§ãã
- çªã®ç«¯ã§ç§ãã¡ã®äžçã«æ¥ãã4ã€ã®å£ã
- äžçãé£ãã§ããããŒã«ã
- ããŒã«ãæã€ããã®ããŠã£ã³ããŠã®äžéšã«ãããã©ãããã©ãŒã ã
- çªã®äžéšã«ããããã€ãã®ã¬ã³ã¬ã¯ãããŒã«ã§å©ãèœãšããªããã°ãªããŸããã
- ç»é¢äžã®æéã«ãŠã³ã¿ãŒã
- ã²ãŒã ã®ç»é¢ãéå§ããã³çµäºããŸãã
å®äºããã¿ã¹ã¯ãå®çŸããŸã
ãã®ã·ã³ãã«ãªTKã«ã€ããŠã¯ãåŒãç¶ãäœæ¥ãé²ããŸãã äžèšã®ããã«ãmain.cppã§ãã¢ããªã±ãŒã·ã§ã³ã«æšªã¢ãŒãã§èµ·åããããã«æ¢ã«æ瀺ããŸããã ããã¯ãC ++ãç·šéããå¿
èŠãããããšãæå³ããŸããã³ãŒãã¯ãããŸããã main.qmlãã¡ã€ã«ãéããŠã次ã®åœ¢åŒã«ããŸãã
import QtQuick 1.0 import Box2D 1.0 Image { id: screen; source: "images/bg.jpeg" width: 640 height: 360 World { id: world width: screen.width height: screen.height gravity.x: 0 gravity.y: 0 } }
ç§ãã¡ã¯äœãããŸãããïŒ 640x360ã®ãµã€ãºã®ãŠã£ã³ããŠãäœæããèæ¯ãèšå®ããŠãå°æ¥çã«ãã¹ãŠã®ç©çãªããžã§ã¯ãã®ç¥å
ãšãªãWorldã¿ã€ãã®åã1ã€è¿œå ããŸããã ãæ³åã®ãšãããWorldãªããžã§ã¯ãã¯ã²ãŒã ã¯ãŒã«ãå
šäœãèšè¿°ãããã®åºæ¬ãã©ã¡ãŒã¿ãŒãèšå®ããŸãã
- éå-Xããã³YéåïŒãã®ã¢ããªã±ãŒã·ã§ã³ã§ã¯ãéåã¯å¿
èŠãããŸããã
- ãããŠãæ®å¿µãªãããç§ã¯åé¡ãæ±ããŠããŸãïŒtimeStepãvelocityIterationsãpositionIterationsãframeTime
ãããã®èª¬æã¯ãããããŒãã¡ã€ã«box2dworld.hã«ãããŸãã
3è¡ã®ç©ºã®ç©çäžçã¯ã¯ãŒã«ã§ãã ããããéçã§åžéããŸãããã ãŸãã¯å£ãããªãã奜ããªãã®ã æ°ããQMLãã¡ã€ã«ãäœæããWall.qmlãšããååãä»ããŸãã ã¢ããªã±ãŒã·ã§ã³ã®æšªã«è¿œå ããŠã次ã®å
容ãå
¥åããŸãã
import QtQuick 1.0 import Box2D 1.0 Body { property alias image: image.source bodyType: Body.Static fixtures: Box { anchors.fill: parent friction: 1.0 } Rectangle { anchors.fill: parent color: "brown" } Image { id: image anchors.fill: parent source: "images/wall.jpg" fillMode: Image.Tile } }
çè«ç Žã
å£ã¯ãã·ãŒã³äžã®ãã¹ãŠã®ãªããžã§ã¯ãïŒããã³ãWoldãªããžã§ã¯ãã¯æ¬è³ªçã«ã·ãŒã³ã§ãïŒãšåæ§ã«ãBodyã¿ã€ãã®ãªããžã§ã¯ãã§ãã ãããã£ãŠãBodyã¯ãã¹ãŠã®ç©çèŠçŽ ã®åºæ¬ã¯ã©ã¹ã§ãã 次ã®ããããã£ããããŸãã
- active-èŠçŽ ã®ç©çãæå¹/ç¡å¹ã«ããŸã
- linearVelocity-ç·åœ¢å é
- ãã£ã¯ã¹ãã£-è¡çªã決å®ãããããã£å¢ç
- bodyType-éçãåçããŸãã¯éååŠçãªããã£ã¿ã€ã
- fixedRotation-å転ãç¡å¹ã«ããŸã
- sleepingAllowed-ç©çãèªåçã«ãªãã«ããŠãªãœãŒã¹ãç¯çŽã§ããããã«ããŸã
- linearDampingãangularDampingãbullet-äžç®ã§ã¯ããããŸãã
ãã®ãããããã£ã¯ä»ã®ãªããžã§ã¯ããšã®è¡çªãåŠçã§ããŸããã äœã«ãããæããã«ã¯ãfixturesããããã£ãèšå®ããå¿
èŠããããŸãã ãã®ããããã£ã®å€ã¯ãCircleãBoxãããã³Polygonã§ãã ãããã¯ãã¹ãŠãä»ã®ãªããžã§ã¯ããšã®å¯Ÿè©±ãæ
åœããFixtureåºæ¬ã¯ã©ã¹ã®åå«ã§ãã ãã¡ãããQMLããã¯ã¢ã¯ã»ã¹ã§ããŸãããã3ã€ã®åå«ããã®ã¿ã¢ã¯ã»ã¹ã§ããŸãã æ確ã«ããããã«ãå©çšå¯èœãªããããã£ããªã¹ãããŸãã
ãã£ã¯ã¹ãã£ã¯ã©ã¹ïŒ
- å¯åºŠ-æ¯é
- æ©æŠ-æ©æŠå
- åçº-匟åæ§/åå
- groupIndex-ã°ã«ãŒãå
ã®ã€ã³ããã¯ã¹ïŒããããã°ã«ãŒãã¯1ã€ã®Bodyãªããžã§ã¯ãã§ãïŒ
- collidesWith-ãªããžã§ã¯ãã®ãªã¹ãã çŸåšã®ãªããžã§ã¯ããçŸåšæ¥è§ŠããŠãããã®
- ã»ã³ãµãŒãã«ããŽãªãŒ-è¿œå ãã©ã¡ãŒã¿ãŒ
ååå«ã¯ãç¬èªã®ããããã£ã䜿çšããŠãã®ã¯ã©ã¹ãå°ãæ¡åŒµããŸãã
- Boxã¯ã©ã¹ã¯æ°ããããããã£ãè¿œå ããŸããããæšæºã®å¹
ãšé«ãã䜿çšããŠåè§åœ¢ã®å¢çç·ãæå®ããŸãã
- Circleã¯ã©ã¹ã«ã¯radiusããããã£ãå°å
¥ãããŠããŸãããããã¯å¥åŠãªããšã«ããã€ãŒã«ãªã©ã®å圢ãªããžã§ã¯ãã®ååŸã§ãã
- Polygonã¯ã©ã¹ã¯ãããæ£ç¢ºãªç©çã·ãã¥ã¬ãŒã·ã§ã³ã®ããã«ããªããžã§ã¯ãã®é ç¹ã®ãªã¹ããå«ãããŒãã£ã¯ã«ããããã£ãè¿œå ããŸãã
ç·Žç¿ã«æ»ã
çè«ãããå£ã¯é·æ¹åœ¢ïŒããã¯ã¹ïŒãªã©ã®ç©ççãªããã£ïŒããã£ïŒã§ãããå¡ãã€ã¶ãã®ããç»åã§ã°ã©ãã£ã«ã«ã«è¡šãããããšãæããã«ãªããŸãã ãããŠä»ã1ã€ã®å£ãããã®ã§ãå¿
èŠãªæ°ã®å£ãäœæã§ããŸãããããã¯å¿
èŠã§ãã
Wall { id: wallLeft width: 10 anchors { bottom: parent.bottom left: parent.left top: parent.top } } Wall { id: wallRight width: 10 anchors { bottom: parent.bottom right: parent.right top: parent.top } } Wall { id: wallTop height: 10 anchors { left: parent.left right: parent.right top: parent.top } } Wall { id: wallBottom height: 10 anchors { left: parent.left right: parent.right bottom: parent.bottom } }
ãã¹ãŠãä¿åããŠã¢ããªã±ãŒã·ã§ã³ãå®è¡ãããšãç»é¢äžã«èæ¯ç»åãš4ã€ã®å£ã衚瀺ããããšããžã®åšãã®äžçããã¬ãŒãã³ã°ãããŸãã
ããã«ãèšç»ã«ããã°ãç§ãã¡ã¯äžçã®äžã§é£ãã§å£ã«ã¶ã€ããããŒã«ãæã£ãŠããŸãã ããŒã«ã説æããã«ã¯ãBall.qmlãã¡ã€ã«ãäœæãã次ã®æ§è³ªã®ã³ã³ãã³ããå
¥åããŸãã
import QtQuick 1.0 import Box2D 1.0 Body { id: ball fixedRotation: false sleepingAllowed: false fixtures: Circle { id: circle radius: 12 anchors.fill: parent density: 0; friction: 10; restitution: 1.05; } Image { id: circleRect anchors.centerIn: parent width: circle.radius * 2 height: width smooth: true source: "images/ball.png" } }
å£ãšåãã§ãããBoxã®ä»£ããã«CircleããããŸãã Worldãªããžã§ã¯ãã®æåŸã®å£ãèšè¿°ããåŸãäœæããã¯ãŒã«ãã«ããŒã«ãè¿œå ããããŒã«ã®èª¬æãè¿œå ããŸãã
Ball { id: ball x: parent.width/2 y: parent.height/2 }
ãŸããç»é¢ã®äžå€®ã«ããŒã«ããããŸãããéåããªããçŽç·å é床ããªããããã©ãã«ã移åããŸããã ãªããŠè³¢ã...
次ã®ã¹ãããã¯ãããŒã«ãæã€å¯äžã®ãã¬ãŒã€ãŒã³ã³ãããŒã«ãè¡šããã©ãããã©ãŒã ã§ãã åã®ã¹ããŒã ã«ãããšããã®äžã®æ°ããPlatform.qmlãã¡ã€ã«ïŒ
import QtQuick 1.0 import Box2D 1.0 Body { id: platform width: platformBg.width height: platformBg.height x: parent.width/2 - width/2 y: parent.height - platformBg.height - 5 bodyType: Body.Static fixtures: Box { id: platformBox anchors.fill: parent friction: 10 density: 300; } Image { id: platformBg smooth: true source: "images/platform.png" } MouseArea { anchors.fill: parent drag.target: platform drag.axis: Drag.XAxis drag.minimumX: 0 drag.maximumX: screen.width - platform.width } }
ãã®ç©çãªããžã§ã¯ãã¯ããŠãŒã¶ãŒãããŠã¹/æã«ãŒãœã«ãæ°Žå¹³æ¹åã«äœ¿çšããŠç»é¢äžã§é§åã§ããããã«ãããšããç¹ã§ä»ãšç°ãªããŸãã main.qmlã§ãããŒã«ã®èª¬æã®åŸã«ããã©ãããã©ãŒã ã®èª¬æãè¿œå ããŸãã
Platform { id: platform }
çŸæç¹ã§ã¯ãç§ãã¡ã®å£ãæãåºããŠãã ããã å©çã®ããã«ãããããæ©èœããããšã¯ç¢ºãã§ãããç»é¢ã®ãµã€ãºã«ãã£ãŠå¶éããããããç»é¢ã®å€åŽã«å£ãé ãããšãã§ããŸãã ã«ã«ã¹ã®ç®ãšå¹²æžããªãããã«ã ãããè¡ãã«ã¯ãWorldå
ã®åWallãªããžã§ã¯ãã§ãå·ŠleftMarginïŒ-widthãrightrightMarginïŒ-widthãtopMarginïŒ-heightãbottomMarginïŒ-heightã®ããããã®ããããã£ãè¿œå ããŸãã ãã®åŸãå床å®è¡ããŠãåŸããããã®ã確èªããŸãã
èšç»ã®æ¬¡ã®é
ç®ã ããŒã«ã§ããã¯ããŠã³ããã¬ã³ã¬ã ãããïŒ ç»é¢ã«ååãªã¹ããŒã¹ããªãããšãå¿ããŠã¯ãªããŸããã ãããã£ãŠãã²ãŒã ã®ãã®éšåãç°ãªãæ¹æ³ã§å®è£
ããããšããŸãã ã€ãŸããç»é¢ã®äžéšã«ã¯ããã€ãã®ç·ã®ã¬ã³ã¬ããããããããåžžã«ããŒã«ã§å¥ããå¿
èŠããããŸãããèµ€ã«ã¯ãªããŸããã ã¬ã³ã¬ãå®å
šã«èµ€ããªãå Žå-ãããæã€ããšã¯ãã§ã«åœ¹ã«ç«ããªãã ãããŠãã²ãŒã ã§ã¯ããã¹ãŠã®ã¬ã³ã¬ãèµ€ããªããŸã§ã®æéãã«ãŠã³ãããã¿ã€ããŒãå°å
¥ããŸãã ç·ããèµ€ãžã®é·ç§»ã®ã¢ãã¡ãŒã·ã§ã³ã¯ãããšãã°20ç§ã«ãªããŸãã ã¬ã³ã¬ãå®å
šã«èµ€ããªããšæ¶ããŸãã ãªããšãããªãã¯ã«ä¹ãããšã20ç§ã¿ã€ããŒããªã»ãããããããªãã¯ãåã³èµ€ããªãå§ããŸãã Brick.qmlãã¡ã€ã«ã®ããªãã¯ã®èª¬æããå§ããŸãããã
import QtQuick 1.0 import Box2D 1.0 Body { id: brick width: parent.width/5 - 5 height: 15 anchors { top: parent.top topMargin: -height/2 } signal disappear() property bool contacted : false bodyType: Body.Static fixtures: Box { anchors.fill: parent friction: 1.0 onBeginContact: { contacted = true } onEndContact: { contacted = false } } Timer { id: timer interval: 20000; running: true; repeat: false onTriggered: { brick.visible = false; brick.active = false; disappear(); } } Rectangle { id: brickRect anchors.fill: parent radius: 6 state: "green" states: [ State { name: "green" when: brick.contacted PropertyChanges { target: brickRect color: "#7FFF00" } PropertyChanges { target: timer running: false } }, State { name: "red" when: !brick.contacted PropertyChanges { target: brickRect color: "red" } PropertyChanges { target: timer running: true } } ] transitions: [ Transition { from: "green" to: "red" ColorAnimation { from: "#7FFF00"; to: "red"; duration: 20000; } } ] } function show() { brick.visible = true; brick.active = true; state = "green" } function hide() { brick.visible = false; brick.active = false; } }
ã芧ã®ãšãããããã§ãè€éãªããšã¯ãããŸããïŒããã£ã®èª¬æããã®è¡šç€ºã®èª¬æããããã®éã®é·ç§»ã®ã¹ã ãŒãºãªã¢ãã¡ãŒã·ã§ã³ã䌎ã2ã€ã®ç¶æ
ãããŒã«ãšã®åè¡çªåŸã®åèµ·åã§20ç§ãã«ãŠã³ãããã¿ã€ããŒãããã³è£å©æ©èœshowïŒïŒ main.qmlãã¡ã€ã«ã§ããã©ãããã©ãŒã 宣èšã®åŸã«ãããªãã¯ã®å®£èšãè¿œå ããŸãã
Brick { id: brick1 x: 3; onDisappear: bricksCount-- } Brick { id: brick2 anchors { left:brick1.right leftMargin: 5 } onDisappear: bricksCount-- } Brick { id: brick3 anchors { left:brick2.right leftMargin: 5 } onDisappear: bricksCount-- } Brick { id: brick4 anchors { left:brick3.right leftMargin: 5 } onDisappear: bricksCount-- } Brick { id: brick5 anchors { left:brick4.right leftMargin: 5 } onDisappear: bricksCount-- }
ã¡ãªã¿ã«ãè¡èŠçŽ ãšç¹°ãè¿ãèŠçŽ ã䜿çšããªãã£ãçç±ãèããªãã§ãã ããããããã䜿çšããŠãBodyã¿ã€ãã®èŠçŽ ãèªåçã«äœæãããšãã¢ããªã±ãŒã·ã§ã³ãã¯ã©ãã·ã¥ããŸãã ãã¡ã€ã«ã®æåã«ãé«ããšå¹
ã決å®ããåŸãæ°ããå€æ°ã®å®£èšãè¿œå ããŸãã
property int bricksCount: 5
ããã«å¿ããŠãããšãã°2ã«çããå Žåãæ®ãã®ã¬ã³ã¬ã®æ°ãèæ
®ããŸã-ã²ãŒã ãçµäºããŸãã ã€ãŸãããŠãŒã¶ãŒãšã²ãŒã ãšã®ããåãã®ããžãã¯ã¯åçŽã§ã-å°ãªããšã3ã€ã®ããªãã¯ãã§ããã ãç»é¢ã«æ®ã£ãŠããå¿
èŠããããŸãã Worldãªããžã§ã¯ãã®äžçªäžã«ããç§ã«ãŠã³ã¿ãŒã«ã€ããŠèª¬æããŸãããã
Text { id: secondsPerGame anchors { bottom: parent.bottom left: parent.left } color: "white" font.pixelSize: 36 text: "0" Timer { interval: 1000; running: true; repeat: true onTriggered: secondsPerGame.text = parseInt(secondsPerGame.text) + 1 } }
ç§ãã¡ã«ã¯äœãæ®ã£ãŠããŸããïŒ éå§ç»é¢ãšçµäºç»é¢ãè¿œå ããã²ãŒã ã®ããžãã¯ããããã«ä¿®æ£ããŸãã å®éããããã¯èšäºã§ã¯çç¥ã§ããäºçŽ°ãªããšã§ãã æåŸã«ãmain.qmlãã¡ã€ã«ã®å®å
šãªæçµãªã¹ãã®ã¿ãæäŸããŸãã
import QtQuick 1.0 import Box2D 1.0 Image { id: screen; source: "images/bg.jpeg" width: 640 height: 360 property int bricksCount: 5 World { id: world width: screen.width height: screen.height visible: false gravity.x: 0 gravity.y: 0 Wall { id: wallLeft width: 10 anchors { bottom: parent.bottom left: parent.left leftMargin: -width top: parent.top } } Wall { id: wallRight width: 10 anchors { bottom: parent.bottom right: parent.right rightMargin: -width top: parent.top } } Wall { id: wallTop height: 10 anchors { left: parent.left right: parent.right topMargin: -height top: parent.top } } Wall { id: wallBottom height: 10 anchors { left: parent.left right: parent.right bottom: parent.bottom bottomMargin: -height } onBeginContact: { console.log(other) finishGame() } } Ball { id: ball x: parent.width/2 y: parent.height/2 } Platform { id: platform } Brick { id: brick1 x: 3; onDisappear: bricksCount-- } Brick { id: brick2 anchors { left:brick1.right leftMargin: 5 } onDisappear: bricksCount-- } Brick { id: brick3 anchors { left:brick2.right leftMargin: 5 } onDisappear: bricksCount-- } Brick { id: brick4 anchors { left:brick3.right leftMargin: 5 } onDisappear: bricksCount-- } Brick { id: brick5 anchors { left:brick4.right leftMargin: 5 } onDisappear: bricksCount-- } Text { id: secondsPerGame anchors { bottom: parent.bottom left: parent.left } color: "white" font.pixelSize: 36 text: "0" Timer { id: scoreTimer interval: 1000; running: true; repeat: true onTriggered: secondsPerGame.text = parseInt(secondsPerGame.text) + 1 } } } Item { id:screenStart anchors.fill: parent visible: false Text { id: startGame anchors.centerIn: parent color: "white" font.pixelSize: 36 text: "Start Game!" MouseArea { anchors.fill: parent onClicked: { screen.startGame() } } } } Item { id:screenFinish anchors.fill: parent visible: false Text { id: score anchors.centerIn: parent color: "white" font.pixelSize: 36 text: "Game over! Your score is: " + secondsPerGame.text } Text { id: restartGame anchors { top: score.bottom horizontalCenter: parent.horizontalCenter } color: "white" font.pixelSize: 36 text: "Restart Game!" MouseArea { anchors.fill: parent onClicked: { screen.startGame() } } } } function startGame() { screen.state = "InGame"; bricksCount = 5 brick1.show() brick2.show() brick3.show() brick4.show() brick5.show() secondsPerGame.text = "0" platform.x = screen.width/2 - platform.width/2 ball.linearVelocity.x = 0 ball.linearVelocity.y = 0 ball.active = true; ball.x = platform.x + platform.width/2 ball.y = platform.y - ball.height ball.x = screen.width/2 ball.y = screen.height/2 ball.applyLinearImpulse(Qt.point(50, 300), Qt.point(ball.x, ball.y)) scoreTimer.running = true } function finishGame(){ screen.state = "FinishScreen"; brick1.hide() brick2.hide() brick3.hide() brick4.hide() brick5.hide() ball.active = false; ball.applyLinearImpulse(Qt.point(0,0), Qt.point(ball.x, ball.y)) scoreTimer.running = false } onBricksCountChanged: { console.log(bricksCount) if (bricksCount <=2){ finishGame() } } Component.onCompleted: { startGame() } states: [ State { name: "StartScreen" PropertyChanges { target: screenStart visible: true } }, State { name: "InGame" PropertyChanges { target: world visible: true } }, State { name: "FinishScreen" PropertyChanges { target: screenFinish visible: true } } ] state: "StartScreen" }
åèšã§
ããããã¢ã¢ããªã±ãŒã·ã§ã³ã§ãã 次ã«ãæåŸã«äœãèµ·ãã£ãã®ããèŠãŠãããæåŸã®æ°è¡ãèªãã§ããã©ã°ã€ã³ã®éçºè
ã«ãã£ãŠè¡ãããäœæ¥ã®å°è±¡ãæžããŠã¿ãããšãææ¡ããŸãã ç§ãã¡ã¯èŠãŸãïŒ
ç§ã®æèŠã§ã¯ãããŸããããŸããã å®éã®ãšãããã¢ããªã±ãŒã·ã§ã³èªäœãéçºããŠãã®èšäºãæžãã®ã«ãã£ã2æ©ïŒæšæ¥ãšä»æ¥ïŒããããããŸããã§ããã 第äžã«ãQMLã䜿çšããŠéçºãéå§ããããã®ã·ã³ãã«ããšéåžžã«äœããããå€ã«ã€ããŠããããŠç¬¬äºã«ãQtãã¬ãŒã ã¯ãŒã¯èªäœãšãµãŒãããŒãã£éçºè
ã®äž¡æ¹ã®éçºè
ãäœåºŠãäœåºŠãåæ§ã®ãã©ã°ã€ã³ãäœæããã³ãŒãã®å質ã«ã€ããŠèªã£ãŠããŸãã
ãã©ã¹ã ãã¡ãããBox2Dèªäœã¯ã©ã®OSã«ãçµã³ä»ããããŠãããããã©ãããã©ãŒã ã«äŸåããªããããäœæããã¢ããªã±ãŒã·ã§ã³ã¯ãã¹ã¯ããããã©ãããã©ãŒã ãšã¢ãã€ã«ãã©ãããã©ãŒã ã®äž¡æ¹ã§åæ§ã«æ©èœããããšã«æ³šæããŠãã ããã ãã®äŸã§ããWindowsã®ã¹ã¯ãªãŒã³ã·ã§ãããšLinuxã®ãããªãèŠãããšãã§ããŸãã
ãã¡ããã ãã®èšäºã§ã¯ãQMLã«ç§»æ€ããããã¹ãŠã®Box2Dæ©èœãèæ
®ãããããã§ã¯ãªããå°ãªããšããžã§ã€ã³ãã¯æ®ããŸããã äžæ¹ã§ããã®è³æã¯ç©äºã®æ¬è³ªãç解ããã®ã«ååã ãšæããŸãã ãããŠããã§ã«QML / Box2Dã®æã®ã¢ã€ãã¢ãæã£ãŠããã®ã§ãç©çåŠã䜿çšããŠããã¡ããç°¡åã«ãªãããã§ããŸãã æºåž¯é»è©±ã®å é床èšãšèœäžãã¥ãŒãã䜿çšããè¿·è·¯ãäºãã«ã¶ã€ããåã£ãŠé£ã³å»ã楜ãããX-Motoãªã©ã®è»ããã€ã¯ãªã©ããããŸãã ãã®å Žåãå¿ããªãã§ãã ããã QMLã¯C ++ã¯ã©ã¹ã®åãªãã©ãããŒã§ãããã¢ããªã±ãŒã·ã§ã³èªäœã¯å
ã
C ++ã§æžãããŠãããã®ããã«åäœããŸãã
éåžžã©ããããœãŒã¹ã³ãŒãã¯ãããžã§ã¯ãããŒãžã§
åéã§ããŸãïŒ
code.google.com/p/quickanoid/downloads/listãæéãããã ãããããšãããããŸãã