Doodle Jump Game
import QtQuick 2.0
import Felgo 4.0
EntityBase {
id:frogEntity
entityType: "Frog"
state: frogCollider.linearVelocity.y < 0 ? "jumping" : "falling"
property int impulse: y-frogCollider.linearVelocity.y
property alias controller: twoAxisController
TwoAxisController {
id: twoAxisController
}
GameSpriteSequence {
id: frogAnimation
defaultSource: Qt.resolvedUrl("../assets/spritesheet.png")
scale: 0.35
anchors.centerIn: frogCollider
rotation: frogEntity.state == "jumping" ?
(system.desktopPlatform ?
twoAxisController.xAxis * 15
: (accelerometer.reading !== null ? -accelerometer.reading.x * 10 : 0))
: 0
GameSprite {
name: "sitting"
frameWidth: 128
frameHeight: 128
startFrameColumn: 2
}
GameSprite {
name: "jumping"
frameCount: 4
frameRate: 8
frameWidth: 128
frameHeight: 256
frameX: 0
frameY: 128
}
}
BoxCollider {
id: frogCollider
width: 25
height: 5
bodyType: gameScene.state == "playing" ? Body.Dynamic : Body.Static
linearVelocity.x: system.desktopPlatform ?
twoAxisController.xAxis * 200 :
(accelerometer.reading !== null ? -accelerometer.reading.x * 100 : 0)
fixture.onContactChanged: other => {
var otherEntity = other.getBody().target
var otherEntityType = otherEntity.entityType
if(otherEntityType === "Border") {
frogEntity.die()
}
else if(otherEntityType === "Platform" && frogEntity.state == "falling") {
frogCollider.linearVelocity.y = -400
otherEntity.playWobbleAnimation()
}
}
}
onStateChanged: {
if(frogEntity.state == "jumping") {
frogAnimation.jumpTo("jumping")
}
if(frogEntity.state == "falling") {
frogAnimation.jumpTo("sitting")
}
}
onYChanged: {
if(y < 200) {
y = 200
score += 1
}
}
function die() {
frogEntity.x = gameScene.width / 2
frogEntity.y = 220
frogCollider.linearVelocity.y = 0
frogAnimation.jumpTo("sitting")
gameNetwork.reportScore(score)
score = 0
gameScene.state = "gameOver"